@drincs/nqtr 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/dist/{StageProps-CJSp_a54.d.mts → StageProps-W85kcacG.d.mts} +3 -3
  2. package/dist/{StageProps-CV4rWD7t.d.ts → StageProps-vR-NLl0n.d.ts} +3 -3
  3. package/dist/classes/index.d.mts +1 -1
  4. package/dist/classes/index.d.ts +1 -1
  5. package/dist/classes/index.js +3 -3
  6. package/dist/classes/index.js.map +1 -1
  7. package/dist/classes/index.mjs +3 -3
  8. package/dist/classes/index.mjs.map +1 -1
  9. package/dist/classes/navigation/Room.js.map +1 -1
  10. package/dist/classes/navigation/Room.mjs.map +1 -1
  11. package/dist/classes/quest/Quest.d.mts +1 -1
  12. package/dist/classes/quest/Quest.d.ts +1 -1
  13. package/dist/classes/quest/Quest.js +3 -3
  14. package/dist/classes/quest/Quest.js.map +1 -1
  15. package/dist/classes/quest/Quest.mjs +3 -3
  16. package/dist/classes/quest/Quest.mjs.map +1 -1
  17. package/dist/classes/quest/Stage.d.mts +1 -1
  18. package/dist/classes/quest/Stage.d.ts +1 -1
  19. package/dist/classes/quest/Stage.js +3 -3
  20. package/dist/classes/quest/Stage.js.map +1 -1
  21. package/dist/classes/quest/Stage.mjs +3 -3
  22. package/dist/classes/quest/Stage.mjs.map +1 -1
  23. package/dist/decorators/QuestDecorator.d.mts +1 -1
  24. package/dist/decorators/QuestDecorator.d.ts +1 -1
  25. package/dist/decorators/QuestDecorator.js +3 -3
  26. package/dist/decorators/QuestDecorator.js.map +1 -1
  27. package/dist/decorators/QuestDecorator.mjs +3 -3
  28. package/dist/decorators/QuestDecorator.mjs.map +1 -1
  29. package/dist/decorators/index.d.mts +1 -1
  30. package/dist/decorators/index.d.ts +1 -1
  31. package/dist/decorators/index.js +3 -3
  32. package/dist/decorators/index.js.map +1 -1
  33. package/dist/decorators/index.mjs +3 -3
  34. package/dist/decorators/index.mjs.map +1 -1
  35. package/dist/functions/ActivityFunctions.js.map +1 -1
  36. package/dist/functions/ActivityFunctions.mjs.map +1 -1
  37. package/dist/functions/NavigationFunctions.js.map +1 -1
  38. package/dist/functions/NavigationFunctions.mjs.map +1 -1
  39. package/dist/functions/QuestFunctions.js.map +1 -1
  40. package/dist/functions/QuestFunctions.mjs.map +1 -1
  41. package/dist/functions/RoutineFunctions.js.map +1 -1
  42. package/dist/functions/RoutineFunctions.mjs.map +1 -1
  43. package/dist/functions/index.js.map +1 -1
  44. package/dist/functions/index.mjs.map +1 -1
  45. package/dist/index.d.mts +1 -1
  46. package/dist/index.d.ts +1 -1
  47. package/dist/index.js +3 -3
  48. package/dist/index.js.map +1 -1
  49. package/dist/index.mjs +3 -3
  50. package/dist/index.mjs.map +1 -1
  51. package/dist/interface/index.d.mts +1 -1
  52. package/dist/interface/index.d.ts +1 -1
  53. package/dist/interface/quest/QuestProps.d.mts +1 -1
  54. package/dist/interface/quest/QuestProps.d.ts +1 -1
  55. package/dist/interface/quest/StageProps.d.mts +1 -1
  56. package/dist/interface/quest/StageProps.d.ts +1 -1
  57. package/dist/override/{OnEndStage.d.mts → OnEndStageQuest.d.mts} +3 -3
  58. package/dist/override/{OnEndStage.d.ts → OnEndStageQuest.d.ts} +3 -3
  59. package/dist/override/{OnEndStage.js → OnEndStageQuest.js} +1 -1
  60. package/dist/override/OnEndStageQuest.mjs +3 -0
  61. package/dist/override/OnNextStageQuest.d.mts +19 -0
  62. package/dist/override/OnNextStageQuest.d.ts +19 -0
  63. package/dist/override/{OnStartStage.js → OnNextStageQuest.js} +1 -1
  64. package/dist/override/OnNextStageQuest.mjs +3 -0
  65. package/dist/override/{OnStartStage.d.mts → OnStartStageQuest.d.mts} +3 -3
  66. package/dist/override/{OnStartStage.d.ts → OnStartStageQuest.d.ts} +3 -3
  67. package/dist/override/OnStartStageQuest.js +4 -0
  68. package/dist/override/OnStartStageQuest.js.map +1 -0
  69. package/dist/override/OnStartStageQuest.mjs +3 -0
  70. package/dist/override/OnStartStageQuest.mjs.map +1 -0
  71. package/dist/override/index.d.mts +3 -2
  72. package/dist/override/index.d.ts +3 -2
  73. package/dist/types/QuestsRequired.d.mts +1 -1
  74. package/dist/types/QuestsRequired.d.ts +1 -1
  75. package/dist/types/index.d.mts +1 -1
  76. package/dist/types/index.d.ts +1 -1
  77. package/package.json +1 -1
  78. package/dist/override/OnEndStage.mjs +0 -3
  79. package/dist/override/OnStartStage.mjs +0 -3
  80. /package/dist/override/{OnEndStage.js.map → OnEndStageQuest.js.map} +0 -0
  81. /package/dist/override/{OnEndStage.mjs.map → OnEndStageQuest.mjs.map} +0 -0
  82. /package/dist/override/{OnStartStage.js.map → OnNextStageQuest.js.map} +0 -0
  83. /package/dist/override/{OnStartStage.mjs.map → OnNextStageQuest.mjs.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/decorators/RoomDecorator.ts","../../src/functions/NavigationFunctions.ts","../../src/classes/Commitment.ts","../../src/managers/TimeManager.ts","../../src/classes/ActivityStoredAbstract.ts","../../src/classes/navigation/Location.ts","../../src/classes/navigation/Map.ts","../../src/classes/navigation/Room.ts","../../src/classes/Activity.ts","../../src/decorators/CommitmentDecorator.ts","../../src/classes/quest/Quest.ts","../../src/classes/quest/Stage.ts","../../src/classes/quest/Goal.ts","../../src/functions/ActivityFunctions.ts"],"names":["GameStorageManager","getFlag","StoredClassModel"],"mappings":";AAEO,IAAM,kBAAmD,CAAC;AA2B1D,SAAS,YAAyD,IAA+B;AACpG,MAAI;AACA,QAAI,OAAO,gBAAgB,EAAE;AAC7B,QAAI,CAAC,MAAM;AACP,cAAQ,MAAM,eAAe,EAAE,YAAY;AAC3C;AAAA,IACJ;AACA,WAAO;AAAA,EACX,SACO,GAAG;AACN,YAAQ,MAAM,mCAAmC,EAAE,IAAI,CAAC;AACxD;AAAA,EACJ;AACJ;;;AC1CA,SAAS,sBAAAA,2BAA0B;;;ACCnC,SAA6B,SAAS,wBAAwB;;;ACD9D,SAAS,0BAA0B;;;ACCnC,SAAS,WAAAC,gBAAe;;;ACAxB,SAAS,WAAAA,UAAS,oBAAAC,yBAAwB;;;ACA1C,SAAS,WAAAD,UAAS,oBAAAC,yBAAwB;;;ACA1C,SAAS,WAAAD,UAAS,oBAAAC,yBAAwB;;;ACA1C,SAAS,WAAAD,gBAAe;;;ACDxB,SAAS,sBAAAD,2BAA0B;;;ACCnC,SAAS,oBAAAE,yBAAwB;;;ACAjC,SAAS,oBAAAA,mBAAkB,WAAAD,gBAAe;;;ACD1C,SAAS,oBAAAC,yBAAwB;;;AXIjC,IAAM,0BAA0B;AA8BzB,SAAS,iBAAiF;AAC7F,MAAI,SAASF,oBAAmB,YAAoB,uBAAuB;AAC3E,MAAI,CAAC,QAAQ;AACT,YAAQ,MAAM,8CAA8C;AAC5D;AAAA,EACJ;AACA,MAAI,OAAO,YAAmB,MAAM;AACpC,MAAI,CAAC,MAAM;AACP,YAAQ,MAAM,uBAAuB,MAAM,YAAY;AACvD;AAAA,EACJ;AACA,SAAO;AACX;;;AYvCO,SAAS,yBAAyB;AACrC,SAAO,QAAQ,eAAe,EAAE,QAAQ,CAAC,CAAC,GAAG,IAAI,MAAM;AACnD,SAAK,uBAAuB;AAAA,EAChC,CAAC;AACL;AAMO,SAAS,oBAAoC;AAChD,MAAI,cAAc,eAAe;AACjC,MAAI,CAAC,aAAa;AACd,WAAO,CAAC;AAAA,EACZ;AACA,SAAO,YAAY,WAAW,OAAO,cAAY,CAAC,SAAS,MAAM;AACrE","sourcesContent":["import { LocationBaseModel, MapBaseModel, RoomBaseModel } from \"../classes\"\n\nexport const registeredRooms: { [id: string]: RoomBaseModel } = {}\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<TRoom extends RoomBaseModel = RoomBaseModel>(room: TRoom | TRoom[]) {\n if (Array.isArray(room)) {\n room.forEach(c => saveRoom(c))\n return\n }\n if (registeredRooms[room.id]) {\n console.warn(`[NQTR] Room id ${room.id} already exists, it will be overwritten`)\n }\n registeredRooms[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<TRoom extends RoomBaseModel = RoomBaseModel>(id: string): TRoom | undefined {\n try {\n let room = registeredRooms[id]\n if (!room) {\n console.error(`[NQTR] Room ${id} not found`)\n return\n }\n return room as TRoom\n }\n catch (e) {\n console.error(`[NQTR] Error while getting Room ${id}`, e)\n return\n }\n}\n\n/**\n * Get all rooms in a location.\n * @param location The location where the rooms are.\n * @returns The rooms in the location.\n */\nexport function getRoomsByLocation<TRoom extends RoomBaseModel = RoomBaseModel>(location: LocationBaseModel): TRoom[] {\n return Object.values(registeredRooms).filter(room => room.location.id === location.id) as TRoom[]\n}\n\n/**\n * Get all locations in the registered rooms.\n * @returns All locations in the registered rooms.\n */\nexport function getAllLocations<TLocation extends LocationBaseModel = LocationBaseModel>(): TLocation[] {\n let result: { [id: string]: TLocation } = {}\n Object.values(registeredRooms).forEach(room => {\n result[room.location.id] = room.location as TLocation\n })\n return Object.values(result)\n}\n\n/**\n * Get all locations in a map.\n * @param map The map where the locations are.\n * @returns The locations in the map.\n */\nexport function getLocationsByMap<TLocation extends LocationBaseModel = LocationBaseModel>(map: MapBaseModel): TLocation[] {\n return getAllLocations<TLocation>().filter(location => location.map.id === map.id) as TLocation[]\n}\n\n/**\n * Get all maps in the registered rooms.\n * @returns All maps in the registered rooms.\n */\nexport function getAllMaps<TMap extends MapBaseModel = MapBaseModel>(): TMap[] {\n let result: { [id: string]: TMap } = {}\n Object.values(registeredRooms).forEach(room => {\n result[room.location.map.id] = room.location.map as TMap\n })\n return Object.values(result)\n}\n","import { GameStorageManager } from \"@drincs/pixi-vn\";\nimport { LocationBaseModel, MapBaseModel, RoomBaseModel } from \"../classes\";\nimport { getRoomById } from \"../decorators/RoomDecorator\";\n\nconst CURRENT_ROOM_MEMORY_KEY = '___nqtr-current_room_memory___';\n\n/**\n * Set the current room.\n * @param room The room to set as current room.\n * @returns\n */\nexport function setCurrentRoom<TRoom extends RoomBaseModel = RoomBaseModel>(room: TRoom | LocationBaseModel) {\n if (room instanceof LocationBaseModel) {\n let entrance = room.getEntrance<TRoom>();\n if (!entrance) {\n console.error(`[NQTR] The location ${room.id} has no entrance room`);\n return;\n }\n room = entrance;\n }\n else {\n let roomRegistrated = getRoomById(room.id);\n if (!roomRegistrated) {\n console.error(`[NQTR] The room ${room.id} is not registered, so it can't be set as current room`);\n return;\n }\n }\n GameStorageManager.setVariable(CURRENT_ROOM_MEMORY_KEY, room.id);\n}\n\n/**\n * Get the current room.\n * @returns The current room or undefined if not set.\n */\nexport function getCurrentRoom<TRoom extends RoomBaseModel = RoomBaseModel>(): TRoom | undefined {\n let roomId = GameStorageManager.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<TRoom>(roomId);\n if (!room) {\n console.error(`[NQTR] Current room ${roomId} not found`);\n return\n }\n return room\n}\n\n/**\n * Get the current location.\n * @returns The current location or undefined if not set.\n */\nexport function getCurrenrLocation<TLocation extends LocationBaseModel = LocationBaseModel>(): TLocation | undefined {\n let room = getCurrentRoom<RoomBaseModel<TLocation>>();\n if (!room) {\n return\n }\n return room.location\n}\n\n/**\n * Get the current map.\n * @returns The current map or undefined if not set.\n */\nexport function getCurrentMap<TMap extends MapBaseModel = MapBaseModel>(): TMap | undefined {\n let location = getCurrenrLocation<LocationBaseModel<TMap>>();\n if (!location) {\n return\n }\n return location.map\n}\n","import { GraphicItemType, OnRenderGraphicItemProps, OnRunProps } from \"@drincs/nqtr/dist/override\";\nimport { CharacterBaseModel, getFlag, StoredClassModel } from \"@drincs/pixi-vn\";\nimport { CommitmentProps } from \"../interface\";\nimport TimeManager from \"../managers/TimeManager\";\nimport { ExecutionType } from \"../types\";\nimport { OnRunCommitmentEvent } from \"../types/OnRunCommitmentEvent\";\nimport RoomBaseModel from \"./navigation/Room\";\n\nconst COMMITMENT_CATEGORY = \"__nqtr-commitment__\"\n\n/**\n * The base model of a commitment. I suggest you extend this class to create your own commitment model.\n * You must use the saveRoom function to save the commitment in the registered commitments.\n * @example\n * ```ts\n * export const mcRoom = new CommitmentBaseModel(\"test\", character, room, {\n * name: \"Test\",\n * image: \"https://image.jpg\",\n * executionType: ExecutionTypeEnum.INTERACTION,\n * onRun: (commitment) => {\n * // Do something\n * }\n * })\n * saveCommitment(mcRoom)\n * ```\n */\nexport default class CommitmentBaseModel<TCharacter extends CharacterBaseModel = CharacterBaseModel, TRoom extends RoomBaseModel = RoomBaseModel> extends StoredClassModel {\n /**\n * @param id The id of the commitment, it must be unique.\n * @param character The character or characters that are in the commitment and so in the room.\n * @param room The room where the commitment is.\n * @param props The properties of the commitment.\n */\n constructor(id: string, character: TCharacter | TCharacter[] | undefined, room: TRoom, props: CommitmentProps<TCharacter, TRoom>) {\n super(COMMITMENT_CATEGORY, id)\n this._characters = character ? Array.isArray(character) ? character : [character] : []\n this._room = room\n this._name = props.name || \"\"\n this.defaultFromHour = props.fromHour\n this.defaultToHour = props.toHour\n this.defaultFromDay = props.fromDay\n this.defaultToDay = props.toDay\n this._renderImage = props.renderImage\n this._executionType = props.executionType || \"interaction\"\n this._onRun = props.onRun\n this.defaultDisabled = props.disabled || false\n this.defaultHidden = props.hidden || false\n this._renderIcon = props.renderIcon\n this.defaultPriority = props.priority || 0\n }\n\n private _characters: TCharacter[]\n /**\n * The character or characters that are in the commitment and so in the room.\n */\n get characters(): TCharacter[] {\n return this._characters\n }\n\n private _room: TRoom\n /**\n * The room where the commitment is.\n */\n get room(): TRoom {\n return this._room\n }\n\n private _name: string\n /**\n * The name\n */\n get name(): string {\n return this._name\n }\n\n private defaultFromHour?: number\n /**\n * The hour when the commitment starts. If the commitment is not started yet, it will be hidden.\n * If you set undefined, it will return the initial value of fromHour.\n */\n get fromHour(): number {\n return this.getStorageProperty<number>(\"fromHour\") || this.defaultFromHour || TimeManager.minDayHours\n }\n set fromHour(value: number | undefined) {\n this.setStorageProperty(\"fromHour\", value)\n }\n\n private defaultToHour?: number\n /**\n * The hour when the commitment ends. If the commitment is ended yet, it will be hidden.\n * If you set undefined, it will return the initial value of toHour.\n */\n get toHour(): number {\n return this.getStorageProperty<number>(\"toHour\") || this.defaultToHour || (TimeManager.maxDayHours + 1)\n }\n set toHour(value: number | undefined) {\n this.setStorageProperty(\"toHour\", value)\n }\n\n private defaultFromDay?: number\n /**\n * The day when the commitment starts. If the commitment is not started yet, it will be hidden.\n * If you set undefined, it will return the initial value of fromDay.\n */\n get fromDay(): number | undefined {\n return this.getStorageProperty<number>(\"fromDay\") || this.defaultFromDay\n }\n set fromDay(value: number | undefined) {\n this.setStorageProperty(\"fromDay\", value)\n }\n\n private defaultToDay?: number\n /**\n * The day when the commitment ends. If the commitment is ended yet, it will be deleted or hidden.\n * If you set undefined, it will return the initial value of toDay.\n */\n get toDay(): number | undefined {\n return this.getStorageProperty<number>(\"toDay\") || this.defaultToDay\n }\n set toDay(value: number | undefined) {\n this.setStorageProperty(\"toDay\", value)\n }\n\n private _renderImage?: GraphicItemType | ((commitment: CommitmentBaseModel<TCharacter, TRoom>, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the image of the room.\n */\n get renderImage(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderImage\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private _executionType: ExecutionType\n /**\n * Execution type. If is \"automatic\" the onRun() runned automatically when the palayer is in the room. If is \"interaction\" the player must interact with the character to run the onRun() function.\n * If you set \"automatic\" remember to remove the commitment when it is no longer needed, because otherwise it repeats itself every time.\n */\n get executionType(): ExecutionType {\n return this._executionType\n }\n\n private _renderIcon?: GraphicItemType | ((commitment: CommitmentBaseModel, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the icon of the commitment.\n */\n get renderIcon(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderIcon\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private _onRun?: OnRunCommitmentEvent<CommitmentBaseModel>\n /**\n * Is a function that is called when the player interacts with the character.\n */\n get run(): undefined | ((props: OnRunProps) => void) {\n let onRun = this._onRun\n if (!onRun) {\n return\n }\n return (props) => onRun(this, props)\n }\n\n private defaultDisabled: boolean | string\n /**\n * Whether is disabled. You can also pass a Pixi'VN flag name.\n */\n get disabled(): boolean {\n let value = this.getStorageProperty<boolean>(\"disabled\") || this.defaultDisabled\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set disabled(value: boolean | string) {\n this.setStorageProperty(\"disabled\", value)\n }\n\n private defaultHidden: boolean | string\n /**\n * Whether is hidden. You can also pass a Pixi'VN flag name.\n */\n get hidden(): boolean {\n if (this.fromDay && this.fromDay > TimeManager.currentDay) {\n return true\n }\n if (!TimeManager.nowIsBetween(this.fromHour, this.toHour)) {\n return true\n }\n if (!this.isExpired) {\n return true\n }\n let value = this.getStorageProperty<boolean>(\"hidden\") || this.defaultHidden\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set hidden(value: boolean | string) {\n this.setStorageProperty(\"hidden\", value)\n }\n\n private defaultPriority: number\n /**\n * The priority. The higher the number, the higher the priority.\n * To ensure that a character is not in 2 places at the same time, if there are 2 or more valid commits at the same time and with the same character, the one with the highest priority will be chosen.\n */\n get priority(): number {\n return this.getStorageProperty<number>(\"priority\") || this.defaultPriority || 0\n }\n set priority(value: number) {\n this.setStorageProperty(\"priority\", value)\n }\n\n /**\n * Whether the commitment is expired.\n * @returns Whether the commitment is expired.\n */\n isExpired(): boolean {\n if (this.toDay && this.toDay <= TimeManager.currentDay) {\n return true\n }\n return false\n }\n}\n","import { GameStorageManager } from \"@drincs/pixi-vn\";\nimport { ITimeStlot, TimeSettings } from \"../types/TimeSettings\";\n\nconst TIME_SETTINGS_KEY = '___nqtr-time_manager_settings___';\nconst TIME_DATA_KEY = '___nqtr-time_manager_data___';\n\ntype ITimeData = {\n currentHour?: number\n currentDay?: number\n}\n\nexport default class TimeManager {\n private constructor() { }\n private static editSettings(settings: TimeSettings) {\n let data: any = {}\n if (typeof settings.minDayHours === 'number') {\n data['minDayHours'] = settings.minDayHours\n }\n if (typeof settings.maxDayHours === 'number') {\n data['maxDayHours'] = settings.maxDayHours\n }\n if (typeof settings.minDayHours === 'number') {\n data['defaultTimeSpent'] = settings.defaultTimeSpent\n }\n if (Array.isArray(settings.timeSlots)) {\n data['timeSlots'] = settings.timeSlots\n }\n if (typeof settings.weekLength === 'number') {\n data['weekLength'] = settings.weekLength\n }\n if (typeof settings.weekendStartDay === 'number') {\n let weekLength = settings.weekLength || TimeManager.weekLength\n if (settings.weekendStartDay >= weekLength) {\n console.warn(`[NQTR] Weekend start day should be less than week length ${weekLength}`)\n }\n data['weekendStartDay'] = settings.weekendStartDay\n }\n if (Array.isArray(settings.weekDaysNames)) {\n let weekLength = settings.weekLength || TimeManager.weekLength\n if (settings.weekDaysNames.length !== weekLength) {\n console.warn(`[NQTR] Week days names should be equal to week length ${weekLength}`)\n }\n data['weekDaysNames'] = settings.weekDaysNames\n }\n GameStorageManager.setVariable(TIME_SETTINGS_KEY, data)\n }\n /**\n * Get time settings\n * @default {}\n */\n static get settings(): TimeSettings {\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY) || {}\n return settings\n }\n /**\n * Set time settings, Is very important to set the settings before using the nqtr library, bacause more of the features are based on the time settings.\n */\n static set settings(value: TimeSettings) {\n TimeManager.editSettings(value)\n }\n static get minDayHours(): number {\n let result = 0\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('minDayHours')) {\n result = settings.minDayHours || 0\n }\n return result\n }\n static get maxDayHours(): number {\n let result = 24\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('maxDayHours')) {\n result = settings.maxDayHours || 24\n }\n return result\n }\n static get defaultTimeSpent(): number {\n let result = 1\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('defaultTimeSpent')) {\n result = settings.defaultTimeSpent || 1\n }\n return result\n }\n static get timeSlots(): ITimeStlot[] {\n let result: ITimeStlot[] = []\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('timeSlots')) {\n result = settings.timeSlots || []\n }\n return result\n }\n static get weekLength(): number {\n let result = 7\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('weekLength')) {\n result = settings.weekLength || 7\n }\n return result\n }\n static get weekendStartDay(): number {\n let result = TimeManager.weekLength - 1\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('weekendStartDay')) {\n result = settings.weekendStartDay || TimeManager.weekLength - 1\n }\n return result\n }\n static get weekDaysNames(): string[] {\n let result: string[] = []\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('weekDaysNames')) {\n result = settings.weekDaysNames || result\n }\n return result\n }\n\n /**\n * Get the current hour\n */\n static get currentHour(): number {\n let data = GameStorageManager.getVariable<ITimeData>(TIME_DATA_KEY) || {}\n if (data.hasOwnProperty('currentHour') && typeof data.currentHour === 'number') {\n return data.currentHour\n }\n return TimeManager.minDayHours\n }\n static set currentHour(value: number | undefined) {\n let data = GameStorageManager.getVariable<ITimeData>(TIME_DATA_KEY) || {}\n if (typeof value === 'number') {\n data.currentHour = value\n } else {\n delete data.currentHour\n }\n GameStorageManager.setVariable(TIME_DATA_KEY, data)\n }\n /**\n * Get the current day\n */\n static get currentDay(): number {\n let data = GameStorageManager.getVariable<ITimeData>(TIME_DATA_KEY) || {}\n if (data.hasOwnProperty('currentDay') && typeof data.currentDay === 'number') {\n return data.currentDay\n }\n return 0\n }\n static set currentDay(value: number | undefined) {\n let data = GameStorageManager.getVariable<ITimeData>(TIME_DATA_KEY) || {}\n if (typeof value === 'number') {\n data.currentDay = value\n }\n else {\n delete data.currentDay\n }\n GameStorageManager.setVariable(TIME_DATA_KEY, data)\n }\n /**\n * If the current day is greater than or equal to the weekend start day, then it will return true.\n */\n static get isWeekend(): boolean {\n return TimeManager.currentWeekDayNumber >= TimeManager.weekendStartDay\n }\n /**\n * Get the current week day number (1-TimeManager.weekLength).\n * For example, if the week length is 7 and the current day is 10, then the result will be 4.\n */\n static get currentWeekDayNumber(): number {\n let result = TimeManager.currentDay % TimeManager.weekLength\n return result + 1\n }\n /**\n * Get the current week day name. If the week days names are not defined, then it will return undefined.\n * For example, if the week days names are ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] and the current day is 10, then the result will be 'Thursday'.\n * @default \"\"\n */\n static get currentDayName(): string {\n let weekDayNumber = TimeManager.currentWeekDayNumber - 1\n if (weekDayNumber >= TimeManager.weekDaysNames.length) {\n console.warn(`[NQTR] Week day name is not defined for day ${weekDayNumber}`, TimeManager.weekDaysNames)\n return \"\"\n }\n return TimeManager.weekDaysNames[weekDayNumber]\n }\n /**\n * Get the current TimeManager.timeSlots index.\n * You can use this property to create \"Image that changes based on the time period\":\n * @example\n * ```tsx\n * import { TimeManager } from '@drincs/nqtr';\n * \n * function changeBackground() {\n * return (\n * <img src={`background-${TimeManager.currentTimeSlot}.png`} />\n * )\n * }\n */\n static get currentTimeSlot(): number {\n if (TimeManager.timeSlots.length === 0) {\n console.warn('[NQTR] Time slots are not defined')\n return 0\n }\n for (let index = 0; index < TimeManager.timeSlots.length; index++) {\n let slot = TimeManager.timeSlots[index]\n if (TimeManager.timeSlots.length > index + 1) {\n if (TimeManager.nowIsBetween(slot.startHour, TimeManager.timeSlots[index + 1].startHour)) {\n return index\n }\n }\n }\n return TimeManager.timeSlots.length - 1\n }\n\n /**\n * This function will increase the current hour by the given time spent.\n * If the new hour is greater than or equal to the max day hours, then it will increase the day and set the new hour.\n * @param timeSpent is the time spent in hours (default: TimeManager.defaultTimeSpent)\n * @returns TimeManager.currentHour\n */\n static increaseHour(timeSpent: number = TimeManager.defaultTimeSpent): number {\n let newHour = TimeManager.currentHour + timeSpent\n if (newHour >= TimeManager.maxDayHours) {\n TimeManager.increaseDay()\n newHour = TimeManager.minDayHours + (newHour - TimeManager.maxDayHours)\n }\n TimeManager.currentHour = newHour\n return TimeManager.currentHour\n }\n\n /**\n * This function will increase the current day by the given days.\n * @param newDayHour is the hour of the new day (default: TimeManager.minDayHours)\n * @param days is the number of days to increase (default: 1)\n * @returns TimeManager.currentDay\n */\n static increaseDay(newDayHour: number = TimeManager.minDayHours, days: number = 1): number {\n let newDay = TimeManager.currentDay + days\n TimeManager.currentDay = newDay\n TimeManager.currentHour = newDayHour\n return TimeManager.currentDay\n }\n\n /**\n * This function will check if the current hour is between the given hours.\n * @param fromHour the starting hour. If the TimeManager.currentHour is equal to this hour, the function will return true.\n * @param toHour the ending hour.\n * @returns true if the current hour is between the given hours, otherwise false.\n */\n static nowIsBetween(fromHour: number, toHour: number): boolean {\n let currentHour = TimeManager.currentHour\n if (fromHour < toHour) {\n return currentHour >= fromHour && currentHour < toHour\n }\n return currentHour >= fromHour || currentHour < toHour\n }\n}\n","import { GraphicItemType, OnRenderGraphicItemProps, OnRunProps } from \"@drincs/nqtr/dist/override\"\nimport { getFlag } from \"@drincs/pixi-vn\"\nimport { ActivityProps } from \"../interface\"\nimport { TimeManager } from \"../managers\"\nimport { OnRunActivityEvent } from \"../types/OnRunActivityEvent\"\n\nexport abstract class ActivityStoredAbstract {\n /**\n * @param onRun The function that is called when the activity is runned. Have 2 parameters: the runned activity and the yourParams object, that is an object with the parameters that you want to pass to the onRun function.\n * @param props The activity properties.\n */\n constructor(onRun: OnRunActivityEvent<ActivityStoredAbstract>, props: ActivityProps) {\n this.defaultName = props.name\n this.defaultFromHour = props.fromHour\n this.defaultToHour = props.toHour\n this.defaultFromDay = props.fromDay\n this.defaultToDay = props.toDay\n this.defaultDisabled = props.disabled || false\n this.defaultHidden = props.hidden || false\n this._renderIcon = props.renderIcon\n this._onRun = onRun\n }\n\n abstract setStorageProperty<T>(propertyName: string, value: T | undefined): void;\n abstract getStorageProperty<T>(propertyName: string): T | undefined;\n abstract get id(): string\n\n private defaultName?: string\n /**\n * The name\n */\n get name(): string {\n return this.getStorageProperty<string>(\"name\") || this.defaultName || \"\"\n }\n set name(value: string | undefined) {\n this.setStorageProperty(\"name\", value)\n }\n\n private defaultFromHour?: number\n /**\n * The hour when the activity starts. If the activity is not started yet, it will be hidden.\n */\n get fromHour(): number {\n return this.getStorageProperty<number>(\"fromHour\") || this.defaultFromHour || TimeManager.minDayHours\n }\n set fromHour(value: number | undefined) {\n this.setStorageProperty(\"fromHour\", value)\n }\n\n private defaultToHour?: number\n /**\n * The hour when the activity ends. If the activity is ended yet, it will be hidden.\n */\n get toHour(): number {\n return this.getStorageProperty<number>(\"toHour\") || this.defaultToHour || (TimeManager.maxDayHours + 1)\n }\n set toHour(value: number | undefined) {\n this.setStorageProperty(\"toHour\", value)\n }\n\n private defaultFromDay?: number\n /**\n * The day when the activity starts. If the activity is not started yet, it will be hidden.\n */\n get fromDay(): number | undefined {\n return this.getStorageProperty<number>(\"fromDay\") || this.defaultFromDay\n }\n set fromDay(value: number | undefined) {\n this.setStorageProperty(\"fromDay\", value)\n }\n\n private defaultToDay?: number\n /**\n * The day when the activity ends. If the activity is ended yet, it will be deleted or hidden.\n */\n get toDay(): number | undefined {\n return this.getStorageProperty<number>(\"toDay\") || this.defaultToDay\n }\n set toDay(value: number | undefined) {\n this.setStorageProperty(\"toDay\", value)\n }\n\n private defaultDisabled: boolean | string\n /**\n * Whether is disabled.\n */\n get disabled(): boolean {\n let value = this.getStorageProperty<boolean>(\"disabled\") || this.defaultDisabled\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set disabled(value: boolean | string) {\n this.setStorageProperty(\"disabled\", value)\n }\n\n private defaultHidden: boolean | string\n /**\n * Whether is hidden. If the activity is not started yet, it will be hidden.\n */\n get hidden(): boolean {\n if (this.fromDay && this.fromDay > TimeManager.currentDay) {\n return true\n }\n if (!TimeManager.nowIsBetween(this.fromHour, this.toHour)) {\n return true\n }\n if (!this.isExpired) {\n return true\n }\n let value = this.getStorageProperty<boolean>(\"hidden\") || this.defaultHidden\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set hidden(value: boolean | string) {\n this.setStorageProperty(\"hidden\", value)\n }\n\n private _renderIcon?: GraphicItemType | ((activity: ActivityStoredAbstract, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the icon of the activity.\n */\n get renderIcon(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderIcon\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private _onRun: (activity: ActivityStoredAbstract, props: OnRunProps) => void\n /**\n * The function that is called when the activity is runned.\n */\n get run(): (props: OnRunProps) => void {\n return (props) => { return this._onRun(this, props) }\n }\n\n /**\n * Whether the activity is a deadline.\n * @returns Whether the activity is a deadline.\n */\n isExpired(): boolean {\n if (this.toDay && this.toDay <= TimeManager.currentDay) {\n return true\n }\n return false\n }\n\n /**\n * Export the activity properties.\n * @returns The activity properties.\n */\n export(): ActivityProps {\n return {\n name: this.getStorageProperty<string>(\"name\") || this.defaultName,\n fromHour: this.getStorageProperty<number>(\"fromHour\") || this.defaultFromHour,\n toHour: this.getStorageProperty<number>(\"toHour\") || this.defaultToHour,\n fromDay: this.getStorageProperty<number>(\"fromDay\") || this.defaultFromDay,\n toDay: this.getStorageProperty<number>(\"toDay\") || this.defaultToDay,\n disabled: this.getStorageProperty<boolean>(\"disabled\") || this.defaultDisabled,\n hidden: this.getStorageProperty<boolean>(\"hidden\") || this.defaultHidden,\n renderIcon: this._renderIcon\n }\n }\n}\n","import { GraphicItemType, OnRenderGraphicItemProps } from \"@drincs/nqtr/dist/override\";\nimport { getFlag, StoredClassModel } from \"@drincs/pixi-vn\";\nimport { getRoomsByLocation } from \"../../decorators/RoomDecorator\";\nimport { LocationProps } from \"../../interface\";\nimport MapBaseModel from \"./Map\";\nimport RoomBaseModel from \"./Room\";\n\nconst LOCATION_CATEGORY = \"__nqtr-location__\"\n\n/**\n * The base model of a location. I suggest you extend this class to create your own location model.\n * @example\n * ```typescript\n * export const mcHome = new LocationBaseModel('mc_home', mainMap, {\n * name: 'MC Home',\n * icon: \"https://icon.jpg\",\n * });\n * ```\n */\nexport default class LocationBaseModel<TMap extends MapBaseModel = MapBaseModel> extends StoredClassModel {\n /**\n * @param id The id of the location, it must be unique.\n * @param map The map where the location is.\n * @param props The properties of the location.\n */\n constructor(id: string, map: TMap, props: LocationProps<TMap> = {}) {\n super(LOCATION_CATEGORY, id)\n this.defaultName = props.name || \"\"\n this.defaultDisabled = props.disabled || false\n this.defaultHidden = props.hidden || false\n this._renderIcon = props.renderIcon\n this._map = map\n }\n\n private defaultName: string\n /**\n * The name of the location.\n * If you set undefined, it will return the initial value of name.\n */\n get name(): string {\n return this.getStorageProperty<string>(\"name\") || this.defaultName\n }\n set name(value: string | undefined) {\n this.setStorageProperty(\"name\", value)\n }\n\n private defaultDisabled: boolean | string\n /**\n * Whether is disabled. If it is a string, it is a Pixi'VN flag name.\n */\n get disabled(): boolean {\n let value = this.getStorageProperty<boolean>(\"disabled\") || this.defaultDisabled\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set disabled(value: boolean | string) {\n this.setStorageProperty(\"disabled\", value)\n }\n\n private defaultHidden: boolean | string\n /**\n * Whether is hidden. If it is a string, it is a Pixi'VN flag name.\n */\n get hidden(): boolean {\n let value = this.getStorageProperty<boolean>(\"hidden\") || this.defaultHidden\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set hidden(value: boolean | string) {\n this.setStorageProperty(\"hidden\", value)\n }\n\n private _renderIcon?: GraphicItemType | ((location: LocationBaseModel<TMap>, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the icon of the location.\n */\n get renderIcon(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderIcon\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private _map: TMap\n /**\n * The map where the location is.\n */\n get map(): TMap {\n return this._map\n }\n\n /**\n * Get the entrance room of the location.\n * You can cast the room to a specific type that extends RoomBaseModel.\n * @returns The entrance room or the first room if there is no entrance.\n * @example\n * ```typescript\n * const entranceHome = new RoomBaseModel(\"entrance-home\", home, { isEntrance: true })\n * saveRoom(entranceHome)\n * const home = new LocationBaseModel(\"home\", map, { name: \"Home\" })\n * \n * const entrance = home.getEntrance() // entrance === entranceHome\n * ```\n */\n getEntrance<TRoom extends RoomBaseModel = RoomBaseModel>(): TRoom | undefined {\n let rooms = this.getRooms<TRoom>()\n if (rooms.length === 0) {\n console.error(`[NQTR] The location ${this.id} has no rooms`)\n return\n }\n return rooms.find(room => room.isEntrance) || rooms[0]\n }\n\n /**\n * Get all rooms in the location.\n * You can cast the rooms to a specific type that extends RoomBaseModel.\n * @returns The rooms in the location.\n */\n getRooms<TRoom extends RoomBaseModel = RoomBaseModel>(): TRoom[] {\n return getRoomsByLocation<TRoom>(this)\n }\n}\n","import { GraphicItemType, OnRenderGraphicItemProps } from \"@drincs/nqtr/dist/override\"\nimport { getFlag, StoredClassModel } from \"@drincs/pixi-vn\"\nimport { getLocationsByMap } from \"../../decorators/RoomDecorator\"\nimport { MapProps } from \"../../interface\"\nimport LocationBaseModel from \"./Location\"\n\nconst MAP_CATEGORY = \"__nqtr-map__\"\n\n/**\n * The base model of a map. I suggest you extend this class to create your own map model.\n * @example\n * ```typescript\n * export const mainMap = new MapBaseModel('main_map', {\n * name: 'Main Map',\n * image: \"https://image.jpg\",\n * neighboringMaps: {\n * \"north\": \"atlanta_map_id\",\n * \"south\": \"miami_map_id\",\n * \"east\": \"new_york_map_id\",\n * \"west\": \"los_angeles_map_id\"\n * }\n * });\n * ```\n */\nexport default class MapBaseModel extends StoredClassModel {\n /**\n * @param id The id of the map, it must be unique.\n * @param props The properties of the map. \n */\n constructor(id: string, props: MapProps = {}) {\n super(MAP_CATEGORY, id)\n this.defaultName = props.name || \"\"\n this._renderImage = props.renderImage\n this.defaultDisabled = props.disabled || false\n this.defaultHidden = props.hidden || false\n }\n\n private defaultName: string\n /**\n * The name of the map.\n * If you set undefined, it will return the initial value of name.\n */\n get name(): string {\n return this.getStorageProperty<string>(\"name\") || this.defaultName\n }\n set name(value: string | undefined) {\n this.setStorageProperty(\"name\", value)\n }\n\n private _renderImage?: GraphicItemType | ((map: MapBaseModel, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the image of the map.\n */\n get renderImage(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderImage\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private defaultDisabled: boolean | string\n /**\n * Whether is disabled. If it is a string, it is a Pixi'VN flag name.\n */\n get disabled(): boolean {\n let value = this.getStorageProperty<boolean>(\"disabled\") || this.defaultDisabled\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set disabled(value: boolean | string) {\n this.setStorageProperty(\"disabled\", value)\n }\n\n private defaultHidden: boolean | string\n /**\n * Whether is hidden. If it is a string, it is a Pixi'VN flag name.\n */\n get hidden(): boolean {\n let value = this.getStorageProperty<boolean>(\"hidden\") || this.defaultHidden\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set hidden(value: boolean | string) {\n this.setStorageProperty(\"hidden\", value)\n }\n\n private _neighboringMaps?: { [key: string]: string }\n /**\n * The neighboring maps that are available in this map.\n * @example\n * ```ts\n * {\n * \"north\": \"atlanta_map_id\",\n * \"south\": \"miami_map_id\",\n * \"east\": \"new_york_map_id\",\n * \"west\": \"los_angeles_map_id\"\n * }\n * ```\n */\n get neighboringMaps(): { [key: string]: string } {\n return this._neighboringMaps || {}\n }\n set neighboringMaps(value: { [key: string]: string } | undefined) {\n this._neighboringMaps = value\n }\n\n /**\n * Get all locations in the map.\n * @returns The locations in the map.\n */\n getLocations<TLocation extends LocationBaseModel = LocationBaseModel>(): TLocation[] {\n return getLocationsByMap<TLocation>(this)\n }\n}\n","import { GraphicItemType, OnRenderGraphicItemProps } from \"@drincs/nqtr/dist/override\";\nimport { getFlag, StoredClassModel } from \"@drincs/pixi-vn\";\nimport { getActivityById, saveRoom } from \"../../decorators\";\nimport { getCurrentRoutine } from \"../../functions/RoutineFunctions\";\nimport { RoomProps } from \"../../interface\";\nimport { RoomActivityMemory } from \"../../interface/RoomActivityMemory\";\nimport ActivityModel from \"../Activity\";\nimport CommitmentBaseModel from \"../Commitment\";\nimport ActivityRoom from \"./ActivityRoom\";\nimport LocationBaseModel from \"./Location\";\n\nexport const ROOM_CATEGORY = \"__nqtr-room__\"\n\n/**\n * The base model of a room. I suggest you extend this class to create your own room model.\n * **You must use the {@link saveRoom} function to save the room in the registered rooms.**\n * @example\n * ```ts\n * export const mcRoom = new RoomBaseModel('mc_room', mcHome, {\n * name: \"MC Room\",\n * icon: \"https://icon.jpg\",\n * image: \"https://image.jpg\",\n * isEntrance: false,\n * })\n * saveRoom(mcRoom)\n * ```\n */\nexport default class RoomBaseModel<TLocation extends LocationBaseModel = LocationBaseModel> extends StoredClassModel {\n /**\n * @param id The id of the room, it must be unique.\n * @param location The location where the room is.\n * @param props The properties of the room.\n */\n constructor(id: string, location: TLocation, props: RoomProps<TLocation> = {}) {\n super(ROOM_CATEGORY, id)\n this._location = location\n this.defaultName = props.name || \"\"\n this._renderImage = props.renderImage\n this.defaultActivityIds = props.defaultActivities?.map(activity => activity.id) || []\n this.defaultDisabled = props.disabled || false\n this.defaultHidden = props.hidden || false\n this._renderIcon = props.renderIcon\n this._isEntrance = props.isEntrance\n }\n\n private _location: TLocation\n /**\n * The location where the room is.\n */\n get location(): TLocation {\n return this._location\n }\n\n private _isEntrance?: boolean\n /**\n * Whether is an entrance room, so when the player enters in the location, it will be the first room to be shown.\n */\n get isEntrance(): boolean {\n return this._isEntrance || false\n }\n\n private defaultName: string\n /**\n * The name.\n * If you set undefined, it will return the initial value of name.\n */\n get name(): string {\n return this.getStorageProperty<string>(\"name\") || this.defaultName\n }\n set name(value: string | undefined) {\n this.setStorageProperty(\"name\", value)\n }\n\n private _renderImage?: GraphicItemType | ((room: RoomBaseModel<TLocation>, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the image of the room.\n */\n get renderImage(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderImage\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private defaultActivityIds: string[]\n /**\n * The activities that are available in this room.\n */\n get defaultActivities(): ActivityRoom<this>[] {\n let roomMemories = this.getStorageProperty<RoomActivityMemory>(\"activities_memory\") || {}\n let activities = this.defaultActivityIds.map(id => {\n let activity = getActivityById(id)\n if (!activity) {\n console.warn(`[NQTR] Activity with id ${id} not found, so it will be ignored.`)\n return undefined\n }\n let memory = activity.export()\n if (roomMemories && roomMemories[id]) {\n memory = {\n ...memory,\n ...roomMemories[id]\n }\n }\n return new ActivityRoom(id, this, activity._initialOnRun, memory)\n }).filter(activity => activity !== undefined)\n return activities as ActivityRoom<this>[]\n }\n\n private get activityIds(): string[] {\n let addedActivityIds = this.getStorageProperty<string[]>(`addedActivityIds`) || []\n return this.defaultActivityIds.concat(addedActivityIds)\n }\n /**\n * The activities that are available in this room.\n */\n get activities(): ActivityRoom<this>[] {\n let activities = this.activityIds.map(id => {\n return this.getActivity(id)\n }).filter(activity => activity !== undefined && !activity.hidden)\n return activities as ActivityRoom<this>[]\n }\n /**\n * Get the memory of an activity. This function can be used into olther libraries to get the memory of the activity.\n * @param id The id of the activity.\n * @returns The memory of the activity.\n */\n getActivityMemory(id: string): object | undefined {\n let roomMemories = this.getStorageProperty<RoomActivityMemory>(\"activities_memory\") || {}\n let roomMemory = roomMemories[id] || {}\n return roomMemory\n }\n /**\n * Get the activity by id.\n * @param id The id of the activity.\n * @returns The room activity.\n */\n getActivity(id: string): ActivityRoom<this> | undefined {\n if (!this.activityIds.includes(id)) {\n console.error(`[NQTR] Activity with id ${id} not found in room ${this.id}`)\n return undefined\n }\n let activity = getActivityById(id)\n if (!activity) {\n console.error(`[NQTR] Activity with id ${id} not found`)\n return undefined\n }\n let roomMemories = this.getStorageProperty<RoomActivityMemory>(\"activities_memory\") || {}\n let roomMemory = roomMemories[id] || {}\n roomMemory = {\n ...activity.export(),\n ...roomMemory\n }\n return new ActivityRoom(id, this, activity._initialOnRun, roomMemory)\n }\n /**\n * Set the memory of an activity. This function can be used into olther libraries to set the memory of the activity.\n * @param id The id of the activity.\n * @param memory The memory of the activity.\n */\n setActivity(activity: ActivityRoom) {\n let roomMemories = this.getStorageProperty<RoomActivityMemory>(\"activities_memory\") || {}\n roomMemories[activity.id] = activity.export()\n this.setStorageProperty(\"activities_memory\", roomMemories)\n }\n /**\n * Add an activity to the room.\n * @param activity The activity to add.\n */\n addActivity(activity: ActivityModel) {\n if (this.activityIds.includes(activity.id)) {\n let currentActivity = this.getActivity(activity.id)\n if (currentActivity && currentActivity.isExpired()) {\n this.removeActivity(activity.id)\n return\n } else {\n console.error(`[NQTR] Activity with id ${activity.id} already exists in room ${this.id}, so it will be ignored.`)\n return\n }\n }\n let addedActivityIds = this.getStorageProperty<string[]>(`addedActivityIds`) || []\n addedActivityIds.push(activity.id)\n this.setStorageProperty(\"addedActivityIds\", addedActivityIds)\n }\n /**\n * Remove an activity from the room.\n * @param activity The activity to remove.\n */\n removeActivity(activity: ActivityModel | string) {\n let activityId = typeof activity === \"string\" ? activity : activity.id\n if (this.defaultActivityIds.includes(activityId)) {\n console.warn(`[NQTR] Activity with id ${activityId} is a default activity, so it can't be removed. It will be hidden instead.`)\n let activityToEdit = this.getActivity(activityId)\n if (!activityToEdit) {\n console.error(`[NQTR] Activity with id ${activityId} not found, so it can't be hidden.`)\n return\n }\n activityToEdit.hidden = true\n return\n }\n let addedActivityIds = this.getStorageProperty<string[]>(`addedActivityIds`) || []\n let index = addedActivityIds.indexOf(activityId)\n if (index === -1) {\n console.error(`[NQTR] Activity with id ${activityId} not found, so it can't be removed.`)\n return\n }\n addedActivityIds.splice(index, 1)\n this.setStorageProperty(\"addedActivityIds\", addedActivityIds)\n let roomMemories = this.getStorageProperty<RoomActivityMemory>(\"activities_memory\") || {}\n delete roomMemories[activityId]\n this.setStorageProperty(\"activities_memory\", roomMemories)\n }\n /**\n * Clear all expired activities.\n */\n clearExpiredActivities() {\n this.activities.forEach(activity => {\n if (activity.isExpired()) {\n this.removeActivity(activity.id)\n }\n })\n }\n\n private defaultDisabled: boolean | string\n /**\n * Whether is disabled. If it is a string, it is a Pixi'VN flag name.\n */\n get disabled(): boolean {\n let value = this.getStorageProperty<boolean>(\"disabled\") || this.defaultDisabled\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set disabled(value: boolean | string) {\n this.setStorageProperty(\"disabled\", value)\n }\n\n private defaultHidden: boolean | string\n /**\n * Whether is hidden. If it is a string, it is a Pixi'VN flag name.\n */\n get hidden(): boolean {\n let value = this.getStorageProperty<boolean>(\"hidden\") || this.defaultHidden\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set hidden(value: boolean | string) {\n this.setStorageProperty(\"hidden\", value)\n }\n\n private _renderIcon?: GraphicItemType | ((room: RoomBaseModel<TLocation>, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the icon of the room.\n */\n get renderIcon(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderIcon\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n /**\n * Get the character commitments of the room.\n * @returns The character commitments of the room.\n */\n getRoutine<TCommitment extends CommitmentBaseModel = CommitmentBaseModel>(): TCommitment[] {\n let commitments = getCurrentRoutine<TCommitment>()\n return commitments.filter(c => c.room.id === this.id)\n }\n}\n","import { GraphicItemType, OnRenderGraphicItemProps, OnRunProps } from '@drincs/nqtr/dist/override';\nimport { getFlag } from \"@drincs/pixi-vn\";\nimport { ActivityProps } from '../interface';\nimport TimeManager from \"../managers/TimeManager\";\nimport { OnRunActivityEvent } from '../types/OnRunActivityEvent';\nimport { ActivityStoredAbstract } from './ActivityStoredAbstract';\n\n/**\n * The activity model. It is used to create an activity.\n * @example\n * ```tsx\n * export const nap = new ActivityModel(\"nap\",\n * (_, event) => {\n * if (event) {\n * event.navigate(\"/game\")\n * callLabelWithGoNavigationCallBack(napLabel, event)\n * }\n * else {\n * console.error(\"Event is undefined\")\n * }\n * },\n * {\n * name: \"Nap\",\n * fromHour: 5,\n * toHour: 23,\n * renderIcon: (activity, props) => {\n * return <Button\n * disabled={activity.disabled}\n * onClick={() => {\n * if (!props) {\n * console.error(\"Props is undefined\")\n * return\n * }\n * activity.onRun(props)\n * }}\n * ariaLabel={activity.name}\n * >\n * <BedIcon />\n * </Button>\n * },\n * }\n * )\n * ```\n */\nexport default class ActivityModel {\n /**\n * @param id The activity id, that must be unique.\n * @param onRun The function that is called when the activity is runned. Have 2 parameters: the runned activity and the yourParams object, that is an object with the parameters that you want to pass to the onRun function.\n * @param props The activity properties.\n */\n constructor(id: string, onRun: OnRunActivityEvent<ActivityModel>, props: ActivityProps) {\n this._id = id\n this._name = props.name\n this._fromHour = props.fromHour\n this._toHour = props.toHour\n this._fromDay = props.fromDay\n this._toDay = props.toDay\n this._disabled = props.disabled || false\n this._hidden = props.hidden || false\n this._renderIcon = props.renderIcon\n this._onRun = onRun\n }\n\n private _id: string\n /**\n * The activity id, that is unique.\n */\n get id(): string {\n return this._id\n }\n\n private _name?: string\n /**\n * The name\n */\n get name(): string | undefined {\n return this._name\n }\n\n private _fromHour?: number\n /**\n * The hour when the activity starts. If the activity is not started yet, it will be hidden.\n */\n get fromHour(): number | undefined {\n return this._fromHour\n }\n\n private _toHour?: number\n /**\n * The hour when the activity ends. If the activity is ended yet, it will be hidden.\n */\n get toHour(): number | undefined {\n return this._toHour\n }\n\n private _fromDay?: number\n /**\n * The day when the activity starts. If the activity is not started yet, it will be hidden.\n */\n get fromDay(): number | undefined {\n return this._fromDay\n }\n\n private _toDay?: number\n /**\n * The day when the activity ends. If the activity is ended yet, it will be deleted or hidden.\n */\n get toDay(): number | undefined {\n return this._toDay\n }\n\n private _disabled?: boolean | string\n /**\n * Whether is disabled.\n */\n get disabled(): boolean | undefined {\n if (typeof this._disabled === \"string\") {\n return getFlag(this._disabled)\n }\n return this._disabled\n }\n\n private _hidden: boolean | string\n /**\n * Whether is hidden. If the activity is not started yet, it will be hidden.\n */\n get hidden(): boolean {\n if (this.fromDay && this.fromDay > TimeManager.currentDay) {\n return true\n }\n if (!this.isDeadline) {\n return true\n }\n if (typeof this._hidden === \"string\") {\n return getFlag(this._hidden)\n }\n return this._hidden\n }\n\n private _renderIcon?: GraphicItemType | ((activity: ActivityModel, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the icon of the activity.\n */\n get renderIcon(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderIcon\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private _onRun: OnRunActivityEvent<ActivityModel>\n get _initialOnRun(): OnRunActivityEvent<ActivityStoredAbstract> {\n return this._onRun as any\n }\n /**\n * The function that is called when the activity is runned.\n */\n get run(): (props: OnRunProps) => void {\n return (props) => this._onRun(this, props)\n }\n\n /**\n * Whether the activity is a deadline.\n * @returns Whether the activity is a deadline.\n */\n isDeadline(): boolean {\n if (this.toDay && this.toDay <= TimeManager.currentDay) {\n return true\n }\n return false\n }\n\n /**\n * Export the activity properties.\n * @returns The activity properties.\n */\n export(): ActivityProps {\n return {\n name: this._name,\n fromHour: this._fromHour,\n toHour: this._toHour,\n fromDay: this._fromDay,\n toDay: this._toDay,\n disabled: this._disabled,\n hidden: this._hidden,\n renderIcon: this._renderIcon,\n }\n }\n}\n","import { GameStorageManager } from \"@drincs/pixi-vn\"\nimport CommitmentBaseModel from \"../classes/Commitment\"\n\nconst TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY = \"___nqtr-temporary_commitment___\"\nexport const registeredCommitments: { [id: string]: CommitmentBaseModel } = {}\nexport const fixedCommitments: { [id: string]: CommitmentBaseModel } = {}\n\n/**\n * Save a commitment in the registered commitments. If the commitment already exists, it will be overwritten.\n * @param commitment The commitment or commitments to save.\n * @returns \n */\nexport function saveCommitment<TCommitment extends CommitmentBaseModel = CommitmentBaseModel>(commitment: TCommitment | TCommitment[]) {\n if (Array.isArray(commitment)) {\n commitment.forEach(c => saveCommitment(c))\n return\n }\n if (registeredCommitments[commitment.id]) {\n console.warn(`[NQTR] Commitment id ${commitment.id} already exists, it will be overwritten`)\n }\n registeredCommitments[commitment.id] = commitment\n}\n\n/**\n * Get a commitment by its id.\n * @param id The id of the commitment.\n * @returns The commitment or undefined if not found.\n */\nexport function getCommitmentById<TCommitment extends CommitmentBaseModel = CommitmentBaseModel>(id: string): TCommitment | undefined {\n try {\n let commitment = registeredCommitments[id]\n if (!commitment) {\n console.error(`[NQTR] Commitment ${id} not found`)\n return\n }\n return commitment as TCommitment\n }\n catch (e) {\n console.error(`[NQTR] Error while getting Commitment ${id}`, e)\n return\n }\n}\n\n/**\n * Set a commitment as fixed, it will be always available. They cannot be deleted or edit during the game session.\n * @param commitment The commitment or commitments to set as fixed.\n */\nexport function setFixedRoutine<TCommitment extends CommitmentBaseModel = CommitmentBaseModel>(commitments: TCommitment[] | TCommitment) {\n if (Array.isArray(commitments)) {\n commitments.forEach(c => setFixedRoutine(c))\n return\n }\n if (fixedCommitments[commitments.id]) {\n console.warn(`[NQTR] Commitment id ${commitments.id} already exists, it will be overwritten`)\n }\n fixedCommitments[commitments.id] = commitments\n}\n\n/**\n * This feature adds the commitments during the game session.\n * @param commitment The commitment or commitments to add.\n */\nexport function addCommitment<TCommitment extends CommitmentBaseModel = CommitmentBaseModel>(commitment: TCommitment[] | TCommitment) {\n if (!Array.isArray(commitment)) {\n commitment = [commitment]\n }\n let commitmentsIds = commitment.map(commitment => {\n let commitmentTest = getCommitmentById(commitment.id)\n if (!commitmentTest) {\n console.warn(`[NQTR] Commitment ${commitment.id} not found, it will be ignored`)\n return undefined\n }\n return commitment.id\n }).filter(id => id !== undefined)\n\n GameStorageManager.setVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY, commitmentsIds)\n}\n\n/**\n * Remove the commitments added during the game session.\n * @param commitment The commitment or commitments to remove.\n * @returns \n */\nexport function removeCommitment<TCommitment extends CommitmentBaseModel = CommitmentBaseModel>(commitment: TCommitment[] | TCommitment) {\n if (!Array.isArray(commitment)) {\n commitment = [commitment]\n }\n let commitmentsIds = commitment.map(commitment => {\n return commitment.id\n })\n\n let currentCommitments = GameStorageManager.getVariable<string[]>(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY)\n if (!currentCommitments) {\n return\n }\n currentCommitments = currentCommitments.filter(id => !commitmentsIds.includes(id))\n GameStorageManager.setVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY, currentCommitments)\n}\n\n/**\n * Get the fixed commitments by its id.\n * @returns The fixed commitments.\n */\nexport function getFixedRoutine<TCommitment extends CommitmentBaseModel = CommitmentBaseModel>(): TCommitment[] {\n return Object.values(fixedCommitments) as TCommitment[]\n}\n\n/**\n * Get the temporary commitments by its id.\n * @returns The temporary commitments.\n */\nexport function getTemporaryCommitments<TCommitment extends CommitmentBaseModel = CommitmentBaseModel>(): TCommitment[] {\n let commitmentsIds = GameStorageManager.getVariable<string[]>(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY)\n if (!commitmentsIds) {\n return []\n }\n let commitments = commitmentsIds.map(id => getCommitmentById<TCommitment>(id)).filter(commitment => commitment !== undefined)\n return commitments as TCommitment[]\n}\n","import { GraphicItemType, OnEndStage, OnRenderGraphicItemProps, OnStartStage } from \"@drincs/nqtr/dist/override\";\nimport { StoredClassModel } from \"@drincs/pixi-vn\";\nimport { QuestProps } from \"../../interface\";\nimport Stage, { StageQuest } from \"./Stage\";\n\nconst QUEST_CATEGORY = \"__nqtr-quest__\"\n\nexport default class Quest extends StoredClassModel {\n constructor(id: string, stages: Stage[], props: QuestProps) {\n super(QUEST_CATEGORY, id)\n this._stages = stages\n this._name = props.name || \"\"\n this._description = props.description || \"\"\n this._renderIcon = props.renderIcon\n this._renderImage = props.renderImage\n this._isInDevelopment = props.isInDevelopment || false\n }\n\n private _stages: Stage[]\n /**\n * The stages of the quest.\n */\n get stages(): StageQuest[] {\n return this._stages.map((stage, index) => {\n return new StageQuest(stage.id, stage)\n })\n }\n\n private _name: string\n /**\n * The name of the quest.\n */\n get name(): string {\n return this._name\n }\n\n private _description: string\n /**\n * The description of the quest.\n */\n get description(): string {\n return this._description\n }\n\n private _renderIcon?: GraphicItemType | ((room: Quest, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the icon of the quest.\n */\n get renderIcon(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderIcon\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private _renderImage?: GraphicItemType | ((room: Quest, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the image of the quest.\n */\n get renderImage(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderImage\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private _isInDevelopment: boolean\n /**\n * If the quest is in development.\n */\n get isInDevelopment(): boolean {\n return this._isInDevelopment\n }\n\n /**\n * The index of the current stage.\n */\n get currentStageIndex(): number | undefined {\n return this.getStorageProperty<number>('currentStageIndex')\n }\n private set currentStageIndex(value: number | undefined) {\n this.setStorageProperty('currentStageIndex', value)\n }\n\n /**\n * The current stage.\n */\n get currentStage(): StageQuest | undefined {\n let index = this.currentStageIndex\n if (index === undefined || index >= this.stages.length) {\n return undefined\n }\n return this.stages[index]\n }\n\n /**\n * If the quest is started.\n */\n get started(): boolean {\n return this.currentStageIndex !== undefined\n }\n\n /**\n * If the quest is completed.\n */\n get completed(): boolean {\n if (this.currentStageIndex === undefined) {\n return false\n }\n return this.currentStageIndex > this.stages.length - 1\n }\n\n /**\n * Start the quest.\n * @param props The properties for the start stage. If you not want to pass any property, you can pass an {}.\n * @returns \n */\n start(props: OnStartStage): void {\n if (this.started) {\n console.warn(`[NQTR] Quest ${this.id} is already started`)\n return\n }\n if (this.stages.length === 0) {\n console.error(`[NQTR] Quest ${this.id} has no stages`)\n return\n }\n this.currentStageIndex = 0\n let currentStage = this.currentStage\n if (currentStage && currentStage.start) {\n return currentStage.start(props)\n }\n else {\n console.error(`[NQTR] Quest ${this.id} has no start stage`)\n }\n }\n\n /**\n * Go to the next stage if the current stage is completed.\n * If you want to force the change of stage, use goNextStage.\n * @param startProps The properties for the start stage. If you not want to pass any property, you can pass an {}.\n * @param endProps The properties for the end stage. If you not want to pass any property, you can pass an {}.\n * @returns true if the stage was changed, false otherwise.\n */\n tryToGoNextStage(\n startProps: OnStartStage,\n endProps: OnEndStage\n ): boolean {\n if (!this.started) {\n return false\n }\n if (this.completed) {\n return false\n }\n let currentStage = this.currentStage\n if (!currentStage) {\n console.error(`[NQTR] Quest ${this.id} has no current stage`)\n return false\n }\n if (currentStage.completed) {\n return this.goNextStage(startProps, endProps)\n }\n return false\n }\n\n /**\n * Complete the current stage and go to the next stage.\n * If you want to go to the next stage only if the current stage is completed, use tryToGoNextStage.\n * @param startProps The properties for the start stage. If you not want to pass any property, you can pass an {}.\n * @param endProps The properties for the end stage. If you not want to pass any property, you can pass an {}.\n * @returns true if the stage was changed, false otherwise.\n */\n completeCurrentStageAndGoNext(\n startProps: OnStartStage,\n endProps: OnEndStage\n ): boolean {\n let currentStage = this.currentStage\n if (!currentStage) {\n console.error(`[NQTR] Quest ${this.id} has no current stage`)\n return false\n }\n currentStage.completed = true\n return this.goNextStage(startProps, endProps)\n }\n\n /**\n * Go to the next stage without checking if the current stage is completed.\n * If you want to go to the next stage only if the current stage is completed, use tryToGoNextStage.\n * @param startProps \n * @param endProps \n * @returns returns true if the stage was changed, false otherwise.\n */\n goNextStage(\n startProps: OnStartStage,\n endProps: OnEndStage\n ): boolean {\n if (!this.started) {\n console.warn(`[NQTR] Quest ${this.id} is not started`)\n return false\n }\n if (this.completed) {\n console.warn(`[NQTR] Quest ${this.id} is already completed`)\n return false\n }\n let prevStage = this.currentStage\n let currentStageIndex = this.currentStageIndex\n if (!prevStage || currentStageIndex === undefined) {\n console.error(`[NQTR] Quest ${this.id} has no current stage`)\n return false\n }\n this.currentStageIndex = currentStageIndex + 1\n if (prevStage && prevStage.onEnd) {\n prevStage.onEnd(endProps)\n }\n let nextCurrentStage = this.currentStage\n if (nextCurrentStage) {\n nextCurrentStage.inizialize()\n if (this.currentStageMustStart) {\n this.startCurrentStage(startProps)\n }\n }\n\n return true\n }\n\n /**\n * If the current stage must start. It is true if the current stage is not started, can start and not completed.\n */\n get currentStageMustStart(): boolean {\n let currentStage = this.currentStage\n if (!currentStage) {\n return false\n }\n return !currentStage.started && currentStage.canStart && !currentStage.completed\n }\n\n /**\n * Start the current stage.\n * @param props The properties for the start stage. If you not want to pass any property, you can pass an {}.\n */\n startCurrentStage(props: OnStartStage): void {\n let newCurrentStage = this.currentStage\n if (newCurrentStage && this.currentStageMustStart) {\n newCurrentStage.start(props)\n }\n else {\n console.warn(`[NQTR] Quest ${this.id} can't start the current stage`)\n }\n }\n}\n","import { GraphicItemType, OnEndStage, OnRenderGraphicItemProps, OnStartStage } from \"@drincs/nqtr/dist/override\";\nimport { StoredClassModel, getFlag } from \"@drincs/pixi-vn\";\nimport { StageProps } from \"../../interface\";\nimport StageFlags from \"../../interface/quest/StageFlags\";\nimport { TimeManager } from \"../../managers\";\nimport { QuestsRequiredType } from \"../../types/QuestsRequired\";\nimport Goal, { GoalStage } from \"./Goal\";\n\nconst STAGE_CATEGORY = \"__nqtr-stage__\"\n\nexport default class Stage extends StoredClassModel implements StageProps {\n constructor(id: string, props: StageProps) {\n super(STAGE_CATEGORY, id)\n this._name = props.name || \"\"\n this._defaultGoals = props.goals || []\n this._flags = props.flags || []\n this._description = props.description || \"\"\n this._adviceDescription = props.adviceDescription || \"\"\n this._renderImage = props.renderImage\n this._daysRequiredToStart = props.daysRequiredToStart\n this._flagsRequiredToStart = props.flagsRequired || []\n this._questsRequiredToStart = props.questsRequired || []\n this._requestDescriptionToStart = props.requestDescription || \"\"\n this._onStart = props.onStart\n this._onEnd = props.onEnd\n }\n\n private _name: string\n /**\n * The name of the stage.\n */\n get name(): string {\n return this._name\n }\n\n private _description: string\n /**\n * The description of the stage.\n */\n get description(): string {\n return this._description\n }\n\n private _adviceDescription: string\n /**\n * The advice description of the stage.\n */\n get adviceDescription(): string {\n return this._adviceDescription\n }\n\n private _renderImage?: GraphicItemType | ((room: Stage, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the image of the stage.\n */\n get renderImage(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderImage\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private _defaultGoals: Goal[]\n /**\n * The list of goals that the player needs to complete to finish the stage.\n * This is the list set by the developer. if you want to get the current goals, use the goals property.\n */\n get defaultGoals(): Goal[] {\n return this._defaultGoals\n }\n\n private _flags: StageFlags[]\n /**\n * The list of flags that the player must complete to finish the stage.\n */\n get flags(): StageFlags[] {\n return this._flags\n }\n\n // request to start\n\n private _daysRequiredToStart?: number\n /**\n * The number of days required to start the stage.\n */\n get daysRequiredToStart(): number {\n return this._daysRequiredToStart || 0\n }\n\n private _flagsRequiredToStart: StageFlags[]\n /**\n * The list of flags required to start the stage.\n */\n get flagsRequiredToStart(): StageFlags[] {\n return this._flagsRequiredToStart\n }\n\n private _questsRequiredToStart: QuestsRequiredType[]\n /**\n * The list of quests required to start the stage.\n */\n get questsRequiredToStart(): QuestsRequiredType[] {\n return this._questsRequiredToStart || []\n }\n\n private _requestDescriptionToStart: string\n /**\n * The description of the request to start the stage.\n */\n get requestDescriptionToStart(): string {\n return this._requestDescriptionToStart\n }\n\n // function\n\n private _onStart?: (props: OnStartStage) => void\n /**\n * The function that will be called when the stage starts.\n */\n get onStart(): undefined | ((props: OnStartStage) => void) {\n return this._onStart\n }\n\n private _onEnd?: (props: OnEndStage) => void\n /**\n * The function that will be called when the stage ends.\n */\n get onEnd(): undefined | ((props: OnEndStage) => void) {\n return this._onEnd\n }\n}\n\nexport class StageQuest extends Stage {\n constructor(id: string, props: StageProps) {\n super(id, props)\n }\n\n /**\n * Check if the flag and goals are completed.\n * You can force the completion of the stage by setting the completed property to true.\n */\n get completed(): boolean {\n let storedCompleted = this.getStorageProperty<boolean>('completed')\n if (storedCompleted) {\n return storedCompleted\n }\n if (this.flags.length > 0 && this.goals.length > 0) {\n if (!this.flags.every(flag => getFlag(flag.flag))) {\n return false\n }\n if (!this.goals.every(goal => goal.completed)) {\n return false\n }\n return true\n }\n return false\n }\n set completed(value: boolean) {\n this.setStorageProperty('completed', value)\n }\n\n /**\n * If the stage is started.\n */\n get started(): boolean {\n return this.getStorageProperty<boolean>('started') || false\n }\n set started(value: boolean) {\n this.setStorageProperty('started', value)\n }\n\n /**\n * The list of goals that the player needs to complete to finish the stage.\n */\n get goals(): GoalStage[] {\n return this.defaultGoals.map((goal) => {\n return new GoalStage(goal.id, this.id, goal)\n })\n }\n\n private get prevStageEndDay(): number | undefined {\n return this.getStorageProperty<number>('prevStageEndDay')\n }\n private set prevStageEndDay(value: number | undefined) {\n this.setStorageProperty('prevStageEndDay', value)\n }\n\n /**\n * The day when the stage starts.\n */\n get startDay(): number | undefined {\n let prevStageEndDay = this.prevStageEndDay\n if (prevStageEndDay === undefined) {\n return undefined\n }\n return prevStageEndDay + this.daysRequiredToStart\n }\n\n /**\n * Check if the stage can start.\n */\n get canStart(): boolean {\n let daysRequired = this.daysRequiredToStart\n if (daysRequired > 0) {\n let prevStageEndDay = this.prevStageEndDay\n if (prevStageEndDay === undefined) {\n return false\n }\n if (prevStageEndDay + daysRequired > TimeManager.currentDay) {\n return false\n }\n }\n if (this.flagsRequiredToStart.length > 0 && !this.flagsRequiredToStart.every(flag => getFlag(flag.flag))) {\n return false\n }\n if (this.questsRequiredToStart.length > 0 && !this.questsRequiredToStart.every(q =>\n q.quest.currentStageIndex && q.quest.currentStageIndex >= q.stageNumber\n )) {\n return false\n }\n return true\n }\n\n /**\n * Inizialize the stage. **This function should be called only by the Quest class.**\n */\n inizialize() {\n if (this.daysRequiredToStart > 0) {\n this.prevStageEndDay = TimeManager.currentDay\n console.log(`[NQTR] Stage ${this.id} will start on day ${this.startDay}`)\n }\n }\n\n /**\n * The function that will be called when the stage starts.\n */\n start(props: OnStartStage) {\n if (this.canStart) {\n this.started = true\n if (this.onStart) {\n this.onStart(props)\n }\n }\n else {\n console.warn(`[NQTR] Stage ${this.id} can't start`)\n }\n }\n}\n","import { StoredClassModel } from \"@drincs/pixi-vn\"\nimport { GoalProps } from \"../../interface\"\n\nconst GOAL_CATEGORY = \"__nqtr-goal__\"\n\nexport default class Goal extends StoredClassModel implements GoalProps {\n constructor(id: string, props: GoalProps) {\n super(GOAL_CATEGORY, id)\n this._description = props.description\n this._need = props.need || 1\n this._defaultHave = props.have || 0\n }\n\n private _description: string\n /**\n * The description of the goal.\n */\n get description(): string {\n return this._description\n }\n\n private _need: number\n /**\n * The number of times the goal must be completed.\n */\n get need(): number {\n return this._need\n }\n\n private _defaultHave: number\n /**\n * The default number of times the goal has been completed.\n */\n get defaultHave(): number {\n return this._defaultHave\n }\n}\n\nexport class GoalStage extends Goal {\n constructor(id: string, stageId: string, props: GoalProps) {\n super(id, props)\n this._stageId = stageId\n }\n\n private _stageId?: string\n /**\n * The id of the stage that the goal belongs to.\n */\n get stageId(): string | undefined {\n return this._stageId\n }\n set stageId(value: string) {\n this._stageId = value\n }\n\n /**\n * The number of times the goal has been completed.\n */\n get have(): number {\n return this.getStorageProperty<number>('have-' + this._stageId) || this.defaultHave\n }\n set have(value: number) {\n if (!this._stageId) {\n console.error(`[NQTR] The stage id is not set for the goal ${this.id}, so the have value can't be set.`)\n return\n }\n this.setStorageProperty('have-' + this._stageId, value)\n }\n\n /**\n * If the goal is completed.\n */\n get completed(): boolean {\n return this.have >= this.need\n }\n set completed(value: boolean) {\n if (value) {\n this.have = this.need\n } else {\n console.warn(`[NQTR] The goal can't be set as not completed. You must edit the have value manually.`)\n }\n }\n\n /**\n * Find the goal. It will increment the have value.\n */\n find(): void {\n this.have++\n }\n}\n","import { ActivityRoom } from \"../classes\"\nimport { registeredRooms } from \"../decorators/RoomDecorator\"\nimport { getCurrentRoom } from \"./NavigationFunctions\"\n\n/**\n * Clear all the expired activities.\n */\nexport function clearExpiredActivities() {\n Object.entries(registeredRooms).forEach(([_, room]) => {\n room.clearExpiredActivities()\n })\n}\n\n/**\n * Get the current activities. The hidden activities are not included.\n * @returns The current activities.\n */\nexport function currentActivities(): ActivityRoom[] {\n let currentRoom = getCurrentRoom()\n if (!currentRoom) {\n return []\n }\n return currentRoom.activities.filter(activity => !activity.hidden)\n}\n"]}
