mirror of
https://github.com/demostf/demo.js
synced 2026-06-03 16:44:12 +02:00
Fix flattening of prop definitions
This commit is contained in:
parent
5b1b11220d
commit
a5bfe128ed
4 changed files with 36 additions and 24 deletions
|
|
@ -16,7 +16,7 @@ export class SendTable {
|
|||
}
|
||||
|
||||
private flatten() {
|
||||
let excludes: SendPropDefinition[] = [];
|
||||
let excludes: SendPropDefinition[] = this.excludes;
|
||||
let props: SendPropDefinition[] = [];
|
||||
this.getAllProps(excludes, props);
|
||||
|
||||
|
|
@ -38,19 +38,18 @@ export class SendTable {
|
|||
getAllProps(excludes: SendPropDefinition[], props: SendPropDefinition[]) {
|
||||
let localProps = [];
|
||||
this.getAllPropsIteratorProps(excludes, localProps, props);
|
||||
for (let i = 0; i < localProps.length; i++) {
|
||||
props.push(localProps[i]);
|
||||
for (const localProp of localProps) {
|
||||
props.push(localProp);
|
||||
}
|
||||
}
|
||||
|
||||
getAllPropsIteratorProps(excludes: SendPropDefinition[], props: SendPropDefinition[], childProps: SendPropDefinition[]) {
|
||||
for (let i = 0; i < this.props.length; i++) {
|
||||
const prop = this.props[i];
|
||||
for (const prop of this.props) {
|
||||
if (prop.hasFlag(SendPropFlag.SPROP_EXCLUDE) || excludes.indexOf(prop) !== -1) {
|
||||
continue;
|
||||
}
|
||||
if (excludes.filter((exclude) => {
|
||||
return prop.table && exclude.name == prop.name && exclude.excludeDTName == prop.table.name;
|
||||
return exclude.name == prop.name && exclude.excludeDTName == prop.ownerTableName;
|
||||
}).length > 0) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -61,7 +60,7 @@ export class SendTable {
|
|||
} else {
|
||||
prop.table.getAllProps(excludes, childProps);
|
||||
}
|
||||
} else if (!prop.hasFlag(SendPropFlag.SPROP_EXCLUDE)) {
|
||||
} else {
|
||||
props.push(prop);
|
||||
}
|
||||
}
|
||||
|
|
@ -73,6 +72,18 @@ export class SendTable {
|
|||
}
|
||||
return this._flattenedProps;
|
||||
}
|
||||
|
||||
get excludes() {
|
||||
let result: SendPropDefinition[] = [];
|
||||
for (const prop of this.props) {
|
||||
if (prop.hasFlag(SendPropFlag.SPROP_EXCLUDE)) {
|
||||
result.push(prop);
|
||||
} else if (prop.type === SendPropType.DPT_DataTable && prop.table) {
|
||||
result = result.concat(prop.table.excludes);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -12,11 +12,12 @@ export function applyEntityUpdate(entity: Entity, stream: BitStream): Entity {
|
|||
throw new Error('prop index out of bounds while applying update for ' + entity.sendTable.name + ' got ' + index
|
||||
+ ' proptype only has ' + allProps.length + ' properties');
|
||||
}
|
||||
|
||||
const propDefinition = allProps[index];
|
||||
const existingProp = entity.getPropByDefinition(propDefinition);
|
||||
|
||||
const prop = existingProp ? existingProp : new SendProp(propDefinition);
|
||||
prop.value = SendPropParser.decode(propDefinition, stream);
|
||||
console.log(prop);
|
||||
|
||||
if (!existingProp) {
|
||||
entity.props.push(prop);
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ function readEnterPVS(stream: BitStream, entityId: number, match: Match, baseLin
|
|||
if (staticBaseLine) {
|
||||
staticBaseLine.index = 0;
|
||||
applyEntityUpdate(entity, staticBaseLine);
|
||||
if(staticBaseLine.bitsLeft > 7) {
|
||||
if (staticBaseLine.bitsLeft > 7) {
|
||||
console.log(staticBaseLine.length, staticBaseLine.index);
|
||||
throw new Error('Unexpected data left at the end of staticBaseline, ' + stream.bitsLeft + ' bits left');
|
||||
}
|
||||
|
|
@ -127,7 +127,7 @@ export function PacketEntities(stream: BitStream, match: Match): Packet { //26:
|
|||
if (entity) {
|
||||
applyEntityUpdate(entity, stream);
|
||||
} else {
|
||||
console.log( entityId, match.entities.length);
|
||||
console.log(entityId, match.entities.length);
|
||||
throw new Error("unknown entity");
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -56,12 +56,7 @@ export function parseStringTable(stream: BitStream, table: StringTable, entries:
|
|||
existingEntry.extraData = userData;
|
||||
}
|
||||
if (table.name === 'instancebaseline') {
|
||||
console.log('updating instancebaseline');
|
||||
if (userData) {
|
||||
match.staticBaseLines[parseInt(existingEntry.text, 10)] = userData;
|
||||
} else {
|
||||
throw new Error('Missing baseline');
|
||||
}
|
||||
saveInstanceBaseLine(existingEntry, match);
|
||||
}
|
||||
history.push(existingEntry);
|
||||
|
||||
|
|
@ -69,17 +64,14 @@ export function parseStringTable(stream: BitStream, table: StringTable, entries:
|
|||
existingEntry.text = value;
|
||||
}
|
||||
} else {
|
||||
if (table.name === 'instancebaseline') {
|
||||
if (userData) {
|
||||
match.staticBaseLines[parseInt(value, 10)] = userData;
|
||||
} else {
|
||||
throw new Error('Missing baseline');
|
||||
}
|
||||
}
|
||||
table.entries[entryIndex] = {
|
||||
const entry = {
|
||||
text: value,
|
||||
extraData: userData
|
||||
};
|
||||
if (table.name === 'instancebaseline') {
|
||||
saveInstanceBaseLine(entry, match);
|
||||
}
|
||||
table.entries[entryIndex] = entry;
|
||||
history.push(table.entries[entryIndex]);
|
||||
}
|
||||
if (history.length > 32) {
|
||||
|
|
@ -87,3 +79,11 @@ 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');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue