Skip to content

Commit

Permalink
fix: wrong game version log selected
Browse files Browse the repository at this point in the history
  • Loading branch information
sepi4 committed Mar 2, 2023
1 parent 63acf63 commit a63944d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/MainView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function MainView(props: { handleSetSettingsView: () => void }): JSX.Element {

if (players) {
players.forEach((p) => {
teams[p.teamSlot].push(p)
teams[p?.teamSlot]?.push(p)
})
}

Expand Down
17 changes: 15 additions & 2 deletions src/functions/readLog/readLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ export function getCurrentUserAliasCoh3(lines: string[]) {
}
}

export function getLines(lines: string[]) {
export function checkGameVersionIsCorrect(lines: string[], coh3: boolean) {
if (coh3) {
return lines[0].match(/RelicCoH3/)
}
return lines[0].match(/RELICCOH2/)
}

export function getLines(lines: string[], coh3: boolean) {
const arr: string[] = []
let stop = false
let wasGame = false
Expand Down Expand Up @@ -82,9 +89,15 @@ export async function readLog(
const data = await fs.readFile(fileLocation, 'utf-8')
const lines = data.split('\n')

if (!checkGameVersionIsCorrect(lines, coh3)) {
return new Promise<Player[]>((resolve) => {
resolve([])
})
}

const currentUserAlias: string | undefined = coh3 ? getCurrentUserAliasCoh3(lines) : getCurrentUserAlias(lines)

const arr: string[] = getLines(lines)
const arr: string[] = getLines(lines, coh3)
let psInfo = coh3 ? getPlayersInfoCoh3(arr) : getPlayersInfo(arr)

if (currentUserAlias) {
Expand Down
2 changes: 0 additions & 2 deletions src/functions/writeRankings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ function getLimitedWord(str: string, limit: number, padLeft: boolean) {
let newStr = ''
for (const x of str) {
const sw = stringWidth(x)
// console.log(x, sw)
if (sum + sw <= limit) {
sum += sw
newStr += x
Expand Down Expand Up @@ -86,7 +85,6 @@ export function writeRankings(
}

const faction = players[i].faction
console.log(faction)
const teamSlot = Number(players[i].teamSlot)

const nameFun = coh3 ? commonNameCoh3 : commonName
Expand Down

0 comments on commit a63944d

Please sign in to comment.