1.4.0 • Published 1 year ago

logstf-parser v1.4.0

Weekly downloads
-
License
AGPL
Repository
github
Last release
1 year ago

Logs.tf Parser

Build

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

Installation

Install it from npm:

$ npm install logstf-parser

Brief Example

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

Adding modules

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.

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
    }

}

List of events

1.4.0

1 year ago

1.3.0

3 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago