Add better object updates
This commit is contained in:
parent
fd80a299b6
commit
e83c58e1a5
29 changed files with 289 additions and 123 deletions
|
|
@ -1,14 +1,15 @@
|
|||
import { GameObject } from '../../objects/game-object';
|
||||
import { vec2 } from 'gl-matrix';
|
||||
import { UpdateObjectMessage } from '../../objects/update-object-message';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
export class UpdateObjectsCommand extends Command {
|
||||
public constructor(public readonly objects: Array<GameObject>) {
|
||||
public constructor(public readonly updates: Array<UpdateObjectMessage>) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.objects];
|
||||
return [this.updates];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ export * from './commands/command';
|
|||
export * from './commands/types/create-objects';
|
||||
export * from './commands/types/create-player';
|
||||
export * from './commands/types/delete-objects';
|
||||
export * from './commands/types/update-objects';
|
||||
export * from './commands/types/ternary-action';
|
||||
export * from './commands/types/move-action';
|
||||
export * from './commands/types/primary-action';
|
||||
export * from './commands/types/update-objects';
|
||||
export * from './commands/types/secondary-action';
|
||||
export * from './commands/command-receiver';
|
||||
export * from './commands/command-executors';
|
||||
|
|
@ -36,9 +36,13 @@ export * from './transport/serialization/serializes-to';
|
|||
export * from './transport/serialization/serializable';
|
||||
export * from './transport/serialization/override-deserialization';
|
||||
export * from './objects/types/character-base';
|
||||
export * from './objects/update-message';
|
||||
export * from './objects/types/player-character-base';
|
||||
export * from './objects/types/lamp-base';
|
||||
export * from './objects/types/planet-base';
|
||||
export * from './objects/types/projectile-base';
|
||||
export * from './objects/update-message';
|
||||
export * from './objects/update-object-message';
|
||||
export * from './settings';
|
||||
export * from './transport/transport-events';
|
||||
export * from './transport/identity';
|
||||
|
|
|
|||
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];
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,5 @@
|
|||
"module": "commonjs",
|
||||
"composite": true,
|
||||
"lib": ["dom", "es2017"]
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue