Add better object updates
This commit is contained in:
parent
fd80a299b6
commit
e83c58e1a5
4 changed files with 289 additions and 123 deletions
5
shared/src/objects/interpolation-type.ts
Normal file
5
shared/src/objects/interpolation-type.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
export enum InterpolationType {
|
||||
flat = 'flat',
|
||||
linear = 'linear',
|
||||
linearRotation = 'linearRotation',
|
||||
}
|
||||
23
shared/src/objects/types/player-character-base.ts
Normal file
23
shared/src/objects/types/player-character-base.ts
Normal 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];
|
||||
}
|
||||
}
|
||||
15
shared/src/objects/update-message.ts
Normal file
15
shared/src/objects/update-message.ts
Normal 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];
|
||||
}
|
||||
}
|
||||
12
shared/src/objects/update-object-message.ts
Normal file
12
shared/src/objects/update-object-message.ts
Normal 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];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue