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

Fix calculating entity diff from baseline

This commit is contained in:
Robin Appelman 2017-11-20 21:10:03 +01:00
commit 9eaf826814
3 changed files with 27 additions and 1 deletions

View file

@ -77,7 +77,7 @@ export class PacketEntity {
public diffFromBaseLine(baselineProps: SendProp[]): SendProp[] {
return this.props.filter((prop) => {
const baseProp = PacketEntity.getPropByFullName(baselineProps, prop.definition.fullName);
return (!baseProp || prop.value !== baseProp.value);
return (!baseProp || !SendProp.areEqual(prop, baseProp));
});
}

View file

@ -15,6 +15,28 @@ export class SendProp {
prop.value = this.value;
return prop;
}
public static areEqual(a: SendProp, b: SendProp) {
return a.definition.fullName !== b.definition.fullName ? false : SendProp.valuesAreEqual(a.value, b.value);
}
private static valuesAreEqual(a: SendPropValue | null, b: SendPropValue | null) {
if (Array.isArray(a) && Array.isArray(b)) {
if (a.length !== b.length) {
return false;
}
for (let i = 0; i < a.length; i++) {
if (!SendProp.valuesAreEqual(a[i], b[i])) {
return false;
}
}
return true;
} else if (a instanceof Vector && b instanceof Vector) {
return Vector.areEqual(a, b);
} else {
return a === b;
}
}
}
export type SendPropArrayValue = Vector | number | string;

View file

@ -8,4 +8,8 @@ export class Vector {
this.y = y;
this.z = z;
}
public static areEqual(a: Vector, b: Vector) {
return a.x === b.x && a.y === b.y && a.z === b.z;
}
}