Skip to content

Commit

Permalink
load map boundary data from remote
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Nov 26, 2023
1 parent f701033 commit 63e7ff1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 466 deletions.
6 changes: 5 additions & 1 deletion script/viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import {download} from "./download";
import {AsyncParser} from "./viewer/Analyse/Data/AsyncParser";
import {render} from "solid-js/web";
import {Analyser} from "./viewer/Analyse/Analyser";
import {loadMapData} from "./viewer/Analyse/MapBoundries";

ready(async () => {
let mapPromise = loadMapData();
document.querySelectorAll('.onlyscript').forEach(e => e.classList.remove('onlyscript'));
const fileInput: HTMLInputElement | null = document.querySelector(`.dropzone input[type="file"]`);
const urlInput: HTMLInputElement | null = document.querySelector(`.viewer-page input[name="url"]`);
Expand All @@ -22,6 +24,7 @@ ready(async () => {

if (header.type === "HL2DEMO" && header.game === "tf") {
drop_text.textContent = "Parsing...";
await mapPromise;
parse(data, parseProgress, false);
} else {
drop_text.textContent = "Malformed demo or not a TF2 demo";
Expand All @@ -31,6 +34,7 @@ ready(async () => {
const url = urlInput.value;
console.log(url);
const data = await download(url, (progress) => downloadProgress.value = progress);
await mapPromise;
parse(data, parseProgress, true);
}
})
Expand All @@ -44,4 +48,4 @@ const parse = async (data: ArrayBuffer, parseProgress: HTMLProgressElement, stor
const page = document.querySelector('.viewer-page');

render(() => <Analyser parser={parser} header={header} isStored={stored}/>, page);
}
}
17 changes: 14 additions & 3 deletions script/viewer/Analyse/MapBoundries.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import {mapBoundaries} from './boundaries';
let mapBoundaries = {};

mapBoundaries['koth_viaduct'] = mapBoundaries['koth_product_rc8'];
mapBoundaries['cp_prolands'] = mapBoundaries['cp_badlands'];

export const loadMapData = async () => {
if (Object.keys(mapBoundaries).length > 0) {
return;
}
const map_root = document.querySelector('[data-maps]').getAttribute('data-maps');
const res = await fetch(`${map_root}boundaries.json`);

mapBoundaries = await res.json();

mapBoundaries['koth_viaduct'] = mapBoundaries['koth_product_rc8'];
mapBoundaries['cp_prolands'] = mapBoundaries['cp_badlands'];
}

const mapAliases = new Map<string, string>([
['cp_prolands', 'cp_badlands']
Expand Down
Loading

0 comments on commit 63e7ff1

Please sign in to comment.