This commit is contained in:
Robin Appelman 2024-11-30 00:59:54 +01:00
commit c94606b569
13 changed files with 45 additions and 14316 deletions

View file

@ -36,8 +36,8 @@ version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "052a5a614540ae9bb7de25c2c86a94b6de7374cb7e3230f3128955bdaea62c3f" checksum = "052a5a614540ae9bb7de25c2c86a94b6de7374cb7e3230f3128955bdaea62c3f"
dependencies = [ dependencies = [
"proc-macro2 1.0.92", "proc-macro2",
"quote 1.0.37", "quote",
"syn 1.0.109", "syn 1.0.109",
"syn_util", "syn_util",
] ]
@ -60,16 +60,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "console_error_panic_hook"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
dependencies = [
"cfg-if 1.0.0",
"wasm-bindgen",
]
[[package]] [[package]]
name = "either" name = "either"
version = "1.13.0" version = "1.13.0"
@ -101,8 +91,8 @@ version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8" checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8"
dependencies = [ dependencies = [
"proc-macro2 1.0.92", "proc-macro2",
"quote 1.0.37", "quote",
"syn 2.0.90", "syn 2.0.90",
] ]
@ -119,8 +109,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c34a887c8df3ed90498c1c437ce21f211c8e27672921a8ffa293cb8d6d4caa9e" checksum = "c34a887c8df3ed90498c1c437ce21f211c8e27672921a8ffa293cb8d6d4caa9e"
dependencies = [ dependencies = [
"proc-macro-error", "proc-macro-error",
"proc-macro2 1.0.92", "proc-macro2",
"quote 1.0.37", "quote",
"rustversion", "rustversion",
"syn 1.0.109", "syn 1.0.109",
"synstructure", "synstructure",
@ -132,12 +122,6 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "futures"
version = "0.1.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678"
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.15.2" version = "0.15.2"
@ -314,8 +298,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799" checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2 1.0.92", "proc-macro2",
"quote 1.0.37", "quote",
"syn 1.0.109", "syn 1.0.109",
] ]
@ -343,8 +327,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68517892c8daf78da08c0db777fcc17e07f2f63ef70041718f8a7630ad84f341" checksum = "68517892c8daf78da08c0db777fcc17e07f2f63ef70041718f8a7630ad84f341"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"proc-macro2 1.0.92", "proc-macro2",
"quote 1.0.37", "quote",
"regex", "regex",
"regex-syntax 0.7.5", "regex-syntax 0.7.5",
"structmeta", "structmeta",
@ -368,8 +352,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [ dependencies = [
"proc-macro-error-attr", "proc-macro-error-attr",
"proc-macro2 1.0.92", "proc-macro2",
"quote 1.0.37", "quote",
"syn 1.0.109", "syn 1.0.109",
"version_check", "version_check",
] ]
@ -380,20 +364,11 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [ dependencies = [
"proc-macro2 1.0.92", "proc-macro2",
"quote 1.0.37", "quote",
"version_check", "version_check",
] ]
[[package]]
name = "proc-macro2"
version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
dependencies = [
"unicode-xid 0.1.0",
]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.92" version = "1.0.92"
@ -403,22 +378,13 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "quote"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
dependencies = [
"proc-macro2 0.4.30",
]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.37" version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
dependencies = [ dependencies = [
"proc-macro2 1.0.92", "proc-macro2",
] ]
[[package]] [[package]]
@ -468,12 +434,6 @@ version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
[[package]]
name = "scoped-tls"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.215" version = "1.0.215"
@ -489,8 +449,8 @@ version = "1.0.215"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0"
dependencies = [ dependencies = [
"proc-macro2 1.0.92", "proc-macro2",
"quote 1.0.37", "quote",
"syn 2.0.90", "syn 2.0.90",
] ]
@ -512,8 +472,8 @@ version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9"
dependencies = [ dependencies = [
"proc-macro2 1.0.92", "proc-macro2",
"quote 1.0.37", "quote",
"syn 2.0.90", "syn 2.0.90",
] ]
@ -544,8 +504,8 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ad9e09554f0456d67a69c1584c9798ba733a5b50349a6c0d0948710523922d" checksum = "78ad9e09554f0456d67a69c1584c9798ba733a5b50349a6c0d0948710523922d"
dependencies = [ dependencies = [
"proc-macro2 1.0.92", "proc-macro2",
"quote 1.0.37", "quote",
"structmeta-derive", "structmeta-derive",
"syn 2.0.90", "syn 2.0.90",
] ]
@ -556,8 +516,8 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a60bcaff7397072dca0017d1db428e30d5002e00b6847703e2e42005c95fbe00" checksum = "a60bcaff7397072dca0017d1db428e30d5002e00b6847703e2e42005c95fbe00"
dependencies = [ dependencies = [
"proc-macro2 1.0.92", "proc-macro2",
"quote 1.0.37", "quote",
"syn 2.0.90", "syn 2.0.90",
] ]
@ -567,8 +527,8 @@ version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [ dependencies = [
"proc-macro2 1.0.92", "proc-macro2",
"quote 1.0.37", "quote",
"unicode-ident", "unicode-ident",
] ]
@ -578,8 +538,8 @@ version = "2.0.90"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31"
dependencies = [ dependencies = [
"proc-macro2 1.0.92", "proc-macro2",
"quote 1.0.37", "quote",
"unicode-ident", "unicode-ident",
] ]
@ -589,8 +549,8 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6754c4559b79657554e9d8a0d56e65e490c76d382b9c23108364ec4125dea23c" checksum = "6754c4559b79657554e9d8a0d56e65e490c76d382b9c23108364ec4125dea23c"
dependencies = [ dependencies = [
"proc-macro2 1.0.92", "proc-macro2",
"quote 1.0.37", "quote",
"syn 1.0.109", "syn 1.0.109",
] ]
@ -600,10 +560,10 @@ version = "0.12.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f"
dependencies = [ dependencies = [
"proc-macro2 1.0.92", "proc-macro2",
"quote 1.0.37", "quote",
"syn 1.0.109", "syn 1.0.109",
"unicode-xid 0.2.6", "unicode-xid",
] ]
[[package]] [[package]]
@ -632,12 +592,9 @@ dependencies = [
name = "tf-demos-viewer" name = "tf-demos-viewer"
version = "0.1.2" version = "0.1.2"
dependencies = [ dependencies = [
"futures",
"js-sys", "js-sys",
"tf-demo-parser", "tf-demo-parser",
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-futures",
"wasm-bindgen-test",
"web-sys", "web-sys",
"wee_alloc", "wee_alloc",
] ]
@ -657,8 +614,8 @@ version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
dependencies = [ dependencies = [
"proc-macro2 1.0.92", "proc-macro2",
"quote 1.0.37", "quote",
"syn 2.0.90", "syn 2.0.90",
] ]
@ -685,12 +642,6 @@ version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.2.6" version = "0.2.6"
@ -723,32 +674,19 @@ dependencies = [
"bumpalo", "bumpalo",
"log", "log",
"once_cell", "once_cell",
"proc-macro2 1.0.92", "proc-macro2",
"quote 1.0.37", "quote",
"syn 2.0.90", "syn 2.0.90",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
[[package]]
name = "wasm-bindgen-futures"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83420b37346c311b9ed822af41ec2e82839bfe99867ec6c54e2da43b7538771c"
dependencies = [
"cfg-if 0.1.10",
"futures",
"js-sys",
"wasm-bindgen",
"web-sys",
]
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.96" version = "0.2.96"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "920b0ffe069571ebbfc9ddc0b36ba305ef65577c94b06262ed793716a1afd981" checksum = "920b0ffe069571ebbfc9ddc0b36ba305ef65577c94b06262ed793716a1afd981"
dependencies = [ dependencies = [
"quote 1.0.37", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
] ]
@ -758,8 +696,8 @@ version = "0.2.96"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf59002391099644be3524e23b781fa43d2be0c5aa0719a18c0731b9d195cab6" checksum = "bf59002391099644be3524e23b781fa43d2be0c5aa0719a18c0731b9d195cab6"
dependencies = [ dependencies = [
"proc-macro2 1.0.92", "proc-macro2",
"quote 1.0.37", "quote",
"syn 2.0.90", "syn 2.0.90",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
@ -771,31 +709,6 @@ version = "0.2.96"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5047c5392700766601942795a436d7d2599af60dcc3cc1248c9120bfb0827b0" checksum = "e5047c5392700766601942795a436d7d2599af60dcc3cc1248c9120bfb0827b0"
[[package]]
name = "wasm-bindgen-test"
version = "0.2.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2d9693b63a742d481c7f80587e057920e568317b2806988c59cd71618bc26c1"
dependencies = [
"console_error_panic_hook",
"futures",
"js-sys",
"scoped-tls",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-bindgen-test-macro",
]
[[package]]
name = "wasm-bindgen-test-macro"
version = "0.2.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0789dac148a8840bbcf9efe13905463b733fa96543bfbf263790535c11af7ba5"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
]
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.73" version = "0.3.73"

View file

@ -22,14 +22,9 @@ wasm-opt = true
[features] [features]
[dependencies] [dependencies]
wasm-bindgen = "0.2.45" wasm-bindgen = "0.2.96"
wee_alloc = { version = "0.4.2", optional = true } wee_alloc = { version = "0.4.2", optional = true }
web-sys = { version = "0.3.22", features = ["console"] } web-sys = { version = "0.3.22", features = ["console"] }
js-sys = "0.3.22" js-sys = "0.3.22"
tf-demo-parser = "0.5.1" tf-demo-parser = "0.5.1"
[dev-dependencies]
wasm-bindgen-test = "0.2.45"
futures = "0.1.27"
js-sys = "0.3.22"
wasm-bindgen-futures = "0.3.22"

View file

@ -1 +1,5 @@
JS bindings for demo parser JS bindings for demo parser
## Building
wasm-pack build -s demostf -t web

View file

@ -1 +0,0 @@
export {parseDemo, ParsedDemo, PlayerState, WorldBoundaries, Class, Team, BuildingType} from "./parser";

View file

@ -1,245 +0,0 @@
import {FlatState, XY} from '@demostf/tf-demos-viewer';
export async function parseDemo(bytes: Uint8Array, progressCallback : (progress: number) => void): Promise<ParsedDemo> {
let m = await import("@demostf/tf-demos-viewer");
const state = m.parse_demo(bytes, progressCallback);
let playerCount = state.player_count;
let buildingCount = state.building_count;
let boundaries = state.boundaries;
let interval_per_tick = state.interval_per_tick;
let tickCount = state.tick_count;
let kill_ticks = m.get_kill_ticks(state);
let attackers = m.get_attacker_ids(state);
let assisters = m.get_assister_ids(state);
let victims = m.get_victim_ids(state);
let playerInfo = [];
for (let i = 0; i < playerCount; i++) {
playerInfo.push({
name: m.get_player_name(state, i),
steamId: m.get_player_steam_id(state, i),
entityId: m.get_player_entity_id(state, i),
userId: m.get_player_user_id(state, i),
})
}
let kills = [];
for (let i = 0; i < kill_ticks.length; i++) {
kills.push({
tick: kill_ticks[i],
attacker: attackers[i],
assister: assisters[i],
victim: victims[i],
weapon: m.get_weapon(state, i),
})
}
let map = m.get_map(state);
let data = m.get_data(state);
return new ParsedDemo(
playerCount,
buildingCount,
{
boundary_min: {
x: boundaries.boundary_min.x,
y: boundaries.boundary_min.y,
},
boundary_max: {
x: boundaries.boundary_max.x,
y: boundaries.boundary_max.y,
}
},
{
map,
interval_per_tick
},
data,
kills,
playerInfo,
tickCount,
);
}
export interface PlayerInfo {
entityId: number,
name: string,
steamId: string,
userId: number,
}
export enum Team {
Other = 0,
Spectator = 1,
Red = 2,
Blue = 3,
}
export enum Class {
Other = 0,
Scout = 1,
Sniper = 2,
Solder = 3,
Demoman = 4,
Medic = 5,
Heavy = 6,
Pyro = 7,
Spy = 8,
Engineer = 9,
}
export enum BuildingType {
TeleporterEntrance = 0,
TeleporterExit = 1,
Dispenser = 2,
Level1Sentry = 3,
Level2Sentry = 4,
Level3Sentry = 5,
MiniSentry = 6,
Unknown = 7,
}
export interface WorldBoundaries {
boundary_min: {
x: number,
y: number
},
boundary_max: {
x: number,
y: number
}
}
export interface PlayerState {
position: {
x: number,
y: number
},
angle: number,
health: number,
team: Team,
playerClass: Class,
info: PlayerInfo,
charge: number,
}
export interface BuildingState {
position: {
x: number,
y: number
},
angle: number,
health: number,
level: number,
team: Team,
buildingType: BuildingType,
}
export interface Header {
interval_per_tick: number,
map: string
}
export interface Kill {
tick: number,
attacker: number,
assister: number,
victim: number,
weapon: string,
}
function unpack_f32(val: number, min: number, max: number): number {
const ratio = val / (Math.pow(2, 16) - 1);
return ratio * (max - min) + min;
}
function unpack_angle(val: number): number {
const ratio = val / (Math.pow(2, 8) - 1);
return ratio * 360;
}
export class ParsedDemo {
public readonly playerCount: number;
public readonly buildingCount: number;
public readonly world: WorldBoundaries;
public readonly data: Uint8Array;
private readonly header: Header;
public readonly tickCount: number;
public readonly kills: Kill[];
public readonly playerInfo: PlayerInfo[];
constructor(playerCount: number, buildingCount: number, world: WorldBoundaries, header: Header, data: Uint8Array, kills: Kill[], playerInfo: PlayerInfo[], tickCount: number) {
this.playerCount = playerCount;
this.buildingCount = buildingCount;
this.world = world;
this.header = header;
this.data = data;
this.kills = kills;
this.playerInfo = playerInfo;
this.tickCount = tickCount;
}
getPlayer(tick: number, playerIndex: number): PlayerState {
if (playerIndex >= this.playerCount) {
throw new Error("Player out of bounds");
}
const base = ((playerIndex * this.tickCount) + tick) * PLAYER_PACK_SIZE;
return unpackPlayer(this.data, base, this.world, this.playerInfo[playerIndex]);
}
getBuilding(tick: number, buildingIndex: number): BuildingState {
if (buildingIndex >= this.buildingCount) {
throw new Error("Building out of bounds");
}
const base = (this.playerCount * this.tickCount * PLAYER_PACK_SIZE) + ((buildingIndex * this.tickCount) + tick) * BUILDING_PACK_SIZE;
return unpackBuilding(this.data, base, this.world);
}
}
const PLAYER_PACK_SIZE = 8;
const BUILDING_PACK_SIZE = 7;
function unpackPlayer(bytes: Uint8Array, base: number, world: WorldBoundaries, info: PlayerInfo): PlayerState {
const x = unpack_f32(bytes[base] + (bytes[base + 1] << 8), world.boundary_min.x, world.boundary_max.x);
const y = unpack_f32(bytes[base + 2] + (bytes[base + 3] << 8), world.boundary_min.y, world.boundary_max.y);
const team_class_health = bytes[base + 4] + (bytes[base + 5] << 8);
const angle = unpack_angle(bytes[base + 6]);
const health = team_class_health & 1013;
const team = (team_class_health >> 14) as Team;
const playerClass = ((team_class_health >> 10) & 15) as Class;
const charge = bytes[base + 7];
return {
position: {x, y},
angle,
health,
team,
playerClass,
info,
charge
}
}
function unpackBuilding(bytes: Uint8Array, base: number, world: WorldBoundaries): BuildingState {
const x = unpack_f32(bytes[base] + (bytes[base + 1] << 8), world.boundary_min.x, world.boundary_max.x);
const y = unpack_f32(bytes[base + 2] + (bytes[base + 3] << 8), world.boundary_min.y, world.boundary_max.y);
const team_type_health = bytes[base + 4] + (bytes[base + 5] << 8);
const angle = unpack_angle(bytes[base + 6]);
const health = team_type_health & 1013;
const team = (((team_type_health >> 13) & 1) === 0) ? Team.Blue : Team.Red;
const level = (team_type_health >> 14);
const buildingType = ((team_type_health >> 10) & 7) as BuildingType;
return {
position: {x, y},
angle,
health,
team,
buildingType,
level,
}
}

View file

@ -1,22 +0,0 @@
import {parseDemo} from "./parser";
window.addEventListener('DOMContentLoaded', () => {
document.getElementById('file').onchange = e => {
let file = (e.target as HTMLInputElement).files[0];
let reader = new FileReader();
reader.readAsArrayBuffer(file);
reader.onload = async function () {
let bytes = new Uint8Array(reader.result as ArrayBuffer);
console.time('demo_parse');
let parsed = await parseDemo(bytes, () => {});
console.timeEnd('demo_parse');
console.log(parsed.getPlayer(150, 2));
};
reader.onerror = function () {
console.log(reader.error);
};
};
});

13847
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,19 +0,0 @@
{
"author": "Robin Appelman <robin@icewind.nl>",
"name": "@demostf/parser-worker",
"version": "0.1.2",
"scripts": {
"build": "./node_modules/.bin/rimraf dist pkg && webpack",
"start": "./node_modules/.bin/rimraf dist pkg && webpack-dev-server --open -d",
},
"devDependencies": {
"@demostf/tf-demos-viewer": "0.1.0",
"rimraf": "^3.0.2",
"ts-loader": "^8.0.4",
"typescript": "^4.0.3",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
},
"main": "../dist/index.js"
}

View file

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My Rust + Webpack project!</title>
</head>
<body>
<script src="test.js"></script>
<input type="file" id="file"/>
</body>
</html>

View file

@ -1,8 +0,0 @@
{
"compilerOptions": {
"noImplicitAny": true,
"module": "esnext",
"target": "es5",
"allowJs": true
}
}

View file

@ -1,30 +0,0 @@
const path = require("path");
const dist = path.resolve(__dirname, "dist");
module.exports = {
mode: "production",
entry: {
index: "./js/index.ts"
},
output: {
path: dist,
filename: "[name].js",
libraryTarget: 'commonjs-module'
},
devServer: {
contentBase: dist,
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules|pkg/,
},
],
},
};