1
0
Fork 0
mirror of https://github.com/demostf/demo.js synced 2026-06-04 00:54:14 +02:00

save baseline in packet handler instead of parser

This commit is contained in:
Robin Appelman 2017-02-14 22:28:16 +01:00
commit 5fcbbe540e
2 changed files with 15 additions and 16 deletions

View file

@ -1,5 +1,6 @@
import {StringTablePacket} from "../Data/Packet"; import {StringTablePacket} from "../Data/Packet";
import {Match} from "../Data/Match"; import {Match} from "../Data/Match";
import {StringTableEntry} from "../Data/StringTable";
export function handleStringTable(packet: StringTablePacket, match: Match) { export function handleStringTable(packet: StringTablePacket, match: Match) {
for (const table of packet.tables) { for (const table of packet.tables) {
@ -20,5 +21,18 @@ export function handleStringTable(packet: StringTablePacket, match: Match) {
} }
} }
} }
if (table.name === 'instancebaseline') {
for (const instanceBaseLine of table.entries) {
saveInstanceBaseLine(instanceBaseLine, match);
}
}
}
}
function saveInstanceBaseLine(entry: StringTableEntry, match: Match) {
if (entry.extraData) {
match.staticBaseLines[parseInt(entry.text, 10)] = entry.extraData;
} else {
throw new Error('Missing baseline');
} }
} }

View file

@ -55,23 +55,16 @@ export function parseStringTable(stream: BitStream, table: StringTable, entries:
if (userData) { if (userData) {
existingEntry.extraData = userData; existingEntry.extraData = userData;
} }
if (table.name === 'instancebaseline') {
saveInstanceBaseLine(existingEntry, match);
}
history.push(existingEntry); history.push(existingEntry);
if (value) { if (value) {
existingEntry.text = value; existingEntry.text = value;
} }
} else { } else {
const entry = { table.entries[entryIndex] = {
text: value, text: value,
extraData: userData extraData: userData
}; };
if (table.name === 'instancebaseline') {
saveInstanceBaseLine(entry, match);
}
table.entries[entryIndex] = entry;
history.push(table.entries[entryIndex]); history.push(table.entries[entryIndex]);
} }
if (history.length > 32) { if (history.length > 32) {
@ -79,11 +72,3 @@ export function parseStringTable(stream: BitStream, table: StringTable, entries:
} }
} }
} }
function saveInstanceBaseLine(entry: StringTableEntry, match: Match) {
if (entry.extraData) {
match.staticBaseLines[parseInt(entry.text, 10)] = entry.extraData;
} else {
throw new Error('Missing baseline');
}
}