Open JernejHabjan opened 11 months ago
how to achieve this in typescript:
I have complex nested object of classes like this:
class GameState{ playTime = 0; howLongPlaying(){...} } class Weapon{ attackDmg=10, currentCooldown = 5 } class Warrior{ health:100, weapon: Weapon attack(){...}, } class Player{ warriors:Warrior[]=[] getWarriors(){...} getPlayerId(){...} }
class Game{ gameState: GameState players:Player[] = []; }
I want to replicate this game object between server and client. How do I do that in Typescript? Server is NestJs, and client is Angular
Mark property as replicable easier way?
Maybe use proxy and in proxy send socket-io request to server
https://stackoverflow.com/a/50723478/5909875
https://www.npmjs.com/package/proxy-deep
https://www.npmjs.com/package/@qiwi/deep-proxy
how to achieve this in typescript:
I have complex nested object of classes like this:
class GameState{ playTime = 0; howLongPlaying(){...} } class Weapon{ attackDmg=10, currentCooldown = 5 } class Warrior{ health:100, weapon: Weapon attack(){...}, } class Player{ warriors:Warrior[]=[] getWarriors(){...} getPlayerId(){...} }
class Game{ gameState: GameState players:Player[] = []; }
I want to replicate this game object between server and client. How do I do that in Typescript? Server is NestJs, and client is Angular