How to use the @colyseus/schema.Context 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 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);