1
+ {"version":3,"sources":["../../src/decorators/RoomDecorator.ts","../../src/functions/NavigationFunctions.ts","../../src/classes/Commitment.ts","../../src/managers/TimeManager.ts","../../src/classes/ActivityStoredAbstract.ts","../../src/classes/navigation/Location.ts","../../src/classes/navigation/Map.ts","../../src/classes/navigation/Room.ts","../../src/classes/Activity.ts","../../src/decorators/CommitmentDecorator.ts","../../src/classes/quest/Quest.ts","../../src/classes/quest/Stage.ts","../../src/classes/quest/Goal.ts","../../src/functions/ActivityFunctions.ts"],"names":["GameStorageManager","getFlag","StoredClassModel"],"mappings":";AAEO,IAAM,kBAAmD,CAAC;AA2B1D,SAAS,YAAyD,IAA+B;AACpG,MAAI;AACA,QAAI,OAAO,gBAAgB,EAAE;AAC7B,QAAI,CAAC,MAAM;AACP,cAAQ,MAAM,eAAe,EAAE,YAAY;AAC3C;AAAA,IACJ;AACA,WAAO;AAAA,EACX,SACO,GAAG;AACN,YAAQ,MAAM,mCAAmC,EAAE,IAAI,CAAC;AACxD;AAAA,EACJ;AACJ;;;AC1CA,SAAS,sBAAAA,2BAA0B;;;ACCnC,SAA6B,SAAS,wBAAwB;;;ACD9D,SAAS,0BAA0B;;;ACCnC,SAAS,WAAAC,gBAAe;;;ACAxB,SAAS,WAAAA,UAAS,oBAAAC,yBAAwB;;;ACA1C,SAAS,WAAAD,UAAS,oBAAAC,yBAAwB;;;ACA1C,SAAS,WAAAD,UAAS,oBAAAC,yBAAwB;;;ACA1C,SAAS,WAAAD,gBAAe;;;ACDxB,SAAS,sBAAAD,2BAA0B;;;ACCnC,SAAS,oBAAAE,yBAAwB;;;ACAjC,SAAS,oBAAAA,mBAAkB,WAAAD,gBAAe;;;ACD1C,SAAS,oBAAAC,yBAAwB;;;AXIjC,IAAM,0BAA0B;AA8BzB,SAAS,iBAAiF;AAC7F,MAAI,SAASF,oBAAmB,YAAoB,uBAAuB;AAC3E,MAAI,CAAC,QAAQ;AACT,YAAQ,MAAM,8CAA8C;AAC5D;AAAA,EACJ;AACA,MAAI,OAAO,YAAmB,MAAM;AACpC,MAAI,CAAC,MAAM;AACP,YAAQ,MAAM,uBAAuB,MAAM,YAAY;AACvD;AAAA,EACJ;AACA,SAAO;AACX;;;AYvCO,SAAS,yBAAyB;AACrC,SAAO,QAAQ,eAAe,EAAE,QAAQ,CAAC,CAAC,GAAG,IAAI,MAAM;AACnD,SAAK,uBAAuB;AAAA,EAChC,CAAC;AACL;AAMO,SAAS,oBAAoC;AAChD,MAAI,cAAc,eAAe;AACjC,MAAI,CAAC,aAAa;AACd,WAAO,CAAC;AAAA,EACZ;AACA,SAAO,YAAY,WAAW,OAAO,cAAY,CAAC,SAAS,MAAM;AACrE","sourcesContent":["import { LocationBaseModel, MapBaseModel, RoomBaseModel } from \"../classes\"\n\nexport const registeredRooms: { [id: string]: RoomBaseModel } = {}\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<TRoom extends RoomBaseModel = RoomBaseModel>(room: TRoom | TRoom[]) {\n if (Array.isArray(room)) {\n room.forEach(c => saveRoom(c))\n return\n }\n if (registeredRooms[room.id]) {\n console.warn(`[NQTR] Room id ${room.id} already exists, it will be overwritten`)\n }\n registeredRooms[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<TRoom extends RoomBaseModel = RoomBaseModel>(id: string): TRoom | undefined {\n try {\n let room = registeredRooms[id]\n if (!room) {\n console.error(`[NQTR] Room ${id} not found`)\n return\n }\n return room as TRoom\n }\n catch (e) {\n console.error(`[NQTR] Error while getting Room ${id}`, e)\n return\n }\n}\n\n/**\n * Get all rooms in a location.\n * @param location The location where the rooms are.\n * @returns The rooms in the location.\n */\nexport function getRoomsByLocation<TRoom extends RoomBaseModel = RoomBaseModel>(location: LocationBaseModel): TRoom[] {\n return Object.values(registeredRooms).filter(room => room.location.id === location.id) as TRoom[]\n}\n\n/**\n * Get all locations in the registered rooms.\n * @returns All locations in the registered rooms.\n */\nexport function getAllLocations<TLocation extends LocationBaseModel = LocationBaseModel>(): TLocation[] {\n let result: { [id: string]: TLocation } = {}\n Object.values(registeredRooms).forEach(room => {\n result[room.location.id] = room.location as TLocation\n })\n return Object.values(result)\n}\n\n/**\n * Get all locations in a map.\n * @param map The map where the locations are.\n * @returns The locations in the map.\n */\nexport function getLocationsByMap<TLocation extends LocationBaseModel = LocationBaseModel>(map: MapBaseModel): TLocation[] {\n return getAllLocations<TLocation>().filter(location => location.map.id === map.id) as TLocation[]\n}\n\n/**\n * Get all maps in the registered rooms.\n * @returns All maps in the registered rooms.\n */\nexport function getAllMaps<TMap extends MapBaseModel = MapBaseModel>(): TMap[] {\n let result: { [id: string]: TMap } = {}\n Object.values(registeredRooms).forEach(room => {\n result[room.location.map.id] = room.location.map as TMap\n })\n return Object.values(result)\n}\n","import { GameStorageManager } from \"@drincs/pixi-vn\";\nimport { LocationBaseModel, MapBaseModel, RoomBaseModel } from \"../classes\";\nimport { getRoomById } from \"../decorators/RoomDecorator\";\n\nconst CURRENT_ROOM_MEMORY_KEY = '___nqtr-current_room_memory___';\n\n/**\n * Set the current room.\n * @param room The room to set as current room.\n * @returns\n */\nexport function setCurrentRoom<TRoom extends RoomBaseModel = RoomBaseModel>(room: TRoom | LocationBaseModel) {\n if (room instanceof LocationBaseModel) {\n let entrance = room.getEntrance<TRoom>();\n if (!entrance) {\n console.error(`[NQTR] The location ${room.id} has no entrance room`);\n return;\n }\n room = entrance;\n }\n else {\n let roomRegistrated = getRoomById(room.id);\n if (!roomRegistrated) {\n console.error(`[NQTR] The room ${room.id} is not registered, so it can't be set as current room`);\n return;\n }\n }\n GameStorageManager.setVariable(CURRENT_ROOM_MEMORY_KEY, room.id);\n}\n\n/**\n * Get the current room.\n * @returns The current room or undefined if not set.\n */\nexport function getCurrentRoom<TRoom extends RoomBaseModel = RoomBaseModel>(): TRoom | undefined {\n let roomId = GameStorageManager.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<TRoom>(roomId);\n if (!room) {\n console.error(`[NQTR] Current room ${roomId} not found`);\n return\n }\n return room\n}\n\n/**\n * Get the current location.\n * @returns The current location or undefined if not set.\n */\nexport function getCurrenrLocation<TLocation extends LocationBaseModel = LocationBaseModel>(): TLocation | undefined {\n let room = getCurrentRoom<RoomBaseModel<TLocation>>();\n if (!room) {\n return\n }\n return room.location\n}\n\n/**\n * Get the current map.\n * @returns The current map or undefined if not set.\n */\nexport function getCurrentMap<TMap extends MapBaseModel = MapBaseModel>(): TMap | undefined {\n let location = getCurrenrLocation<LocationBaseModel<TMap>>();\n if (!location) {\n return\n }\n return location.map\n}\n","import { GraphicItemType, OnRenderGraphicItemProps, OnRunProps } from \"@drincs/nqtr/dist/override\";\nimport { CharacterBaseModel, getFlag, StoredClassModel } from \"@drincs/pixi-vn\";\nimport { CommitmentProps } from \"../interface\";\nimport TimeManager from \"../managers/TimeManager\";\nimport { ExecutionType } from \"../types\";\nimport { OnRunCommitmentEvent } from \"../types/OnRunCommitmentEvent\";\nimport RoomBaseModel from \"./navigation/Room\";\n\nconst COMMITMENT_CATEGORY = \"__nqtr-commitment__\"\n\n/**\n * The base model of a commitment. I suggest you extend this class to create your own commitment model.\n * You must use the saveRoom function to save the commitment in the registered commitments.\n * @example\n * ```ts\n * export const mcRoom = new CommitmentBaseModel(\"test\", character, room, {\n * name: \"Test\",\n * image: \"https://image.jpg\",\n * executionType: ExecutionTypeEnum.INTERACTION,\n * onRun: (commitment) => {\n * // Do something\n * }\n * })\n * saveCommitment(mcRoom)\n * ```\n */\nexport default class CommitmentBaseModel<TCharacter extends CharacterBaseModel = CharacterBaseModel, TRoom extends RoomBaseModel = RoomBaseModel> extends StoredClassModel {\n /**\n * @param id The id of the commitment, it must be unique.\n * @param character The character or characters that are in the commitment and so in the room.\n * @param room The room where the commitment is.\n * @param props The properties of the commitment.\n */\n constructor(id: string, character: TCharacter | TCharacter[] | undefined, room: TRoom, props: CommitmentProps<TCharacter, TRoom>) {\n super(COMMITMENT_CATEGORY, id)\n this._characters = character ? Array.isArray(character) ? character : [character] : []\n this._room = room\n this._name = props.name || \"\"\n this.defaultFromHour = props.fromHour\n this.defaultToHour = props.toHour\n this.defaultFromDay = props.fromDay\n this.defaultToDay = props.toDay\n this._renderImage = props.renderImage\n this._executionType = props.executionType || \"interaction\"\n this._onRun = props.onRun\n this.defaultDisabled = props.disabled || false\n this.defaultHidden = props.hidden || false\n this._renderIcon = props.renderIcon\n this.defaultPriority = props.priority || 0\n }\n\n private _characters: TCharacter[]\n /**\n * The character or characters that are in the commitment and so in the room.\n */\n get characters(): TCharacter[] {\n return this._characters\n }\n\n private _room: TRoom\n /**\n * The room where the commitment is.\n */\n get room(): TRoom {\n return this._room\n }\n\n private _name: string\n /**\n * The name\n */\n get name(): string {\n return this._name\n }\n\n private defaultFromHour?: number\n /**\n * The hour when the commitment starts. If the commitment is not started yet, it will be hidden.\n * If you set undefined, it will return the initial value of fromHour.\n */\n get fromHour(): number {\n return this.getStorageProperty<number>(\"fromHour\") || this.defaultFromHour || TimeManager.minDayHours\n }\n set fromHour(value: number | undefined) {\n this.setStorageProperty(\"fromHour\", value)\n }\n\n private defaultToHour?: number\n /**\n * The hour when the commitment ends. If the commitment is ended yet, it will be hidden.\n * If you set undefined, it will return the initial value of toHour.\n */\n get toHour(): number {\n return this.getStorageProperty<number>(\"toHour\") || this.defaultToHour || (TimeManager.maxDayHours + 1)\n }\n set toHour(value: number | undefined) {\n this.setStorageProperty(\"toHour\", value)\n }\n\n private defaultFromDay?: number\n /**\n * The day when the commitment starts. If the commitment is not started yet, it will be hidden.\n * If you set undefined, it will return the initial value of fromDay.\n */\n get fromDay(): number | undefined {\n return this.getStorageProperty<number>(\"fromDay\") || this.defaultFromDay\n }\n set fromDay(value: number | undefined) {\n this.setStorageProperty(\"fromDay\", value)\n }\n\n private defaultToDay?: number\n /**\n * The day when the commitment ends. If the commitment is ended yet, it will be deleted or hidden.\n * If you set undefined, it will return the initial value of toDay.\n */\n get toDay(): number | undefined {\n return this.getStorageProperty<number>(\"toDay\") || this.defaultToDay\n }\n set toDay(value: number | undefined) {\n this.setStorageProperty(\"toDay\", value)\n }\n\n private _renderImage?: GraphicItemType | ((commitment: CommitmentBaseModel<TCharacter, TRoom>, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the image of the room.\n */\n get renderImage(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderImage\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private _executionType: ExecutionType\n /**\n * Execution type. If is \"automatic\" the onRun() runned automatically when the palayer is in the room. If is \"interaction\" the player must interact with the character to run the onRun() function.\n * If you set \"automatic\" remember to remove the commitment when it is no longer needed, because otherwise it repeats itself every time.\n */\n get executionType(): ExecutionType {\n return this._executionType\n }\n\n private _renderIcon?: GraphicItemType | ((commitment: CommitmentBaseModel, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the icon of the commitment.\n */\n get renderIcon(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderIcon\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private _onRun?: OnRunCommitmentEvent<CommitmentBaseModel>\n /**\n * Is a function that is called when the player interacts with the character.\n */\n get run(): undefined | ((props: OnRunProps) => void) {\n let onRun = this._onRun\n if (!onRun) {\n return\n }\n return (props) => onRun(this, props)\n }\n\n private defaultDisabled: boolean | string\n /**\n * Whether is disabled. You can also pass a Pixi'VN flag name.\n */\n get disabled(): boolean {\n let value = this.getStorageProperty<boolean>(\"disabled\") || this.defaultDisabled\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set disabled(value: boolean | string) {\n this.setStorageProperty(\"disabled\", value)\n }\n\n private defaultHidden: boolean | string\n /**\n * Whether is hidden. You can also pass a Pixi'VN flag name.\n */\n get hidden(): boolean {\n if (this.fromDay && this.fromDay > TimeManager.currentDay) {\n return true\n }\n if (!TimeManager.nowIsBetween(this.fromHour, this.toHour)) {\n return true\n }\n if (!this.isExpired) {\n return true\n }\n let value = this.getStorageProperty<boolean>(\"hidden\") || this.defaultHidden\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set hidden(value: boolean | string) {\n this.setStorageProperty(\"hidden\", value)\n }\n\n private defaultPriority: number\n /**\n * The priority. The higher the number, the higher the priority.\n * To ensure that a character is not in 2 places at the same time, if there are 2 or more valid commits at the same time and with the same character, the one with the highest priority will be chosen.\n */\n get priority(): number {\n return this.getStorageProperty<number>(\"priority\") || this.defaultPriority || 0\n }\n set priority(value: number) {\n this.setStorageProperty(\"priority\", value)\n }\n\n /**\n * Whether the commitment is expired.\n * @returns Whether the commitment is expired.\n */\n isExpired(): boolean {\n if (this.toDay && this.toDay <= TimeManager.currentDay) {\n return true\n }\n return false\n }\n}\n","import { GameStorageManager } from \"@drincs/pixi-vn\";\nimport { ITimeStlot, TimeSettings } from \"../types/TimeSettings\";\n\nconst TIME_SETTINGS_KEY = '___nqtr-time_manager_settings___';\nconst TIME_DATA_KEY = '___nqtr-time_manager_data___';\n\ntype ITimeData = {\n currentHour?: number\n currentDay?: number\n}\n\nexport default class TimeManager {\n private constructor() { }\n private static editSettings(settings: TimeSettings) {\n let data: any = {}\n if (typeof settings.minDayHours === 'number') {\n data['minDayHours'] = settings.minDayHours\n }\n if (typeof settings.maxDayHours === 'number') {\n data['maxDayHours'] = settings.maxDayHours\n }\n if (typeof settings.minDayHours === 'number') {\n data['defaultTimeSpent'] = settings.defaultTimeSpent\n }\n if (Array.isArray(settings.timeSlots)) {\n data['timeSlots'] = settings.timeSlots\n }\n if (typeof settings.weekLength === 'number') {\n data['weekLength'] = settings.weekLength\n }\n if (typeof settings.weekendStartDay === 'number') {\n let weekLength = settings.weekLength || TimeManager.weekLength\n if (settings.weekendStartDay >= weekLength) {\n console.warn(`[NQTR] Weekend start day should be less than week length ${weekLength}`)\n }\n data['weekendStartDay'] = settings.weekendStartDay\n }\n if (Array.isArray(settings.weekDaysNames)) {\n let weekLength = settings.weekLength || TimeManager.weekLength\n if (settings.weekDaysNames.length !== weekLength) {\n console.warn(`[NQTR] Week days names should be equal to week length ${weekLength}`)\n }\n data['weekDaysNames'] = settings.weekDaysNames\n }\n GameStorageManager.setVariable(TIME_SETTINGS_KEY, data)\n }\n /**\n * Get time settings\n * @default {}\n */\n static get settings(): TimeSettings {\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY) || {}\n return settings\n }\n /**\n * Set time settings, Is very important to set the settings before using the nqtr library, bacause more of the features are based on the time settings.\n */\n static set settings(value: TimeSettings) {\n TimeManager.editSettings(value)\n }\n static get minDayHours(): number {\n let result = 0\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('minDayHours')) {\n result = settings.minDayHours || 0\n }\n return result\n }\n static get maxDayHours(): number {\n let result = 24\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('maxDayHours')) {\n result = settings.maxDayHours || 24\n }\n return result\n }\n static get defaultTimeSpent(): number {\n let result = 1\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('defaultTimeSpent')) {\n result = settings.defaultTimeSpent || 1\n }\n return result\n }\n static get timeSlots(): ITimeStlot[] {\n let result: ITimeStlot[] = []\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('timeSlots')) {\n result = settings.timeSlots || []\n }\n return result\n }\n static get weekLength(): number {\n let result = 7\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('weekLength')) {\n result = settings.weekLength || 7\n }\n return result\n }\n static get weekendStartDay(): number {\n let result = TimeManager.weekLength - 1\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('weekendStartDay')) {\n result = settings.weekendStartDay || TimeManager.weekLength - 1\n }\n return result\n }\n static get weekDaysNames(): string[] {\n let result: string[] = []\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('weekDaysNames')) {\n result = settings.weekDaysNames || result\n }\n return result\n }\n\n /**\n * Get the current hour\n */\n static get currentHour(): number {\n let data = GameStorageManager.getVariable<ITimeData>(TIME_DATA_KEY) || {}\n if (data.hasOwnProperty('currentHour') && typeof data.currentHour === 'number') {\n return data.currentHour\n }\n return TimeManager.minDayHours\n }\n static set currentHour(value: number | undefined) {\n let data = GameStorageManager.getVariable<ITimeData>(TIME_DATA_KEY) || {}\n if (typeof value === 'number') {\n data.currentHour = value\n } else {\n delete data.currentHour\n }\n GameStorageManager.setVariable(TIME_DATA_KEY, data)\n }\n /**\n * Get the current day\n */\n static get currentDay(): number {\n let data = GameStorageManager.getVariable<ITimeData>(TIME_DATA_KEY) || {}\n if (data.hasOwnProperty('currentDay') && typeof data.currentDay === 'number') {\n return data.currentDay\n }\n return 0\n }\n static set currentDay(value: number | undefined) {\n let data = GameStorageManager.getVariable<ITimeData>(TIME_DATA_KEY) || {}\n if (typeof value === 'number') {\n data.currentDay = value\n }\n else {\n delete data.currentDay\n }\n GameStorageManager.setVariable(TIME_DATA_KEY, data)\n }\n /**\n * If the current day is greater than or equal to the weekend start day, then it will return true.\n */\n static get isWeekend(): boolean {\n return TimeManager.currentWeekDayNumber >= TimeManager.weekendStartDay\n }\n /**\n * Get the current week day number (1-TimeManager.weekLength).\n * For example, if the week length is 7 and the current day is 10, then the result will be 4.\n */\n static get currentWeekDayNumber(): number {\n let result = TimeManager.currentDay % TimeManager.weekLength\n return result + 1\n }\n /**\n * Get the current week day name. If the week days names are not defined, then it will return undefined.\n * For example, if the week days names are ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] and the current day is 10, then the result will be 'Thursday'.\n * @default \"\"\n */\n static get currentDayName(): string {\n let weekDayNumber = TimeManager.currentWeekDayNumber - 1\n if (weekDayNumber >= TimeManager.weekDaysNames.length) {\n console.warn(`[NQTR] Week day name is not defined for day ${weekDayNumber}`, TimeManager.weekDaysNames)\n return \"\"\n }\n return TimeManager.weekDaysNames[weekDayNumber]\n }\n /**\n * Get the current TimeManager.timeSlots index.\n * You can use this property to create \"Image that changes based on the time period\":\n * @example\n * ```tsx\n * import { TimeManager } from '@drincs/nqtr';\n * \n * function changeBackground() {\n * return (\n * <img src={`background-${TimeManager.currentTimeSlot}.png`} />\n * )\n * }\n */\n static get currentTimeSlot(): number {\n if (TimeManager.timeSlots.length === 0) {\n console.warn('[NQTR] Time slots are not defined')\n return 0\n }\n for (let index = 0; index < TimeManager.timeSlots.length; index++) {\n let slot = TimeManager.timeSlots[index]\n if (TimeManager.timeSlots.length > index + 1) {\n if (TimeManager.nowIsBetween(slot.startHour, TimeManager.timeSlots[index + 1].startHour)) {\n return index\n }\n }\n }\n return TimeManager.timeSlots.length - 1\n }\n\n /**\n * This function will increase the current hour by the given time spent.\n * If the new hour is greater than or equal to the max day hours, then it will increase the day and set the new hour.\n * @param timeSpent is the time spent in hours (default: TimeManager.defaultTimeSpent)\n * @returns TimeManager.currentHour\n */\n static increaseHour(timeSpent: number = TimeManager.defaultTimeSpent): number {\n let newHour = TimeManager.currentHour + timeSpent\n if (newHour >= TimeManager.maxDayHours) {\n TimeManager.increaseDay()\n newHour = TimeManager.minDayHours + (newHour - TimeManager.maxDayHours)\n }\n TimeManager.currentHour = newHour\n return TimeManager.currentHour\n }\n\n /**\n * This function will increase the current day by the given days.\n * @param newDayHour is the hour of the new day (default: TimeManager.minDayHours)\n * @param days is the number of days to increase (default: 1)\n * @returns TimeManager.currentDay\n */\n static increaseDay(newDayHour: number = TimeManager.minDayHours, days: number = 1): number {\n let newDay = TimeManager.currentDay + days\n TimeManager.currentDay = newDay\n TimeManager.currentHour = newDayHour\n return TimeManager.currentDay\n }\n\n /**\n * This function will check if the current hour is between the given hours.\n * @param fromHour the starting hour. If the TimeManager.currentHour is equal to this hour, the function will return true.\n * @param toHour the ending hour.\n * @returns true if the current hour is between the given hours, otherwise false.\n */\n static nowIsBetween(fromHour: number, toHour: number): boolean {\n let currentHour = TimeManager.currentHour\n if (fromHour < toHour) {\n return currentHour >= fromHour && currentHour < toHour\n }\n return currentHour >= fromHour || currentHour < toHour\n }\n}\n","import { GraphicItemType, OnRenderGraphicItemProps, OnRunProps } from \"@drincs/nqtr/dist/override\"\nimport { getFlag } from \"@drincs/pixi-vn\"\nimport { ActivityProps } from \"../interface\"\nimport { TimeManager } from \"../managers\"\nimport { OnRunActivityEvent } from \"../types/OnRunActivityEvent\"\n\nexport abstract class ActivityStoredAbstract {\n /**\n * @param onRun The function that is called when the activity is runned. Have 2 parameters: the runned activity and the yourParams object, that is an object with the parameters that you want to pass to the onRun function.\n * @param props The activity properties.\n */\n constructor(onRun: OnRunActivityEvent<ActivityStoredAbstract>, props: ActivityProps) {\n this.defaultName = props.name\n this.defaultFromHour = props.fromHour\n this.defaultToHour = props.toHour\n this.defaultFromDay = props.fromDay\n this.defaultToDay = props.toDay\n this.defaultDisabled = props.disabled || false\n this.defaultHidden = props.hidden || false\n this._renderIcon = props.renderIcon\n this._onRun = onRun\n }\n\n abstract setStorageProperty<T>(propertyName: string, value: T | undefined): void;\n abstract getStorageProperty<T>(propertyName: string): T | undefined;\n abstract get id(): string\n\n private defaultName?: string\n /**\n * The name\n */\n get name(): string {\n return this.getStorageProperty<string>(\"name\") || this.defaultName || \"\"\n }\n set name(value: string | undefined) {\n this.setStorageProperty(\"name\", value)\n }\n\n private defaultFromHour?: number\n /**\n * The hour when the activity starts. If the activity is not started yet, it will be hidden.\n */\n get fromHour(): number {\n return this.getStorageProperty<number>(\"fromHour\") || this.defaultFromHour || TimeManager.minDayHours\n }\n set fromHour(value: number | undefined) {\n this.setStorageProperty(\"fromHour\", value)\n }\n\n private defaultToHour?: number\n /**\n * The hour when the activity ends. If the activity is ended yet, it will be hidden.\n */\n get toHour(): number {\n return this.getStorageProperty<number>(\"toHour\") || this.defaultToHour || (TimeManager.maxDayHours + 1)\n }\n set toHour(value: number | undefined) {\n this.setStorageProperty(\"toHour\", value)\n }\n\n private defaultFromDay?: number\n /**\n * The day when the activity starts. If the activity is not started yet, it will be hidden.\n */\n get fromDay(): number | undefined {\n return this.getStorageProperty<number>(\"fromDay\") || this.defaultFromDay\n }\n set fromDay(value: number | undefined) {\n this.setStorageProperty(\"fromDay\", value)\n }\n\n private defaultToDay?: number\n /**\n * The day when the activity ends. If the activity is ended yet, it will be deleted or hidden.\n */\n get toDay(): number | undefined {\n return this.getStorageProperty<number>(\"toDay\") || this.defaultToDay\n }\n set toDay(value: number | undefined) {\n this.setStorageProperty(\"toDay\", value)\n }\n\n private defaultDisabled: boolean | string\n /**\n * Whether is disabled.\n */\n get disabled(): boolean {\n let value = this.getStorageProperty<boolean>(\"disabled\") || this.defaultDisabled\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set disabled(value: boolean | string) {\n this.setStorageProperty(\"disabled\", value)\n }\n\n private defaultHidden: boolean | string\n /**\n * Whether is hidden. If the activity is not started yet, it will be hidden.\n */\n get hidden(): boolean {\n if (this.fromDay && this.fromDay > TimeManager.currentDay) {\n return true\n }\n if (!TimeManager.nowIsBetween(this.fromHour, this.toHour)) {\n return true\n }\n if (!this.isExpired) {\n return true\n }\n let value = this.getStorageProperty<boolean>(\"hidden\") || this.defaultHidden\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set hidden(value: boolean | string) {\n this.setStorageProperty(\"hidden\", value)\n }\n\n private _renderIcon?: GraphicItemType | ((activity: ActivityStoredAbstract, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the icon of the activity.\n */\n get renderIcon(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderIcon\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private _onRun: (activity: ActivityStoredAbstract, props: OnRunProps) => void\n /**\n * The function that is called when the activity is runned.\n */\n get run(): (props: OnRunProps) => void {\n return (props) => { return this._onRun(this, props) }\n }\n\n /**\n * Whether the activity is a deadline.\n * @returns Whether the activity is a deadline.\n */\n isExpired(): boolean {\n if (this.toDay && this.toDay <= TimeManager.currentDay) {\n return true\n }\n return false\n }\n\n /**\n * Export the activity properties.\n * @returns The activity properties.\n */\n export(): ActivityProps {\n return {\n name: this.getStorageProperty<string>(\"name\") || this.defaultName,\n fromHour: this.getStorageProperty<number>(\"fromHour\") || this.defaultFromHour,\n toHour: this.getStorageProperty<number>(\"toHour\") || this.defaultToHour,\n fromDay: this.getStorageProperty<number>(\"fromDay\") || this.defaultFromDay,\n toDay: this.getStorageProperty<number>(\"toDay\") || this.defaultToDay,\n disabled: this.getStorageProperty<boolean>(\"disabled\") || this.defaultDisabled,\n hidden: this.getStorageProperty<boolean>(\"hidden\") || this.defaultHidden,\n renderIcon: this._renderIcon\n }\n }\n}\n","import { GraphicItemType, OnRenderGraphicItemProps } from \"@drincs/nqtr/dist/override\";\nimport { getFlag, StoredClassModel } from \"@drincs/pixi-vn\";\nimport { getRoomsByLocation } from \"../../decorators/RoomDecorator\";\nimport { LocationProps } from \"../../interface\";\nimport MapBaseModel from \"./Map\";\nimport RoomBaseModel from \"./Room\";\n\nconst LOCATION_CATEGORY = \"__nqtr-location__\"\n\n/**\n * The base model of a location. I suggest you extend this class to create your own location model.\n * @example\n * ```typescript\n * export const mcHome = new LocationBaseModel('mc_home', mainMap, {\n * name: 'MC Home',\n * icon: \"https://icon.jpg\",\n * });\n * ```\n */\nexport default class LocationBaseModel<TMap extends MapBaseModel = MapBaseModel> extends StoredClassModel {\n /**\n * @param id The id of the location, it must be unique.\n * @param map The map where the location is.\n * @param props The properties of the location.\n */\n constructor(id: string, map: TMap, props: LocationProps<TMap> = {}) {\n super(LOCATION_CATEGORY, id)\n this.defaultName = props.name || \"\"\n this.defaultDisabled = props.disabled || false\n this.defaultHidden = props.hidden || false\n this._renderIcon = props.renderIcon\n this._map = map\n }\n\n private defaultName: string\n /**\n * The name of the location.\n * If you set undefined, it will return the initial value of name.\n */\n get name(): string {\n return this.getStorageProperty<string>(\"name\") || this.defaultName\n }\n set name(value: string | undefined) {\n this.setStorageProperty(\"name\", value)\n }\n\n private defaultDisabled: boolean | string\n /**\n * Whether is disabled. If it is a string, it is a Pixi'VN flag name.\n */\n get disabled(): boolean {\n let value = this.getStorageProperty<boolean>(\"disabled\") || this.defaultDisabled\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set disabled(value: boolean | string) {\n this.setStorageProperty(\"disabled\", value)\n }\n\n private defaultHidden: boolean | string\n /**\n * Whether is hidden. If it is a string, it is a Pixi'VN flag name.\n */\n get hidden(): boolean {\n let value = this.getStorageProperty<boolean>(\"hidden\") || this.defaultHidden\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set hidden(value: boolean | string) {\n this.setStorageProperty(\"hidden\", value)\n }\n\n private _renderIcon?: GraphicItemType | ((location: LocationBaseModel<TMap>, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the icon of the location.\n */\n get renderIcon(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderIcon\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private _map: TMap\n /**\n * The map where the location is.\n */\n get map(): TMap {\n return this._map\n }\n\n /**\n * Get the entrance room of the location.\n * You can cast the room to a specific type that extends RoomBaseModel.\n * @returns The entrance room or the first room if there is no entrance.\n * @example\n * ```typescript\n * const entranceHome = new RoomBaseModel(\"entrance-home\", home, { isEntrance: true })\n * saveRoom(entranceHome)\n * const home = new LocationBaseModel(\"home\", map, { name: \"Home\" })\n * \n * const entrance = home.getEntrance() // entrance === entranceHome\n * ```\n */\n getEntrance<TRoom extends RoomBaseModel = RoomBaseModel>(): TRoom | undefined {\n let rooms = this.getRooms<TRoom>()\n if (rooms.length === 0) {\n console.error(`[NQTR] The location ${this.id} has no rooms`)\n return\n }\n return rooms.find(room => room.isEntrance) || rooms[0]\n }\n\n /**\n * Get all rooms in the location.\n * You can cast the rooms to a specific type that extends RoomBaseModel.\n * @returns The rooms in the location.\n */\n getRooms<TRoom extends RoomBaseModel = RoomBaseModel>(): TRoom[] {\n return getRoomsByLocation<TRoom>(this)\n }\n}\n","import { GraphicItemType, OnRenderGraphicItemProps } from \"@drincs/nqtr/dist/override\"\nimport { getFlag, StoredClassModel } from \"@drincs/pixi-vn\"\nimport { getLocationsByMap } from \"../../decorators/RoomDecorator\"\nimport { MapProps } from \"../../interface\"\nimport LocationBaseModel from \"./Location\"\n\nconst MAP_CATEGORY = \"__nqtr-map__\"\n\n/**\n * The base model of a map. I suggest you extend this class to create your own map model.\n * @example\n * ```typescript\n * export const mainMap = new MapBaseModel('main_map', {\n * name: 'Main Map',\n * image: \"https://image.jpg\",\n * neighboringMaps: {\n * \"north\": \"atlanta_map_id\",\n * \"south\": \"miami_map_id\",\n * \"east\": \"new_york_map_id\",\n * \"west\": \"los_angeles_map_id\"\n * }\n * });\n * ```\n */\nexport default class MapBaseModel extends StoredClassModel {\n /**\n * @param id The id of the map, it must be unique.\n * @param props The properties of the map. \n */\n constructor(id: string, props: MapProps = {}) {\n super(MAP_CATEGORY, id)\n this.defaultName = props.name || \"\"\n this._renderImage = props.renderImage\n this.defaultDisabled = props.disabled || false\n this.defaultHidden = props.hidden || false\n }\n\n private defaultName: string\n /**\n * The name of the map.\n * If you set undefined, it will return the initial value of name.\n */\n get name(): string {\n return this.getStorageProperty<string>(\"name\") || this.defaultName\n }\n set name(value: string | undefined) {\n this.setStorageProperty(\"name\", value)\n }\n\n private _renderImage?: GraphicItemType | ((map: MapBaseModel, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the image of the map.\n */\n get renderImage(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderImage\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private defaultDisabled: boolean | string\n /**\n * Whether is disabled. If it is a string, it is a Pixi'VN flag name.\n */\n get disabled(): boolean {\n let value = this.getStorageProperty<boolean>(\"disabled\") || this.defaultDisabled\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set disabled(value: boolean | string) {\n this.setStorageProperty(\"disabled\", value)\n }\n\n private defaultHidden: boolean | string\n /**\n * Whether is hidden. If it is a string, it is a Pixi'VN flag name.\n */\n get hidden(): boolean {\n let value = this.getStorageProperty<boolean>(\"hidden\") || this.defaultHidden\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set hidden(value: boolean | string) {\n this.setStorageProperty(\"hidden\", value)\n }\n\n private _neighboringMaps?: { [key: string]: string }\n /**\n * The neighboring maps that are available in this map.\n * @example\n * ```ts\n * {\n * \"north\": \"atlanta_map_id\",\n * \"south\": \"miami_map_id\",\n * \"east\": \"new_york_map_id\",\n * \"west\": \"los_angeles_map_id\"\n * }\n * ```\n */\n get neighboringMaps(): { [key: string]: string } {\n return this._neighboringMaps || {}\n }\n set neighboringMaps(value: { [key: string]: string } | undefined) {\n this._neighboringMaps = value\n }\n\n /**\n * Get all locations in the map.\n * @returns The locations in the map.\n */\n getLocations<TLocation extends LocationBaseModel = LocationBaseModel>(): TLocation[] {\n return getLocationsByMap<TLocation>(this)\n }\n}\n","import { GraphicItemType, OnRenderGraphicItemProps } from \"@drincs/nqtr/dist/override\";\nimport { getFlag, StoredClassModel } from \"@drincs/pixi-vn\";\nimport { getActivityById, saveRoom } from \"../../decorators\";\nimport { getCurrentRoutine } from \"../../functions/RoutineFunctions\";\nimport { RoomProps } from \"../../interface\";\nimport { RoomActivityMemory } from \"../../interface/RoomActivityMemory\";\nimport ActivityModel from \"../Activity\";\nimport CommitmentBaseModel from \"../Commitment\";\nimport ActivityRoom from \"./ActivityRoom\";\nimport LocationBaseModel from \"./Location\";\n\nexport const ROOM_CATEGORY = \"__nqtr-room__\"\n\n/**\n * The base model of a room. I suggest you extend this class to create your own room model.\n * **You must use the {@link saveRoom} function to save the room in the registered rooms.**\n * @example\n * ```ts\n * export const mcRoom = new RoomBaseModel('mc_room', mcHome, {\n * name: \"MC Room\",\n * icon: \"https://icon.jpg\",\n * image: \"https://image.jpg\",\n * isEntrance: false,\n * })\n * saveRoom(mcRoom)\n * ```\n */\nexport default class RoomBaseModel<TLocation extends LocationBaseModel = LocationBaseModel> extends StoredClassModel {\n /**\n * @param id The id of the room, it must be unique.\n * @param location The location where the room is.\n * @param props The properties of the room.\n */\n constructor(id: string, location: TLocation, props: RoomProps<TLocation> = {}) {\n super(ROOM_CATEGORY, id)\n this._location = location\n this.defaultName = props.name || \"\"\n this._renderImage = props.renderImage\n this.defaultActivityIds = props.defaultActivities?.map(activity => activity.id) || []\n this.defaultDisabled = props.disabled || false\n this.defaultHidden = props.hidden || false\n this._renderIcon = props.renderIcon\n this._isEntrance = props.isEntrance\n }\n\n private _location: TLocation\n /**\n * The location where the room is.\n */\n get location(): TLocation {\n return this._location\n }\n\n private _isEntrance?: boolean\n /**\n * Whether is an entrance room, so when the player enters in the location, it will be the first room to be shown.\n */\n get isEntrance(): boolean {\n return this._isEntrance || false\n }\n\n private defaultName: string\n /**\n * The name.\n * If you set undefined, it will return the initial value of name.\n */\n get name(): string {\n return this.getStorageProperty<string>(\"name\") || this.defaultName\n }\n set name(value: string | undefined) {\n this.setStorageProperty(\"name\", value)\n }\n\n private _renderImage?: GraphicItemType | ((room: RoomBaseModel<TLocation>, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the image of the room.\n */\n get renderImage(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderImage\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private defaultActivityIds: string[]\n /**\n * The activities that are available in this room.\n */\n get defaultActivities(): ActivityRoom<this>[] {\n let roomMemories = this.getStorageProperty<RoomActivityMemory>(\"activities_memory\") || {}\n let activities = this.defaultActivityIds.map(id => {\n let activity = getActivityById(id)\n if (!activity) {\n console.warn(`[NQTR] Activity with id ${id} not found, so it will be ignored.`)\n return undefined\n }\n let memory = activity.export()\n if (roomMemories && roomMemories[id]) {\n memory = {\n ...memory,\n ...roomMemories[id]\n }\n }\n return new ActivityRoom(id, this, activity._initialOnRun, memory)\n }).filter(activity => activity !== undefined)\n return activities as ActivityRoom<this>[]\n }\n\n private get activityIds(): string[] {\n let addedActivityIds = this.getStorageProperty<string[]>(`addedActivityIds`) || []\n return this.defaultActivityIds.concat(addedActivityIds)\n }\n /**\n * The activities that are available in this room.\n */\n get activities(): ActivityRoom<this>[] {\n let activities = this.activityIds.map(id => {\n return this.getActivity(id)\n }).filter(activity => activity !== undefined && !activity.hidden)\n return activities as ActivityRoom<this>[]\n }\n /**\n * Get the memory of an activity. This function can be used into olther libraries to get the memory of the activity.\n * @param id The id of the activity.\n * @returns The memory of the activity.\n */\n getActivityMemory(id: string): object | undefined {\n let roomMemories = this.getStorageProperty<RoomActivityMemory>(\"activities_memory\") || {}\n let roomMemory = roomMemories[id] || {}\n return roomMemory\n }\n /**\n * Get the activity by id.\n * @param id The id of the activity.\n * @returns The room activity.\n */\n getActivity(id: string): ActivityRoom<this> | undefined {\n if (!this.activityIds.includes(id)) {\n console.error(`[NQTR] Activity with id ${id} not found in room ${this.id}`)\n return undefined\n }\n let activity = getActivityById(id)\n if (!activity) {\n console.error(`[NQTR] Activity with id ${id} not found`)\n return undefined\n }\n let roomMemories = this.getStorageProperty<RoomActivityMemory>(\"activities_memory\") || {}\n let roomMemory = roomMemories[id] || {}\n roomMemory = {\n ...activity.export(),\n ...roomMemory\n }\n return new ActivityRoom(id, this, activity._initialOnRun, roomMemory)\n }\n /**\n * Set the memory of an activity. This function can be used into olther libraries to set the memory of the activity.\n * @param id The id of the activity.\n * @param memory The memory of the activity.\n */\n setActivity(activity: ActivityRoom) {\n let roomMemories = this.getStorageProperty<RoomActivityMemory>(\"activities_memory\") || {}\n roomMemories[activity.id] = activity.export()\n this.setStorageProperty(\"activities_memory\", roomMemories)\n }\n /**\n * Add an activity to the room.\n * @param activity The activity to add.\n */\n addActivity(activity: ActivityModel) {\n if (this.activityIds.includes(activity.id)) {\n let currentActivity = this.getActivity(activity.id)\n if (currentActivity && currentActivity.isExpired()) {\n this.removeActivity(activity.id)\n return\n } else {\n console.error(`[NQTR] Activity with id ${activity.id} already exists in room ${this.id}, so it will be ignored.`)\n return\n }\n }\n let addedActivityIds = this.getStorageProperty<string[]>(`addedActivityIds`) || []\n addedActivityIds.push(activity.id)\n this.setStorageProperty(\"addedActivityIds\", addedActivityIds)\n }\n /**\n * Remove an activity from the room.\n * @param activity The activity to remove.\n */\n removeActivity(activity: ActivityModel | string) {\n let activityId = typeof activity === \"string\" ? activity : activity.id\n if (this.defaultActivityIds.includes(activityId)) {\n console.warn(`[NQTR] Activity with id ${activityId} is a default activity, so it can't be removed. It will be hidden instead.`)\n let activityToEdit = this.getActivity(activityId)\n if (!activityToEdit) {\n console.error(`[NQTR] Activity with id ${activityId} not found, so it can't be hidden.`)\n return\n }\n activityToEdit.hidden = true\n return\n }\n let addedActivityIds = this.getStorageProperty<string[]>(`addedActivityIds`) || []\n let index = addedActivityIds.indexOf(activityId)\n if (index === -1) {\n console.error(`[NQTR] Activity with id ${activityId} not found, so it can't be removed.`)\n return\n }\n addedActivityIds.splice(index, 1)\n this.setStorageProperty(\"addedActivityIds\", addedActivityIds)\n let roomMemories = this.getStorageProperty<RoomActivityMemory>(\"activities_memory\") || {}\n delete roomMemories[activityId]\n this.setStorageProperty(\"activities_memory\", roomMemories)\n }\n /**\n * Clear all expired activities.\n */\n clearExpiredActivities() {\n this.activities.forEach(activity => {\n if (activity.isExpired()) {\n this.removeActivity(activity.id)\n }\n })\n }\n\n private defaultDisabled: boolean | string\n /**\n * Whether is disabled. If it is a string, it is a Pixi'VN flag name.\n */\n get disabled(): boolean {\n let value = this.getStorageProperty<boolean>(\"disabled\") || this.defaultDisabled\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set disabled(value: boolean | string) {\n this.setStorageProperty(\"disabled\", value)\n }\n\n private defaultHidden: boolean | string\n /**\n * Whether is hidden. If it is a string, it is a Pixi'VN flag name.\n */\n get hidden(): boolean {\n let value = this.getStorageProperty<boolean>(\"hidden\") || this.defaultHidden\n if (typeof value === \"string\") {\n return getFlag(value)\n }\n return value\n }\n set hidden(value: boolean | string) {\n this.setStorageProperty(\"hidden\", value)\n }\n\n private _renderIcon?: GraphicItemType | ((room: RoomBaseModel<TLocation>, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the icon of the room.\n */\n get renderIcon(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderIcon\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n /**\n * Get the character commitments of the room.\n * @returns The character commitments of the room.\n */\n getRoutine<TCommitment extends CommitmentBaseModel = CommitmentBaseModel>(): TCommitment[] {\n let commitments = getCurrentRoutine<TCommitment>()\n return commitments.filter(c => c.room.id === this.id)\n }\n}\n","import { GraphicItemType, OnRenderGraphicItemProps, OnRunProps } from '@drincs/nqtr/dist/override';\nimport { getFlag } from \"@drincs/pixi-vn\";\nimport { ActivityProps } from '../interface';\nimport TimeManager from \"../managers/TimeManager\";\nimport { OnRunActivityEvent } from '../types/OnRunActivityEvent';\nimport { ActivityStoredAbstract } from './ActivityStoredAbstract';\n\n/**\n * The activity model. It is used to create an activity.\n * @example\n * ```tsx\n * export const nap = new ActivityModel(\"nap\",\n * (_, event) => {\n * if (event) {\n * event.navigate(\"/game\")\n * callLabelWithGoNavigationCallBack(napLabel, event)\n * }\n * else {\n * console.error(\"Event is undefined\")\n * }\n * },\n * {\n * name: \"Nap\",\n * fromHour: 5,\n * toHour: 23,\n * renderIcon: (activity, props) => {\n * return <Button\n * disabled={activity.disabled}\n * onClick={() => {\n * if (!props) {\n * console.error(\"Props is undefined\")\n * return\n * }\n * activity.onRun(props)\n * }}\n * ariaLabel={activity.name}\n * >\n * <BedIcon />\n * </Button>\n * },\n * }\n * )\n * ```\n */\nexport default class ActivityModel {\n /**\n * @param id The activity id, that must be unique.\n * @param onRun The function that is called when the activity is runned. Have 2 parameters: the runned activity and the yourParams object, that is an object with the parameters that you want to pass to the onRun function.\n * @param props The activity properties.\n */\n constructor(id: string, onRun: OnRunActivityEvent<ActivityModel>, props: ActivityProps) {\n this._id = id\n this._name = props.name\n this._fromHour = props.fromHour\n this._toHour = props.toHour\n this._fromDay = props.fromDay\n this._toDay = props.toDay\n this._disabled = props.disabled || false\n this._hidden = props.hidden || false\n this._renderIcon = props.renderIcon\n this._onRun = onRun\n }\n\n private _id: string\n /**\n * The activity id, that is unique.\n */\n get id(): string {\n return this._id\n }\n\n private _name?: string\n /**\n * The name\n */\n get name(): string | undefined {\n return this._name\n }\n\n private _fromHour?: number\n /**\n * The hour when the activity starts. If the activity is not started yet, it will be hidden.\n */\n get fromHour(): number | undefined {\n return this._fromHour\n }\n\n private _toHour?: number\n /**\n * The hour when the activity ends. If the activity is ended yet, it will be hidden.\n */\n get toHour(): number | undefined {\n return this._toHour\n }\n\n private _fromDay?: number\n /**\n * The day when the activity starts. If the activity is not started yet, it will be hidden.\n */\n get fromDay(): number | undefined {\n return this._fromDay\n }\n\n private _toDay?: number\n /**\n * The day when the activity ends. If the activity is ended yet, it will be deleted or hidden.\n */\n get toDay(): number | undefined {\n return this._toDay\n }\n\n private _disabled?: boolean | string\n /**\n * Whether is disabled.\n */\n get disabled(): boolean | undefined {\n if (typeof this._disabled === \"string\") {\n return getFlag(this._disabled)\n }\n return this._disabled\n }\n\n private _hidden: boolean | string\n /**\n * Whether is hidden. If the activity is not started yet, it will be hidden.\n */\n get hidden(): boolean {\n if (this.fromDay && this.fromDay > TimeManager.currentDay) {\n return true\n }\n if (!this.isDeadline) {\n return true\n }\n if (typeof this._hidden === \"string\") {\n return getFlag(this._hidden)\n }\n return this._hidden\n }\n\n private _renderIcon?: GraphicItemType | ((activity: ActivityModel, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the icon of the activity.\n */\n get renderIcon(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderIcon\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private _onRun: OnRunActivityEvent<ActivityModel>\n get _initialOnRun(): OnRunActivityEvent<ActivityStoredAbstract> {\n return this._onRun as any\n }\n /**\n * The function that is called when the activity is runned.\n */\n get run(): (props: OnRunProps) => void {\n return (props) => this._onRun(this, props)\n }\n\n /**\n * Whether the activity is a deadline.\n * @returns Whether the activity is a deadline.\n */\n isDeadline(): boolean {\n if (this.toDay && this.toDay <= TimeManager.currentDay) {\n return true\n }\n return false\n }\n\n /**\n * Export the activity properties.\n * @returns The activity properties.\n */\n export(): ActivityProps {\n return {\n name: this._name,\n fromHour: this._fromHour,\n toHour: this._toHour,\n fromDay: this._fromDay,\n toDay: this._toDay,\n disabled: this._disabled,\n hidden: this._hidden,\n renderIcon: this._renderIcon,\n }\n }\n}\n","import { GameStorageManager } from \"@drincs/pixi-vn\"\nimport CommitmentBaseModel from \"../classes/Commitment\"\n\nconst TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY = \"___nqtr-temporary_commitment___\"\nexport const registeredCommitments: { [id: string]: CommitmentBaseModel } = {}\nexport const fixedCommitments: { [id: string]: CommitmentBaseModel } = {}\n\n/**\n * Save a commitment in the registered commitments. If the commitment already exists, it will be overwritten.\n * @param commitment The commitment or commitments to save.\n * @returns \n */\nexport function saveCommitment<TCommitment extends CommitmentBaseModel = CommitmentBaseModel>(commitment: TCommitment | TCommitment[]) {\n if (Array.isArray(commitment)) {\n commitment.forEach(c => saveCommitment(c))\n return\n }\n if (registeredCommitments[commitment.id]) {\n console.warn(`[NQTR] Commitment id ${commitment.id} already exists, it will be overwritten`)\n }\n registeredCommitments[commitment.id] = commitment\n}\n\n/**\n * Get a commitment by its id.\n * @param id The id of the commitment.\n * @returns The commitment or undefined if not found.\n */\nexport function getCommitmentById<TCommitment extends CommitmentBaseModel = CommitmentBaseModel>(id: string): TCommitment | undefined {\n try {\n let commitment = registeredCommitments[id]\n if (!commitment) {\n console.error(`[NQTR] Commitment ${id} not found`)\n return\n }\n return commitment as TCommitment\n }\n catch (e) {\n console.error(`[NQTR] Error while getting Commitment ${id}`, e)\n return\n }\n}\n\n/**\n * Set a commitment as fixed, it will be always available. They cannot be deleted or edit during the game session.\n * @param commitment The commitment or commitments to set as fixed.\n */\nexport function setFixedRoutine<TCommitment extends CommitmentBaseModel = CommitmentBaseModel>(commitments: TCommitment[] | TCommitment) {\n if (Array.isArray(commitments)) {\n commitments.forEach(c => setFixedRoutine(c))\n return\n }\n if (fixedCommitments[commitments.id]) {\n console.warn(`[NQTR] Commitment id ${commitments.id} already exists, it will be overwritten`)\n }\n fixedCommitments[commitments.id] = commitments\n}\n\n/**\n * This feature adds the commitments during the game session.\n * @param commitment The commitment or commitments to add.\n */\nexport function addCommitment<TCommitment extends CommitmentBaseModel = CommitmentBaseModel>(commitment: TCommitment[] | TCommitment) {\n if (!Array.isArray(commitment)) {\n commitment = [commitment]\n }\n let commitmentsIds = commitment.map(commitment => {\n let commitmentTest = getCommitmentById(commitment.id)\n if (!commitmentTest) {\n console.warn(`[NQTR] Commitment ${commitment.id} not found, it will be ignored`)\n return undefined\n }\n return commitment.id\n }).filter(id => id !== undefined)\n\n GameStorageManager.setVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY, commitmentsIds)\n}\n\n/**\n * Remove the commitments added during the game session.\n * @param commitment The commitment or commitments to remove.\n * @returns \n */\nexport function removeCommitment<TCommitment extends CommitmentBaseModel = CommitmentBaseModel>(commitment: TCommitment[] | TCommitment) {\n if (!Array.isArray(commitment)) {\n commitment = [commitment]\n }\n let commitmentsIds = commitment.map(commitment => {\n return commitment.id\n })\n\n let currentCommitments = GameStorageManager.getVariable<string[]>(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY)\n if (!currentCommitments) {\n return\n }\n currentCommitments = currentCommitments.filter(id => !commitmentsIds.includes(id))\n GameStorageManager.setVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY, currentCommitments)\n}\n\n/**\n * Get the fixed commitments by its id.\n * @returns The fixed commitments.\n */\nexport function getFixedRoutine<TCommitment extends CommitmentBaseModel = CommitmentBaseModel>(): TCommitment[] {\n return Object.values(fixedCommitments) as TCommitment[]\n}\n\n/**\n * Get the temporary commitments by its id.\n * @returns The temporary commitments.\n */\nexport function getTemporaryCommitments<TCommitment extends CommitmentBaseModel = CommitmentBaseModel>(): TCommitment[] {\n let commitmentsIds = GameStorageManager.getVariable<string[]>(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY)\n if (!commitmentsIds) {\n return []\n }\n let commitments = commitmentsIds.map(id => getCommitmentById<TCommitment>(id)).filter(commitment => commitment !== undefined)\n return commitments as TCommitment[]\n}\n","import { GraphicItemType, OnEndStage, OnRenderGraphicItemProps, OnStartStage } from \"@drincs/nqtr/dist/override\";\nimport { StoredClassModel } from \"@drincs/pixi-vn\";\nimport { QuestProps } from \"../../interface\";\nimport Stage, { StageQuest } from \"./Stage\";\n\nconst QUEST_CATEGORY = \"__nqtr-quest__\"\n\nexport default class Quest extends StoredClassModel {\n constructor(id: string, stages: Stage[], props: QuestProps) {\n super(QUEST_CATEGORY, id)\n this._stages = stages\n this._name = props.name || \"\"\n this._description = props.description || \"\"\n this._renderIcon = props.renderIcon\n this._renderImage = props.renderImage\n this._isInDevelopment = props.isInDevelopment || false\n }\n\n private _stages: Stage[]\n /**\n * The stages of the quest.\n */\n get stages(): StageQuest[] {\n return this._stages.map((stage, index) => {\n return new StageQuest(stage.id, stage)\n })\n }\n\n private _name: string\n /**\n * The name of the quest.\n */\n get name(): string {\n return this._name\n }\n\n private _description: string\n /**\n * The description of the quest.\n */\n get description(): string {\n return this._description\n }\n\n private _renderIcon?: GraphicItemType | ((room: Quest, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the icon of the quest.\n */\n get renderIcon(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderIcon\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private _renderImage?: GraphicItemType | ((room: Quest, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the image of the quest.\n */\n get renderImage(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderImage\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private _isInDevelopment: boolean\n /**\n * If the quest is in development.\n */\n get isInDevelopment(): boolean {\n return this._isInDevelopment\n }\n\n /**\n * The index of the current stage.\n */\n get currentStageIndex(): number | undefined {\n return this.getStorageProperty<number>('currentStageIndex')\n }\n private set currentStageIndex(value: number | undefined) {\n this.setStorageProperty('currentStageIndex', value)\n }\n\n /**\n * The current stage.\n */\n get currentStage(): StageQuest | undefined {\n let index = this.currentStageIndex\n if (index === undefined || index >= this.stages.length) {\n return undefined\n }\n return this.stages[index]\n }\n\n /**\n * If the quest is started.\n */\n get started(): boolean {\n return this.currentStageIndex !== undefined\n }\n\n /**\n * If the quest is completed.\n */\n get completed(): boolean {\n if (this.currentStageIndex === undefined) {\n return false\n }\n return this.currentStageIndex > this.stages.length - 1\n }\n\n /**\n * Start the quest.\n * @param props The properties for the start stage. If you not want to pass any property, you can pass an {}.\n * @returns \n */\n start(props: OnStartStage): void {\n if (this.started) {\n console.warn(`[NQTR] Quest ${this.id} is already started`)\n return\n }\n if (this.stages.length === 0) {\n console.error(`[NQTR] Quest ${this.id} has no stages`)\n return\n }\n this.currentStageIndex = 0\n let currentStage = this.currentStage\n if (currentStage && currentStage.start) {\n return currentStage.start(props)\n }\n else {\n console.error(`[NQTR] Quest ${this.id} has no start stage`)\n }\n }\n\n /**\n * Go to the next stage if the current stage is completed.\n * If you want to force the change of stage, use goNextStage.\n * @param startProps The properties for the start stage. If you not want to pass any property, you can pass an {}.\n * @param endProps The properties for the end stage. If you not want to pass any property, you can pass an {}.\n * @returns true if the stage was changed, false otherwise.\n */\n tryToGoNextStage(\n startProps: OnStartStage,\n endProps: OnEndStage\n ): boolean {\n if (!this.started) {\n return false\n }\n if (this.completed) {\n return false\n }\n let currentStage = this.currentStage\n if (!currentStage) {\n console.error(`[NQTR] Quest ${this.id} has no current stage`)\n return false\n }\n if (currentStage.completed) {\n return this.goNextStage(startProps, endProps)\n }\n return false\n }\n\n /**\n * Complete the current stage and go to the next stage.\n * If you want to go to the next stage only if the current stage is completed, use tryToGoNextStage.\n * @param startProps The properties for the start stage. If you not want to pass any property, you can pass an {}.\n * @param endProps The properties for the end stage. If you not want to pass any property, you can pass an {}.\n * @returns true if the stage was changed, false otherwise.\n */\n completeCurrentStageAndGoNext(\n startProps: OnStartStage,\n endProps: OnEndStage\n ): boolean {\n let currentStage = this.currentStage\n if (!currentStage) {\n console.error(`[NQTR] Quest ${this.id} has no current stage`)\n return false\n }\n currentStage.completed = true\n return this.goNextStage(startProps, endProps)\n }\n\n /**\n * Go to the next stage without checking if the current stage is completed.\n * If you want to go to the next stage only if the current stage is completed, use tryToGoNextStage.\n * @param startProps \n * @param endProps \n * @returns returns true if the stage was changed, false otherwise.\n */\n goNextStage(\n startProps: OnStartStage,\n endProps: OnEndStage\n ): boolean {\n if (!this.started) {\n console.warn(`[NQTR] Quest ${this.id} is not started`)\n return false\n }\n if (this.completed) {\n console.warn(`[NQTR] Quest ${this.id} is already completed`)\n return false\n }\n let prevStage = this.currentStage\n let currentStageIndex = this.currentStageIndex\n if (!prevStage || currentStageIndex === undefined) {\n console.error(`[NQTR] Quest ${this.id} has no current stage`)\n return false\n }\n this.currentStageIndex = currentStageIndex + 1\n if (prevStage && prevStage.onEnd) {\n prevStage.onEnd(endProps)\n }\n let nextCurrentStage = this.currentStage\n if (nextCurrentStage) {\n nextCurrentStage.inizialize()\n if (this.currentStageMustStart) {\n this.startCurrentStage(startProps)\n }\n }\n\n return true\n }\n\n /**\n * If the current stage must start. It is true if the current stage is not started, can start and not completed.\n */\n get currentStageMustStart(): boolean {\n let currentStage = this.currentStage\n if (!currentStage) {\n return false\n }\n return !currentStage.started && currentStage.canStart && !currentStage.completed\n }\n\n /**\n * Start the current stage.\n * @param props The properties for the start stage. If you not want to pass any property, you can pass an {}.\n */\n startCurrentStage(props: OnStartStage): void {\n let newCurrentStage = this.currentStage\n if (newCurrentStage && this.currentStageMustStart) {\n newCurrentStage.start(props)\n }\n else {\n console.warn(`[NQTR] Quest ${this.id} can't start the current stage`)\n }\n }\n}\n","import { GraphicItemType, OnEndStage, OnRenderGraphicItemProps, OnStartStage } from \"@drincs/nqtr/dist/override\";\nimport { StoredClassModel, getFlag } from \"@drincs/pixi-vn\";\nimport { StageProps } from \"../../interface\";\nimport StageFlags from \"../../interface/quest/StageFlags\";\nimport { TimeManager } from \"../../managers\";\nimport { QuestsRequiredType } from \"../../types/QuestsRequired\";\nimport Goal, { GoalStage } from \"./Goal\";\n\nconst STAGE_CATEGORY = \"__nqtr-stage__\"\n\nexport default class Stage extends StoredClassModel implements StageProps {\n constructor(id: string, props: StageProps) {\n super(STAGE_CATEGORY, id)\n this._name = props.name || \"\"\n this._defaultGoals = props.goals || []\n this._flags = props.flags || []\n this._description = props.description || \"\"\n this._adviceDescription = props.adviceDescription || \"\"\n this._renderImage = props.renderImage\n this._daysRequiredToStart = props.daysRequiredToStart\n this._flagsRequiredToStart = props.flagsRequiredToStart || []\n this._questsRequiredToStart = props.questsRequiredToStart || []\n this._requestDescriptionToStart = props.requestDescriptionToStart || \"\"\n this._onStart = props.onStart\n this._onEnd = props.onEnd\n }\n\n private _name: string\n /**\n * The name of the stage.\n */\n get name(): string {\n return this._name\n }\n\n private _description: string\n /**\n * The description of the stage.\n */\n get description(): string {\n return this._description\n }\n\n private _adviceDescription: string\n /**\n * The advice description of the stage.\n */\n get adviceDescription(): string {\n return this._adviceDescription\n }\n\n private _renderImage?: GraphicItemType | ((room: Stage, props: OnRenderGraphicItemProps) => GraphicItemType)\n /**\n * The function for rendering the image of the stage.\n */\n get renderImage(): ((props: OnRenderGraphicItemProps) => GraphicItemType) | undefined {\n let render = this._renderImage\n if (render === undefined) {\n return undefined\n }\n if (typeof render === \"function\") {\n return (props: OnRenderGraphicItemProps) => {\n return render(this, props)\n }\n }\n return (props: OnRenderGraphicItemProps) => render\n }\n\n private _defaultGoals: Goal[]\n /**\n * The list of goals that the player needs to complete to finish the stage.\n * This is the list set by the developer. if you want to get the current goals, use the goals property.\n */\n get defaultGoals(): Goal[] {\n return this._defaultGoals\n }\n\n private _flags: StageFlags[]\n /**\n * The list of flags that the player must complete to finish the stage.\n */\n get flags(): StageFlags[] {\n return this._flags\n }\n\n // request to start\n\n private _daysRequiredToStart?: number\n /**\n * The number of days required to start the stage.\n */\n get daysRequiredToStart(): number {\n return this._daysRequiredToStart || 0\n }\n\n private _flagsRequiredToStart: StageFlags[]\n /**\n * The list of flags required to start the stage.\n */\n get flagsRequiredToStart(): StageFlags[] {\n return this._flagsRequiredToStart\n }\n\n private _questsRequiredToStart: QuestsRequiredType[]\n /**\n * The list of quests required to start the stage.\n */\n get questsRequiredToStart(): QuestsRequiredType[] {\n return this._questsRequiredToStart || []\n }\n\n private _requestDescriptionToStart: string\n /**\n * The description of the request to start the stage.\n */\n get requestDescriptionToStart(): string {\n return this._requestDescriptionToStart\n }\n\n // function\n\n private _onStart?: (props: OnStartStage) => void\n /**\n * The function that will be called when the stage starts.\n */\n get onStart(): undefined | ((props: OnStartStage) => void) {\n return this._onStart\n }\n\n private _onEnd?: (props: OnEndStage) => void\n /**\n * The function that will be called when the stage ends.\n */\n get onEnd(): undefined | ((props: OnEndStage) => void) {\n return this._onEnd\n }\n}\n\nexport class StageQuest extends Stage {\n constructor(id: string, props: StageProps) {\n super(id, props)\n }\n\n /**\n * Check if the flag and goals are completed.\n * You can force the completion of the stage by setting the completed property to true.\n */\n get completed(): boolean {\n let storedCompleted = this.getStorageProperty<boolean>('completed')\n if (storedCompleted) {\n return storedCompleted\n }\n if (this.flags.length > 0 && this.goals.length > 0) {\n if (!this.flags.every(flag => getFlag(flag.flag))) {\n return false\n }\n if (!this.goals.every(goal => goal.completed)) {\n return false\n }\n return true\n }\n return false\n }\n set completed(value: boolean) {\n this.setStorageProperty('completed', value)\n }\n\n /**\n * If the stage is started.\n */\n get started(): boolean {\n return this.getStorageProperty<boolean>('started') || false\n }\n set started(value: boolean) {\n this.setStorageProperty('started', value)\n }\n\n /**\n * The list of goals that the player needs to complete to finish the stage.\n */\n get goals(): GoalStage[] {\n return this.defaultGoals.map((goal) => {\n return new GoalStage(goal.id, this.id, goal)\n })\n }\n\n private get prevStageEndDay(): number | undefined {\n return this.getStorageProperty<number>('prevStageEndDay')\n }\n private set prevStageEndDay(value: number | undefined) {\n this.setStorageProperty('prevStageEndDay', value)\n }\n\n /**\n * The day when the stage starts.\n */\n get startDay(): number | undefined {\n let prevStageEndDay = this.prevStageEndDay\n if (prevStageEndDay === undefined) {\n return undefined\n }\n return prevStageEndDay + this.daysRequiredToStart\n }\n\n /**\n * Check if the stage can start.\n */\n get canStart(): boolean {\n let daysRequired = this.daysRequiredToStart\n if (daysRequired > 0) {\n let prevStageEndDay = this.prevStageEndDay\n if (prevStageEndDay === undefined) {\n return false\n }\n if (prevStageEndDay + daysRequired > TimeManager.currentDay) {\n return false\n }\n }\n if (this.flagsRequiredToStart.length > 0 && !this.flagsRequiredToStart.every(flag => getFlag(flag.flag))) {\n return false\n }\n if (this.questsRequiredToStart.length > 0 && !this.questsRequiredToStart.every(q =>\n q.quest.currentStageIndex && q.quest.currentStageIndex >= q.stageNumber\n )) {\n return false\n }\n return true\n }\n\n /**\n * Inizialize the stage. **This function should be called only by the Quest class.**\n */\n inizialize() {\n if (this.daysRequiredToStart > 0) {\n this.prevStageEndDay = TimeManager.currentDay\n console.log(`[NQTR] Stage ${this.id} will start on day ${this.startDay}`)\n }\n }\n\n /**\n * The function that will be called when the stage starts.\n */\n start(props: OnStartStage) {\n if (this.canStart) {\n this.started = true\n if (this.onStart) {\n this.onStart(props)\n }\n }\n else {\n console.warn(`[NQTR] Stage ${this.id} can't start`)\n }\n }\n}\n","import { StoredClassModel } from \"@drincs/pixi-vn\"\nimport { GoalProps } from \"../../interface\"\n\nconst GOAL_CATEGORY = \"__nqtr-goal__\"\n\nexport default class Goal extends StoredClassModel implements GoalProps {\n constructor(id: string, props: GoalProps) {\n super(GOAL_CATEGORY, id)\n this._description = props.description\n this._need = props.need || 1\n this._defaultHave = props.have || 0\n }\n\n private _description: string\n /**\n * The description of the goal.\n */\n get description(): string {\n return this._description\n }\n\n private _need: number\n /**\n * The number of times the goal must be completed.\n */\n get need(): number {\n return this._need\n }\n\n private _defaultHave: number\n /**\n * The default number of times the goal has been completed.\n */\n get defaultHave(): number {\n return this._defaultHave\n }\n}\n\nexport class GoalStage extends Goal {\n constructor(id: string, stageId: string, props: GoalProps) {\n super(id, props)\n this._stageId = stageId\n }\n\n private _stageId?: string\n /**\n * The id of the stage that the goal belongs to.\n */\n get stageId(): string | undefined {\n return this._stageId\n }\n set stageId(value: string) {\n this._stageId = value\n }\n\n /**\n * The number of times the goal has been completed.\n */\n get have(): number {\n return this.getStorageProperty<number>('have-' + this._stageId) || this.defaultHave\n }\n set have(value: number) {\n if (!this._stageId) {\n console.error(`[NQTR] The stage id is not set for the goal ${this.id}, so the have value can't be set.`)\n return\n }\n this.setStorageProperty('have-' + this._stageId, value)\n }\n\n /**\n * If the goal is completed.\n */\n get completed(): boolean {\n return this.have >= this.need\n }\n set completed(value: boolean) {\n if (value) {\n this.have = this.need\n } else {\n console.warn(`[NQTR] The goal can't be set as not completed. You must edit the have value manually.`)\n }\n }\n\n /**\n * Find the goal. It will increment the have value.\n */\n find(): void {\n this.have++\n }\n}\n","import { ActivityRoom } from \"../classes\"\nimport { registeredRooms } from \"../decorators/RoomDecorator\"\nimport { getCurrentRoom } from \"./NavigationFunctions\"\n\n/**\n * Clear all the expired activities.\n */\nexport function clearExpiredActivities() {\n Object.entries(registeredRooms).forEach(([_, room]) => {\n room.clearExpiredActivities()\n })\n}\n\n/**\n * Get the current activities. The hidden activities are not included.\n * @returns The current activities.\n */\nexport function currentActivities(): ActivityRoom[] {\n let currentRoom = getCurrentRoom()\n if (!currentRoom) {\n return []\n }\n return currentRoom.activities.filter(activity => !activity.hidden)\n}\n"]}