UNPKG

@dev-dungeon/mud-engine

Version:

TypeScript game engine library for MUDs that handles core logic, including entity creation, room management, and game interactions in a modular and extensible way.

162 lines (154 loc) 4.8 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var index_exports = {}; __export(index_exports, { Area: () => Area, AreaFactory: () => AreaFactory, Orientation: () => Orientation, Place: () => Place, PlaceType: () => PlaceType, RoomPlaceFactory: () => RoomPlaceFactory }); module.exports = __toCommonJS(index_exports); var import_register = require("module-alias/register"); // src/domain/entities/area/Area.ts var Area = class { constructor(id = "", name = "", maximumLevel = 1, minimumLevel = 1, places = []) { this.id = id; this.name = name; this.maximumLevel = maximumLevel; this.minimumLevel = minimumLevel; this.places = places; } addPlace(place) { this.places.push(place); } removePlace(placeId) { this.places = this.places.filter((place) => place.id !== placeId); } }; // src/domain/entities/place/Place.ts var Place = class { constructor(attrs = [], code, exits = [], id = "", isExitToOtherArea = false, npcs = [], placeType, players = [], security) { this.attrs = attrs; this.code = code; this.exits = exits; this.id = id; this.isExitToOtherArea = isExitToOtherArea; this.npcs = npcs; this.placeType = placeType; this.players = players; this.security = security; } addPlayer(player) { const playerExists = this.players.find((p) => p.id === player.id); if (!playerExists) this.players.push(player); } removePlayer(playerId) { this.players = this.players.filter((player) => player.id !== playerId); } addNpc(npc) { const npcExists = this.npcs.find((npc2) => npc2.id === npc2.id); if (!npcExists) this.npcs.push(npc); } removeNpc(npcName) { this.npcs = this.npcs.filter((npc) => npc.name !== npcName); } addExit(exit) { const currentPlace = this.exits.find((e) => e.id === exit.id); if (currentPlace) throw new Error(`the site already has an exit to ${exit.id}`); const orientation = this.exits.find( (e) => e.orientation === exit.orientation ); if (orientation) throw new Error(`the site already has an exit to ${exit.orientation}`); this.exits.push(exit); } removeExit(exitId) { this.exits = this.exits.filter((e) => e.id !== exitId); } getVisibleExits() { return this.exits.filter((e) => e.visible && !e.disabled); } toJSON() { return { attrs: this.attrs, code: this.code, exits: this.exits, id: this.id, isExitToOtherArea: this.isExitToOtherArea, npcs: this.npcs, placeType: this.placeType, players: this.players, security: this.security }; } }; // src/domain/entities/place/Place.enums.ts var PlaceType = /* @__PURE__ */ ((PlaceType2) => { PlaceType2["ROOM"] = "ROOM"; PlaceType2["CITY"] = "CITY"; PlaceType2["FOREST"] = "FOREST"; return PlaceType2; })(PlaceType || {}); var Orientation = /* @__PURE__ */ ((Orientation2) => { Orientation2["N"] = "N"; Orientation2["S"] = "S"; Orientation2["E"] = "E"; Orientation2["W"] = "W"; Orientation2["NE"] = "NE"; Orientation2["SE"] = "SE"; Orientation2["SW"] = "SW"; Orientation2["NW"] = "NW"; Orientation2["UP"] = "UP"; Orientation2["DOWN"] = "DOWN"; return Orientation2; })(Orientation || {}); // src/domain/factories/area/Creator.ts var Creator = class { }; var Creator_default = Creator; // src/domain/factories/area/AreaFactory.ts var AreaFactory = class extends Creator_default { createArea(name) { return new Area("", name, 1, 1, []); } }; // src/domain/factories/place/Creator.ts var Creator2 = class { }; var Creator_default2 = Creator2; // src/domain/factories/place/RoomPlaceFactory.ts var RoomPlaceFactory = class extends Creator_default2 { createPlace(code, security) { return new Place([], code, [], "", false, [], "ROOM" /* ROOM */, [], security); } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Area, AreaFactory, Orientation, Place, PlaceType, RoomPlaceFactory }); //# sourceMappingURL=index.cjs.map