@drincs/nqtr
Version:
A complete system introducing the concepts of location, time and event, producing the framework of a not-quite-point-and-click adventure game.
1 lines • 5.45 kB
Source Map (JSON)
{"version":3,"sources":["../../src/decorators/RoomDecorator.ts","../../src/managers/NavigatorManager.ts"],"names":["registeredRooms","getRoomById","id","room","CURRENT_ROOM_MEMORY_KEY","NavigatorManager","result","roomId","storage","_"],"mappings":"sCAEO,IAAMA,CAAAA,CAAmD,EA2BzD,CAAA,SAASC,CAAYC,CAAAA,CAAAA,CAAuC,CAClE,GAAI,CACH,IAAIC,CAAAA,CAAOH,CAAgBE,CAAAA,CAAE,CAC7B,CAAA,GAAI,CAACC,CAAM,CAAA,CACV,OAAQ,CAAA,KAAA,CAAM,CAAeD,YAAAA,EAAAA,CAAE,YAAY,CAC3C,CAAA,MACD,CACA,OAAOC,CACR,CAAA,MAAS,EAAG,CACX,OAAA,CAAQ,KAAM,CAAA,CAAA,gCAAA,EAAmCD,CAAE,CAAA,CAAA,CAAI,CAAC,CACxD,CAAA,MACD,CACD,CCrCME,IAAAA,CAAAA,CAA0B,iCACXC,CAArB,CAAA,KAAsC,CAClC,IAAI,KAAQ,EAAA,CACR,OAAO,MAAO,CAAA,MAAA,CAAOL,CAAe,CACxC,CACA,IAAI,WAAY,CACZ,IAAIM,CAA8C,CAAA,EAClD,CAAA,OAAA,MAAA,CAAO,OAAON,CAAe,CAAA,CAAE,OAASG,CAAAA,CAAAA,EAAS,CAC7CG,CAAAA,CAAOH,EAAK,QAAS,CAAA,EAAE,CAAIA,CAAAA,CAAAA,CAAK,SACpC,CAAC,EACM,MAAO,CAAA,MAAA,CAAOG,CAAM,CAC/B,CACA,IAAI,MAAO,CACP,IAAIA,CAAyC,CAAA,EAC7C,CAAA,OAAA,MAAA,CAAO,OAAON,CAAe,CAAA,CAAE,OAASG,CAAAA,CAAAA,EAAS,CAC7CG,CAAAA,CAAOH,CAAK,CAAA,QAAA,CAAS,GAAI,CAAA,EAAE,CAAIA,CAAAA,CAAAA,CAAK,QAAS,CAAA,IACjD,CAAC,CACM,CAAA,MAAA,CAAO,MAAOG,CAAAA,CAAM,CAC/B,CACA,IAAI,WAAyC,EAAA,CACzC,IAAIC,CAAAA,CAASC,OAAQ,CAAA,WAAA,CAAoBJ,CAAuB,CAChE,CAAA,GAAI,CAACG,CAAAA,CAAQ,CACT,OAAA,CAAQ,MAAM,8CAA8C,CAAA,CAC5D,MACJ,CACA,IAAIJ,CAAAA,CAAOF,EAAYM,CAAM,CAAA,CAC7B,GAAI,CAACJ,CAAM,CAAA,CACP,QAAQ,KAAM,CAAA,CAAA,oBAAA,EAAuBI,CAAM,CAAA,UAAA,CAAY,CACvD,CAAA,MACJ,CACA,OAAOJ,CACX,CACA,IAAI,WAAYA,CAAAA,CAAAA,CAA8B,CAK1C,GAJI,OAAOA,CAAS,EAAA,QAAA,GAChBA,CAAOA,CAAAA,CAAAA,CAAK,IAGZ,CADkBF,CAAAA,CAAYE,CAAI,CAAA,CAChB,CAClB,OAAA,CAAQ,MAAM,CAAmBA,gBAAAA,EAAAA,CAAI,CAAwD,sDAAA,CAAA,CAAA,CAC7F,MACJ,CACAK,QAAQ,WAAYJ,CAAAA,CAAAA,CAAyBD,CAAI,EACrD,CACA,IAAI,iBAAiD,CACjD,OAAO,IAAK,CAAA,WAAA,EAAa,QAC7B,CACA,IAAI,UAAuC,EAAA,CACvC,OAAO,IAAA,CAAK,WAAa,EAAA,QAAA,CAAS,GACtC,CAIA,sBAAA,EAAyB,CACrB,MAAA,CAAO,OAAQH,CAAAA,CAAe,EAAE,OAAQ,CAAA,CAAC,CAACS,CAAAA,CAAGN,CAAI,CAAA,GAAM,CACnDA,CAAAA,CAAK,sBAAuB,GAChC,CAAC,EACL,CACJ","file":"NavigatorManager.mjs","sourcesContent":["import { RoomInterface } from \"../interface\";\n\nexport const registeredRooms: { [id: string]: RoomInterface } = {};\n\n/**\n * Save a room in the registered rooms. If the room already exists, it will be overwritten.\n * @param room The room to save.\n * @returns\n * @example\n * ```ts\n * saveRoom([mcRoom, aliceRoom, annRoom, bathroom, lounge, terrace, gymRoom]);\n * ```\n */\nexport function saveRoom(room: RoomInterface | RoomInterface[]) {\n\tif (Array.isArray(room)) {\n\t\troom.forEach((c) => saveRoom(c));\n\t\treturn;\n\t}\n\tif (registeredRooms[room.id]) {\n\t\tconsole.warn(`[NQTR] Room id ${room.id} already exists, it will be overwritten`);\n\t}\n\tregisteredRooms[room.id] = room;\n}\n\n/**\n * Get a room by its id.\n * @param id The id of the room.\n * @returns The room or undefined if not found.\n */\nexport function getRoomById(id: string): RoomInterface | undefined {\n\ttry {\n\t\tlet room = registeredRooms[id];\n\t\tif (!room) {\n\t\t\tconsole.error(`[NQTR] Room ${id} not found`);\n\t\t\treturn;\n\t\t}\n\t\treturn room;\n\t} catch (e) {\n\t\tconsole.error(`[NQTR] Error while getting Room ${id}`, e);\n\t\treturn;\n\t}\n}\n","import { storage } from \"@drincs/pixi-vn\";\nimport { getRoomById, registeredRooms } from \"../decorators/RoomDecorator\";\nimport { LocationInterface, MapInterface, RoomInterface } from \"../interface\";\n\nconst CURRENT_ROOM_MEMORY_KEY = \"___nqtr-current_room_memory___\";\nexport default class NavigatorManager {\n get rooms() {\n return Object.values(registeredRooms);\n }\n get locations() {\n let result: { [id: string]: LocationInterface } = {};\n Object.values(registeredRooms).forEach((room) => {\n result[room.location.id] = room.location;\n });\n return Object.values(result);\n }\n get maps() {\n let result: { [id: string]: MapInterface } = {};\n Object.values(registeredRooms).forEach((room) => {\n result[room.location.map.id] = room.location.map;\n });\n return Object.values(result);\n }\n get currentRoom(): RoomInterface | undefined {\n let roomId = storage.getVariable<string>(CURRENT_ROOM_MEMORY_KEY);\n if (!roomId) {\n console.error(`[NQTR] The current room has not yet been set`);\n return;\n }\n let room = getRoomById(roomId);\n if (!room) {\n console.error(`[NQTR] Current room ${roomId} not found`);\n return;\n }\n return room;\n }\n set currentRoom(room: RoomInterface | string) {\n if (typeof room !== \"string\") {\n room = room.id;\n }\n let roomRegistrated = getRoomById(room);\n if (!roomRegistrated) {\n console.error(`[NQTR] The room ${room} is not registered, so it can't be set as current room`);\n return;\n }\n storage.setVariable(CURRENT_ROOM_MEMORY_KEY, room);\n }\n get currentLocation(): LocationInterface | undefined {\n return this.currentRoom?.location;\n }\n get currentMap(): MapInterface | undefined {\n return this.currentRoom?.location.map;\n }\n /**\n * Clear all the expired activities.\n */\n clearExpiredActivities() {\n Object.entries(registeredRooms).forEach(([_, room]) => {\n room.clearExpiredActivities();\n });\n }\n}\n"]}