Solve serialization
This commit is contained in:
parent
ba8b1a29fd
commit
8e44dd3733
45 changed files with 242 additions and 201 deletions
|
|
@ -1,8 +1,9 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { CharacterBase, CommandExecutors } from 'shared';
|
||||
import { CharacterBase, CommandExecutors, deserializable } from 'shared';
|
||||
import { RenderCommand } from '../commands/types/render';
|
||||
import { BlobShape } from '../shapes/blob-shape';
|
||||
|
||||
@deserializable(CharacterBase)
|
||||
export class CharacterView extends CharacterBase {
|
||||
private shape = new BlobShape();
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import {
|
|||
StepCommand,
|
||||
UpdateObjectsCommand,
|
||||
} from 'shared';
|
||||
import { deserialize, deserializeJsonArray } from '../transport/deserialize';
|
||||
import { Camera } from './camera';
|
||||
import { CharacterView } from './character-view';
|
||||
|
||||
|
|
@ -21,7 +20,7 @@ export class GameObjectContainer extends CommandReceiver {
|
|||
|
||||
protected commandExecutors: CommandExecutors = {
|
||||
[CreatePlayerCommand.type]: (c: CreatePlayerCommand) => {
|
||||
this.player = deserialize(c.serializedPlayer) as CharacterView;
|
||||
this.player = c.character as CharacterView;
|
||||
this.camera = new Camera();
|
||||
this.addObject(this.player);
|
||||
this.addObject(this.camera);
|
||||
|
|
@ -34,13 +33,13 @@ export class GameObjectContainer extends CommandReceiver {
|
|||
},
|
||||
|
||||
[CreateObjectsCommand.type]: (c: CreateObjectsCommand) =>
|
||||
deserializeJsonArray(c.serializedObjects).forEach((o) => this.addObject(o)),
|
||||
c.objects.forEach((o) => this.addObject(o)),
|
||||
|
||||
[DeleteObjectsCommand.type]: (c: DeleteObjectsCommand) =>
|
||||
c.ids.forEach((id: Id) => this.objects.delete(id)),
|
||||
|
||||
[UpdateObjectsCommand.type]: (c: UpdateObjectsCommand) =>
|
||||
deserializeJsonArray(c.serializedObjects).forEach((o) => {
|
||||
c.objects.forEach((o) => {
|
||||
this.objects.delete(o.id);
|
||||
this.addObject(o);
|
||||
if (o.id === this.player.id) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { vec2, vec3 } from 'gl-matrix';
|
||||
import { CircleLight } from 'sdf-2d';
|
||||
import { CommandExecutors, Id, LampBase } from 'shared';
|
||||
import { CommandExecutors, deserializable, Id, LampBase } from 'shared';
|
||||
import { RenderCommand } from '../commands/types/render';
|
||||
|
||||
@deserializable(LampBase)
|
||||
export class LampView extends LampBase {
|
||||
private light: CircleLight;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { InvertedTunnel } from 'sdf-2d';
|
||||
import { CommandExecutors, Id, TunnelBase } from 'shared';
|
||||
import { CommandExecutors, deserializable, Id, TunnelBase } from 'shared';
|
||||
import { RenderCommand } from '../commands/types/render';
|
||||
|
||||
@deserializable(TunnelBase)
|
||||
export class TunnelView extends TunnelBase {
|
||||
private shape: InvertedTunnel;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue