UNPKG

@natewilcox/zelda-server

Version:

Server application for zelda multiplayer game

30 lines (29 loc) 1.6 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.JoinCommand = void 0; const command_1 = require("@colyseus/command"); const PlayerState_1 = require("../rooms/schema/PlayerState"); const SimulationEvents_1 = require("../utils/SimulationEvents"); let id_index = 0; class JoinCommand extends command_1.Command { execute(_a) { return __awaiter(this, arguments, void 0, function* ({ client, x, y }) { console.log("JoinCommand executed"); //create a new player state for the client const playerState = new PlayerState_1.PlayerState(++id_index, client.id, x, y); //add the player to the room state this.state.players.push(playerState); SimulationEvents_1.SimulationEventEmitter.emit(SimulationEvents_1.SimulationEvents.PlayerJoined, playerState); }); } } exports.JoinCommand = JoinCommand;