1
0
Fork 0
mirror of https://github.com/demostf/demo.js synced 2026-06-03 16:44:12 +02:00
This commit is contained in:
Robin Appelman 2017-03-07 18:28:19 +01:00
commit d4716edca1

View file

@ -23,10 +23,34 @@ fs.readFile("example.dem", function (err, data) {
var head = parser.readHeader();
console.log(head);
var body = parser.parseBody();
console.log(body);
console.log(body.getState());
});
```
### more information from packets
Using the javascript api it's possible to get far more information out of a demo
file than the basic state provided by the cli interface.
```js
var Demo = require('tf2-demo');
var fs = require('fs');
fs.readFile("example.dem", function (err, data) {
if (err) throw err;
var demo = Demo.fromNodeBuffer(data);
var parser = demo.getParser();
var head = parser.readHeader();
var match = parser.match;
parser.on('packet', function(packet) {
// where you can either get information directly from the packet (see ./src/Data/Packet.ts)
// or use the `match` object which has contains an (incomplete) state of the match at the current tick
});
parser.parseBody();
});
```
## A note on POV demos
During the development of this project the main focus has always been on parsing
@ -36,3 +60,13 @@ STV demos. Parsing POV demos is a lot more error prone and has known issues.
- Not all player names can be parsed correctly, resulting in multiple players
having `null` as a name in the output.
## Credits
Special thanks goes to
- Panzer for [DemoLib](https://github.com/PazerOP/DemoLib)
- The StatsHelix team for [DemoInfo](https://github.com/StatsHelix/demoinfo)
- The SkadiStats for [smoke](https://github.com/skadistats/smoke)
Without the information provided by these projects this would not have been possible