Hi,
I dont understand how nested states needs to be changed on server side to trigger the listen event on client side.
I would like to use following classes as custom states.
Room
...
onInit() {
this.state.setState(new GameState());
}
GameState
export class GameState {
players: EntityMap<PlayerState> = {};
...
PlayerState
export class PlayerState {
tilePosX: number = 0;
tilePosY: number = 0;
isNpc: boolean = false;
moveDirState: MoveDirState = MoveDirState.NONE();
MoveDirState
export class MoveDirState {
moveDir: MOVE_DIR = MOVE_DIR.NONE;
time: number = 0;
Problem is that any change to PlayerState.moveDirState does not trigger listen events on client. Even that moveDirState is initially send to client
// Initial update with moveDirState as attribute
{ operation: "add", attribute: "moveDirState" , value: { moveDir: 4, time: 0} ... }
any update on serverside (this is a player instance)
// Not working tries
// 1 Not working helper to set values inside the class
// this.moveDirState.set(moveDir, time);
// 2 Not working set attributes from player class
this.moveDirState.moveDir = moveDir;
this.moveDirState.time = time;
// 3 Not working creating new instance
this.moveDirState = new MoveDirState(moveDir, time);
// Just to check if update working, this is working
this.tilePosX -= 1;
Listener on client side looks like this.
this.room.listen("players/:id/:attribute", (change: DataChange) => {
console.log("Update state for " + change.path.id, change);
...
});
Thank you very much