Skip to content

Commit

Permalink
feat: version 2.0 with new parser and async interface
Browse files Browse the repository at this point in the history
BREAKING CHANGE: introduce version 2.0

* feat: async replay parser interface

* refactor: use composition instead of inheritance, working async parser

* improvement: prepare 2.0, use prettier, remove rollupjs

* style: formatting

* improvement: proper tsconfig, fix linting errors

* cicd: remove nodejs 9 from build pipeline

* test: change testfile layout, use one parser for Reforged and Netease

* improvement: remove Platform parameter requirement

* improvement: better action typings, remove formatters from parsers

* style: remove CR as suggested by prettier

* improvement: code formatting

* improvement: use package.lockfile

* improvement: better parser typings

* improvement: typings for GameDataBlocks

* improvement: some more typescript refactoring

* improvement: remove the custom types for binary-parser

* improvement: only use async replay parsing interface, new parser classes

* refactor: remove obsolete files

* refactor: make typings comply with linter

* improvement: non-binary parser action parsing

* refactor: implement action parsing, connect with W3GReplay

* chore: remove unused dependencies, update remaining

* refactor: use composition if where mixin was used

* chore: set up github pages with typedoc

* docs: .nojekyll to enable proper typedoc serving

* chore: configuration for transpilation to commonjs

* improvement: remove redundant examples directory

* docs: README update

* docs: add examples folder

* docs: update README

* chore: deploy github pages after all test jobs passed

* improvement: player class toJSON, generate sample output from test
  • Loading branch information
PBug90 committed Aug 16, 2020
1 parent 1f5c486 commit 4eedbff
Show file tree
Hide file tree
Showing 69 changed files with 6,196 additions and 7,546 deletions.
48 changes: 0 additions & 48 deletions .eslintrc

This file was deleted.

16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
extends: [
"plugin:@typescript-eslint/recommended", // Uses the recommended rules from @typescript-eslint/eslint-plugin
"plugin:prettier/recommended",
],
rules: {},
plugins: ["@typescript-eslint", "prettier"],
settings: {
"import/resolver": {
node: {
extensions: [".js", ".ts"],
},
},
},
};
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ node_modules
.npmignore
replays_batch/
yarn.lock
package-lock.json
.nyc_output
coverage
yarn-error.log
dist
.vscode
.rpt2_cache
playground.js
playground.js
doc
20 changes: 19 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,22 @@ script:
- npm run coverage

after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT


jobs:
include:
- stage: build docs
node_js: "12"
script:
- npm i -g typescript typedoc
- typedoc --out doc src
- touch ./doc/.nojekyll
deploy:
provider: pages
local_dir: ./doc
skip_cleanup: true
github_token: $GITHUB_TOKEN
keep_history: true
on:
branch: async-replay-parser
71 changes: 35 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# w3gjs
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![Build Status](https://travis-ci.org/PBug90/w3gjs.svg?branch=master)](https://travis-ci.org/w3gjs/w3gjs)
[![Test Coverage](https://api.codeclimate.com/v1/badges/8499316ea1ee69d2dd0b/test_coverage)](https://codeclimate.com/github/PBug90/w3gjs/test_coverage)
[![Maintainability](https://api.codeclimate.com/v1/badges/8499316ea1ee69d2dd0b/maintainability)](https://codeclimate.com/github/PBug90/w3gjs/maintainability)

## Parser
From scratch JavaScript implementation of a w3g parser for WarCraft 3 replay files.
Uses the excellent https://github.com/keichi/binary-parser to parse the replay file.
From scratch asynchronous, fully typed and tested TypeScript implementation of a w3g parser for WarCraft 3 replay files.
Zero external dependencies.

This parser is aimed to be more modular than other parsers.
You can easily add your custom action parsing logic by overriding the processTimeSlot() function
of a W3GReplay instance or by listening for one of the five main events:
You can use the subcomponents to create your own parser that suits your requirements or just use the high-level parser output that is best suited for
standard game mode game analysis.



Expand All @@ -23,49 +22,49 @@ of a W3GReplay instance or by listening for one of the five main events:

## Usage

Check out the examples folder of this repository to find usage examples for both typescript and javascript.

For detailed API documentation check out https://pbug90.github.io/w3gjs
Please keep in mind that as of now, parallel parsing with the same W3GReplay instance is not yet supported. Instantiate multiple instances or parse replays sequentially.

### High Level API

```javascript
const W3GReplay = require('w3gjs')
const Parser = new W3GReplay()
const replay = Parser.parse('./replays/sample1.w3g')
console.log(replay)
```
High level API is best suited to parse standard melee replays.

#### Netease 1.32 Replays
Netease 1.32 replays do not contain reforged meta data, do have the same build number and version. Therefore, currently the user must
determine whether the given replay should be treated like a netease replay. Use an optional second argument to the .parse function to
treat the replay as a netease replay.
```javascript
const W3GReplay = require('w3gjs')
const Parser = new W3GReplay()
const replay = Parser.parse('./replays/sample1.w3g','netease')
console.log(replay)
const W3GReplay = require('w3gjs').default
const parser = new W3GReplay();

( async () => {
const result = await parser.parse("replay.w3g")
console.log(result)
})().catch(console.error);
```


### Low Level API
Low level API allows you to either implement your own logic on top of the ReplayParser class by extending it or
to register callbacks to listen for parser events as it encounters the different kinds of blocks in a replay.

```javascript
const W3GReplay = require('w3gjs')
const Parser = new W3GReplay()

Parser.on('gamemetadata', (metadata) => console.log(metadata))
Parser.on('gamedatablock', (block) => console.log('game data block.'))
Parser.on('timeslotblock', (block) => console.log('time slot block.', Parser.msElapsed))
Parser.on('commandblock', (block) => console.log('command block.'))
Parser.on('actionblock', (block) => console.log('action block.'))
In previous versions, multiple events were emitted. In version 2 there are exactly two events.

Parser.parse('./replays/999.w3g')
```
**basic_replay_information** provides you with metadata about the replay
that was parsed from the header information.

### Example output of the observers.w3g example replay
Check the example_output.json file in the root of this repository.
The **gamedatablock** event provides you with all blocks that make up the actual game data, fully parsed and in correct order. You can check their *id* property to distinguish the blocks from each other. For more information, consult the auto-generated docs for properties of specific blocks.

### Example demo app
You can see the parser in action here and parse your own replays aswell:
https://enigmatic-springs-58797.herokuapp.com/
```javascript
const ReplayParser = require('w3gjs/dist/lib/parsers/ReplayParser').default;
const fs = require('fs')
( async () => {
const buffer = fs.readFileSync("./reforged1.w3g")
const parser = new ReplayParser();
parser.on("basic_replay_information", (info) => console.log(info))
parser.on("gamedatablock", (block) => console.log(block))
const result = await parser.parse(buffer)
console.log(result)
})().catch(console.error)
```

## Contributing
There is no point in hiding the implementation of tools that the community can use. So please feel free to discuss in the issues section or provide a pull request if you think you can improve this parser.
Expand Down
39 changes: 0 additions & 39 deletions example.js

This file was deleted.

Loading

0 comments on commit 4eedbff

Please sign in to comment.