Add basic multiplayer
This commit is contained in:
parent
0f0a1eaf67
commit
46a48e7c15
113 changed files with 1362 additions and 754 deletions
28
frontend/src/scripts/transport/deserialize.ts
Normal file
28
frontend/src/scripts/transport/deserialize.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import {
|
||||
CharacterBase,
|
||||
commandConstructors,
|
||||
GameObject,
|
||||
LampBase,
|
||||
TunnelBase,
|
||||
} from 'shared';
|
||||
import { CharacterView } from '../objects/character-view';
|
||||
import { LampView } from '../objects/lamp-view';
|
||||
import { TunnelView } from '../objects/tunnel-view';
|
||||
|
||||
const constructors: { [type: string]: new (...values: Array<any>) => GameObject } = {
|
||||
[TunnelBase.type]: TunnelView,
|
||||
[LampBase.type]: LampView,
|
||||
[CharacterBase.type]: CharacterView,
|
||||
...commandConstructors,
|
||||
};
|
||||
|
||||
export const deserialize = (json: string): GameObject => {
|
||||
const [type, ...values] = JSON.parse(json);
|
||||
return new constructors[type](...values);
|
||||
};
|
||||
|
||||
export const deserializeJsonArray = (json: string): Array<GameObject> => {
|
||||
return (JSON.parse(json) as Array<any>).map(
|
||||
([type, ...values]) => new constructors[type](...values)
|
||||
);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue