Add better object updates

This commit is contained in:
schmelczerandras 2020-10-17 18:35:09 +02:00
commit e83c58e1a5
4 changed files with 289 additions and 123 deletions

View file

@ -0,0 +1,5 @@
export enum InterpolationType {
flat = 'flat',
linear = 'linear',
linearRotation = 'linearRotation',
}

View file

@ -0,0 +1,23 @@
import { CharacterBase } from './character-base';
import { Circle } from '../../helper/circle';
import { Id } from '../../transport/identity';
import { serializable } from '../../transport/serialization/serializable';
@serializable
export class PlayerCharacterBase extends CharacterBase {
constructor(
id: Id,
public name: string,
colorIndex: number,
head?: Circle,
leftFoot?: Circle,
rightFoot?: Circle,
) {
super(id, colorIndex, head, leftFoot, rightFoot);
}
public toArray(): Array<any> {
const { id, name, colorIndex, head, leftFoot, rightFoot } = this;
return [id, name, colorIndex, head, leftFoot, rightFoot];
}
}

View file

@ -0,0 +1,15 @@
import { serializable } from '../transport/serialization/serializable';
import { InterpolationType } from './interpolation-type';
@serializable
export class UpdateMessage {
constructor(
public key: string,
public value: any,
public interpolationType?: InterpolationType,
) {}
public toArray(): Array<any> {
return [this.key, this.value, this.interpolationType];
}
}

View file

@ -0,0 +1,12 @@
import { Id } from '../main';
import { serializable } from '../transport/serialization/serializable';
import { UpdateMessage } from './update-message';
@serializable
export class UpdateObjectMessage {
constructor(public id: Id, public updates: Array<UpdateMessage>) {}
public toArray(): Array<any> {
return [this.id, this.updates];
}
}