Last active
August 24, 2025 06:08
-
-
Save lucasmonstrox/7923db3dbe21536417b266bd4ff6ba44 to your computer and use it in GitHub Desktop.
Parsing @laihoe/demoparser2 rounds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const demoPath = "demo.dem"; | |
const roundStartEvents = parseEvent( | |
demoPath, | |
"round_start", | |
[], | |
["total_rounds_played", "is_warmup_period", "game_time"] | |
); | |
const rounds = []; | |
for (const round of roundStartEvents) { | |
if (round.is_warmup_period) { | |
continue; | |
} | |
const roundData = { | |
round: round.round, | |
startTick: round.tick, | |
}; | |
const existingRoundIndex = rounds.findIndex((r) => r.round === round.round); | |
if (existingRoundIndex !== -1) { | |
rounds[existingRoundIndex] = roundData; | |
} else { | |
rounds.push(roundData); | |
} | |
} | |
const roundEndEvents = parseEvent( | |
demoPath, | |
"round_end", | |
[], | |
["total_rounds_played", "is_warmup_period", "game_time"] | |
); | |
for (const roundEnd of roundEndEvents) { | |
if (roundEnd.is_warmup_period) { | |
continue; | |
} | |
const roundIndex = rounds.findIndex( | |
(r) => r.round === roundEnd.total_rounds_played | |
); | |
if (roundIndex !== -1) { | |
rounds[roundIndex].endTick = roundEnd.tick; | |
} | |
} | |
const roundOfficiallyEndedEvents = parseEvent( | |
demoPath, | |
"round_officially_ended", | |
[], | |
["total_rounds_played", "is_warmup_period", "game_time"] | |
); | |
for (const roundOfficiallyEnded of roundOfficiallyEndedEvents) { | |
if (roundOfficiallyEnded.is_warmup_period) { | |
continue; | |
} | |
const roundIndex = rounds.findIndex( | |
(r) => r.round === roundOfficiallyEnded.total_rounds_played | |
); | |
if (roundIndex !== -1) { | |
rounds[roundIndex].officiallyEndedTick = roundOfficiallyEnded.tick; | |
} | |
} | |
for (const round of rounds) { | |
if (!round.officiallyEndedTick && round.endTick) { | |
round.officiallyEndedTick = round.endTick; | |
} else if (!round.officiallyEndedTick) { | |
const roundEndEvent = roundEndEvents.find( | |
(event) => | |
event.total_rounds_played === round.round && !event.is_warmup_period | |
); | |
if (roundEndEvent) { | |
round.officiallyEndedTick = roundEndEvent.tick; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment