Add better object updates

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

View file

@ -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];
}
}

View file

@ -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';

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];
}
}

View file

@ -13,6 +13,5 @@
"module": "commonjs",
"composite": true,
"lib": ["dom", "es2017"]
},
"include": ["src/**/*.ts"]
}
}