Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { type } from '@colyseus/schema';
import { Types } from '@tosios/common';
import { Rectangle } from './Rectangle';
export class Prop extends Rectangle {
@type('string')
public type: Types.PropType;
@type('boolean')
public active: boolean;
// Init
constructor(type: Types.PropType, x: number, y: number, width: number, height: number) {
super(x, y, width, height);
this.type = type;
this.active = true;
}
}
import { type } from '@colyseus/schema';
import { Circle } from './Circle';
export class Bullet extends Circle {
@type('string')
public playerId: string;
@type('number')
public rotation: number;
@type('number')
public fromX: number;
@type('number')
public fromY: number;
@type('boolean')
public active: boolean;
@type('string')
public color: string;
@type('number')
public shotAt: number;
// Init
constructor(
import { Schema, type } from '@colyseus/schema';
import { Types } from '@tosios/common';
export class Game extends Schema {
@type('string')
public mapName: string;
@type('string')
public state: Types.GameState;
@type('number')
public lobbyEndsAt: number;
@type('number')
public gameEndsAt: number;
@type('number')
public maxPlayers: number;
private lobbyDuration: number;
private gameDuration: number;
// Init
constructor(
import { Schema, type } from '@colyseus/schema';
import { Room } from '../Room';
class RoomData extends Schema { // tslint:disable-line
@type('string') public id: string;
@type('string') public name: string;
@type('number') public clients: number;
@type('number') public maxClients: number;
@type('string') public metadata: string;
}
class LobbyState extends Schema { // tslint:disable-line
@type([RoomData]) public rooms: RoomData[];
}
export class LobbyRoom extends Room { // tslint:disable-line
public onCreate(options: any) {
this.setState(new LobbyState());
this.clock.setInterval(() => this.fetch(), Math.max(1, options.updateInterval || 5000) * 1000);
}
public fetch() {
import { type } from '@colyseus/schema';
import { Types } from '@tosios/common';
import { Rectangle } from './Rectangle';
export class Prop extends Rectangle {
@type('string')
public type: Types.PropType;
@type('boolean')
public active: boolean;
// Init
constructor(type: Types.PropType, x: number, y: number, width: number, height: number) {
super(x, y, width, height);
this.type = type;
this.active = true;
}
}
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;
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
* });
*/
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());
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);
constructor(roomData)
{
super();
// @NOTE: this JSON is to send the scene data to the client, here we could remove data we don't want to send.
this.sceneData = JSON.stringify(roomData);
this.players = new MapSchema();
}