UNPKG

@natewilcox/zelda-server

Version:

Server application for zelda multiplayer game

30 lines (29 loc) 1.58 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.LeaveCommand = void 0; const command_1 = require("@colyseus/command"); const SimulationEvents_1 = require("../utils/SimulationEvents"); class LeaveCommand extends command_1.Command { execute(_a) { return __awaiter(this, arguments, void 0, function* ({ client }) { console.log("LeaveCommand executed"); //remove the player from the room state const index = this.state.players.findIndex(p => p.clientId == client.id); const player = this.state.players.find(p => p.clientId == client.id); SimulationEvents_1.SimulationEventEmitter.emit(SimulationEvents_1.SimulationEvents.PlayerLeft, player); if (player) { this.state.players.splice(index, 1); } }); } } exports.LeaveCommand = LeaveCommand;