Solve serialization
This commit is contained in:
parent
ba8b1a29fd
commit
8e44dd3733
45 changed files with 242 additions and 201 deletions
|
|
@ -1,3 +1,9 @@
|
|||
import { Typed } from '../transport/typed';
|
||||
export abstract class Command {
|
||||
public static get type(): string {
|
||||
return (this as any).name;
|
||||
}
|
||||
|
||||
export abstract class Command extends Typed { }
|
||||
public get type(): string {
|
||||
return (this as any).constructor.name;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
import { GameObject } from '../../objects/game-object';
|
||||
import { serializable } from '../../transport/serializable/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable()
|
||||
export class CreateObjectsCommand extends Command {
|
||||
public constructor(public readonly serializedObjects: string) {
|
||||
public constructor(public readonly objects: Array<GameObject>) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toJSON(): any {
|
||||
return [this.type, this.serializedObjects];
|
||||
public toArray(): Array<any> {
|
||||
return [this.objects];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
import { CharacterBase } from '../../objects/types/character-base';
|
||||
import { serializable } from '../../transport/serializable/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable()
|
||||
export class CreatePlayerCommand extends Command {
|
||||
public constructor(public readonly serializedPlayer: string) {
|
||||
public constructor(public readonly character: CharacterBase) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toJSON(): any {
|
||||
return [this.type, this.serializedPlayer];
|
||||
public toArray(): Array<any> {
|
||||
return [this.character];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import { Id } from '../../transport/identity';
|
||||
import { serializable } from '../../transport/serializable/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable()
|
||||
export class DeleteObjectsCommand extends Command {
|
||||
public constructor(public readonly ids: Array<Id>) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toJSON(): any {
|
||||
return [this.type, this.ids];
|
||||
public toArray(): Array<any> {
|
||||
return [this.ids];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { serializable } from '../../transport/serializable/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable()
|
||||
export class MoveActionCommand extends Command {
|
||||
public constructor(public readonly delta: vec2) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toJSON(): any {
|
||||
return [this.type, this.delta];
|
||||
public toArray(): Array<any> {
|
||||
return [this.delta];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { serializable } from '../../transport/serializable/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable()
|
||||
export class PrimaryActionCommand extends Command {
|
||||
public constructor(public readonly position: vec2) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toJSON(): any {
|
||||
return [this.type, this.position];
|
||||
public toArray(): Array<any> {
|
||||
return [this.position];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { serializable } from '../../transport/serializable/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable()
|
||||
export class SecondaryActionCommand extends Command {
|
||||
public constructor(public readonly position: vec2) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toJSON(): any {
|
||||
return [this.type, this.position];
|
||||
public toArray(): Array<any> {
|
||||
return [this.position];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import { Rectangle } from '../../helper/rectangle';
|
||||
import { serializable } from '../../transport/serializable/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable()
|
||||
export class SetViewAreaActionCommand extends Command {
|
||||
public constructor(public readonly viewArea: Rectangle) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toJSON(): any {
|
||||
return [this.type, this.viewArea];
|
||||
public toArray(): Array<any> {
|
||||
return [this.viewArea];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { serializable } from '../../transport/serializable/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable()
|
||||
export class TernaryActionCommand extends Command {
|
||||
public constructor(public readonly position: vec2) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toJSON(): any {
|
||||
return [this.type, this.position];
|
||||
public toArray(): Array<any> {
|
||||
return [this.position];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
import { GameObject } from '../../objects/game-object';
|
||||
import { serializable } from '../../transport/serializable/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable()
|
||||
export class UpdateObjectsCommand extends Command {
|
||||
public constructor(public readonly serializedObjects: string) {
|
||||
public constructor(public readonly objects: Array<GameObject>) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toJSON(): any {
|
||||
return [this.type, this.serializedObjects];
|
||||
public toArray(): Array<any> {
|
||||
return [this.objects];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue