Hi,
I'm having trouble using Schema for my state. If I comment the setState line it works.
Here's what I got:
import { Room, Client } from 'colyseus';
import { type, Schema } from '@colyseus/schema';
import { BattleState } from './BattleState';
import { MessageType } from '../utils';
export class BattleRoom extends Room {
@type('number') maxClients = 2;
onInit(options: any) {
this.setState(new BattleState());
}
onJoin(client: Client, options: any) {
console.log('onJoin', options);
if (this.clients.length === 2) {
this.lock();
}
}
onLeave(client: Client, consented: boolean) {
console.log('onLeave', consented);
}
onMessage(client: Client, message: any) {
console.log('onMessage', message);
}
onDispose() {
console.log('onDispose');
}
}
import { MapSchema, Schema, type } from '@colyseus/schema';
import { BattleTeam } from '../entities/BattleTeam';
export class BattleState extends Schema {
@type('uint8') round = 0;
@type('string') status = 'READY';
@type('uint8') moves = 0;
@type('uint8') teamCount = 0;
@type({ map: BattleTeam }) teams = new MapSchema<BattleTeam>();
}
import { Schema, type } from '@colyseus/schema';
import { BattleTeamData } from '../utils';
export class BattleTeam extends Schema {
@type('uint8') move: number;
constructor(teamData: BattleTeamData) {
super();
this.move = 0;
console.log('---- BattleTeam ----');
console.log(this.toJSON());
}
}
interface BattleTeamData {
move: number;
}