This is an updated version of the logs.tf parser which aims to recreate the parser currently used by logs.tf as closely as possible while still fixing/improving upon various issues.
This parser is currently being used for demoticks.tf
Install it from npm:
$ npm install logstf-parser
const parser = require("logstf-parser");
const LogsParser = new parser.LogParser();
const lines = fs.readFileSync(filePath, "UTF-8").split("\n");
const game = LogsParser.parseLines(lines)
console.log(game.toJson())
console.log(game.toLogstf())
// Returns a format like the one logs.tf json provides this however requires one to have some
// of the default modules loaded
By default only the GameStateModule will be loaded other modules can be included like so:
const LogsParser = new parser.LogParser();
//Note that we're passing the class and not an instance!
LogsParser.addModule(parser.defaultModules.KillstreakModule);
//To load all modules one can iterate through the object e.g.:
for (const module of Object.values(parser.defaultModules)){
LogsParser.addModule(module);
}
//If you want to define your own GameStateModule you should disable the provided one like this:
LogsParser.useCustomGameState();
Similar to this you can create and load custom modules.
One can also define custom modules to extract other events from the logfiles. Each module must be a class which should contain an identifier as well as a finish() and toJson() method. Example:
import {events} from "logstf-parser";
import {IGameState} from "logstf-parser";
class MyModule implements events.IStats {
public identifier: string
private killEvents: events.IKillEvent[]
private gameStartTime: number | null
constructor(gameState: IGameState) {
this.identifier = 'myModule'
this.killEvents = []
this.gameStartTime = null
}
onRoundStart(event: events.IRoundStartEvent) {
if (!this.gameStartTime) this.gameStartTime = event.timestamp
}
onKill(event: events.IKillEvent) {
if (!this.gameStartTime) return;
killEvents.push(event)
}
finish(){
//Get's called after every line has been processed
}
toJSON(): events.IKillEvent[] {
return this.killEvents
}
}
- onDamage: IDamageEvent
- onHeal: IHealEvent
- onShot: IShotEvent
- onShotHit: IShotHitEvent
- onKill: IKillEvent
- onAssist: IAssistEvent
- onPickup: IPickupEvent
- onSuicide: ISuicideEvent
- onSpawn: ISpawnEvent
- onRole: IRoleEvent
- onCapture: ICaptureEvent
- onMedicDeath: IMedicDeathEvent
- onMiniRoundStart: IRoundStartEvent
- onMiniRoundSelected: IMiniRoundSelected
- onMiniRoundWin: IMiniRoundWin
- onMiniRoundLength: IRoundLengthEvent
- onRoundStart: IRoundStartEvent
- onRoundSetupBegin: IRoundSetupBegin
- onRoundSetupEnd: IRoundSetupEnd
- onRoundEnd: IRoundEndEvent
- onGameOver: IGameOverEvent
- onJoinTeam: IJoinTeamEvent
- onDisconnect: IDisconnectEvent
- onCharge: IChargeEvent
- onChat: IChatEvent
- onBuild: IBuildEvent
- onObjectDestroyed: IObjectDestroyedEvent
- onFlag: IFlagEvent
- onScore: IRoundScoreEvent
- onPause: IPauseEvent
- onUnpause: IUnpauseEvent
- onMapLoad: IMapLoadEvent
- onFirstHeal: IFirstHealEvent
- onChargeReady: IChargeReadyEvent
- onChargeEnded: IChargeEndedEvent
- onMedicDeathEx: IMedicDeathExEvent
- onEmptyUber: IEmptyUberEvent
- onLostUberAdv: ILostUberAdvantageEvent
- onTriggered: ITriggeredEvent