How to use the @colyseus/schema.defineTypes function in @colyseus/schema

To help you get started, we’ve selected a few @colyseus/schema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github damian-pastorini / reldens / packages / users / server / player.js View on Github external
this.username = data.username;
            this.p2body = false;
            // set scene and position:
            this.state = new PlayerState(player.state);
            this.canAttack = true;
        } catch (err) {
            ErrorManager.error(['Missing user data.', err]);
        }
    }

}

type('string')(Player.prototype, 'sessionId');
type('string')(Player.prototype, 'username');
type('number')(Player.prototype, 'status');
schema.defineTypes(Player, {state: PlayerState});

module.exports.Player = Player;
github colyseus / colyseus / src / rooms / RelayRoom.ts View on Github external
import { Context, defineTypes, MapSchema, Schema, type } from '@colyseus/schema';

import { Client } from '..';
import { Room } from '../Room';

/**
 * Create another context to avoid these types from being in the user's global `Context`
 */
const context = new Context();

class Player extends Schema { // tslint:disable-line
  public connected: boolean;
  public sessionId: string;
}
defineTypes(Player, {
  connected: 'boolean',
  sessionId: 'string',
}, context);

class State extends Schema { // tslint:disable-line
  public players = new MapSchema();
}
defineTypes(State, {
  players: { map: Player },
}, context);

/**
 * client.joinOrCreate("relayroom", {
 *   maxClients: 10,
 *   allowReconnectionTime: 20
 * });
github colyseus / colyseus / src / rooms / RelayRoom.ts View on Github external
*/
const context = new Context();

class Player extends Schema { // tslint:disable-line
  public connected: boolean;
  public sessionId: string;
}
defineTypes(Player, {
  connected: 'boolean',
  sessionId: 'string',
}, context);

class State extends Schema { // tslint:disable-line
  public players = new MapSchema();
}
defineTypes(State, {
  players: { map: Player },
}, context);

/**
 * client.joinOrCreate("relayroom", {
 *   maxClients: 10,
 *   allowReconnectionTime: 20
 * });
 */

export class RelayRoom extends Room { // tslint:disable-line
  public allowReconnectionTime: number = 0;

  public onCreate(options) {
    this.setState(new State());