This commit is contained in:
Robin Appelman 2020-01-31 21:58:00 +01:00
commit cf385c207d
4 changed files with 10 additions and 20 deletions

View file

@ -4,8 +4,8 @@ export async function parseDemo(bytes: Uint8Array): Promise<ParsedDemo> {
let m = await import("../pkg/index.js");
const state = m.parse_demo(bytes);
let playerCount = m.get_player_count(state);
let boundaries = m.get_boundaries(state);
let playerCount = state.player_count;
let boundaries = state.boundaries;
let data = m.get_data(state);
return new ParsedDemo(playerCount, {
@ -73,10 +73,10 @@ function unpack_angle(val: number): number {
}
export class ParsedDemo {
private playerCount: number;
private world: WorldBoundaries;
private data: Uint8Array;
private tickCount: number;
private readonly playerCount: number;
private readonly world: WorldBoundaries;
private readonly data: Uint8Array;
private readonly tickCount: number;
constructor(playerCount: number, world: WorldBoundaries, data: Uint8Array) {
this.playerCount = playerCount;

2
package-lock.json generated
View file

@ -1,5 +1,5 @@
{
"name": "tf-demos-viewer",
"name": "@demostf/parser",
"version": "0.1.0",
"lockfileVersion": 1,
"requires": true,

View file

@ -1,6 +1,6 @@
{
"author": "Robin Appelman <robin@icewind.nl>",
"name": "tf-demos-viewer",
"name": "@demostf/parser",
"version": "0.1.0",
"scripts": {
"build": "rimraf dist pkg && webpack",

View file

@ -45,9 +45,9 @@ impl From<World> for WorldBoundaries {
#[wasm_bindgen]
pub struct FlatState {
player_count: usize,
pub player_count: usize,
pub boundaries: WorldBoundaries,
data: Box<[u8]>,
boundaries: WorldBoundaries,
}
impl FlatState {
@ -70,16 +70,6 @@ pub fn parse_demo(buffer: Box<[u8]>) -> Result<FlatState, JsValue> {
Ok(FlatState::new(parsed, world))
}
#[wasm_bindgen]
pub fn get_boundaries(state: &FlatState) -> WorldBoundaries {
state.boundaries.clone()
}
#[wasm_bindgen]
pub fn get_player_count(state: &FlatState) -> usize {
state.player_count
}
#[wasm_bindgen]
pub fn get_data(state: FlatState) -> Box<[u8]> {
state.data