@drincs/nqtr 0.7.2 → 0.8.1

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.
package/README.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Navigation Quest Time Routine (NQTR)
2
2
 
3
+ ![cover](https://github.com/user-attachments/assets/9b514c5c-8243-4cdd-9129-ca5e45caec62)
4
+
5
+ <p align="center">
6
+ <a href="https://www.npmjs.com/package/@drincs/nqtr" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/npm/v/@drincs/nqtr?label=version" alt="npm version"></a>
7
+ <a href="https://www.npmjs.com/package/@drincs/nqtr" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/npm/dm/@drincs/nqtr" alt="npm downloads per month"></a>
8
+ <a target="_blank" href="https://www.jsdelivr.com/package/npm/@drincs/nqtr" rel="noopener noreferrer nofollow"><img alt="jsDelivr hits (npm)" src="https://img.shields.io/jsdelivr/npm/hm/@drincs/nqtr?logo=jsdeliver"></a>
9
+ <a href="https://www.npmjs.com/package/@drincs/nqtr" rel="noopener noreferrer nofollow"><img alt="NPM License" src="https://img.shields.io/npm/l/@drincs/nqtr"></a>
10
+ <a target="_blank" href="https://discord.gg/E95FZWakzp" rel="noopener noreferrer nofollow"><img alt="Discord" src="https://img.shields.io/discord/1263071210011496501?color=7289da&label=discord"></a>
11
+ </p>
12
+
3
13
  **What is NQTR?** NQTR (Navigation Quest Time Routine) is an extension for Pixi'VN that adds advanced systems for navigation, quests, time management, and game state handling. It is fully customizable and extensible, enabling developers to implement complex game mechanics with ease.
4
14
 
5
15
  ## Installation
package/dist/handlers.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var registries=require('@drincs/nqtr/registries'),storage=require('@drincs/pixi-vn/storage');var C=Object.defineProperty;var N=(a,e,t)=>e in a?C(a,e,{enumerable:true,configurable:true,writable:true,value:t}):a[e]=t;var u=(a,e,t)=>N(a,typeof e!="symbol"?e+"":e,t);var f="___nqtr-time_manager_data___",T="___nqtr-current_room_memory___",D="___nqtr-last_event_memory___";function l(a){storage.storage.set(D,a);}var c;(i=>(i.log=(m,...s)=>console.log(`[NQTR] ${m}`,...s),i.warn=(m,...s)=>console.warn(`[NQTR] ${m}`,...s),i.error=(m,...s)=>console.error(`[NQTR] ${m}`,...s),i.info=(m,...s)=>console.info(`[NQTR] ${m}`,...s)))(c||(c={}));var p=class{get rooms(){return registries.RegisteredRooms.values()}get locations(){return registries.RegisteredLocations.values()}get maps(){return registries.RegisteredMaps.values()}get currentRoomId(){return storage.storage.get(T)}get currentRoom(){let e=this.currentRoomId;if(!e){c.error("The current room has not yet been set");return}let t=registries.RegisteredRooms.get(e);if(!t){c.error(`Current room ${e} not found`);return}return t}set currentRoom(e){if(typeof e!="string"&&(e=e.id),!registries.RegisteredRooms.get(e)){c.error(`The room ${e} is not registered, so it can't be set as current room`);return}let r=storage.storage.get(T);r!==e&&(l({type:"editroom",prev:r,value:e}),storage.storage.set(T,e));}get currentLocation(){return this.currentRoom?.location}get currentMap(){return this.currentRoom?.location.map}clearExpiredActivities(){registries.RegisteredRooms.values().forEach(e=>{e.clearExpiredActivities();});}};var g=class{get quests(){return registries.RegisteredQuests.values()}get startedQuests(){return this.quests.filter(e=>e.started)}get inProgressQuests(){return this.quests.filter(e=>e.inProgress)}get completedQuests(){return this.quests.filter(e=>e.completed)}get failedQuests(){return this.quests.filter(e=>e.failed)}get notStartedQuests(){return this.quests.filter(e=>!e.started)}find(e){return registries.RegisteredQuests.get(e)}async startsStageMustBeStarted(e){let t=this.quests.map(r=>r.currentStageMustStart?r.startCurrentStage(e):Promise.resolve());await Promise.all(t);}};var I="___nqtr-temporary_commitment___",y=class{get fixedRoutine(){return [...registries.fixedCommitments.values()]}set fixedRoutine(e){e.forEach(t=>{registries.fixedCommitments.has(t.id)&&console.warn(`[NQTR] Commitment id ${t.id} already exists, it will be overwritten`),registries.fixedCommitments.set(t.id,t);});}get temporaryRoutine(){let e=storage.storage.get(I);return e?e.map(r=>registries.RegisteredCommitments.get(r)).filter(r=>r!==void 0):[]}get allRoutine(){return [...this.fixedRoutine,...this.temporaryRoutine]}add(e){Array.isArray(e)||(e=[e]);let t=e.map(r=>{if(!registries.RegisteredCommitments.get(r.id)){console.warn(`[NQTR] Commitment ${r.id} not found, it will be ignored`);return}return r.id}).filter(r=>r!==void 0);storage.storage.set(I,t);}find(e){return registries.RegisteredCommitments.get(e)}remove(e){Array.isArray(e)||(e=[e]);let t=e.map(i=>i.id),r=storage.storage.get(I);r&&(r=r.filter(i=>!t.includes(i)),storage.storage.set(I,r));}clearExpiredRoutine(){registries.RegisteredCommitments.values().forEach(e=>{e.expired&&registries.registeredCommitments.delete(e.id);});}get currentRoutine(){let e={};return [...this.fixedRoutine,...this.temporaryRoutine].forEach(t=>{t.isActive()&&(t.characters.length>0?t.characters.every(i=>!e[i.id]||t.priority>e[i.id].priority)&&t.characters.forEach(i=>{e[i.id]=t;}):c.error(`The commitment ${t.id} has no characters assigned`));}),Object.values(e)}getCommitmentByCharacter(e){this.currentRoutine.forEach(t=>{if(t.characters.map(r=>r.id).includes(e.id))return t});}};var o=class o{};u(o,"dayStartTime",0),u(o,"dayEndTime",24),u(o,"defaultTimeSpent",1),u(o,"timeSlots",[]),u(o,"weekLength",7),u(o,"weekendStartDay",o.weekLength-1),u(o,"getDayName");var n=o;var h=class{initialize(e){let{dayStartTime:t=0,dayEndTime:r=24,defaultTimeSpent:i=1,timeSlots:m=[],weekLength:s=7,weekendStartDay:w=s-1,getDayName:x}=e;n.dayStartTime=t,n.dayEndTime=r,n.defaultTimeSpent=i,n.timeSlots=m,n.weekLength=s,w>=n.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${s}, so will be ignored`):n.weekendStartDay=w,n.getDayName=x;}get dayStartTime(){return n.dayStartTime}get dayEndTime(){return n.dayEndTime}get defaultTimeSpent(){return n.defaultTimeSpent}get timeSlots(){return n.timeSlots}get weekLength(){return n.weekLength}get weekendStartDay(){return n.weekendStartDay}get getDayName(){return n.getDayName}get currentTime(){let e=storage.storage.get(f)||{};return e.hasOwnProperty("currentTime")&&typeof e.currentTime=="number"?e.currentTime:this.dayStartTime}set currentTime(e){let t=storage.storage.get(f)||{},r={...t};typeof e=="number"?r.currentTime=e:delete r.currentTime,l({type:"edittime",prev:t,value:r}),storage.storage.set(f,r);}get currentDate(){let e=storage.storage.get(f)||{};return e.hasOwnProperty("currentDate")&&typeof e.currentDate=="number"?e.currentDate:0}set currentDate(e){let t=storage.storage.get(f)||{},r={...t};typeof e=="number"?r.currentDate=e:delete r.currentDate,l({type:"edittime",prev:t,value:r}),storage.storage.set(f,r);}get isWeekend(){return this.currentWeekDayNumber>=this.weekendStartDay}get currentWeekDayNumber(){return this.currentDate%this.weekLength+1}get currentDayName(){return this.getDayName?this.getDayName(this.currentWeekDayNumber-1):(console.warn("[NQTR] Week days names are not defined, so currentDayName will be empty"),"")}get currentTimeSlot(){if(this.timeSlots.length===0)return console.warn("[NQTR] Time slots are not defined"),0;for(let e=0;e<this.timeSlots.length;e++){let t=this.timeSlots[e];if(this.timeSlots.length>e+1&&this.nowIsBetween(t.startTime,this.timeSlots[e+1].startTime))return e}return this.timeSlots.length-1}increaseTime(e=this.defaultTimeSpent){let t=this.currentTime+e;return t>=this.dayEndTime&&(this.increaseDate(),t=this.dayStartTime+(t-this.dayEndTime)),this.currentTime=t,this.currentTime}increaseDate(e=1,t=this.dayStartTime){let r=this.currentDate+e;return this.currentDate=r,this.currentTime=t,this.currentDate}nowIsBetween(e,t){e===void 0&&(e=this.dayStartTime-1),t===void 0&&(t=this.dayEndTime+1);let r=this.currentTime;return e<t?r>=e&&r<t:r>=e||r<t}};var ce=new h,fe=new p,de=new y,le=new g;exports.navigator=fe;exports.questsNotebook=le;exports.routine=de;exports.timeTracker=ce;
1
+ 'use strict';var registries=require('@drincs/nqtr/registries'),storage=require('@drincs/pixi-vn/storage'),core=require('@drincs/pixi-vn/core');var N=Object.defineProperty;var k=(o,e,t)=>e in o?N(o,e,{enumerable:true,configurable:true,writable:true,value:t}):o[e]=t;var c=(o,e,t)=>k(o,typeof e!="symbol"?e+"":e,t);var d="___nqtr-time_manager_data___",I="___nqtr-current_room_memory___",v="___nqtr-last_event_memory___";function p(o){storage.storage.set(v,o);}var m;(i=>(i.log=(a,...s)=>console.log(`[NQTR] ${a}`,...s),i.warn=(a,...s)=>console.warn(`[NQTR] ${a}`,...s),i.error=(a,...s)=>console.error(`[NQTR] ${a}`,...s),i.info=(a,...s)=>console.info(`[NQTR] ${a}`,...s)))(m||(m={}));var g=class{get rooms(){return registries.RegisteredRooms.values()}get locations(){return registries.RegisteredLocations.values()}get maps(){return registries.RegisteredMaps.values()}get currentRoomId(){return storage.storage.get(I)}get currentRoom(){let e=this.currentRoomId;if(!e){m.error("The current room has not yet been set");return}let t=registries.RegisteredRooms.get(e);if(!t){m.error(`Current room ${e} not found`);return}return t}set currentRoom(e){if(typeof e!="string"&&(e=e.id),!registries.RegisteredRooms.get(e)){m.error(`The room ${e} is not registered, so it can't be set as current room`);return}let r=storage.storage.get(I);r!==e&&(p({type:"editroom",prev:r,value:e}),storage.storage.set(I,e));}get currentLocation(){return this.currentRoom?.location}get currentMap(){return this.currentRoom?.location.map}clearExpiredActivities(){registries.RegisteredRooms.values().forEach(e=>{e.clearExpiredActivities();});}};var y=class{get quests(){return registries.RegisteredQuests.values()}get startedQuests(){return this.quests.filter(e=>e.started)}get inProgressQuests(){return this.quests.filter(e=>e.inProgress)}get completedQuests(){return this.quests.filter(e=>e.completed)}get failedQuests(){return this.quests.filter(e=>e.failed)}get notStartedQuests(){return this.quests.filter(e=>!e.started)}find(e){return registries.RegisteredQuests.get(e)}async startsStageMustBeStarted(e){let t=this.quests.map(r=>r.currentStageMustStart?r.startCurrentStage(e):Promise.resolve());await Promise.all(t);}};var w="___nqtr-temporary_commitment___",T=class{get temporaryRoutine(){let e=storage.storage.get(w);if(e){if(Array.isArray(e)){if(e.length>0)throw new core.PixiError("obsolete_save","The save you loaded is not compatible with the current version of NQTR. Please delete the save and start a new game.");return {}}}else return {};return e}get commitmentsIds(){return [...registries.fixedCommitments.keys(),...Object.keys(this.temporaryRoutine)]}add(e,t,r={}){Array.isArray(e)||(e=[e]);let i=this.temporaryRoutine;e.forEach(a=>{registries.RegisteredCommitments.get(a.id)&&m.warn(`The commitment ${a.id} is already registered, it will be overwritten`),registries.RegisteredCommitments.add(a),i[a.id]={id:a.id,roomId:t,...r};}),storage.storage.set(w,i);}find(e){return registries.RegisteredCommitments.get(e)}remove(e,t){typeof e!="string"&&(e=e.id);let r=this.temporaryRoutine;r[e]?(!t||r[e].roomId===t)&&delete r[e]:m.warn(`The commitment ${e} was not found in the temporary routine, so it will be ignored. If you want to remove a fixed commitment, you can add it to the temporary routine with a same character.`),storage.storage.set(w,r);}clearExpiredRoutine(){registries.RegisteredCommitments.values().forEach(e=>{e.expired&&this.remove(e);});}get characterCommitments(){let e=this.temporaryRoutine;return this.commitmentsIds.reduce((t,r)=>{let i=registries.RegisteredCommitments.get(r),a=e[r],s=a?.roomId||registries.fixedCommitments.get(r)?.[1];return s&&i&&i.isActive(a)&&(i.characters.length>0?i.characters.every(f=>!t[f.id]||i.priority>t[f.id][0].priority)&&i.characters.forEach(f=>{t[f.id]=[i,s];}):m.error(`The commitment ${i.id} has no characters assigned`)),t},{})}get currentRoutine(){return Object.values(this.characterCommitments).map(([e])=>e)}get roomCommitments(){return Object.values(this.characterCommitments).reduce((e,t)=>{let r=t[1];return e[r]||(e[r]=[]),e[r].push(t[0]),e},{})}getCommitmentByCharacter(e){return this.currentRoutine.find(t=>{if(t.characters.map(r=>r.id).includes(e.id))return t})}};var u=class u{};c(u,"dayStartTime",0),c(u,"dayEndTime",24),c(u,"defaultTimeSpent",1),c(u,"timeSlots",[]),c(u,"weekLength",7),c(u,"weekendStartDay",u.weekLength-1),c(u,"getDayName");var n=u;var _=class{initialize(e){let{dayStartTime:t=0,dayEndTime:r=24,defaultTimeSpent:i=1,timeSlots:a=[],weekLength:s=7,weekendStartDay:E=s-1,getDayName:f}=e;n.dayStartTime=t,n.dayEndTime=r,n.defaultTimeSpent=i,n.timeSlots=a,n.weekLength=s,E>=n.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${s}, so will be ignored`):n.weekendStartDay=E,n.getDayName=f;}get dayStartTime(){return n.dayStartTime}get dayEndTime(){return n.dayEndTime}get defaultTimeSpent(){return n.defaultTimeSpent}get timeSlots(){return n.timeSlots}get weekLength(){return n.weekLength}get weekendStartDay(){return n.weekendStartDay}get getDayName(){return n.getDayName}get currentTime(){let e=storage.storage.get(d)||{};return e.hasOwnProperty("currentTime")&&typeof e.currentTime=="number"?e.currentTime:this.dayStartTime}set currentTime(e){let t=storage.storage.get(d)||{},r={...t};typeof e=="number"?r.currentTime=e:delete r.currentTime,p({type:"edittime",prev:t,value:r}),storage.storage.set(d,r);}get currentDate(){let e=storage.storage.get(d)||{};return e.hasOwnProperty("currentDate")&&typeof e.currentDate=="number"?e.currentDate:0}set currentDate(e){let t=storage.storage.get(d)||{},r={...t};typeof e=="number"?r.currentDate=e:delete r.currentDate,p({type:"edittime",prev:t,value:r}),storage.storage.set(d,r);}get isWeekend(){return this.currentWeekDayNumber>=this.weekendStartDay}get currentWeekDayNumber(){return this.currentDate%this.weekLength+1}get currentDayName(){return this.getDayName?this.getDayName(this.currentWeekDayNumber-1):(console.warn("[NQTR] Week days names are not defined, so currentDayName will be empty"),"")}get currentTimeSlot(){if(this.timeSlots.length===0)return console.warn("[NQTR] Time slots are not defined"),0;for(let e=0;e<this.timeSlots.length;e++){let t=this.timeSlots[e];if(this.timeSlots.length>e+1&&this.nowIsBetween(t.startTime,this.timeSlots[e+1].startTime))return e}return this.timeSlots.length-1}increaseTime(e=this.defaultTimeSpent){let t=this.currentTime+e;return t>=this.dayEndTime&&(this.increaseDate(),t=this.dayStartTime+(t-this.dayEndTime)),this.currentTime=t,this.currentTime}increaseDate(e=1,t=this.dayStartTime){let r=this.currentDate+e;return this.currentDate=r,this.currentTime=t,this.currentDate}nowIsBetween(e,t){e===void 0&&(e=this.dayStartTime-1),t===void 0&&(t=this.dayEndTime+1);let r=this.currentTime;return e<t?r>=e&&r<t:r>=e||r<t}};var de=new _,fe=new g,le=new T,pe=new y;exports.navigator=fe;exports.questsNotebook=pe;exports.routine=le;exports.timeTracker=de;
@@ -147,10 +147,6 @@ interface CommitmentBaseInternalInterface extends ActivityBaseInternalInterface
147
147
  * The character or characters that are in the commitment and so in the room.
148
148
  */
149
149
  readonly characters: CharacterInterface[];
150
- /**
151
- * The room where the commitment is.
152
- */
153
- readonly room: RoomInterface;
154
150
  /**
155
151
  * 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.
156
152
  * If you set "automatic" remember to remove the commitment when it is no longer needed, because otherwise it repeats itself every time.
@@ -170,22 +166,13 @@ interface NavigationAbstractInterface extends StoredClassModel {
170
166
  * @param options
171
167
  * @returns
172
168
  */
173
- addActivity(activity: ActivityInterface, options?: {
174
- /**
175
- * Time slot in which activity will be active.
176
- */
177
- timeSlot?: TimeSchedulingInterface;
178
- /**
179
- * Used to schedule what date it will be added and removed.
180
- */
181
- dateScheduling?: DateSchedulingInterface;
182
- }): void;
169
+ addActivity(activity: ActivityInterface, options?: ActiveScheduling): void;
183
170
  /**
184
171
  * Disconnects the activity from the class.
185
172
  * @param activity The activity to disconnect from the class.
186
173
  * @param options
187
174
  */
188
- removeActivity(activity: ActivityInterface | string, options?: Pick<DateSchedulingInterface, "to">): void;
175
+ removeActivity(activity: ActivityInterface | string): void;
189
176
  /**
190
177
  * Removes the useless activities.
191
178
  */
@@ -243,6 +230,19 @@ interface RoomBaseInternalInterface extends NavigationAbstractInterface {
243
230
  * The location where the room is.
244
231
  */
245
232
  readonly location: LocationInterface;
233
+ /**
234
+ * Connects the commitment to the class.
235
+ * @param commitment The commitment to connect to the class.
236
+ * @param options
237
+ * @returns
238
+ */
239
+ addCommitment(commitment: CommitmentInterface, options?: ActiveScheduling): void;
240
+ /**
241
+ * Disconnects the commitment from the class.
242
+ * @param commitment The commitment to disconnect from the class.
243
+ * @param options
244
+ */
245
+ removeCommitment(commitment: CommitmentInterface | string): void;
246
246
  /**
247
247
  * Get the character commitments of the room.
248
248
  */
@@ -468,22 +468,18 @@ declare class QuestHandler {
468
468
  }
469
469
 
470
470
  declare class RoutineHandler {
471
- get fixedRoutine(): CommitmentInterface[];
472
- /**
473
- * Set a commitment as fixed, it will be always available. They cannot be deleted or edit during the game session.
474
- */
475
- set fixedRoutine(commitments: CommitmentInterface[]);
476
471
  /**
477
472
  * Get the temporary commitments by its id.
478
473
  * @returns The temporary commitments.
479
474
  */
480
- get temporaryRoutine(): CommitmentInterface[];
481
- get allRoutine(): CommitmentInterface[];
475
+ private get temporaryRoutine();
476
+ get commitmentsIds(): string[];
482
477
  /**
483
478
  * This feature adds the commitments during the game session.
484
479
  * @param commitment The commitment or commitments to add.
480
+ * @param roomId The id of the room where the commitment is.
485
481
  */
486
- add(commitment: CommitmentInterface[] | CommitmentInterface): void;
482
+ add(commitment: CommitmentInterface[] | CommitmentInterface, roomId: string, options?: ActiveScheduling): void;
487
483
  /**
488
484
  * Get the commitments added during the game session.
489
485
  * @param id The id of the commitment.
@@ -492,13 +488,17 @@ declare class RoutineHandler {
492
488
  find(id: string): CommitmentInterface | undefined;
493
489
  /**
494
490
  * Remove the commitments added during the game session.
495
- * @param commitment The commitment or commitments to remove.
491
+ * @param commitment The commitment or commitment id to remove.
492
+ * @param roomId The id of the room where the commitment is.
496
493
  */
497
- remove(commitment: CommitmentInterface[] | CommitmentInterface): void;
494
+ remove(commitment: CommitmentInterface | string, roomId?: string): void;
498
495
  /**
499
496
  * Clear all the expired commitments.
500
497
  */
501
498
  clearExpiredRoutine(): void;
499
+ get characterCommitments(): {
500
+ [character: string]: [CommitmentInterface, string];
501
+ };
502
502
  /**
503
503
  * Get the current commitments. The hidden commitments are not included.
504
504
  * In case there is a character who has two or more commitments at the same time, will be selected the commitment with the highest priority.
@@ -509,6 +509,9 @@ declare class RoutineHandler {
509
509
  * @returns The current commitments.
510
510
  */
511
511
  get currentRoutine(): CommitmentInterface[];
512
+ get roomCommitments(): {
513
+ [roomId: string]: CommitmentInterface[];
514
+ };
512
515
  /**
513
516
  * Get the character commitment.
514
517
  * @param character The character.
@@ -147,10 +147,6 @@ interface CommitmentBaseInternalInterface extends ActivityBaseInternalInterface
147
147
  * The character or characters that are in the commitment and so in the room.
148
148
  */
149
149
  readonly characters: CharacterInterface[];
150
- /**
151
- * The room where the commitment is.
152
- */
153
- readonly room: RoomInterface;
154
150
  /**
155
151
  * 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.
156
152
  * If you set "automatic" remember to remove the commitment when it is no longer needed, because otherwise it repeats itself every time.
@@ -170,22 +166,13 @@ interface NavigationAbstractInterface extends StoredClassModel {
170
166
  * @param options
171
167
  * @returns
172
168
  */
173
- addActivity(activity: ActivityInterface, options?: {
174
- /**
175
- * Time slot in which activity will be active.
176
- */
177
- timeSlot?: TimeSchedulingInterface;
178
- /**
179
- * Used to schedule what date it will be added and removed.
180
- */
181
- dateScheduling?: DateSchedulingInterface;
182
- }): void;
169
+ addActivity(activity: ActivityInterface, options?: ActiveScheduling): void;
183
170
  /**
184
171
  * Disconnects the activity from the class.
185
172
  * @param activity The activity to disconnect from the class.
186
173
  * @param options
187
174
  */
188
- removeActivity(activity: ActivityInterface | string, options?: Pick<DateSchedulingInterface, "to">): void;
175
+ removeActivity(activity: ActivityInterface | string): void;
189
176
  /**
190
177
  * Removes the useless activities.
191
178
  */
@@ -243,6 +230,19 @@ interface RoomBaseInternalInterface extends NavigationAbstractInterface {
243
230
  * The location where the room is.
244
231
  */
245
232
  readonly location: LocationInterface;
233
+ /**
234
+ * Connects the commitment to the class.
235
+ * @param commitment The commitment to connect to the class.
236
+ * @param options
237
+ * @returns
238
+ */
239
+ addCommitment(commitment: CommitmentInterface, options?: ActiveScheduling): void;
240
+ /**
241
+ * Disconnects the commitment from the class.
242
+ * @param commitment The commitment to disconnect from the class.
243
+ * @param options
244
+ */
245
+ removeCommitment(commitment: CommitmentInterface | string): void;
246
246
  /**
247
247
  * Get the character commitments of the room.
248
248
  */
@@ -468,22 +468,18 @@ declare class QuestHandler {
468
468
  }
469
469
 
470
470
  declare class RoutineHandler {
471
- get fixedRoutine(): CommitmentInterface[];
472
- /**
473
- * Set a commitment as fixed, it will be always available. They cannot be deleted or edit during the game session.
474
- */
475
- set fixedRoutine(commitments: CommitmentInterface[]);
476
471
  /**
477
472
  * Get the temporary commitments by its id.
478
473
  * @returns The temporary commitments.
479
474
  */
480
- get temporaryRoutine(): CommitmentInterface[];
481
- get allRoutine(): CommitmentInterface[];
475
+ private get temporaryRoutine();
476
+ get commitmentsIds(): string[];
482
477
  /**
483
478
  * This feature adds the commitments during the game session.
484
479
  * @param commitment The commitment or commitments to add.
480
+ * @param roomId The id of the room where the commitment is.
485
481
  */
486
- add(commitment: CommitmentInterface[] | CommitmentInterface): void;
482
+ add(commitment: CommitmentInterface[] | CommitmentInterface, roomId: string, options?: ActiveScheduling): void;
487
483
  /**
488
484
  * Get the commitments added during the game session.
489
485
  * @param id The id of the commitment.
@@ -492,13 +488,17 @@ declare class RoutineHandler {
492
488
  find(id: string): CommitmentInterface | undefined;
493
489
  /**
494
490
  * Remove the commitments added during the game session.
495
- * @param commitment The commitment or commitments to remove.
491
+ * @param commitment The commitment or commitment id to remove.
492
+ * @param roomId The id of the room where the commitment is.
496
493
  */
497
- remove(commitment: CommitmentInterface[] | CommitmentInterface): void;
494
+ remove(commitment: CommitmentInterface | string, roomId?: string): void;
498
495
  /**
499
496
  * Clear all the expired commitments.
500
497
  */
501
498
  clearExpiredRoutine(): void;
499
+ get characterCommitments(): {
500
+ [character: string]: [CommitmentInterface, string];
501
+ };
502
502
  /**
503
503
  * Get the current commitments. The hidden commitments are not included.
504
504
  * In case there is a character who has two or more commitments at the same time, will be selected the commitment with the highest priority.
@@ -509,6 +509,9 @@ declare class RoutineHandler {
509
509
  * @returns The current commitments.
510
510
  */
511
511
  get currentRoutine(): CommitmentInterface[];
512
+ get roomCommitments(): {
513
+ [roomId: string]: CommitmentInterface[];
514
+ };
512
515
  /**
513
516
  * Get the character commitment.
514
517
  * @param character The character.
package/dist/handlers.mjs CHANGED
@@ -1 +1 @@
1
- import {RegisteredRooms,RegisteredLocations,RegisteredMaps,RegisteredQuests,fixedCommitments,RegisteredCommitments,registeredCommitments}from'@drincs/nqtr/registries';import {storage}from'@drincs/pixi-vn/storage';var C=Object.defineProperty;var N=(a,e,t)=>e in a?C(a,e,{enumerable:true,configurable:true,writable:true,value:t}):a[e]=t;var u=(a,e,t)=>N(a,typeof e!="symbol"?e+"":e,t);var f="___nqtr-time_manager_data___",T="___nqtr-current_room_memory___",D="___nqtr-last_event_memory___";function l(a){storage.set(D,a);}var c;(i=>(i.log=(m,...s)=>console.log(`[NQTR] ${m}`,...s),i.warn=(m,...s)=>console.warn(`[NQTR] ${m}`,...s),i.error=(m,...s)=>console.error(`[NQTR] ${m}`,...s),i.info=(m,...s)=>console.info(`[NQTR] ${m}`,...s)))(c||(c={}));var p=class{get rooms(){return RegisteredRooms.values()}get locations(){return RegisteredLocations.values()}get maps(){return RegisteredMaps.values()}get currentRoomId(){return storage.get(T)}get currentRoom(){let e=this.currentRoomId;if(!e){c.error("The current room has not yet been set");return}let t=RegisteredRooms.get(e);if(!t){c.error(`Current room ${e} not found`);return}return t}set currentRoom(e){if(typeof e!="string"&&(e=e.id),!RegisteredRooms.get(e)){c.error(`The room ${e} is not registered, so it can't be set as current room`);return}let r=storage.get(T);r!==e&&(l({type:"editroom",prev:r,value:e}),storage.set(T,e));}get currentLocation(){return this.currentRoom?.location}get currentMap(){return this.currentRoom?.location.map}clearExpiredActivities(){RegisteredRooms.values().forEach(e=>{e.clearExpiredActivities();});}};var g=class{get quests(){return RegisteredQuests.values()}get startedQuests(){return this.quests.filter(e=>e.started)}get inProgressQuests(){return this.quests.filter(e=>e.inProgress)}get completedQuests(){return this.quests.filter(e=>e.completed)}get failedQuests(){return this.quests.filter(e=>e.failed)}get notStartedQuests(){return this.quests.filter(e=>!e.started)}find(e){return RegisteredQuests.get(e)}async startsStageMustBeStarted(e){let t=this.quests.map(r=>r.currentStageMustStart?r.startCurrentStage(e):Promise.resolve());await Promise.all(t);}};var I="___nqtr-temporary_commitment___",y=class{get fixedRoutine(){return [...fixedCommitments.values()]}set fixedRoutine(e){e.forEach(t=>{fixedCommitments.has(t.id)&&console.warn(`[NQTR] Commitment id ${t.id} already exists, it will be overwritten`),fixedCommitments.set(t.id,t);});}get temporaryRoutine(){let e=storage.get(I);return e?e.map(r=>RegisteredCommitments.get(r)).filter(r=>r!==void 0):[]}get allRoutine(){return [...this.fixedRoutine,...this.temporaryRoutine]}add(e){Array.isArray(e)||(e=[e]);let t=e.map(r=>{if(!RegisteredCommitments.get(r.id)){console.warn(`[NQTR] Commitment ${r.id} not found, it will be ignored`);return}return r.id}).filter(r=>r!==void 0);storage.set(I,t);}find(e){return RegisteredCommitments.get(e)}remove(e){Array.isArray(e)||(e=[e]);let t=e.map(i=>i.id),r=storage.get(I);r&&(r=r.filter(i=>!t.includes(i)),storage.set(I,r));}clearExpiredRoutine(){RegisteredCommitments.values().forEach(e=>{e.expired&&registeredCommitments.delete(e.id);});}get currentRoutine(){let e={};return [...this.fixedRoutine,...this.temporaryRoutine].forEach(t=>{t.isActive()&&(t.characters.length>0?t.characters.every(i=>!e[i.id]||t.priority>e[i.id].priority)&&t.characters.forEach(i=>{e[i.id]=t;}):c.error(`The commitment ${t.id} has no characters assigned`));}),Object.values(e)}getCommitmentByCharacter(e){this.currentRoutine.forEach(t=>{if(t.characters.map(r=>r.id).includes(e.id))return t});}};var o=class o{};u(o,"dayStartTime",0),u(o,"dayEndTime",24),u(o,"defaultTimeSpent",1),u(o,"timeSlots",[]),u(o,"weekLength",7),u(o,"weekendStartDay",o.weekLength-1),u(o,"getDayName");var n=o;var h=class{initialize(e){let{dayStartTime:t=0,dayEndTime:r=24,defaultTimeSpent:i=1,timeSlots:m=[],weekLength:s=7,weekendStartDay:w=s-1,getDayName:x}=e;n.dayStartTime=t,n.dayEndTime=r,n.defaultTimeSpent=i,n.timeSlots=m,n.weekLength=s,w>=n.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${s}, so will be ignored`):n.weekendStartDay=w,n.getDayName=x;}get dayStartTime(){return n.dayStartTime}get dayEndTime(){return n.dayEndTime}get defaultTimeSpent(){return n.defaultTimeSpent}get timeSlots(){return n.timeSlots}get weekLength(){return n.weekLength}get weekendStartDay(){return n.weekendStartDay}get getDayName(){return n.getDayName}get currentTime(){let e=storage.get(f)||{};return e.hasOwnProperty("currentTime")&&typeof e.currentTime=="number"?e.currentTime:this.dayStartTime}set currentTime(e){let t=storage.get(f)||{},r={...t};typeof e=="number"?r.currentTime=e:delete r.currentTime,l({type:"edittime",prev:t,value:r}),storage.set(f,r);}get currentDate(){let e=storage.get(f)||{};return e.hasOwnProperty("currentDate")&&typeof e.currentDate=="number"?e.currentDate:0}set currentDate(e){let t=storage.get(f)||{},r={...t};typeof e=="number"?r.currentDate=e:delete r.currentDate,l({type:"edittime",prev:t,value:r}),storage.set(f,r);}get isWeekend(){return this.currentWeekDayNumber>=this.weekendStartDay}get currentWeekDayNumber(){return this.currentDate%this.weekLength+1}get currentDayName(){return this.getDayName?this.getDayName(this.currentWeekDayNumber-1):(console.warn("[NQTR] Week days names are not defined, so currentDayName will be empty"),"")}get currentTimeSlot(){if(this.timeSlots.length===0)return console.warn("[NQTR] Time slots are not defined"),0;for(let e=0;e<this.timeSlots.length;e++){let t=this.timeSlots[e];if(this.timeSlots.length>e+1&&this.nowIsBetween(t.startTime,this.timeSlots[e+1].startTime))return e}return this.timeSlots.length-1}increaseTime(e=this.defaultTimeSpent){let t=this.currentTime+e;return t>=this.dayEndTime&&(this.increaseDate(),t=this.dayStartTime+(t-this.dayEndTime)),this.currentTime=t,this.currentTime}increaseDate(e=1,t=this.dayStartTime){let r=this.currentDate+e;return this.currentDate=r,this.currentTime=t,this.currentDate}nowIsBetween(e,t){e===void 0&&(e=this.dayStartTime-1),t===void 0&&(t=this.dayEndTime+1);let r=this.currentTime;return e<t?r>=e&&r<t:r>=e||r<t}};var ce=new h,fe=new p,de=new y,le=new g;export{fe as navigator,le as questsNotebook,de as routine,ce as timeTracker};
1
+ import {RegisteredRooms,RegisteredLocations,RegisteredMaps,RegisteredQuests,fixedCommitments,RegisteredCommitments}from'@drincs/nqtr/registries';import {storage}from'@drincs/pixi-vn/storage';import {PixiError}from'@drincs/pixi-vn/core';var N=Object.defineProperty;var k=(o,e,t)=>e in o?N(o,e,{enumerable:true,configurable:true,writable:true,value:t}):o[e]=t;var c=(o,e,t)=>k(o,typeof e!="symbol"?e+"":e,t);var d="___nqtr-time_manager_data___",I="___nqtr-current_room_memory___",v="___nqtr-last_event_memory___";function p(o){storage.set(v,o);}var m;(i=>(i.log=(a,...s)=>console.log(`[NQTR] ${a}`,...s),i.warn=(a,...s)=>console.warn(`[NQTR] ${a}`,...s),i.error=(a,...s)=>console.error(`[NQTR] ${a}`,...s),i.info=(a,...s)=>console.info(`[NQTR] ${a}`,...s)))(m||(m={}));var g=class{get rooms(){return RegisteredRooms.values()}get locations(){return RegisteredLocations.values()}get maps(){return RegisteredMaps.values()}get currentRoomId(){return storage.get(I)}get currentRoom(){let e=this.currentRoomId;if(!e){m.error("The current room has not yet been set");return}let t=RegisteredRooms.get(e);if(!t){m.error(`Current room ${e} not found`);return}return t}set currentRoom(e){if(typeof e!="string"&&(e=e.id),!RegisteredRooms.get(e)){m.error(`The room ${e} is not registered, so it can't be set as current room`);return}let r=storage.get(I);r!==e&&(p({type:"editroom",prev:r,value:e}),storage.set(I,e));}get currentLocation(){return this.currentRoom?.location}get currentMap(){return this.currentRoom?.location.map}clearExpiredActivities(){RegisteredRooms.values().forEach(e=>{e.clearExpiredActivities();});}};var y=class{get quests(){return RegisteredQuests.values()}get startedQuests(){return this.quests.filter(e=>e.started)}get inProgressQuests(){return this.quests.filter(e=>e.inProgress)}get completedQuests(){return this.quests.filter(e=>e.completed)}get failedQuests(){return this.quests.filter(e=>e.failed)}get notStartedQuests(){return this.quests.filter(e=>!e.started)}find(e){return RegisteredQuests.get(e)}async startsStageMustBeStarted(e){let t=this.quests.map(r=>r.currentStageMustStart?r.startCurrentStage(e):Promise.resolve());await Promise.all(t);}};var w="___nqtr-temporary_commitment___",T=class{get temporaryRoutine(){let e=storage.get(w);if(e){if(Array.isArray(e)){if(e.length>0)throw new PixiError("obsolete_save","The save you loaded is not compatible with the current version of NQTR. Please delete the save and start a new game.");return {}}}else return {};return e}get commitmentsIds(){return [...fixedCommitments.keys(),...Object.keys(this.temporaryRoutine)]}add(e,t,r={}){Array.isArray(e)||(e=[e]);let i=this.temporaryRoutine;e.forEach(a=>{RegisteredCommitments.get(a.id)&&m.warn(`The commitment ${a.id} is already registered, it will be overwritten`),RegisteredCommitments.add(a),i[a.id]={id:a.id,roomId:t,...r};}),storage.set(w,i);}find(e){return RegisteredCommitments.get(e)}remove(e,t){typeof e!="string"&&(e=e.id);let r=this.temporaryRoutine;r[e]?(!t||r[e].roomId===t)&&delete r[e]:m.warn(`The commitment ${e} was not found in the temporary routine, so it will be ignored. If you want to remove a fixed commitment, you can add it to the temporary routine with a same character.`),storage.set(w,r);}clearExpiredRoutine(){RegisteredCommitments.values().forEach(e=>{e.expired&&this.remove(e);});}get characterCommitments(){let e=this.temporaryRoutine;return this.commitmentsIds.reduce((t,r)=>{let i=RegisteredCommitments.get(r),a=e[r],s=a?.roomId||fixedCommitments.get(r)?.[1];return s&&i&&i.isActive(a)&&(i.characters.length>0?i.characters.every(f=>!t[f.id]||i.priority>t[f.id][0].priority)&&i.characters.forEach(f=>{t[f.id]=[i,s];}):m.error(`The commitment ${i.id} has no characters assigned`)),t},{})}get currentRoutine(){return Object.values(this.characterCommitments).map(([e])=>e)}get roomCommitments(){return Object.values(this.characterCommitments).reduce((e,t)=>{let r=t[1];return e[r]||(e[r]=[]),e[r].push(t[0]),e},{})}getCommitmentByCharacter(e){return this.currentRoutine.find(t=>{if(t.characters.map(r=>r.id).includes(e.id))return t})}};var u=class u{};c(u,"dayStartTime",0),c(u,"dayEndTime",24),c(u,"defaultTimeSpent",1),c(u,"timeSlots",[]),c(u,"weekLength",7),c(u,"weekendStartDay",u.weekLength-1),c(u,"getDayName");var n=u;var _=class{initialize(e){let{dayStartTime:t=0,dayEndTime:r=24,defaultTimeSpent:i=1,timeSlots:a=[],weekLength:s=7,weekendStartDay:E=s-1,getDayName:f}=e;n.dayStartTime=t,n.dayEndTime=r,n.defaultTimeSpent=i,n.timeSlots=a,n.weekLength=s,E>=n.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${s}, so will be ignored`):n.weekendStartDay=E,n.getDayName=f;}get dayStartTime(){return n.dayStartTime}get dayEndTime(){return n.dayEndTime}get defaultTimeSpent(){return n.defaultTimeSpent}get timeSlots(){return n.timeSlots}get weekLength(){return n.weekLength}get weekendStartDay(){return n.weekendStartDay}get getDayName(){return n.getDayName}get currentTime(){let e=storage.get(d)||{};return e.hasOwnProperty("currentTime")&&typeof e.currentTime=="number"?e.currentTime:this.dayStartTime}set currentTime(e){let t=storage.get(d)||{},r={...t};typeof e=="number"?r.currentTime=e:delete r.currentTime,p({type:"edittime",prev:t,value:r}),storage.set(d,r);}get currentDate(){let e=storage.get(d)||{};return e.hasOwnProperty("currentDate")&&typeof e.currentDate=="number"?e.currentDate:0}set currentDate(e){let t=storage.get(d)||{},r={...t};typeof e=="number"?r.currentDate=e:delete r.currentDate,p({type:"edittime",prev:t,value:r}),storage.set(d,r);}get isWeekend(){return this.currentWeekDayNumber>=this.weekendStartDay}get currentWeekDayNumber(){return this.currentDate%this.weekLength+1}get currentDayName(){return this.getDayName?this.getDayName(this.currentWeekDayNumber-1):(console.warn("[NQTR] Week days names are not defined, so currentDayName will be empty"),"")}get currentTimeSlot(){if(this.timeSlots.length===0)return console.warn("[NQTR] Time slots are not defined"),0;for(let e=0;e<this.timeSlots.length;e++){let t=this.timeSlots[e];if(this.timeSlots.length>e+1&&this.nowIsBetween(t.startTime,this.timeSlots[e+1].startTime))return e}return this.timeSlots.length-1}increaseTime(e=this.defaultTimeSpent){let t=this.currentTime+e;return t>=this.dayEndTime&&(this.increaseDate(),t=this.dayStartTime+(t-this.dayEndTime)),this.currentTime=t,this.currentTime}increaseDate(e=1,t=this.dayStartTime){let r=this.currentDate+e;return this.currentDate=r,this.currentTime=t,this.currentDate}nowIsBetween(e,t){e===void 0&&(e=this.dayStartTime-1),t===void 0&&(t=this.dayEndTime+1);let r=this.currentTime;return e<t?r>=e&&r<t:r>=e||r<t}};var de=new _,fe=new g,le=new T,pe=new y;export{fe as navigator,pe as questsNotebook,le as routine,de as timeTracker};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var handlers=require('@drincs/nqtr/handlers'),qe=require('@drincs/nqtr/registries'),storage=require('@drincs/pixi-vn/storage'),narration=require('@drincs/pixi-vn/narration');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var qe__namespace=/*#__PURE__*/_interopNamespace(qe);var U=Object.defineProperty;var oe=(s,r,e)=>r in s?U(s,r,{enumerable:true,configurable:true,writable:true,value:e}):s[r]=e;var W=(s,r)=>{for(var e in r)U(s,e,{get:r[e],enumerable:true});};var n=(s,r,e)=>oe(s,typeof r!="symbol"?r+"":r,e);var F={};W(F,{ActivityBaseModel:()=>T,ActivityStoredClass:()=>f,CommitmentBaseModel:()=>E,CommitmentStoredClass:()=>h,LocationBaseModel:()=>P,LocationStoredClass:()=>S,MapBaseModel:()=>D,MapStoredClass:()=>y,QuestBaseModel:()=>w,QuestStoredClass:()=>I,RoomBaseModel:()=>C,RoomStoredClass:()=>v,StageBaseModel:()=>q,StageStoredClass:()=>_});var ce="__nqtr-activity__",f=class extends storage.StoredClassModel{constructor(e,t,i,a=ce){super(a,e);this._onRun=t;n(this,"_timeSlot");n(this,"_dateScheduling");this._timeSlot=i.timeSlot,this._dateScheduling=i.dateScheduling;}get timeSlot(){return this._timeSlot}get dateScheduling(){return this._dateScheduling}addTempHistoryItem(){narration.narration.addCurrentStepToHistory();}get run(){return async e=>(this.addTempHistoryItem(),await this._onRun(this,e))}get expired(){return !!(this.dateScheduling?.to&&this.dateScheduling.to<=handlers.timeTracker.currentDate)}isActive(e={}){let{timeSlot:t=this.timeSlot,dateScheduling:i=this.dateScheduling}=e;if(i?.from!=null&&i.from>handlers.timeTracker.currentDate||i?.to!=null&&i.to<handlers.timeTracker.currentDate)return false;t&&!Array.isArray(t)&&(t=[t]);for(let a of t||[])if(!handlers.timeTracker.nowIsBetween(a?.from,a?.to))return false;return true}};var T=class extends f{constructor(e,t,i){super(e,t,{dateScheduling:i.dateScheduling,timeSlot:i.timeSlot});n(this,"defaultName");n(this,"defaultDisabled");n(this,"defaultHidden");n(this,"_icon");this.defaultName=i.name||"",this.defaultDisabled=i.disabled||false,this.defaultHidden=i.hidden||false,this._icon=i.renderIcon;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}get icon(){return this._icon}};var l="___nqtr-time_manager_data___",p="___nqtr-current_room_memory___",z="___nqtr-last_event_memory___";function b(s){storage.storage.set(z,s);}function J(){return storage.storage.get(z)}var me="__nqtr-commitment__",h=class extends f{constructor(e,t,i,a,o){a=a||(()=>{});super(e,a,o,me);this._characters=t;this._room=i;n(this,"defaultExecutionType");n(this,"defaultPriority");this.defaultExecutionType=o.executionType||"interaction",this.defaultPriority=o.priority;}get characters(){return this._characters}get room(){return this._room}get executionType(){return this.getStorageProperty("executionType")||this.defaultExecutionType}set executionType(e){this.setStorageProperty("executionType",e);}get priority(){return this.getStorageProperty("priority")||this.defaultPriority||0}set priority(e){this.setStorageProperty("priority",e);}addTempHistoryItem(){let e=handlers.navigator.currentRoom;if(!e||this.executionType!=="automatic")return super.addTempHistoryItem();let t=J();switch(t?.type){case "editroom":storage.storage.set(p,t.prev),super.addTempHistoryItem(),storage.storage.set(p,e.id);break;case "edittime":let i=storage.storage.get(l)||{};storage.storage.set(l,t.prev),super.addTempHistoryItem(),storage.storage.set(l,i);break}}};var E=class extends h{constructor(e,t,i,a){super(e,t?Array.isArray(t)?t:[t]:[],i,a.onRun,{executionType:a.executionType,priority:a.priority,timeSlot:a.timeSlot,dateScheduling:a.dateScheduling});n(this,"_name");n(this,"_image");n(this,"_icon");n(this,"defaultDisabled");n(this,"defaultHidden");this._name=a.name||"",this._image=a.image,this.defaultDisabled=a.disabled||false,this.defaultHidden=a.hidden||false,this._icon=a.icon;}get name(){return this._name}get image(){return this._image}get icon(){return this._icon}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}};var g=class extends storage.StoredClassModel{constructor(e,t,i=[]){super(e,t);this.defaultActivities=i;}get defaultActivitiesIds(){return this.defaultActivities.map(e=>e.id)}get activeActivityScheduling(){return this.getStorageProperty("activeActivityScheduling")||{}}get excludedActivitiesScheduling(){return this.getStorageProperty("excludedActivitiesScheduling")||{}}removeActivityScheduling(e){let t=this.activeActivityScheduling;delete t[e],this.setStorageProperty("activeActivityScheduling",t);let i=this.excludedActivitiesScheduling;delete i[e],this.setStorageProperty("excludedActivitiesScheduling",i);}editActivityScheduling(e,t){this.removeActivityScheduling(e);let i=this.activeActivityScheduling;i[e]=t,this.setStorageProperty("activeActivityScheduling",i);}editExcludedActivityScheduling(e,t){this.removeActivityScheduling(e);let i=this.excludedActivitiesScheduling;i[e]=t,this.setStorageProperty("excludedActivitiesScheduling",i);}get additionalActivitiesIds(){return this.getStorageProperty("additionalActivitiesIds")||[]}get excludedActivitiesIds(){return this.getStorageProperty("excludedActivitiesIds")||[]}get activitiesIds(){return this.additionalActivitiesIds.concat(this.defaultActivitiesIds)}addActivity(e,t={}){let{timeSlot:i,dateScheduling:a}=t;if(i&&!Array.isArray(i)&&(i=[i]),i?.forEach(c=>{let{to:R=handlers.timeTracker.dayEndTime+1}=c||{};if(c&&c.from>=R)throw new Error("[NQTR] The from time must be less than the to time.")}),a?.from!==void 0&&a?.to!==void 0&&a?.from>=a?.to)throw new Error("[NQTR] The from day/date must be less than the to day/date.");if(this.defaultActivitiesIds.includes(e.id)){console.warn(`[NQTR] Activity with id ${e.id} already exists, so it will be ignored.`);return}let o=this.additionalActivitiesIds;o.includes(e.id)?console.warn(`[NQTR] Activity with id ${e.id} already exists, so it will be ignored.`):(o.push(e.id),this.setStorageProperty("additionalActivitiesIds",o)),this.excludedActivitiesIds.includes(e.id)&&(this.removeActivityScheduling(e.id),console.log(`[NQTR] Activity with id ${e.id} was excluded, so it will be associated with this class again.`)),(i||a)&&this.editActivityScheduling(e.id,{timeSlot:i,dateScheduling:a});}removeActivity(e){let t=typeof e=="string"?e:e.id,i=this.additionalActivitiesIds;if(i.includes(t))i=i.filter(a=>a!==t),this.setStorageProperty("additionalActivitiesIds",i),this.removeActivityScheduling(t);else if(this.defaultActivitiesIds.includes(t)){let a=this.excludedActivitiesIds;a.push(t),this.setStorageProperty("excludedActivitiesIds",a);}else console.warn(`[NQTR] Activity with id ${t} not found, so it will be ignored.`);}clearExpiredActivities(){let e=this.activeActivityScheduling,t=this.excludedActivitiesScheduling,i=this.additionalActivitiesIds,a=this.excludedActivitiesIds;i.forEach(o=>{if(o in e){let{to:c}=e[o].dateScheduling||{};c&&c<handlers.timeTracker.currentDate&&(this.removeActivityScheduling(o),i=i.filter(R=>R!==o));}}),a.forEach(o=>{o in t&&t[o]&&(this.removeActivityScheduling(o),a=a.filter(c=>c!==o));});}get activities(){return [...new Set([...this.additionalActivitiesIds,...this.defaultActivitiesIds])].reduce((e,t)=>{let i=qe.RegisteredActivities.get(t);return i&&i.isActive(this.activeActivityScheduling[t])&&!this.excludedActivitiesScheduling[t]&&e.push(i),e},[])}};var he="__nqtr-location__",S=class extends g{constructor(e,t,i=[]){super(he,e,i);this._map=t;}get map(){return this._map}get rooms(){return handlers.navigator.rooms.filter(e=>e.location.id===this.id)}};var P=class extends S{constructor(e,t,i={}){super(e,t,i.activities||[]);n(this,"defaultName");n(this,"defaultDisabled");n(this,"defaultHidden");n(this,"_icon");this.defaultName=i.name||"",this.defaultDisabled=i.disabled||false,this.defaultHidden=i.hidden||false,this._icon=i.icon;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}get icon(){return this._icon}};var ye="__nqtr-map__",y=class extends g{constructor(r,e=[]){super(ye,r,e);}get locations(){return handlers.navigator.locations.filter(r=>r.map.id===this.id)}};var D=class extends y{constructor(e,t={}){super(e,t.activities||[]);n(this,"defaultName");n(this,"_image");this.defaultName=t.name||"",this._image=t.image;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get image(){return this._image}};var Ie="__nqtr-room__",v=class extends g{constructor(e,t,i=[]){super(Ie,e,i);this._location=t;}get routine(){return handlers.routine.currentRoutine.filter(e=>e.room.id===this.id)}get location(){return this._location}get characters(){let e=[];return this.routine.forEach(t=>{e.push(...t.characters);}),e}get automaticFunctions(){return this.routine.filter(e=>e.executionType==="automatic"&&e.run).map(e=>async i=>{await e.run(i);})}};var C=class extends v{constructor(e,t,i={}){super(e,t,i.activities||[]);n(this,"defaultName");n(this,"_image");n(this,"defaultDisabled");n(this,"defaultHidden");n(this,"_icon");this.defaultName=i.name||"",this._image=i.image,this.defaultDisabled=i.disabled||false,this.defaultHidden=i.hidden||false,this._icon=i.icon;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get image(){return this._image}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}get icon(){return this._icon}};var u;(i=>(i.log=(a,...o)=>console.log(`[NQTR] ${a}`,...o),i.warn=(a,...o)=>console.warn(`[NQTR] ${a}`,...o),i.error=(a,...o)=>console.error(`[NQTR] ${a}`,...o),i.info=(a,...o)=>console.info(`[NQTR] ${a}`,...o)))(u||(u={}));var xe="__nqtr-quest__",I=class extends storage.StoredClassModel{constructor(e,t,i={}){super(xe,e);this._stages=t;n(this,"_onStart");n(this,"_onNextStage");this._onStart=i.onStart,this._onNextStage=i.onNextStage;}get stages(){return this._stages}get currentStageIndex(){return this.getStorageProperty("currentStageIndex")}set currentStageIndex(e){this.setStorageProperty("currentStageIndex",e);}get currentStage(){let e=this.currentStageIndex;if(!(e===void 0||e>=this.stages.length))return this.stages[e]}get started(){return this.currentStageIndex!==void 0}get completed(){return this.currentStageIndex===void 0?false:this.currentStageIndex>this.stages.length-1}get inProgress(){return this.completed||this.failed?false:this.started}get failed(){return this.getStorageProperty("failed")||false}set failed(e){this.setStorageProperty("failed",e);}get onStart(){return this._onStart}get onNextStage(){return this._onNextStage}async start(e){if(this.started){console.warn(`[NQTR] Quest ${this.id} is already started`);return}if(this.stages.length===0){u.error(`Quest ${this.id} has no stages`);return}this.currentStageIndex=0;let t=this.currentStage;if(t&&t.start)return this.onStart&&await this.onStart(this,e),await t.start(e);u.error(`Quest ${this.id} has no start stage`);}async goNextIfCompleted(e){return await this.advanceIfCompleted(e)}async advanceIfCompleted(e){if(!this.inProgress)return false;let t=this.currentStage;return t?t.completed?await this.advanceUnconditionally(e):false:(u.error(`Quest ${this.id} has no current stage`),false)}async goNext(e){return await this.continue(e)}async continue(e){let t=this.currentStage;return t?(t.completed=true,await this.advanceUnconditionally(e)):(u.error(`Quest ${this.id} has no current stage`),false)}async forceGoNext(e){return await this.advanceUnconditionally(e)}async advanceUnconditionally(e){if(!this.inProgress)return console.warn(`[NQTR] Quest ${this.id} is not in progress`),false;let t=this.currentStage,i=this.currentStageIndex;if(!t||i===void 0)return u.error(`Quest ${this.id} has no current stage`),false;this.currentStageIndex=i+1,this.onNextStage&&await this.onNextStage(this,e),t&&t.onEnd&&await t.onEnd(t,e);let a=this.currentStage;return a&&(a.inizialize(),this.currentStageMustStart&&await this.startCurrentStage(e)),true}get currentStageMustStart(){let e=this.currentStage;return e?!e.started&&e.canStart&&!e.completed:false}async startCurrentStage(e){let t=this.currentStage;t&&this.currentStageMustStart?await t.start(e):console.warn(`[NQTR] Quest ${this.id} can't start the current stage`);}};var w=class extends I{constructor(e,t,i){super(e,t,{onStart:i.onStart,onNextStage:i.onNextStage});n(this,"_name");n(this,"_description");n(this,"_icon");n(this,"_image");n(this,"_inDevelopment");this._name=i.name||"",this._description=i.description||"",this._icon=i.icon,this._image=i.image,this._inDevelopment=i.inDevelopment||false;}get name(){return this._name}get description(){return this._description}get icon(){return this._icon}get image(){return this._image}get inDevelopment(){return this._inDevelopment}};var Te="__nqtr-stage__",_=class extends storage.StoredClassModel{constructor(e,t={}){super(Te,e);n(this,"_onStart");n(this,"_onEnd");n(this,"_deltaDateRequired");n(this,"_questsRequired");this._onStart=t.onStart,this._onEnd=t.onEnd,this._deltaDateRequired=t.deltaDateRequired,this._questsRequired=t.questsRequired||[];}get onStart(){return this._onStart}get onEnd(){return this._onEnd}get completed(){return this.getStorageProperty("completed")||false}set completed(e){this.setStorageProperty("completed",e);}get started(){return this.getStorageProperty("started")||false}set started(e){this.setStorageProperty("started",e);}get inizializeDate(){return this.getStorageProperty("inizializeDate")}set inizializeDate(e){this.setStorageProperty("inizializeDate",e);}get startDate(){let e=this.inizializeDate;if(e!==void 0)return e+this.deltaDateRequired}get canStart(){let e=this.deltaDateRequired;if(e>0){let t=this.inizializeDate;if(t===void 0||t+e>handlers.timeTracker.currentDate)return false}return !(this.questsRequired.length>0&&!this.questsRequired.every(t=>t.quest.currentStageIndex&&t.quest.currentStageIndex>=t.stageNumber))}inizialize(){this.deltaDateRequired>0&&(this.inizializeDate=handlers.timeTracker.currentDate,console.log(`[NQTR] Stage ${this.id} will start on date ${this.startDate}`));}async start(e){this.canStart?(this.started=true,this.onStart&&await this.onStart(this,e)):console.warn(`[NQTR] Stage ${this.id} can't start`);}get deltaDateRequired(){return this._deltaDateRequired||0}get questsRequired(){return this._questsRequired||[]}};var q=class extends _{constructor(e,t){super(e,{onStart:t.onStart,onEnd:t.onEnd,deltaDateRequired:t.deltaDateRequired,questsRequired:t.questsRequired});n(this,"_name");n(this,"_description");n(this,"_adviceDescription");n(this,"_image");n(this,"_flags");n(this,"_flagsRequired");n(this,"_requestDescriptionToStart");this._name=t.name||"",this._flags=t.flags||[],this._description=t.description||"",this._adviceDescription=t.adviceDescription||"",this._image=t.image,this._flagsRequired=t.flagsRequired||[],this._requestDescriptionToStart=t.requestDescriptionToStart||"";}get name(){return this._name}get description(){return this._description}get adviceDescription(){return this._adviceDescription}get image(){return this._image}get flags(){return this._flags}get flagsRequired(){return this._flagsRequired}get requestDescriptionToStart(){return this._requestDescriptionToStart}get completed(){return super.completed?true:this.flags.length>0?!!this.flags.every(e=>storage.storage.getFlag(e.flag)):false}set completed(e){super.completed=e;}get canStart(){return this.flagsRequired.length>0&&!this.flagsRequired.every(e=>storage.storage.getFlag(e.flag))?false:super.canStart}};var ne={};var ae={};var K={};W(K,{navigator:()=>De,questsNotebook:()=>we,routine:()=>Ce,timeTracker:()=>Pe});var O=class{get rooms(){return qe.RegisteredRooms.values()}get locations(){return qe.RegisteredLocations.values()}get maps(){return qe.RegisteredMaps.values()}get currentRoomId(){return storage.storage.get(p)}get currentRoom(){let r=this.currentRoomId;if(!r){u.error("The current room has not yet been set");return}let e=qe.RegisteredRooms.get(r);if(!e){u.error(`Current room ${r} not found`);return}return e}set currentRoom(r){if(typeof r!="string"&&(r=r.id),!qe.RegisteredRooms.get(r)){u.error(`The room ${r} is not registered, so it can't be set as current room`);return}let t=storage.storage.get(p);t!==r&&(b({type:"editroom",prev:t,value:r}),storage.storage.set(p,r));}get currentLocation(){return this.currentRoom?.location}get currentMap(){return this.currentRoom?.location.map}clearExpiredActivities(){qe.RegisteredRooms.values().forEach(r=>{r.clearExpiredActivities();});}};var N=class{get quests(){return qe.RegisteredQuests.values()}get startedQuests(){return this.quests.filter(r=>r.started)}get inProgressQuests(){return this.quests.filter(r=>r.inProgress)}get completedQuests(){return this.quests.filter(r=>r.completed)}get failedQuests(){return this.quests.filter(r=>r.failed)}get notStartedQuests(){return this.quests.filter(r=>!r.started)}find(r){return qe.RegisteredQuests.get(r)}async startsStageMustBeStarted(r){let e=this.quests.map(t=>t.currentStageMustStart?t.startCurrentStage(r):Promise.resolve());await Promise.all(e);}};var $="___nqtr-temporary_commitment___",M=class{get fixedRoutine(){return [...qe.fixedCommitments.values()]}set fixedRoutine(r){r.forEach(e=>{qe.fixedCommitments.has(e.id)&&console.warn(`[NQTR] Commitment id ${e.id} already exists, it will be overwritten`),qe.fixedCommitments.set(e.id,e);});}get temporaryRoutine(){let r=storage.storage.get($);return r?r.map(t=>qe.RegisteredCommitments.get(t)).filter(t=>t!==void 0):[]}get allRoutine(){return [...this.fixedRoutine,...this.temporaryRoutine]}add(r){Array.isArray(r)||(r=[r]);let e=r.map(t=>{if(!qe.RegisteredCommitments.get(t.id)){console.warn(`[NQTR] Commitment ${t.id} not found, it will be ignored`);return}return t.id}).filter(t=>t!==void 0);storage.storage.set($,e);}find(r){return qe.RegisteredCommitments.get(r)}remove(r){Array.isArray(r)||(r=[r]);let e=r.map(i=>i.id),t=storage.storage.get($);t&&(t=t.filter(i=>!e.includes(i)),storage.storage.set($,t));}clearExpiredRoutine(){qe.RegisteredCommitments.values().forEach(r=>{r.expired&&qe.registeredCommitments.delete(r.id);});}get currentRoutine(){let r={};return [...this.fixedRoutine,...this.temporaryRoutine].forEach(e=>{e.isActive()&&(e.characters.length>0?e.characters.every(i=>!r[i.id]||e.priority>r[i.id].priority)&&e.characters.forEach(i=>{r[i.id]=e;}):u.error(`The commitment ${e.id} has no characters assigned`));}),Object.values(r)}getCommitmentByCharacter(r){this.currentRoutine.forEach(e=>{if(e.characters.map(t=>t.id).includes(r.id))return e});}};var m=class m{};n(m,"dayStartTime",0),n(m,"dayEndTime",24),n(m,"defaultTimeSpent",1),n(m,"timeSlots",[]),n(m,"weekLength",7),n(m,"weekendStartDay",m.weekLength-1),n(m,"getDayName");var d=m;var Q=class{initialize(r){let{dayStartTime:e=0,dayEndTime:t=24,defaultTimeSpent:i=1,timeSlots:a=[],weekLength:o=7,weekendStartDay:c=o-1,getDayName:R}=r;d.dayStartTime=e,d.dayEndTime=t,d.defaultTimeSpent=i,d.timeSlots=a,d.weekLength=o,c>=d.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${o}, so will be ignored`):d.weekendStartDay=c,d.getDayName=R;}get dayStartTime(){return d.dayStartTime}get dayEndTime(){return d.dayEndTime}get defaultTimeSpent(){return d.defaultTimeSpent}get timeSlots(){return d.timeSlots}get weekLength(){return d.weekLength}get weekendStartDay(){return d.weekendStartDay}get getDayName(){return d.getDayName}get currentTime(){let r=storage.storage.get(l)||{};return r.hasOwnProperty("currentTime")&&typeof r.currentTime=="number"?r.currentTime:this.dayStartTime}set currentTime(r){let e=storage.storage.get(l)||{},t={...e};typeof r=="number"?t.currentTime=r:delete t.currentTime,b({type:"edittime",prev:e,value:t}),storage.storage.set(l,t);}get currentDate(){let r=storage.storage.get(l)||{};return r.hasOwnProperty("currentDate")&&typeof r.currentDate=="number"?r.currentDate:0}set currentDate(r){let e=storage.storage.get(l)||{},t={...e};typeof r=="number"?t.currentDate=r:delete t.currentDate,b({type:"edittime",prev:e,value:t}),storage.storage.set(l,t);}get isWeekend(){return this.currentWeekDayNumber>=this.weekendStartDay}get currentWeekDayNumber(){return this.currentDate%this.weekLength+1}get currentDayName(){return this.getDayName?this.getDayName(this.currentWeekDayNumber-1):(console.warn("[NQTR] Week days names are not defined, so currentDayName will be empty"),"")}get currentTimeSlot(){if(this.timeSlots.length===0)return console.warn("[NQTR] Time slots are not defined"),0;for(let r=0;r<this.timeSlots.length;r++){let e=this.timeSlots[r];if(this.timeSlots.length>r+1&&this.nowIsBetween(e.startTime,this.timeSlots[r+1].startTime))return r}return this.timeSlots.length-1}increaseTime(r=this.defaultTimeSpent){let e=this.currentTime+r;return e>=this.dayEndTime&&(this.increaseDate(),e=this.dayStartTime+(e-this.dayEndTime)),this.currentTime=e,this.currentTime}increaseDate(r=1,e=this.dayStartTime){let t=this.currentDate+r;return this.currentDate=t,this.currentTime=e,this.currentDate}nowIsBetween(r,e){r===void 0&&(r=this.dayStartTime-1),e===void 0&&(e=this.dayEndTime+1);let t=this.currentTime;return r<e?t>=r&&t<e:t>=r||t<e}};var Pe=new Q,De=new O,Ce=new M,we=new N;var Oe={...F,...ne,...ae,handlers:K,registries:qe__namespace},qr=Oe;Object.defineProperty(exports,"RegisteredActivities",{enumerable:true,get:function(){return qe.RegisteredActivities}});Object.defineProperty(exports,"RegisteredCommitments",{enumerable:true,get:function(){return qe.RegisteredCommitments}});Object.defineProperty(exports,"RegisteredLocations",{enumerable:true,get:function(){return qe.RegisteredLocations}});Object.defineProperty(exports,"RegisteredMaps",{enumerable:true,get:function(){return qe.RegisteredMaps}});Object.defineProperty(exports,"RegisteredQuests",{enumerable:true,get:function(){return qe.RegisteredQuests}});Object.defineProperty(exports,"RegisteredRooms",{enumerable:true,get:function(){return qe.RegisteredRooms}});exports.ActivityBaseModel=T;exports.ActivityStoredClass=f;exports.CommitmentBaseModel=E;exports.CommitmentStoredClass=h;exports.LocationBaseModel=P;exports.LocationStoredClass=S;exports.MapBaseModel=D;exports.MapStoredClass=y;exports.QuestBaseModel=w;exports.QuestStoredClass=I;exports.RoomBaseModel=C;exports.RoomStoredClass=v;exports.StageBaseModel=q;exports.StageStoredClass=_;exports.default=qr;Object.keys(handlers).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return handlers[k]}})});
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var handlers=require('@drincs/nqtr/handlers'),Qe=require('@drincs/nqtr/registries'),storage=require('@drincs/pixi-vn/storage'),narration=require('@drincs/pixi-vn/narration'),core=require('@drincs/pixi-vn/core');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var Qe__namespace=/*#__PURE__*/_interopNamespace(Qe);var U=Object.defineProperty;var me=(o,r,e)=>r in o?U(o,r,{enumerable:true,configurable:true,writable:true,value:e}):o[r]=e;var W=(o,r)=>{for(var e in r)U(o,e,{get:r[e],enumerable:true});};var n=(o,r,e)=>me(o,typeof r!="symbol"?r+"":r,e);var F={};W(F,{ActivityBaseModel:()=>b,ActivityStoredClass:()=>g,CommitmentBaseModel:()=>P,CommitmentStoredClass:()=>y,LocationBaseModel:()=>E,LocationStoredClass:()=>S,MapBaseModel:()=>C,MapStoredClass:()=>v,QuestBaseModel:()=>w,QuestStoredClass:()=>_,RoomBaseModel:()=>D,RoomStoredClass:()=>I,StageBaseModel:()=>O,StageStoredClass:()=>x});var ge="__nqtr-activity__",g=class extends storage.StoredClassModel{constructor(e,t,i,a=ge){super(a,e);this._onRun=t;n(this,"_timeSlot");n(this,"_dateScheduling");this._timeSlot=i.timeSlot,this._dateScheduling=i.dateScheduling;}_onRun;get timeSlot(){return this._timeSlot}get dateScheduling(){return this._dateScheduling}addTempHistoryItem(){narration.narration.addCurrentStepToHistory();}get run(){return async e=>(this.addTempHistoryItem(),await this._onRun(this,e))}get expired(){return !!(this.dateScheduling?.to&&this.dateScheduling.to<=handlers.timeTracker.currentDate)}isActive(e={}){let{timeSlot:t=this.timeSlot,dateScheduling:i=this.dateScheduling}=e;if(i?.from!=null&&i.from>handlers.timeTracker.currentDate||i?.to!=null&&i.to<handlers.timeTracker.currentDate)return false;t&&!Array.isArray(t)&&(t=[t]);for(let a of t||[])if(!handlers.timeTracker.nowIsBetween(a?.from,a?.to))return false;return true}};var b=class extends g{constructor(e,t,i){super(e,t,{dateScheduling:i.dateScheduling,timeSlot:i.timeSlot});n(this,"defaultName");n(this,"defaultDisabled");n(this,"defaultHidden");n(this,"_icon");this.defaultName=i.name||"",this.defaultDisabled=i.disabled||false,this.defaultHidden=i.hidden||false,this._icon=i.renderIcon;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}get icon(){return this._icon}};var m="___nqtr-time_manager_data___",p="___nqtr-current_room_memory___",Y="___nqtr-last_event_memory___";function R(o){storage.storage.set(Y,o);}function J(){return storage.storage.get(Y)}var pe="__nqtr-commitment__",y=class extends g{constructor(e,t,i,a){i=i||(()=>{});super(e,i,a,pe);this._characters=t;n(this,"defaultExecutionType");n(this,"defaultPriority");this.defaultExecutionType=a.executionType||"interaction",this.defaultPriority=a.priority;}_characters;get characters(){return this._characters}get executionType(){return this.getStorageProperty("executionType")||this.defaultExecutionType}set executionType(e){this.setStorageProperty("executionType",e);}get priority(){return this.getStorageProperty("priority")||this.defaultPriority||0}set priority(e){this.setStorageProperty("priority",e);}addTempHistoryItem(){let e=handlers.navigator.currentRoom;if(!e||this.executionType!=="automatic")return super.addTempHistoryItem();let t=J();switch(t?.type){case "editroom":storage.storage.set(p,t.prev),super.addTempHistoryItem(),storage.storage.set(p,e.id);break;case "edittime":let i=storage.storage.get(m)||{};storage.storage.set(m,t.prev),super.addTempHistoryItem(),storage.storage.set(m,i);break}}};var P=class extends y{constructor(e,t,i){super(e,t?Array.isArray(t)?t:[t]:[],i.onRun,{executionType:i.executionType,priority:i.priority,timeSlot:i.timeSlot,dateScheduling:i.dateScheduling});n(this,"_name");n(this,"_image");n(this,"_icon");n(this,"defaultDisabled");n(this,"defaultHidden");this._name=i.name||"",this._image=i.image,this.defaultDisabled=i.disabled||false,this.defaultHidden=i.hidden||false,this._icon=i.icon;}get name(){return this._name}get image(){return this._image}get icon(){return this._icon}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}};var d;(i=>(i.log=(a,...s)=>console.log(`[NQTR] ${a}`,...s),i.warn=(a,...s)=>console.warn(`[NQTR] ${a}`,...s),i.error=(a,...s)=>console.error(`[NQTR] ${a}`,...s),i.info=(a,...s)=>console.info(`[NQTR] ${a}`,...s)))(d||(d={}));var h=class extends storage.StoredClassModel{constructor(e,t,i=[]){super(e,t);this.defaultActivities=i;}defaultActivities;get defaultActivitiesIds(){return this.defaultActivities.map(e=>e.id)}get activeActivityScheduling(){return this.getStorageProperty("activeActivityScheduling")||{}}get excludedActivitiesScheduling(){return this.getStorageProperty("excludedActivitiesScheduling")||{}}removeActivityScheduling(e){let t=this.activeActivityScheduling;delete t[e],this.setStorageProperty("activeActivityScheduling",t);let i=this.excludedActivitiesScheduling;delete i[e],this.setStorageProperty("excludedActivitiesScheduling",i);}editActivityScheduling(e,t){this.removeActivityScheduling(e);let i=this.activeActivityScheduling;i[e]=t,this.setStorageProperty("activeActivityScheduling",i);}editExcludedActivityScheduling(e,t){this.removeActivityScheduling(e);let i=this.excludedActivitiesScheduling;i[e]=t,this.setStorageProperty("excludedActivitiesScheduling",i);}get additionalActivitiesIds(){return this.getStorageProperty("additionalActivitiesIds")||[]}get excludedActivitiesIds(){return this.getStorageProperty("excludedActivitiesIds")||[]}get activitiesIds(){return this.additionalActivitiesIds.concat(this.defaultActivitiesIds)}addActivity(e,t={}){let{timeSlot:i,dateScheduling:a}=t;if(i&&!Array.isArray(i)&&(i=[i]),i?.forEach(c=>{let{to:l=handlers.timeTracker.dayEndTime+1}=c||{};if(c&&c.from>=l)throw d.error("The from time must be less than the to time."),new core.PixiError("invalid_usage","The from time must be less than the to time.")}),a?.from!==void 0&&a?.to!==void 0&&a?.from>=a?.to)throw d.error("The from day/date must be less than the to day/date."),new core.PixiError("invalid_usage","The from day/date must be less than the to day/date.");let s=this.additionalActivitiesIds;this.defaultActivitiesIds.includes(e.id)||s.includes(e.id)?d.info(`Activity with id ${e.id} already exists in the ${this.id}, so it will be updated with the new scheduling options if they are provided.`):(s.push(e.id),this.setStorageProperty("additionalActivitiesIds",s)),this.excludedActivitiesIds.includes(e.id)&&(this.removeActivityScheduling(e.id),d.log(`Activity with id ${e.id} was excluded from the ${this.id}, but now it will be added again with the new scheduling options. So it will be removed from the excluded activities list.`)),(i||a)&&this.editActivityScheduling(e.id,{timeSlot:i,dateScheduling:a});}removeActivity(e){let t=typeof e=="string"?e:e.id,i=this.additionalActivitiesIds;if(i.includes(t))i=i.filter(a=>a!==t),this.setStorageProperty("additionalActivitiesIds",i);else if(this.defaultActivitiesIds.includes(t)){let a=this.excludedActivitiesIds;a.push(t),this.setStorageProperty("excludedActivitiesIds",a);}else d.warn(`Activity with id ${t} not found, so it will be ignored.`);}clearExpiredActivities(){let e=this.activeActivityScheduling,t=this.excludedActivitiesScheduling,i=this.additionalActivitiesIds,a=this.excludedActivitiesIds;i.forEach(s=>{if(s in e){let{to:c}=e[s].dateScheduling||{};c&&c<handlers.timeTracker.currentDate&&(this.removeActivityScheduling(s),i=i.filter(l=>l!==s));}}),a.forEach(s=>{s in t&&t[s]&&(this.removeActivityScheduling(s),a=a.filter(c=>c!==s));});}get activities(){return [...new Set([...this.additionalActivitiesIds,...this.defaultActivitiesIds])].reduce((e,t)=>{let i=Qe.RegisteredActivities.get(t);return i&&i.isActive(this.activeActivityScheduling[t])&&!this.excludedActivitiesScheduling[t]&&e.push(i),e},[])}};var Ie="__nqtr-location__",S=class extends h{constructor(e,t,i=[]){super(Ie,e,i);this._map=t;}_map;get map(){return this._map}get rooms(){return handlers.navigator.rooms.filter(e=>e.location.id===this.id)}};var E=class extends S{constructor(e,t,i={}){super(e,t,i.activities||[]);n(this,"defaultName");n(this,"defaultDisabled");n(this,"defaultHidden");n(this,"_icon");this.defaultName=i.name||"",this.defaultDisabled=i.disabled||false,this.defaultHidden=i.hidden||false,this._icon=i.icon;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}get icon(){return this._icon}};var xe="__nqtr-map__",v=class extends h{constructor(r,e=[]){super(xe,r,e);}get locations(){return handlers.navigator.locations.filter(r=>r.map.id===this.id)}};var C=class extends v{constructor(e,t={}){super(e,t.activities||[]);n(this,"defaultName");n(this,"_image");this.defaultName=t.name||"",this._image=t.image;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get image(){return this._image}};var ie="__nqtr-room__",I=class extends h{constructor(e,t,i=[]){var r=(...Nt)=>(super(...Nt),this._location=t,this);Array.isArray(i)?r(ie,e,i):(r(ie,e,i.activities),i.routine.forEach(a=>Qe.fixedCommitments.set(a.id,[a,e])));}_location;get routine(){return handlers.routine.roomCommitments[this.id]||[]}addCommitment(e,t={}){let{timeSlot:i,dateScheduling:a}=t;if(i&&!Array.isArray(i)&&(i=[i]),i?.forEach(s=>{let{to:c=handlers.timeTracker.dayEndTime+1}=s||{};if(s&&s.from>=c)throw d.error("The from time must be less than the to time."),new core.PixiError("invalid_usage","The from time must be less than the to time.")}),a?.from!==void 0&&a?.to!==void 0&&a?.from>=a?.to)throw d.error("The from day/date must be less than the to day/date."),new core.PixiError("invalid_usage","The from day/date must be less than the to day/date.");handlers.routine.add(e,this.id,{timeSlot:i,dateScheduling:a});}removeCommitment(e){handlers.routine.remove(e,this.id);}get location(){return this._location}get characters(){return this.routine.reduce((e,t)=>(e.push(...t.characters),e),[])}get automaticFunctions(){return this.routine.reduce((e,t)=>{if(t.executionType==="automatic"&&t.run){let i=async a=>{await t.run(a);};e.push(i);}return e},[])}};var D=class extends I{constructor(e,t,i={}){super(e,t,{activities:i.activities||[],routine:i.routine||[]});n(this,"defaultName");n(this,"_image");n(this,"defaultDisabled");n(this,"defaultHidden");n(this,"_icon");this.defaultName=i.name||"",this._image=i.image,this.defaultDisabled=i.disabled||false,this.defaultHidden=i.hidden||false,this._icon=i.icon;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get image(){return this._image}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}get icon(){return this._icon}};var Ae="__nqtr-quest__",_=class extends storage.StoredClassModel{constructor(e,t,i={}){super(Ae,e);this._stages=t;n(this,"_onStart");n(this,"_onNextStage");this._onStart=i.onStart,this._onNextStage=i.onNextStage;}_stages;get stages(){return this._stages}get currentStageIndex(){return this.getStorageProperty("currentStageIndex")}set currentStageIndex(e){this.setStorageProperty("currentStageIndex",e);}get currentStage(){let e=this.currentStageIndex;if(!(e===void 0||e>=this.stages.length))return this.stages[e]}get started(){return this.currentStageIndex!==void 0}get completed(){return this.currentStageIndex===void 0?false:this.currentStageIndex>this.stages.length-1}get inProgress(){return this.completed||this.failed?false:this.started}get failed(){return this.getStorageProperty("failed")||false}set failed(e){this.setStorageProperty("failed",e);}get onStart(){return this._onStart}get onNextStage(){return this._onNextStage}async start(e){if(this.started){console.warn(`[NQTR] Quest ${this.id} is already started`);return}if(this.stages.length===0){d.error(`Quest ${this.id} has no stages`);return}this.currentStageIndex=0;let t=this.currentStage;if(t&&t.start)return this.onStart&&await this.onStart(this,e),await t.start(e);d.error(`Quest ${this.id} has no start stage`);}async goNextIfCompleted(e){return await this.advanceIfCompleted(e)}async advanceIfCompleted(e){if(!this.inProgress)return false;let t=this.currentStage;return t?t.completed?await this.advanceUnconditionally(e):false:(d.error(`Quest ${this.id} has no current stage`),false)}async goNext(e){return await this.continue(e)}async continue(e){let t=this.currentStage;return t?(t.completed=true,await this.advanceUnconditionally(e)):(d.error(`Quest ${this.id} has no current stage`),false)}async forceGoNext(e){return await this.advanceUnconditionally(e)}async advanceUnconditionally(e){if(!this.inProgress)return console.warn(`[NQTR] Quest ${this.id} is not in progress`),false;let t=this.currentStage,i=this.currentStageIndex;if(!t||i===void 0)return d.error(`Quest ${this.id} has no current stage`),false;this.currentStageIndex=i+1,this.onNextStage&&await this.onNextStage(this,e),t&&t.onEnd&&await t.onEnd(t,e);let a=this.currentStage;return a&&(a.inizialize(),this.currentStageMustStart&&await this.startCurrentStage(e)),true}get currentStageMustStart(){let e=this.currentStage;return e?!e.started&&e.canStart&&!e.completed:false}async startCurrentStage(e){let t=this.currentStage;t&&this.currentStageMustStart?await t.start(e):console.warn(`[NQTR] Quest ${this.id} can't start the current stage`);}};var w=class extends _{constructor(e,t,i){super(e,t,{onStart:i.onStart,onNextStage:i.onNextStage});n(this,"_name");n(this,"_description");n(this,"_icon");n(this,"_image");n(this,"_inDevelopment");this._name=i.name||"",this._description=i.description||"",this._icon=i.icon,this._image=i.image,this._inDevelopment=i.inDevelopment||false;}get name(){return this._name}get description(){return this._description}get icon(){return this._icon}get image(){return this._image}get inDevelopment(){return this._inDevelopment}};var Ee="__nqtr-stage__",x=class extends storage.StoredClassModel{constructor(e,t={}){super(Ee,e);n(this,"_onStart");n(this,"_onEnd");n(this,"_deltaDateRequired");n(this,"_questsRequired");this._onStart=t.onStart,this._onEnd=t.onEnd,this._deltaDateRequired=t.deltaDateRequired,this._questsRequired=t.questsRequired||[];}get onStart(){return this._onStart}get onEnd(){return this._onEnd}get completed(){return this.getStorageProperty("completed")||false}set completed(e){this.setStorageProperty("completed",e);}get started(){return this.getStorageProperty("started")||false}set started(e){this.setStorageProperty("started",e);}get inizializeDate(){return this.getStorageProperty("inizializeDate")}set inizializeDate(e){this.setStorageProperty("inizializeDate",e);}get startDate(){let e=this.inizializeDate;if(e!==void 0)return e+this.deltaDateRequired}get canStart(){let e=this.deltaDateRequired;if(e>0){let t=this.inizializeDate;if(t===void 0||t+e>handlers.timeTracker.currentDate)return false}return !(this.questsRequired.length>0&&!this.questsRequired.every(t=>t.quest.currentStageIndex&&t.quest.currentStageIndex>=t.stageNumber))}inizialize(){this.deltaDateRequired>0&&(this.inizializeDate=handlers.timeTracker.currentDate,console.log(`[NQTR] Stage ${this.id} will start on date ${this.startDate}`));}async start(e){this.canStart?(this.started=true,this.onStart&&await this.onStart(this,e)):console.warn(`[NQTR] Stage ${this.id} can't start`);}get deltaDateRequired(){return this._deltaDateRequired||0}get questsRequired(){return this._questsRequired||[]}};var O=class extends x{constructor(e,t){super(e,{onStart:t.onStart,onEnd:t.onEnd,deltaDateRequired:t.deltaDateRequired,questsRequired:t.questsRequired});n(this,"_name");n(this,"_description");n(this,"_adviceDescription");n(this,"_image");n(this,"_flags");n(this,"_flagsRequired");n(this,"_requestDescriptionToStart");this._name=t.name||"",this._flags=t.flags||[],this._description=t.description||"",this._adviceDescription=t.adviceDescription||"",this._image=t.image,this._flagsRequired=t.flagsRequired||[],this._requestDescriptionToStart=t.requestDescriptionToStart||"";}get name(){return this._name}get description(){return this._description}get adviceDescription(){return this._adviceDescription}get image(){return this._image}get flags(){return this._flags}get flagsRequired(){return this._flagsRequired}get requestDescriptionToStart(){return this._requestDescriptionToStart}get completed(){return super.completed?true:this.flags.length>0?!!this.flags.every(e=>storage.storage.getFlag(e.flag)):false}set completed(e){super.completed=e;}get canStart(){return this.flagsRequired.length>0&&!this.flagsRequired.every(e=>storage.storage.getFlag(e.flag))?false:super.canStart}};var oe={};var de={};var K={};W(K,{navigator:()=>qe,questsNotebook:()=>Ne,routine:()=>Me,timeTracker:()=>Oe});var q=class{get rooms(){return Qe.RegisteredRooms.values()}get locations(){return Qe.RegisteredLocations.values()}get maps(){return Qe.RegisteredMaps.values()}get currentRoomId(){return storage.storage.get(p)}get currentRoom(){let r=this.currentRoomId;if(!r){d.error("The current room has not yet been set");return}let e=Qe.RegisteredRooms.get(r);if(!e){d.error(`Current room ${r} not found`);return}return e}set currentRoom(r){if(typeof r!="string"&&(r=r.id),!Qe.RegisteredRooms.get(r)){d.error(`The room ${r} is not registered, so it can't be set as current room`);return}let t=storage.storage.get(p);t!==r&&(R({type:"editroom",prev:t,value:r}),storage.storage.set(p,r));}get currentLocation(){return this.currentRoom?.location}get currentMap(){return this.currentRoom?.location.map}clearExpiredActivities(){Qe.RegisteredRooms.values().forEach(r=>{r.clearExpiredActivities();});}};var M=class{get quests(){return Qe.RegisteredQuests.values()}get startedQuests(){return this.quests.filter(r=>r.started)}get inProgressQuests(){return this.quests.filter(r=>r.inProgress)}get completedQuests(){return this.quests.filter(r=>r.completed)}get failedQuests(){return this.quests.filter(r=>r.failed)}get notStartedQuests(){return this.quests.filter(r=>!r.started)}find(r){return Qe.RegisteredQuests.get(r)}async startsStageMustBeStarted(r){let e=this.quests.map(t=>t.currentStageMustStart?t.startCurrentStage(r):Promise.resolve());await Promise.all(e);}};var H="___nqtr-temporary_commitment___",Q=class{get temporaryRoutine(){let r=storage.storage.get(H);if(r){if(Array.isArray(r)){if(r.length>0)throw new core.PixiError("obsolete_save","The save you loaded is not compatible with the current version of NQTR. Please delete the save and start a new game.");return {}}}else return {};return r}get commitmentsIds(){return [...Qe.fixedCommitments.keys(),...Object.keys(this.temporaryRoutine)]}add(r,e,t={}){Array.isArray(r)||(r=[r]);let i=this.temporaryRoutine;r.forEach(a=>{Qe.RegisteredCommitments.get(a.id)&&d.warn(`The commitment ${a.id} is already registered, it will be overwritten`),Qe.RegisteredCommitments.add(a),i[a.id]={id:a.id,roomId:e,...t};}),storage.storage.set(H,i);}find(r){return Qe.RegisteredCommitments.get(r)}remove(r,e){typeof r!="string"&&(r=r.id);let t=this.temporaryRoutine;t[r]?(!e||t[r].roomId===e)&&delete t[r]:d.warn(`The commitment ${r} was not found in the temporary routine, so it will be ignored. If you want to remove a fixed commitment, you can add it to the temporary routine with a same character.`),storage.storage.set(H,t);}clearExpiredRoutine(){Qe.RegisteredCommitments.values().forEach(r=>{r.expired&&this.remove(r);});}get characterCommitments(){let r=this.temporaryRoutine;return this.commitmentsIds.reduce((e,t)=>{let i=Qe.RegisteredCommitments.get(t),a=r[t],s=a?.roomId||Qe.fixedCommitments.get(t)?.[1];return s&&i&&i.isActive(a)&&(i.characters.length>0?i.characters.every(l=>!e[l.id]||i.priority>e[l.id][0].priority)&&i.characters.forEach(l=>{e[l.id]=[i,s];}):d.error(`The commitment ${i.id} has no characters assigned`)),e},{})}get currentRoutine(){return Object.values(this.characterCommitments).map(([r])=>r)}get roomCommitments(){return Object.values(this.characterCommitments).reduce((r,e)=>{let t=e[1];return r[t]||(r[t]=[]),r[t].push(e[0]),r},{})}getCommitmentByCharacter(r){return this.currentRoutine.find(e=>{if(e.characters.map(t=>t.id).includes(r.id))return e})}};var f=class f{};n(f,"dayStartTime",0),n(f,"dayEndTime",24),n(f,"defaultTimeSpent",1),n(f,"timeSlots",[]),n(f,"weekLength",7),n(f,"weekendStartDay",f.weekLength-1),n(f,"getDayName");var u=f;var L=class{initialize(r){let{dayStartTime:e=0,dayEndTime:t=24,defaultTimeSpent:i=1,timeSlots:a=[],weekLength:s=7,weekendStartDay:c=s-1,getDayName:l}=r;u.dayStartTime=e,u.dayEndTime=t,u.defaultTimeSpent=i,u.timeSlots=a,u.weekLength=s,c>=u.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${s}, so will be ignored`):u.weekendStartDay=c,u.getDayName=l;}get dayStartTime(){return u.dayStartTime}get dayEndTime(){return u.dayEndTime}get defaultTimeSpent(){return u.defaultTimeSpent}get timeSlots(){return u.timeSlots}get weekLength(){return u.weekLength}get weekendStartDay(){return u.weekendStartDay}get getDayName(){return u.getDayName}get currentTime(){let r=storage.storage.get(m)||{};return r.hasOwnProperty("currentTime")&&typeof r.currentTime=="number"?r.currentTime:this.dayStartTime}set currentTime(r){let e=storage.storage.get(m)||{},t={...e};typeof r=="number"?t.currentTime=r:delete t.currentTime,R({type:"edittime",prev:e,value:t}),storage.storage.set(m,t);}get currentDate(){let r=storage.storage.get(m)||{};return r.hasOwnProperty("currentDate")&&typeof r.currentDate=="number"?r.currentDate:0}set currentDate(r){let e=storage.storage.get(m)||{},t={...e};typeof r=="number"?t.currentDate=r:delete t.currentDate,R({type:"edittime",prev:e,value:t}),storage.storage.set(m,t);}get isWeekend(){return this.currentWeekDayNumber>=this.weekendStartDay}get currentWeekDayNumber(){return this.currentDate%this.weekLength+1}get currentDayName(){return this.getDayName?this.getDayName(this.currentWeekDayNumber-1):(console.warn("[NQTR] Week days names are not defined, so currentDayName will be empty"),"")}get currentTimeSlot(){if(this.timeSlots.length===0)return console.warn("[NQTR] Time slots are not defined"),0;for(let r=0;r<this.timeSlots.length;r++){let e=this.timeSlots[r];if(this.timeSlots.length>r+1&&this.nowIsBetween(e.startTime,this.timeSlots[r+1].startTime))return r}return this.timeSlots.length-1}increaseTime(r=this.defaultTimeSpent){let e=this.currentTime+r;return e>=this.dayEndTime&&(this.increaseDate(),e=this.dayStartTime+(e-this.dayEndTime)),this.currentTime=e,this.currentTime}increaseDate(r=1,e=this.dayStartTime){let t=this.currentDate+r;return this.currentDate=t,this.currentTime=e,this.currentDate}nowIsBetween(r,e){r===void 0&&(r=this.dayStartTime-1),e===void 0&&(e=this.dayEndTime+1);let t=this.currentTime;return r<e?t>=r&&t<e:t>=r||t<e}};var Oe=new L,qe=new q,Me=new Q,Ne=new M;var Le={...F,...oe,...de,handlers:K,registries:Qe__namespace},zr=Le;Object.defineProperty(exports,"RegisteredActivities",{enumerable:true,get:function(){return Qe.RegisteredActivities}});Object.defineProperty(exports,"RegisteredCommitments",{enumerable:true,get:function(){return Qe.RegisteredCommitments}});Object.defineProperty(exports,"RegisteredLocations",{enumerable:true,get:function(){return Qe.RegisteredLocations}});Object.defineProperty(exports,"RegisteredMaps",{enumerable:true,get:function(){return Qe.RegisteredMaps}});Object.defineProperty(exports,"RegisteredQuests",{enumerable:true,get:function(){return Qe.RegisteredQuests}});Object.defineProperty(exports,"RegisteredRooms",{enumerable:true,get:function(){return Qe.RegisteredRooms}});exports.ActivityBaseModel=b;exports.ActivityStoredClass=g;exports.CommitmentBaseModel=P;exports.CommitmentStoredClass=y;exports.LocationBaseModel=E;exports.LocationStoredClass=S;exports.MapBaseModel=C;exports.MapStoredClass=v;exports.QuestBaseModel=w;exports.QuestStoredClass=_;exports.RoomBaseModel=D;exports.RoomStoredClass=I;exports.StageBaseModel=O;exports.StageStoredClass=x;exports.default=zr;Object.keys(handlers).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return handlers[k]}})});
package/dist/index.d.mts CHANGED
@@ -182,10 +182,6 @@ interface CommitmentBaseInternalInterface extends ActivityBaseInternalInterface
182
182
  * The character or characters that are in the commitment and so in the room.
183
183
  */
184
184
  readonly characters: CharacterInterface[];
185
- /**
186
- * The room where the commitment is.
187
- */
188
- readonly room: RoomInterface;
189
185
  /**
190
186
  * 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.
191
187
  * If you set "automatic" remember to remove the commitment when it is no longer needed, because otherwise it repeats itself every time.
@@ -292,22 +288,13 @@ interface NavigationAbstractInterface extends StoredClassModel {
292
288
  * @param options
293
289
  * @returns
294
290
  */
295
- addActivity(activity: ActivityInterface, options?: {
296
- /**
297
- * Time slot in which activity will be active.
298
- */
299
- timeSlot?: TimeSchedulingInterface;
300
- /**
301
- * Used to schedule what date it will be added and removed.
302
- */
303
- dateScheduling?: DateSchedulingInterface;
304
- }): void;
291
+ addActivity(activity: ActivityInterface, options?: ActiveScheduling): void;
305
292
  /**
306
293
  * Disconnects the activity from the class.
307
294
  * @param activity The activity to disconnect from the class.
308
295
  * @param options
309
296
  */
310
- removeActivity(activity: ActivityInterface | string, options?: Pick<DateSchedulingInterface, "to">): void;
297
+ removeActivity(activity: ActivityInterface | string): void;
311
298
  /**
312
299
  * Removes the useless activities.
313
300
  */
@@ -388,6 +375,11 @@ interface RoomBaseModelProps {
388
375
  * @default []
389
376
  */
390
377
  activities?: ActivityInterface[];
378
+ /**
379
+ * The routine of the room, it is an array of commitments that are executed in the room. You can also add commitments during the game session, but this property is useful to set the initial routine of the room.
380
+ * @default undefined
381
+ */
382
+ routine?: CommitmentInterface[];
391
383
  /**
392
384
  * Whether is disabled. You can also pass a Pixi'VN flag name.
393
385
  * @default false
@@ -416,6 +408,19 @@ interface RoomBaseInternalInterface extends NavigationAbstractInterface {
416
408
  * The location where the room is.
417
409
  */
418
410
  readonly location: LocationInterface;
411
+ /**
412
+ * Connects the commitment to the class.
413
+ * @param commitment The commitment to connect to the class.
414
+ * @param options
415
+ * @returns
416
+ */
417
+ addCommitment(commitment: CommitmentInterface, options?: ActiveScheduling): void;
418
+ /**
419
+ * Disconnects the commitment from the class.
420
+ * @param commitment The commitment to disconnect from the class.
421
+ * @param options
422
+ */
423
+ removeCommitment(commitment: CommitmentInterface | string): void;
419
424
  /**
420
425
  * Get the character commitments of the room.
421
426
  */
@@ -783,12 +788,10 @@ interface CommitmentStoredClassProps {
783
788
  }
784
789
  declare class CommitmentStoredClass extends ActivityStoredClass<CommitmentInterface> implements CommitmentBaseInternalInterface {
785
790
  private readonly _characters;
786
- private readonly _room;
787
- constructor(id: string, _characters: CharacterInterface[], _room: RoomInterface, onRun: OnRunEvent<CommitmentInterface> | undefined, props: CommitmentStoredClassProps);
791
+ constructor(id: string, _characters: CharacterInterface[], onRun: OnRunEvent<CommitmentInterface> | undefined, props: CommitmentStoredClassProps);
788
792
  private readonly defaultExecutionType;
789
793
  private readonly defaultPriority?;
790
794
  get characters(): CharacterInterface[];
791
- get room(): RoomInterface;
792
795
  get executionType(): ExecutionType;
793
796
  set executionType(value: ExecutionType);
794
797
  get priority(): number;
@@ -798,10 +801,10 @@ declare class CommitmentStoredClass extends ActivityStoredClass<CommitmentInterf
798
801
 
799
802
  /**
800
803
  * The base model of a commitment. I suggest you extend this class to create your own commitment model.
801
- * You must use the saveRoom function to save the commitment in the registered commitments.
804
+ * You must use the saveCommitment function to save the commitment in the registered commitments.
802
805
  * @example
803
806
  * ```ts
804
- * export const mcRoom = new CommitmentBaseModel("test", character, room, {
807
+ * export const miaPlay = new CommitmentBaseModel("mia_play", mia, {
805
808
  * name: "Test",
806
809
  * image: "https://image.jpg",
807
810
  * executionType: ExecutionTypeEnum.INTERACTION,
@@ -809,17 +812,16 @@ declare class CommitmentStoredClass extends ActivityStoredClass<CommitmentInterf
809
812
  * // Do something
810
813
  * }
811
814
  * })
812
- * saveCommitment(mcRoom)
815
+ * saveCommitment(miaPlay)
813
816
  * ```
814
817
  */
815
818
  declare class CommitmentBaseModel extends CommitmentStoredClass {
816
819
  /**
817
820
  * @param id The id of the commitment, it must be unique.
818
821
  * @param character The character or characters that are in the commitment and so in the room.
819
- * @param room The room where the commitment is.
820
822
  * @param props The properties of the commitment.
821
823
  */
822
- constructor(id: string, character: CharacterInterface | CharacterInterface[] | undefined, room: RoomInterface, props: CommitmentProps);
824
+ constructor(id: string, character: CharacterInterface | CharacterInterface[] | undefined, props: CommitmentProps);
823
825
  private _name;
824
826
  /**
825
827
  * The name of the commitment.
@@ -968,8 +970,13 @@ declare class RoomStoredClass extends NavigationAbstractClass implements RoomBas
968
970
  /**
969
971
  * The location where the room is.
970
972
  */
971
- _location: LocationInterface, activities?: ActivityInterface[]);
973
+ _location: LocationInterface, activities?: ActivityInterface[] | {
974
+ activities: ActivityInterface[];
975
+ routine: CommitmentInterface[];
976
+ });
972
977
  get routine(): CommitmentInterface[];
978
+ addCommitment(commitment: CommitmentInterface, options?: ActiveScheduling): void;
979
+ removeCommitment(commitment: CommitmentInterface | string): void;
973
980
  get location(): LocationInterface;
974
981
  get characters(): CharacterInterface[];
975
982
  get automaticFunctions(): OnRunAsyncFunction[];
@@ -1238,22 +1245,18 @@ declare class QuestHandler {
1238
1245
  }
1239
1246
 
1240
1247
  declare class RoutineHandler {
1241
- get fixedRoutine(): CommitmentInterface[];
1242
- /**
1243
- * Set a commitment as fixed, it will be always available. They cannot be deleted or edit during the game session.
1244
- */
1245
- set fixedRoutine(commitments: CommitmentInterface[]);
1246
1248
  /**
1247
1249
  * Get the temporary commitments by its id.
1248
1250
  * @returns The temporary commitments.
1249
1251
  */
1250
- get temporaryRoutine(): CommitmentInterface[];
1251
- get allRoutine(): CommitmentInterface[];
1252
+ private get temporaryRoutine();
1253
+ get commitmentsIds(): string[];
1252
1254
  /**
1253
1255
  * This feature adds the commitments during the game session.
1254
1256
  * @param commitment The commitment or commitments to add.
1257
+ * @param roomId The id of the room where the commitment is.
1255
1258
  */
1256
- add(commitment: CommitmentInterface[] | CommitmentInterface): void;
1259
+ add(commitment: CommitmentInterface[] | CommitmentInterface, roomId: string, options?: ActiveScheduling): void;
1257
1260
  /**
1258
1261
  * Get the commitments added during the game session.
1259
1262
  * @param id The id of the commitment.
@@ -1262,13 +1265,17 @@ declare class RoutineHandler {
1262
1265
  find(id: string): CommitmentInterface | undefined;
1263
1266
  /**
1264
1267
  * Remove the commitments added during the game session.
1265
- * @param commitment The commitment or commitments to remove.
1268
+ * @param commitment The commitment or commitment id to remove.
1269
+ * @param roomId The id of the room where the commitment is.
1266
1270
  */
1267
- remove(commitment: CommitmentInterface[] | CommitmentInterface): void;
1271
+ remove(commitment: CommitmentInterface | string, roomId?: string): void;
1268
1272
  /**
1269
1273
  * Clear all the expired commitments.
1270
1274
  */
1271
1275
  clearExpiredRoutine(): void;
1276
+ get characterCommitments(): {
1277
+ [character: string]: [CommitmentInterface, string];
1278
+ };
1272
1279
  /**
1273
1280
  * Get the current commitments. The hidden commitments are not included.
1274
1281
  * In case there is a character who has two or more commitments at the same time, will be selected the commitment with the highest priority.
@@ -1279,6 +1286,9 @@ declare class RoutineHandler {
1279
1286
  * @returns The current commitments.
1280
1287
  */
1281
1288
  get currentRoutine(): CommitmentInterface[];
1289
+ get roomCommitments(): {
1290
+ [roomId: string]: CommitmentInterface[];
1291
+ };
1282
1292
  /**
1283
1293
  * Get the character commitment.
1284
1294
  * @param character The character.
package/dist/index.d.ts CHANGED
@@ -182,10 +182,6 @@ interface CommitmentBaseInternalInterface extends ActivityBaseInternalInterface
182
182
  * The character or characters that are in the commitment and so in the room.
183
183
  */
184
184
  readonly characters: CharacterInterface[];
185
- /**
186
- * The room where the commitment is.
187
- */
188
- readonly room: RoomInterface;
189
185
  /**
190
186
  * 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.
191
187
  * If you set "automatic" remember to remove the commitment when it is no longer needed, because otherwise it repeats itself every time.
@@ -292,22 +288,13 @@ interface NavigationAbstractInterface extends StoredClassModel {
292
288
  * @param options
293
289
  * @returns
294
290
  */
295
- addActivity(activity: ActivityInterface, options?: {
296
- /**
297
- * Time slot in which activity will be active.
298
- */
299
- timeSlot?: TimeSchedulingInterface;
300
- /**
301
- * Used to schedule what date it will be added and removed.
302
- */
303
- dateScheduling?: DateSchedulingInterface;
304
- }): void;
291
+ addActivity(activity: ActivityInterface, options?: ActiveScheduling): void;
305
292
  /**
306
293
  * Disconnects the activity from the class.
307
294
  * @param activity The activity to disconnect from the class.
308
295
  * @param options
309
296
  */
310
- removeActivity(activity: ActivityInterface | string, options?: Pick<DateSchedulingInterface, "to">): void;
297
+ removeActivity(activity: ActivityInterface | string): void;
311
298
  /**
312
299
  * Removes the useless activities.
313
300
  */
@@ -388,6 +375,11 @@ interface RoomBaseModelProps {
388
375
  * @default []
389
376
  */
390
377
  activities?: ActivityInterface[];
378
+ /**
379
+ * The routine of the room, it is an array of commitments that are executed in the room. You can also add commitments during the game session, but this property is useful to set the initial routine of the room.
380
+ * @default undefined
381
+ */
382
+ routine?: CommitmentInterface[];
391
383
  /**
392
384
  * Whether is disabled. You can also pass a Pixi'VN flag name.
393
385
  * @default false
@@ -416,6 +408,19 @@ interface RoomBaseInternalInterface extends NavigationAbstractInterface {
416
408
  * The location where the room is.
417
409
  */
418
410
  readonly location: LocationInterface;
411
+ /**
412
+ * Connects the commitment to the class.
413
+ * @param commitment The commitment to connect to the class.
414
+ * @param options
415
+ * @returns
416
+ */
417
+ addCommitment(commitment: CommitmentInterface, options?: ActiveScheduling): void;
418
+ /**
419
+ * Disconnects the commitment from the class.
420
+ * @param commitment The commitment to disconnect from the class.
421
+ * @param options
422
+ */
423
+ removeCommitment(commitment: CommitmentInterface | string): void;
419
424
  /**
420
425
  * Get the character commitments of the room.
421
426
  */
@@ -783,12 +788,10 @@ interface CommitmentStoredClassProps {
783
788
  }
784
789
  declare class CommitmentStoredClass extends ActivityStoredClass<CommitmentInterface> implements CommitmentBaseInternalInterface {
785
790
  private readonly _characters;
786
- private readonly _room;
787
- constructor(id: string, _characters: CharacterInterface[], _room: RoomInterface, onRun: OnRunEvent<CommitmentInterface> | undefined, props: CommitmentStoredClassProps);
791
+ constructor(id: string, _characters: CharacterInterface[], onRun: OnRunEvent<CommitmentInterface> | undefined, props: CommitmentStoredClassProps);
788
792
  private readonly defaultExecutionType;
789
793
  private readonly defaultPriority?;
790
794
  get characters(): CharacterInterface[];
791
- get room(): RoomInterface;
792
795
  get executionType(): ExecutionType;
793
796
  set executionType(value: ExecutionType);
794
797
  get priority(): number;
@@ -798,10 +801,10 @@ declare class CommitmentStoredClass extends ActivityStoredClass<CommitmentInterf
798
801
 
799
802
  /**
800
803
  * The base model of a commitment. I suggest you extend this class to create your own commitment model.
801
- * You must use the saveRoom function to save the commitment in the registered commitments.
804
+ * You must use the saveCommitment function to save the commitment in the registered commitments.
802
805
  * @example
803
806
  * ```ts
804
- * export const mcRoom = new CommitmentBaseModel("test", character, room, {
807
+ * export const miaPlay = new CommitmentBaseModel("mia_play", mia, {
805
808
  * name: "Test",
806
809
  * image: "https://image.jpg",
807
810
  * executionType: ExecutionTypeEnum.INTERACTION,
@@ -809,17 +812,16 @@ declare class CommitmentStoredClass extends ActivityStoredClass<CommitmentInterf
809
812
  * // Do something
810
813
  * }
811
814
  * })
812
- * saveCommitment(mcRoom)
815
+ * saveCommitment(miaPlay)
813
816
  * ```
814
817
  */
815
818
  declare class CommitmentBaseModel extends CommitmentStoredClass {
816
819
  /**
817
820
  * @param id The id of the commitment, it must be unique.
818
821
  * @param character The character or characters that are in the commitment and so in the room.
819
- * @param room The room where the commitment is.
820
822
  * @param props The properties of the commitment.
821
823
  */
822
- constructor(id: string, character: CharacterInterface | CharacterInterface[] | undefined, room: RoomInterface, props: CommitmentProps);
824
+ constructor(id: string, character: CharacterInterface | CharacterInterface[] | undefined, props: CommitmentProps);
823
825
  private _name;
824
826
  /**
825
827
  * The name of the commitment.
@@ -968,8 +970,13 @@ declare class RoomStoredClass extends NavigationAbstractClass implements RoomBas
968
970
  /**
969
971
  * The location where the room is.
970
972
  */
971
- _location: LocationInterface, activities?: ActivityInterface[]);
973
+ _location: LocationInterface, activities?: ActivityInterface[] | {
974
+ activities: ActivityInterface[];
975
+ routine: CommitmentInterface[];
976
+ });
972
977
  get routine(): CommitmentInterface[];
978
+ addCommitment(commitment: CommitmentInterface, options?: ActiveScheduling): void;
979
+ removeCommitment(commitment: CommitmentInterface | string): void;
973
980
  get location(): LocationInterface;
974
981
  get characters(): CharacterInterface[];
975
982
  get automaticFunctions(): OnRunAsyncFunction[];
@@ -1238,22 +1245,18 @@ declare class QuestHandler {
1238
1245
  }
1239
1246
 
1240
1247
  declare class RoutineHandler {
1241
- get fixedRoutine(): CommitmentInterface[];
1242
- /**
1243
- * Set a commitment as fixed, it will be always available. They cannot be deleted or edit during the game session.
1244
- */
1245
- set fixedRoutine(commitments: CommitmentInterface[]);
1246
1248
  /**
1247
1249
  * Get the temporary commitments by its id.
1248
1250
  * @returns The temporary commitments.
1249
1251
  */
1250
- get temporaryRoutine(): CommitmentInterface[];
1251
- get allRoutine(): CommitmentInterface[];
1252
+ private get temporaryRoutine();
1253
+ get commitmentsIds(): string[];
1252
1254
  /**
1253
1255
  * This feature adds the commitments during the game session.
1254
1256
  * @param commitment The commitment or commitments to add.
1257
+ * @param roomId The id of the room where the commitment is.
1255
1258
  */
1256
- add(commitment: CommitmentInterface[] | CommitmentInterface): void;
1259
+ add(commitment: CommitmentInterface[] | CommitmentInterface, roomId: string, options?: ActiveScheduling): void;
1257
1260
  /**
1258
1261
  * Get the commitments added during the game session.
1259
1262
  * @param id The id of the commitment.
@@ -1262,13 +1265,17 @@ declare class RoutineHandler {
1262
1265
  find(id: string): CommitmentInterface | undefined;
1263
1266
  /**
1264
1267
  * Remove the commitments added during the game session.
1265
- * @param commitment The commitment or commitments to remove.
1268
+ * @param commitment The commitment or commitment id to remove.
1269
+ * @param roomId The id of the room where the commitment is.
1266
1270
  */
1267
- remove(commitment: CommitmentInterface[] | CommitmentInterface): void;
1271
+ remove(commitment: CommitmentInterface | string, roomId?: string): void;
1268
1272
  /**
1269
1273
  * Clear all the expired commitments.
1270
1274
  */
1271
1275
  clearExpiredRoutine(): void;
1276
+ get characterCommitments(): {
1277
+ [character: string]: [CommitmentInterface, string];
1278
+ };
1272
1279
  /**
1273
1280
  * Get the current commitments. The hidden commitments are not included.
1274
1281
  * In case there is a character who has two or more commitments at the same time, will be selected the commitment with the highest priority.
@@ -1279,6 +1286,9 @@ declare class RoutineHandler {
1279
1286
  * @returns The current commitments.
1280
1287
  */
1281
1288
  get currentRoutine(): CommitmentInterface[];
1289
+ get roomCommitments(): {
1290
+ [roomId: string]: CommitmentInterface[];
1291
+ };
1282
1292
  /**
1283
1293
  * Get the character commitment.
1284
1294
  * @param character The character.
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import {timeTracker,navigator,routine}from'@drincs/nqtr/handlers';export*from'@drincs/nqtr/handlers';import*as qe from'@drincs/nqtr/registries';import {RegisteredRooms,RegisteredLocations,RegisteredMaps,RegisteredQuests,fixedCommitments,RegisteredCommitments,registeredCommitments,RegisteredActivities}from'@drincs/nqtr/registries';export{RegisteredActivities,RegisteredCommitments,RegisteredLocations,RegisteredMaps,RegisteredQuests,RegisteredRooms}from'@drincs/nqtr/registries';import {StoredClassModel,storage}from'@drincs/pixi-vn/storage';import {narration}from'@drincs/pixi-vn/narration';var U=Object.defineProperty;var oe=(s,r,e)=>r in s?U(s,r,{enumerable:true,configurable:true,writable:true,value:e}):s[r]=e;var W=(s,r)=>{for(var e in r)U(s,e,{get:r[e],enumerable:true});};var n=(s,r,e)=>oe(s,typeof r!="symbol"?r+"":r,e);var F={};W(F,{ActivityBaseModel:()=>T,ActivityStoredClass:()=>f,CommitmentBaseModel:()=>E,CommitmentStoredClass:()=>h,LocationBaseModel:()=>P,LocationStoredClass:()=>S,MapBaseModel:()=>D,MapStoredClass:()=>y,QuestBaseModel:()=>w,QuestStoredClass:()=>I,RoomBaseModel:()=>C,RoomStoredClass:()=>v,StageBaseModel:()=>q,StageStoredClass:()=>_});var ce="__nqtr-activity__",f=class extends StoredClassModel{constructor(e,t,i,a=ce){super(a,e);this._onRun=t;n(this,"_timeSlot");n(this,"_dateScheduling");this._timeSlot=i.timeSlot,this._dateScheduling=i.dateScheduling;}get timeSlot(){return this._timeSlot}get dateScheduling(){return this._dateScheduling}addTempHistoryItem(){narration.addCurrentStepToHistory();}get run(){return async e=>(this.addTempHistoryItem(),await this._onRun(this,e))}get expired(){return !!(this.dateScheduling?.to&&this.dateScheduling.to<=timeTracker.currentDate)}isActive(e={}){let{timeSlot:t=this.timeSlot,dateScheduling:i=this.dateScheduling}=e;if(i?.from!=null&&i.from>timeTracker.currentDate||i?.to!=null&&i.to<timeTracker.currentDate)return false;t&&!Array.isArray(t)&&(t=[t]);for(let a of t||[])if(!timeTracker.nowIsBetween(a?.from,a?.to))return false;return true}};var T=class extends f{constructor(e,t,i){super(e,t,{dateScheduling:i.dateScheduling,timeSlot:i.timeSlot});n(this,"defaultName");n(this,"defaultDisabled");n(this,"defaultHidden");n(this,"_icon");this.defaultName=i.name||"",this.defaultDisabled=i.disabled||false,this.defaultHidden=i.hidden||false,this._icon=i.renderIcon;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}get icon(){return this._icon}};var l="___nqtr-time_manager_data___",p="___nqtr-current_room_memory___",z="___nqtr-last_event_memory___";function b(s){storage.set(z,s);}function J(){return storage.get(z)}var me="__nqtr-commitment__",h=class extends f{constructor(e,t,i,a,o){a=a||(()=>{});super(e,a,o,me);this._characters=t;this._room=i;n(this,"defaultExecutionType");n(this,"defaultPriority");this.defaultExecutionType=o.executionType||"interaction",this.defaultPriority=o.priority;}get characters(){return this._characters}get room(){return this._room}get executionType(){return this.getStorageProperty("executionType")||this.defaultExecutionType}set executionType(e){this.setStorageProperty("executionType",e);}get priority(){return this.getStorageProperty("priority")||this.defaultPriority||0}set priority(e){this.setStorageProperty("priority",e);}addTempHistoryItem(){let e=navigator.currentRoom;if(!e||this.executionType!=="automatic")return super.addTempHistoryItem();let t=J();switch(t?.type){case "editroom":storage.set(p,t.prev),super.addTempHistoryItem(),storage.set(p,e.id);break;case "edittime":let i=storage.get(l)||{};storage.set(l,t.prev),super.addTempHistoryItem(),storage.set(l,i);break}}};var E=class extends h{constructor(e,t,i,a){super(e,t?Array.isArray(t)?t:[t]:[],i,a.onRun,{executionType:a.executionType,priority:a.priority,timeSlot:a.timeSlot,dateScheduling:a.dateScheduling});n(this,"_name");n(this,"_image");n(this,"_icon");n(this,"defaultDisabled");n(this,"defaultHidden");this._name=a.name||"",this._image=a.image,this.defaultDisabled=a.disabled||false,this.defaultHidden=a.hidden||false,this._icon=a.icon;}get name(){return this._name}get image(){return this._image}get icon(){return this._icon}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}};var g=class extends StoredClassModel{constructor(e,t,i=[]){super(e,t);this.defaultActivities=i;}get defaultActivitiesIds(){return this.defaultActivities.map(e=>e.id)}get activeActivityScheduling(){return this.getStorageProperty("activeActivityScheduling")||{}}get excludedActivitiesScheduling(){return this.getStorageProperty("excludedActivitiesScheduling")||{}}removeActivityScheduling(e){let t=this.activeActivityScheduling;delete t[e],this.setStorageProperty("activeActivityScheduling",t);let i=this.excludedActivitiesScheduling;delete i[e],this.setStorageProperty("excludedActivitiesScheduling",i);}editActivityScheduling(e,t){this.removeActivityScheduling(e);let i=this.activeActivityScheduling;i[e]=t,this.setStorageProperty("activeActivityScheduling",i);}editExcludedActivityScheduling(e,t){this.removeActivityScheduling(e);let i=this.excludedActivitiesScheduling;i[e]=t,this.setStorageProperty("excludedActivitiesScheduling",i);}get additionalActivitiesIds(){return this.getStorageProperty("additionalActivitiesIds")||[]}get excludedActivitiesIds(){return this.getStorageProperty("excludedActivitiesIds")||[]}get activitiesIds(){return this.additionalActivitiesIds.concat(this.defaultActivitiesIds)}addActivity(e,t={}){let{timeSlot:i,dateScheduling:a}=t;if(i&&!Array.isArray(i)&&(i=[i]),i?.forEach(c=>{let{to:R=timeTracker.dayEndTime+1}=c||{};if(c&&c.from>=R)throw new Error("[NQTR] The from time must be less than the to time.")}),a?.from!==void 0&&a?.to!==void 0&&a?.from>=a?.to)throw new Error("[NQTR] The from day/date must be less than the to day/date.");if(this.defaultActivitiesIds.includes(e.id)){console.warn(`[NQTR] Activity with id ${e.id} already exists, so it will be ignored.`);return}let o=this.additionalActivitiesIds;o.includes(e.id)?console.warn(`[NQTR] Activity with id ${e.id} already exists, so it will be ignored.`):(o.push(e.id),this.setStorageProperty("additionalActivitiesIds",o)),this.excludedActivitiesIds.includes(e.id)&&(this.removeActivityScheduling(e.id),console.log(`[NQTR] Activity with id ${e.id} was excluded, so it will be associated with this class again.`)),(i||a)&&this.editActivityScheduling(e.id,{timeSlot:i,dateScheduling:a});}removeActivity(e){let t=typeof e=="string"?e:e.id,i=this.additionalActivitiesIds;if(i.includes(t))i=i.filter(a=>a!==t),this.setStorageProperty("additionalActivitiesIds",i),this.removeActivityScheduling(t);else if(this.defaultActivitiesIds.includes(t)){let a=this.excludedActivitiesIds;a.push(t),this.setStorageProperty("excludedActivitiesIds",a);}else console.warn(`[NQTR] Activity with id ${t} not found, so it will be ignored.`);}clearExpiredActivities(){let e=this.activeActivityScheduling,t=this.excludedActivitiesScheduling,i=this.additionalActivitiesIds,a=this.excludedActivitiesIds;i.forEach(o=>{if(o in e){let{to:c}=e[o].dateScheduling||{};c&&c<timeTracker.currentDate&&(this.removeActivityScheduling(o),i=i.filter(R=>R!==o));}}),a.forEach(o=>{o in t&&t[o]&&(this.removeActivityScheduling(o),a=a.filter(c=>c!==o));});}get activities(){return [...new Set([...this.additionalActivitiesIds,...this.defaultActivitiesIds])].reduce((e,t)=>{let i=RegisteredActivities.get(t);return i&&i.isActive(this.activeActivityScheduling[t])&&!this.excludedActivitiesScheduling[t]&&e.push(i),e},[])}};var he="__nqtr-location__",S=class extends g{constructor(e,t,i=[]){super(he,e,i);this._map=t;}get map(){return this._map}get rooms(){return navigator.rooms.filter(e=>e.location.id===this.id)}};var P=class extends S{constructor(e,t,i={}){super(e,t,i.activities||[]);n(this,"defaultName");n(this,"defaultDisabled");n(this,"defaultHidden");n(this,"_icon");this.defaultName=i.name||"",this.defaultDisabled=i.disabled||false,this.defaultHidden=i.hidden||false,this._icon=i.icon;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}get icon(){return this._icon}};var ye="__nqtr-map__",y=class extends g{constructor(r,e=[]){super(ye,r,e);}get locations(){return navigator.locations.filter(r=>r.map.id===this.id)}};var D=class extends y{constructor(e,t={}){super(e,t.activities||[]);n(this,"defaultName");n(this,"_image");this.defaultName=t.name||"",this._image=t.image;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get image(){return this._image}};var Ie="__nqtr-room__",v=class extends g{constructor(e,t,i=[]){super(Ie,e,i);this._location=t;}get routine(){return routine.currentRoutine.filter(e=>e.room.id===this.id)}get location(){return this._location}get characters(){let e=[];return this.routine.forEach(t=>{e.push(...t.characters);}),e}get automaticFunctions(){return this.routine.filter(e=>e.executionType==="automatic"&&e.run).map(e=>async i=>{await e.run(i);})}};var C=class extends v{constructor(e,t,i={}){super(e,t,i.activities||[]);n(this,"defaultName");n(this,"_image");n(this,"defaultDisabled");n(this,"defaultHidden");n(this,"_icon");this.defaultName=i.name||"",this._image=i.image,this.defaultDisabled=i.disabled||false,this.defaultHidden=i.hidden||false,this._icon=i.icon;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get image(){return this._image}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}get icon(){return this._icon}};var u;(i=>(i.log=(a,...o)=>console.log(`[NQTR] ${a}`,...o),i.warn=(a,...o)=>console.warn(`[NQTR] ${a}`,...o),i.error=(a,...o)=>console.error(`[NQTR] ${a}`,...o),i.info=(a,...o)=>console.info(`[NQTR] ${a}`,...o)))(u||(u={}));var xe="__nqtr-quest__",I=class extends StoredClassModel{constructor(e,t,i={}){super(xe,e);this._stages=t;n(this,"_onStart");n(this,"_onNextStage");this._onStart=i.onStart,this._onNextStage=i.onNextStage;}get stages(){return this._stages}get currentStageIndex(){return this.getStorageProperty("currentStageIndex")}set currentStageIndex(e){this.setStorageProperty("currentStageIndex",e);}get currentStage(){let e=this.currentStageIndex;if(!(e===void 0||e>=this.stages.length))return this.stages[e]}get started(){return this.currentStageIndex!==void 0}get completed(){return this.currentStageIndex===void 0?false:this.currentStageIndex>this.stages.length-1}get inProgress(){return this.completed||this.failed?false:this.started}get failed(){return this.getStorageProperty("failed")||false}set failed(e){this.setStorageProperty("failed",e);}get onStart(){return this._onStart}get onNextStage(){return this._onNextStage}async start(e){if(this.started){console.warn(`[NQTR] Quest ${this.id} is already started`);return}if(this.stages.length===0){u.error(`Quest ${this.id} has no stages`);return}this.currentStageIndex=0;let t=this.currentStage;if(t&&t.start)return this.onStart&&await this.onStart(this,e),await t.start(e);u.error(`Quest ${this.id} has no start stage`);}async goNextIfCompleted(e){return await this.advanceIfCompleted(e)}async advanceIfCompleted(e){if(!this.inProgress)return false;let t=this.currentStage;return t?t.completed?await this.advanceUnconditionally(e):false:(u.error(`Quest ${this.id} has no current stage`),false)}async goNext(e){return await this.continue(e)}async continue(e){let t=this.currentStage;return t?(t.completed=true,await this.advanceUnconditionally(e)):(u.error(`Quest ${this.id} has no current stage`),false)}async forceGoNext(e){return await this.advanceUnconditionally(e)}async advanceUnconditionally(e){if(!this.inProgress)return console.warn(`[NQTR] Quest ${this.id} is not in progress`),false;let t=this.currentStage,i=this.currentStageIndex;if(!t||i===void 0)return u.error(`Quest ${this.id} has no current stage`),false;this.currentStageIndex=i+1,this.onNextStage&&await this.onNextStage(this,e),t&&t.onEnd&&await t.onEnd(t,e);let a=this.currentStage;return a&&(a.inizialize(),this.currentStageMustStart&&await this.startCurrentStage(e)),true}get currentStageMustStart(){let e=this.currentStage;return e?!e.started&&e.canStart&&!e.completed:false}async startCurrentStage(e){let t=this.currentStage;t&&this.currentStageMustStart?await t.start(e):console.warn(`[NQTR] Quest ${this.id} can't start the current stage`);}};var w=class extends I{constructor(e,t,i){super(e,t,{onStart:i.onStart,onNextStage:i.onNextStage});n(this,"_name");n(this,"_description");n(this,"_icon");n(this,"_image");n(this,"_inDevelopment");this._name=i.name||"",this._description=i.description||"",this._icon=i.icon,this._image=i.image,this._inDevelopment=i.inDevelopment||false;}get name(){return this._name}get description(){return this._description}get icon(){return this._icon}get image(){return this._image}get inDevelopment(){return this._inDevelopment}};var Te="__nqtr-stage__",_=class extends StoredClassModel{constructor(e,t={}){super(Te,e);n(this,"_onStart");n(this,"_onEnd");n(this,"_deltaDateRequired");n(this,"_questsRequired");this._onStart=t.onStart,this._onEnd=t.onEnd,this._deltaDateRequired=t.deltaDateRequired,this._questsRequired=t.questsRequired||[];}get onStart(){return this._onStart}get onEnd(){return this._onEnd}get completed(){return this.getStorageProperty("completed")||false}set completed(e){this.setStorageProperty("completed",e);}get started(){return this.getStorageProperty("started")||false}set started(e){this.setStorageProperty("started",e);}get inizializeDate(){return this.getStorageProperty("inizializeDate")}set inizializeDate(e){this.setStorageProperty("inizializeDate",e);}get startDate(){let e=this.inizializeDate;if(e!==void 0)return e+this.deltaDateRequired}get canStart(){let e=this.deltaDateRequired;if(e>0){let t=this.inizializeDate;if(t===void 0||t+e>timeTracker.currentDate)return false}return !(this.questsRequired.length>0&&!this.questsRequired.every(t=>t.quest.currentStageIndex&&t.quest.currentStageIndex>=t.stageNumber))}inizialize(){this.deltaDateRequired>0&&(this.inizializeDate=timeTracker.currentDate,console.log(`[NQTR] Stage ${this.id} will start on date ${this.startDate}`));}async start(e){this.canStart?(this.started=true,this.onStart&&await this.onStart(this,e)):console.warn(`[NQTR] Stage ${this.id} can't start`);}get deltaDateRequired(){return this._deltaDateRequired||0}get questsRequired(){return this._questsRequired||[]}};var q=class extends _{constructor(e,t){super(e,{onStart:t.onStart,onEnd:t.onEnd,deltaDateRequired:t.deltaDateRequired,questsRequired:t.questsRequired});n(this,"_name");n(this,"_description");n(this,"_adviceDescription");n(this,"_image");n(this,"_flags");n(this,"_flagsRequired");n(this,"_requestDescriptionToStart");this._name=t.name||"",this._flags=t.flags||[],this._description=t.description||"",this._adviceDescription=t.adviceDescription||"",this._image=t.image,this._flagsRequired=t.flagsRequired||[],this._requestDescriptionToStart=t.requestDescriptionToStart||"";}get name(){return this._name}get description(){return this._description}get adviceDescription(){return this._adviceDescription}get image(){return this._image}get flags(){return this._flags}get flagsRequired(){return this._flagsRequired}get requestDescriptionToStart(){return this._requestDescriptionToStart}get completed(){return super.completed?true:this.flags.length>0?!!this.flags.every(e=>storage.getFlag(e.flag)):false}set completed(e){super.completed=e;}get canStart(){return this.flagsRequired.length>0&&!this.flagsRequired.every(e=>storage.getFlag(e.flag))?false:super.canStart}};var ne={};var ae={};var K={};W(K,{navigator:()=>De,questsNotebook:()=>we,routine:()=>Ce,timeTracker:()=>Pe});var O=class{get rooms(){return RegisteredRooms.values()}get locations(){return RegisteredLocations.values()}get maps(){return RegisteredMaps.values()}get currentRoomId(){return storage.get(p)}get currentRoom(){let r=this.currentRoomId;if(!r){u.error("The current room has not yet been set");return}let e=RegisteredRooms.get(r);if(!e){u.error(`Current room ${r} not found`);return}return e}set currentRoom(r){if(typeof r!="string"&&(r=r.id),!RegisteredRooms.get(r)){u.error(`The room ${r} is not registered, so it can't be set as current room`);return}let t=storage.get(p);t!==r&&(b({type:"editroom",prev:t,value:r}),storage.set(p,r));}get currentLocation(){return this.currentRoom?.location}get currentMap(){return this.currentRoom?.location.map}clearExpiredActivities(){RegisteredRooms.values().forEach(r=>{r.clearExpiredActivities();});}};var N=class{get quests(){return RegisteredQuests.values()}get startedQuests(){return this.quests.filter(r=>r.started)}get inProgressQuests(){return this.quests.filter(r=>r.inProgress)}get completedQuests(){return this.quests.filter(r=>r.completed)}get failedQuests(){return this.quests.filter(r=>r.failed)}get notStartedQuests(){return this.quests.filter(r=>!r.started)}find(r){return RegisteredQuests.get(r)}async startsStageMustBeStarted(r){let e=this.quests.map(t=>t.currentStageMustStart?t.startCurrentStage(r):Promise.resolve());await Promise.all(e);}};var $="___nqtr-temporary_commitment___",M=class{get fixedRoutine(){return [...fixedCommitments.values()]}set fixedRoutine(r){r.forEach(e=>{fixedCommitments.has(e.id)&&console.warn(`[NQTR] Commitment id ${e.id} already exists, it will be overwritten`),fixedCommitments.set(e.id,e);});}get temporaryRoutine(){let r=storage.get($);return r?r.map(t=>RegisteredCommitments.get(t)).filter(t=>t!==void 0):[]}get allRoutine(){return [...this.fixedRoutine,...this.temporaryRoutine]}add(r){Array.isArray(r)||(r=[r]);let e=r.map(t=>{if(!RegisteredCommitments.get(t.id)){console.warn(`[NQTR] Commitment ${t.id} not found, it will be ignored`);return}return t.id}).filter(t=>t!==void 0);storage.set($,e);}find(r){return RegisteredCommitments.get(r)}remove(r){Array.isArray(r)||(r=[r]);let e=r.map(i=>i.id),t=storage.get($);t&&(t=t.filter(i=>!e.includes(i)),storage.set($,t));}clearExpiredRoutine(){RegisteredCommitments.values().forEach(r=>{r.expired&&registeredCommitments.delete(r.id);});}get currentRoutine(){let r={};return [...this.fixedRoutine,...this.temporaryRoutine].forEach(e=>{e.isActive()&&(e.characters.length>0?e.characters.every(i=>!r[i.id]||e.priority>r[i.id].priority)&&e.characters.forEach(i=>{r[i.id]=e;}):u.error(`The commitment ${e.id} has no characters assigned`));}),Object.values(r)}getCommitmentByCharacter(r){this.currentRoutine.forEach(e=>{if(e.characters.map(t=>t.id).includes(r.id))return e});}};var m=class m{};n(m,"dayStartTime",0),n(m,"dayEndTime",24),n(m,"defaultTimeSpent",1),n(m,"timeSlots",[]),n(m,"weekLength",7),n(m,"weekendStartDay",m.weekLength-1),n(m,"getDayName");var d=m;var Q=class{initialize(r){let{dayStartTime:e=0,dayEndTime:t=24,defaultTimeSpent:i=1,timeSlots:a=[],weekLength:o=7,weekendStartDay:c=o-1,getDayName:R}=r;d.dayStartTime=e,d.dayEndTime=t,d.defaultTimeSpent=i,d.timeSlots=a,d.weekLength=o,c>=d.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${o}, so will be ignored`):d.weekendStartDay=c,d.getDayName=R;}get dayStartTime(){return d.dayStartTime}get dayEndTime(){return d.dayEndTime}get defaultTimeSpent(){return d.defaultTimeSpent}get timeSlots(){return d.timeSlots}get weekLength(){return d.weekLength}get weekendStartDay(){return d.weekendStartDay}get getDayName(){return d.getDayName}get currentTime(){let r=storage.get(l)||{};return r.hasOwnProperty("currentTime")&&typeof r.currentTime=="number"?r.currentTime:this.dayStartTime}set currentTime(r){let e=storage.get(l)||{},t={...e};typeof r=="number"?t.currentTime=r:delete t.currentTime,b({type:"edittime",prev:e,value:t}),storage.set(l,t);}get currentDate(){let r=storage.get(l)||{};return r.hasOwnProperty("currentDate")&&typeof r.currentDate=="number"?r.currentDate:0}set currentDate(r){let e=storage.get(l)||{},t={...e};typeof r=="number"?t.currentDate=r:delete t.currentDate,b({type:"edittime",prev:e,value:t}),storage.set(l,t);}get isWeekend(){return this.currentWeekDayNumber>=this.weekendStartDay}get currentWeekDayNumber(){return this.currentDate%this.weekLength+1}get currentDayName(){return this.getDayName?this.getDayName(this.currentWeekDayNumber-1):(console.warn("[NQTR] Week days names are not defined, so currentDayName will be empty"),"")}get currentTimeSlot(){if(this.timeSlots.length===0)return console.warn("[NQTR] Time slots are not defined"),0;for(let r=0;r<this.timeSlots.length;r++){let e=this.timeSlots[r];if(this.timeSlots.length>r+1&&this.nowIsBetween(e.startTime,this.timeSlots[r+1].startTime))return r}return this.timeSlots.length-1}increaseTime(r=this.defaultTimeSpent){let e=this.currentTime+r;return e>=this.dayEndTime&&(this.increaseDate(),e=this.dayStartTime+(e-this.dayEndTime)),this.currentTime=e,this.currentTime}increaseDate(r=1,e=this.dayStartTime){let t=this.currentDate+r;return this.currentDate=t,this.currentTime=e,this.currentDate}nowIsBetween(r,e){r===void 0&&(r=this.dayStartTime-1),e===void 0&&(e=this.dayEndTime+1);let t=this.currentTime;return r<e?t>=r&&t<e:t>=r||t<e}};var Pe=new Q,De=new O,Ce=new M,we=new N;var Oe={...F,...ne,...ae,handlers:K,registries:qe},qr=Oe;export{T as ActivityBaseModel,f as ActivityStoredClass,E as CommitmentBaseModel,h as CommitmentStoredClass,P as LocationBaseModel,S as LocationStoredClass,D as MapBaseModel,y as MapStoredClass,w as QuestBaseModel,I as QuestStoredClass,C as RoomBaseModel,v as RoomStoredClass,q as StageBaseModel,_ as StageStoredClass,qr as default};
1
+ import {timeTracker,navigator,routine}from'@drincs/nqtr/handlers';export*from'@drincs/nqtr/handlers';import*as Qe from'@drincs/nqtr/registries';import {fixedCommitments,RegisteredRooms,RegisteredLocations,RegisteredMaps,RegisteredQuests,RegisteredCommitments,RegisteredActivities}from'@drincs/nqtr/registries';export{RegisteredActivities,RegisteredCommitments,RegisteredLocations,RegisteredMaps,RegisteredQuests,RegisteredRooms}from'@drincs/nqtr/registries';import {StoredClassModel,storage}from'@drincs/pixi-vn/storage';import {narration}from'@drincs/pixi-vn/narration';import {PixiError}from'@drincs/pixi-vn/core';var U=Object.defineProperty;var me=(o,r,e)=>r in o?U(o,r,{enumerable:true,configurable:true,writable:true,value:e}):o[r]=e;var W=(o,r)=>{for(var e in r)U(o,e,{get:r[e],enumerable:true});};var n=(o,r,e)=>me(o,typeof r!="symbol"?r+"":r,e);var F={};W(F,{ActivityBaseModel:()=>b,ActivityStoredClass:()=>g,CommitmentBaseModel:()=>P,CommitmentStoredClass:()=>y,LocationBaseModel:()=>E,LocationStoredClass:()=>S,MapBaseModel:()=>C,MapStoredClass:()=>v,QuestBaseModel:()=>w,QuestStoredClass:()=>_,RoomBaseModel:()=>D,RoomStoredClass:()=>I,StageBaseModel:()=>O,StageStoredClass:()=>x});var ge="__nqtr-activity__",g=class extends StoredClassModel{constructor(e,t,i,a=ge){super(a,e);this._onRun=t;n(this,"_timeSlot");n(this,"_dateScheduling");this._timeSlot=i.timeSlot,this._dateScheduling=i.dateScheduling;}_onRun;get timeSlot(){return this._timeSlot}get dateScheduling(){return this._dateScheduling}addTempHistoryItem(){narration.addCurrentStepToHistory();}get run(){return async e=>(this.addTempHistoryItem(),await this._onRun(this,e))}get expired(){return !!(this.dateScheduling?.to&&this.dateScheduling.to<=timeTracker.currentDate)}isActive(e={}){let{timeSlot:t=this.timeSlot,dateScheduling:i=this.dateScheduling}=e;if(i?.from!=null&&i.from>timeTracker.currentDate||i?.to!=null&&i.to<timeTracker.currentDate)return false;t&&!Array.isArray(t)&&(t=[t]);for(let a of t||[])if(!timeTracker.nowIsBetween(a?.from,a?.to))return false;return true}};var b=class extends g{constructor(e,t,i){super(e,t,{dateScheduling:i.dateScheduling,timeSlot:i.timeSlot});n(this,"defaultName");n(this,"defaultDisabled");n(this,"defaultHidden");n(this,"_icon");this.defaultName=i.name||"",this.defaultDisabled=i.disabled||false,this.defaultHidden=i.hidden||false,this._icon=i.renderIcon;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}get icon(){return this._icon}};var m="___nqtr-time_manager_data___",p="___nqtr-current_room_memory___",Y="___nqtr-last_event_memory___";function R(o){storage.set(Y,o);}function J(){return storage.get(Y)}var pe="__nqtr-commitment__",y=class extends g{constructor(e,t,i,a){i=i||(()=>{});super(e,i,a,pe);this._characters=t;n(this,"defaultExecutionType");n(this,"defaultPriority");this.defaultExecutionType=a.executionType||"interaction",this.defaultPriority=a.priority;}_characters;get characters(){return this._characters}get executionType(){return this.getStorageProperty("executionType")||this.defaultExecutionType}set executionType(e){this.setStorageProperty("executionType",e);}get priority(){return this.getStorageProperty("priority")||this.defaultPriority||0}set priority(e){this.setStorageProperty("priority",e);}addTempHistoryItem(){let e=navigator.currentRoom;if(!e||this.executionType!=="automatic")return super.addTempHistoryItem();let t=J();switch(t?.type){case "editroom":storage.set(p,t.prev),super.addTempHistoryItem(),storage.set(p,e.id);break;case "edittime":let i=storage.get(m)||{};storage.set(m,t.prev),super.addTempHistoryItem(),storage.set(m,i);break}}};var P=class extends y{constructor(e,t,i){super(e,t?Array.isArray(t)?t:[t]:[],i.onRun,{executionType:i.executionType,priority:i.priority,timeSlot:i.timeSlot,dateScheduling:i.dateScheduling});n(this,"_name");n(this,"_image");n(this,"_icon");n(this,"defaultDisabled");n(this,"defaultHidden");this._name=i.name||"",this._image=i.image,this.defaultDisabled=i.disabled||false,this.defaultHidden=i.hidden||false,this._icon=i.icon;}get name(){return this._name}get image(){return this._image}get icon(){return this._icon}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}};var d;(i=>(i.log=(a,...s)=>console.log(`[NQTR] ${a}`,...s),i.warn=(a,...s)=>console.warn(`[NQTR] ${a}`,...s),i.error=(a,...s)=>console.error(`[NQTR] ${a}`,...s),i.info=(a,...s)=>console.info(`[NQTR] ${a}`,...s)))(d||(d={}));var h=class extends StoredClassModel{constructor(e,t,i=[]){super(e,t);this.defaultActivities=i;}defaultActivities;get defaultActivitiesIds(){return this.defaultActivities.map(e=>e.id)}get activeActivityScheduling(){return this.getStorageProperty("activeActivityScheduling")||{}}get excludedActivitiesScheduling(){return this.getStorageProperty("excludedActivitiesScheduling")||{}}removeActivityScheduling(e){let t=this.activeActivityScheduling;delete t[e],this.setStorageProperty("activeActivityScheduling",t);let i=this.excludedActivitiesScheduling;delete i[e],this.setStorageProperty("excludedActivitiesScheduling",i);}editActivityScheduling(e,t){this.removeActivityScheduling(e);let i=this.activeActivityScheduling;i[e]=t,this.setStorageProperty("activeActivityScheduling",i);}editExcludedActivityScheduling(e,t){this.removeActivityScheduling(e);let i=this.excludedActivitiesScheduling;i[e]=t,this.setStorageProperty("excludedActivitiesScheduling",i);}get additionalActivitiesIds(){return this.getStorageProperty("additionalActivitiesIds")||[]}get excludedActivitiesIds(){return this.getStorageProperty("excludedActivitiesIds")||[]}get activitiesIds(){return this.additionalActivitiesIds.concat(this.defaultActivitiesIds)}addActivity(e,t={}){let{timeSlot:i,dateScheduling:a}=t;if(i&&!Array.isArray(i)&&(i=[i]),i?.forEach(c=>{let{to:l=timeTracker.dayEndTime+1}=c||{};if(c&&c.from>=l)throw d.error("The from time must be less than the to time."),new PixiError("invalid_usage","The from time must be less than the to time.")}),a?.from!==void 0&&a?.to!==void 0&&a?.from>=a?.to)throw d.error("The from day/date must be less than the to day/date."),new PixiError("invalid_usage","The from day/date must be less than the to day/date.");let s=this.additionalActivitiesIds;this.defaultActivitiesIds.includes(e.id)||s.includes(e.id)?d.info(`Activity with id ${e.id} already exists in the ${this.id}, so it will be updated with the new scheduling options if they are provided.`):(s.push(e.id),this.setStorageProperty("additionalActivitiesIds",s)),this.excludedActivitiesIds.includes(e.id)&&(this.removeActivityScheduling(e.id),d.log(`Activity with id ${e.id} was excluded from the ${this.id}, but now it will be added again with the new scheduling options. So it will be removed from the excluded activities list.`)),(i||a)&&this.editActivityScheduling(e.id,{timeSlot:i,dateScheduling:a});}removeActivity(e){let t=typeof e=="string"?e:e.id,i=this.additionalActivitiesIds;if(i.includes(t))i=i.filter(a=>a!==t),this.setStorageProperty("additionalActivitiesIds",i);else if(this.defaultActivitiesIds.includes(t)){let a=this.excludedActivitiesIds;a.push(t),this.setStorageProperty("excludedActivitiesIds",a);}else d.warn(`Activity with id ${t} not found, so it will be ignored.`);}clearExpiredActivities(){let e=this.activeActivityScheduling,t=this.excludedActivitiesScheduling,i=this.additionalActivitiesIds,a=this.excludedActivitiesIds;i.forEach(s=>{if(s in e){let{to:c}=e[s].dateScheduling||{};c&&c<timeTracker.currentDate&&(this.removeActivityScheduling(s),i=i.filter(l=>l!==s));}}),a.forEach(s=>{s in t&&t[s]&&(this.removeActivityScheduling(s),a=a.filter(c=>c!==s));});}get activities(){return [...new Set([...this.additionalActivitiesIds,...this.defaultActivitiesIds])].reduce((e,t)=>{let i=RegisteredActivities.get(t);return i&&i.isActive(this.activeActivityScheduling[t])&&!this.excludedActivitiesScheduling[t]&&e.push(i),e},[])}};var Ie="__nqtr-location__",S=class extends h{constructor(e,t,i=[]){super(Ie,e,i);this._map=t;}_map;get map(){return this._map}get rooms(){return navigator.rooms.filter(e=>e.location.id===this.id)}};var E=class extends S{constructor(e,t,i={}){super(e,t,i.activities||[]);n(this,"defaultName");n(this,"defaultDisabled");n(this,"defaultHidden");n(this,"_icon");this.defaultName=i.name||"",this.defaultDisabled=i.disabled||false,this.defaultHidden=i.hidden||false,this._icon=i.icon;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}get icon(){return this._icon}};var xe="__nqtr-map__",v=class extends h{constructor(r,e=[]){super(xe,r,e);}get locations(){return navigator.locations.filter(r=>r.map.id===this.id)}};var C=class extends v{constructor(e,t={}){super(e,t.activities||[]);n(this,"defaultName");n(this,"_image");this.defaultName=t.name||"",this._image=t.image;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get image(){return this._image}};var ie="__nqtr-room__",I=class extends h{constructor(e,t,i=[]){var r=(...Nt)=>(super(...Nt),this._location=t,this);Array.isArray(i)?r(ie,e,i):(r(ie,e,i.activities),i.routine.forEach(a=>fixedCommitments.set(a.id,[a,e])));}_location;get routine(){return routine.roomCommitments[this.id]||[]}addCommitment(e,t={}){let{timeSlot:i,dateScheduling:a}=t;if(i&&!Array.isArray(i)&&(i=[i]),i?.forEach(s=>{let{to:c=timeTracker.dayEndTime+1}=s||{};if(s&&s.from>=c)throw d.error("The from time must be less than the to time."),new PixiError("invalid_usage","The from time must be less than the to time.")}),a?.from!==void 0&&a?.to!==void 0&&a?.from>=a?.to)throw d.error("The from day/date must be less than the to day/date."),new PixiError("invalid_usage","The from day/date must be less than the to day/date.");routine.add(e,this.id,{timeSlot:i,dateScheduling:a});}removeCommitment(e){routine.remove(e,this.id);}get location(){return this._location}get characters(){return this.routine.reduce((e,t)=>(e.push(...t.characters),e),[])}get automaticFunctions(){return this.routine.reduce((e,t)=>{if(t.executionType==="automatic"&&t.run){let i=async a=>{await t.run(a);};e.push(i);}return e},[])}};var D=class extends I{constructor(e,t,i={}){super(e,t,{activities:i.activities||[],routine:i.routine||[]});n(this,"defaultName");n(this,"_image");n(this,"defaultDisabled");n(this,"defaultHidden");n(this,"_icon");this.defaultName=i.name||"",this._image=i.image,this.defaultDisabled=i.disabled||false,this.defaultHidden=i.hidden||false,this._icon=i.icon;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get image(){return this._image}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}get icon(){return this._icon}};var Ae="__nqtr-quest__",_=class extends StoredClassModel{constructor(e,t,i={}){super(Ae,e);this._stages=t;n(this,"_onStart");n(this,"_onNextStage");this._onStart=i.onStart,this._onNextStage=i.onNextStage;}_stages;get stages(){return this._stages}get currentStageIndex(){return this.getStorageProperty("currentStageIndex")}set currentStageIndex(e){this.setStorageProperty("currentStageIndex",e);}get currentStage(){let e=this.currentStageIndex;if(!(e===void 0||e>=this.stages.length))return this.stages[e]}get started(){return this.currentStageIndex!==void 0}get completed(){return this.currentStageIndex===void 0?false:this.currentStageIndex>this.stages.length-1}get inProgress(){return this.completed||this.failed?false:this.started}get failed(){return this.getStorageProperty("failed")||false}set failed(e){this.setStorageProperty("failed",e);}get onStart(){return this._onStart}get onNextStage(){return this._onNextStage}async start(e){if(this.started){console.warn(`[NQTR] Quest ${this.id} is already started`);return}if(this.stages.length===0){d.error(`Quest ${this.id} has no stages`);return}this.currentStageIndex=0;let t=this.currentStage;if(t&&t.start)return this.onStart&&await this.onStart(this,e),await t.start(e);d.error(`Quest ${this.id} has no start stage`);}async goNextIfCompleted(e){return await this.advanceIfCompleted(e)}async advanceIfCompleted(e){if(!this.inProgress)return false;let t=this.currentStage;return t?t.completed?await this.advanceUnconditionally(e):false:(d.error(`Quest ${this.id} has no current stage`),false)}async goNext(e){return await this.continue(e)}async continue(e){let t=this.currentStage;return t?(t.completed=true,await this.advanceUnconditionally(e)):(d.error(`Quest ${this.id} has no current stage`),false)}async forceGoNext(e){return await this.advanceUnconditionally(e)}async advanceUnconditionally(e){if(!this.inProgress)return console.warn(`[NQTR] Quest ${this.id} is not in progress`),false;let t=this.currentStage,i=this.currentStageIndex;if(!t||i===void 0)return d.error(`Quest ${this.id} has no current stage`),false;this.currentStageIndex=i+1,this.onNextStage&&await this.onNextStage(this,e),t&&t.onEnd&&await t.onEnd(t,e);let a=this.currentStage;return a&&(a.inizialize(),this.currentStageMustStart&&await this.startCurrentStage(e)),true}get currentStageMustStart(){let e=this.currentStage;return e?!e.started&&e.canStart&&!e.completed:false}async startCurrentStage(e){let t=this.currentStage;t&&this.currentStageMustStart?await t.start(e):console.warn(`[NQTR] Quest ${this.id} can't start the current stage`);}};var w=class extends _{constructor(e,t,i){super(e,t,{onStart:i.onStart,onNextStage:i.onNextStage});n(this,"_name");n(this,"_description");n(this,"_icon");n(this,"_image");n(this,"_inDevelopment");this._name=i.name||"",this._description=i.description||"",this._icon=i.icon,this._image=i.image,this._inDevelopment=i.inDevelopment||false;}get name(){return this._name}get description(){return this._description}get icon(){return this._icon}get image(){return this._image}get inDevelopment(){return this._inDevelopment}};var Ee="__nqtr-stage__",x=class extends StoredClassModel{constructor(e,t={}){super(Ee,e);n(this,"_onStart");n(this,"_onEnd");n(this,"_deltaDateRequired");n(this,"_questsRequired");this._onStart=t.onStart,this._onEnd=t.onEnd,this._deltaDateRequired=t.deltaDateRequired,this._questsRequired=t.questsRequired||[];}get onStart(){return this._onStart}get onEnd(){return this._onEnd}get completed(){return this.getStorageProperty("completed")||false}set completed(e){this.setStorageProperty("completed",e);}get started(){return this.getStorageProperty("started")||false}set started(e){this.setStorageProperty("started",e);}get inizializeDate(){return this.getStorageProperty("inizializeDate")}set inizializeDate(e){this.setStorageProperty("inizializeDate",e);}get startDate(){let e=this.inizializeDate;if(e!==void 0)return e+this.deltaDateRequired}get canStart(){let e=this.deltaDateRequired;if(e>0){let t=this.inizializeDate;if(t===void 0||t+e>timeTracker.currentDate)return false}return !(this.questsRequired.length>0&&!this.questsRequired.every(t=>t.quest.currentStageIndex&&t.quest.currentStageIndex>=t.stageNumber))}inizialize(){this.deltaDateRequired>0&&(this.inizializeDate=timeTracker.currentDate,console.log(`[NQTR] Stage ${this.id} will start on date ${this.startDate}`));}async start(e){this.canStart?(this.started=true,this.onStart&&await this.onStart(this,e)):console.warn(`[NQTR] Stage ${this.id} can't start`);}get deltaDateRequired(){return this._deltaDateRequired||0}get questsRequired(){return this._questsRequired||[]}};var O=class extends x{constructor(e,t){super(e,{onStart:t.onStart,onEnd:t.onEnd,deltaDateRequired:t.deltaDateRequired,questsRequired:t.questsRequired});n(this,"_name");n(this,"_description");n(this,"_adviceDescription");n(this,"_image");n(this,"_flags");n(this,"_flagsRequired");n(this,"_requestDescriptionToStart");this._name=t.name||"",this._flags=t.flags||[],this._description=t.description||"",this._adviceDescription=t.adviceDescription||"",this._image=t.image,this._flagsRequired=t.flagsRequired||[],this._requestDescriptionToStart=t.requestDescriptionToStart||"";}get name(){return this._name}get description(){return this._description}get adviceDescription(){return this._adviceDescription}get image(){return this._image}get flags(){return this._flags}get flagsRequired(){return this._flagsRequired}get requestDescriptionToStart(){return this._requestDescriptionToStart}get completed(){return super.completed?true:this.flags.length>0?!!this.flags.every(e=>storage.getFlag(e.flag)):false}set completed(e){super.completed=e;}get canStart(){return this.flagsRequired.length>0&&!this.flagsRequired.every(e=>storage.getFlag(e.flag))?false:super.canStart}};var oe={};var de={};var K={};W(K,{navigator:()=>qe,questsNotebook:()=>Ne,routine:()=>Me,timeTracker:()=>Oe});var q=class{get rooms(){return RegisteredRooms.values()}get locations(){return RegisteredLocations.values()}get maps(){return RegisteredMaps.values()}get currentRoomId(){return storage.get(p)}get currentRoom(){let r=this.currentRoomId;if(!r){d.error("The current room has not yet been set");return}let e=RegisteredRooms.get(r);if(!e){d.error(`Current room ${r} not found`);return}return e}set currentRoom(r){if(typeof r!="string"&&(r=r.id),!RegisteredRooms.get(r)){d.error(`The room ${r} is not registered, so it can't be set as current room`);return}let t=storage.get(p);t!==r&&(R({type:"editroom",prev:t,value:r}),storage.set(p,r));}get currentLocation(){return this.currentRoom?.location}get currentMap(){return this.currentRoom?.location.map}clearExpiredActivities(){RegisteredRooms.values().forEach(r=>{r.clearExpiredActivities();});}};var M=class{get quests(){return RegisteredQuests.values()}get startedQuests(){return this.quests.filter(r=>r.started)}get inProgressQuests(){return this.quests.filter(r=>r.inProgress)}get completedQuests(){return this.quests.filter(r=>r.completed)}get failedQuests(){return this.quests.filter(r=>r.failed)}get notStartedQuests(){return this.quests.filter(r=>!r.started)}find(r){return RegisteredQuests.get(r)}async startsStageMustBeStarted(r){let e=this.quests.map(t=>t.currentStageMustStart?t.startCurrentStage(r):Promise.resolve());await Promise.all(e);}};var H="___nqtr-temporary_commitment___",Q=class{get temporaryRoutine(){let r=storage.get(H);if(r){if(Array.isArray(r)){if(r.length>0)throw new PixiError("obsolete_save","The save you loaded is not compatible with the current version of NQTR. Please delete the save and start a new game.");return {}}}else return {};return r}get commitmentsIds(){return [...fixedCommitments.keys(),...Object.keys(this.temporaryRoutine)]}add(r,e,t={}){Array.isArray(r)||(r=[r]);let i=this.temporaryRoutine;r.forEach(a=>{RegisteredCommitments.get(a.id)&&d.warn(`The commitment ${a.id} is already registered, it will be overwritten`),RegisteredCommitments.add(a),i[a.id]={id:a.id,roomId:e,...t};}),storage.set(H,i);}find(r){return RegisteredCommitments.get(r)}remove(r,e){typeof r!="string"&&(r=r.id);let t=this.temporaryRoutine;t[r]?(!e||t[r].roomId===e)&&delete t[r]:d.warn(`The commitment ${r} was not found in the temporary routine, so it will be ignored. If you want to remove a fixed commitment, you can add it to the temporary routine with a same character.`),storage.set(H,t);}clearExpiredRoutine(){RegisteredCommitments.values().forEach(r=>{r.expired&&this.remove(r);});}get characterCommitments(){let r=this.temporaryRoutine;return this.commitmentsIds.reduce((e,t)=>{let i=RegisteredCommitments.get(t),a=r[t],s=a?.roomId||fixedCommitments.get(t)?.[1];return s&&i&&i.isActive(a)&&(i.characters.length>0?i.characters.every(l=>!e[l.id]||i.priority>e[l.id][0].priority)&&i.characters.forEach(l=>{e[l.id]=[i,s];}):d.error(`The commitment ${i.id} has no characters assigned`)),e},{})}get currentRoutine(){return Object.values(this.characterCommitments).map(([r])=>r)}get roomCommitments(){return Object.values(this.characterCommitments).reduce((r,e)=>{let t=e[1];return r[t]||(r[t]=[]),r[t].push(e[0]),r},{})}getCommitmentByCharacter(r){return this.currentRoutine.find(e=>{if(e.characters.map(t=>t.id).includes(r.id))return e})}};var f=class f{};n(f,"dayStartTime",0),n(f,"dayEndTime",24),n(f,"defaultTimeSpent",1),n(f,"timeSlots",[]),n(f,"weekLength",7),n(f,"weekendStartDay",f.weekLength-1),n(f,"getDayName");var u=f;var L=class{initialize(r){let{dayStartTime:e=0,dayEndTime:t=24,defaultTimeSpent:i=1,timeSlots:a=[],weekLength:s=7,weekendStartDay:c=s-1,getDayName:l}=r;u.dayStartTime=e,u.dayEndTime=t,u.defaultTimeSpent=i,u.timeSlots=a,u.weekLength=s,c>=u.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${s}, so will be ignored`):u.weekendStartDay=c,u.getDayName=l;}get dayStartTime(){return u.dayStartTime}get dayEndTime(){return u.dayEndTime}get defaultTimeSpent(){return u.defaultTimeSpent}get timeSlots(){return u.timeSlots}get weekLength(){return u.weekLength}get weekendStartDay(){return u.weekendStartDay}get getDayName(){return u.getDayName}get currentTime(){let r=storage.get(m)||{};return r.hasOwnProperty("currentTime")&&typeof r.currentTime=="number"?r.currentTime:this.dayStartTime}set currentTime(r){let e=storage.get(m)||{},t={...e};typeof r=="number"?t.currentTime=r:delete t.currentTime,R({type:"edittime",prev:e,value:t}),storage.set(m,t);}get currentDate(){let r=storage.get(m)||{};return r.hasOwnProperty("currentDate")&&typeof r.currentDate=="number"?r.currentDate:0}set currentDate(r){let e=storage.get(m)||{},t={...e};typeof r=="number"?t.currentDate=r:delete t.currentDate,R({type:"edittime",prev:e,value:t}),storage.set(m,t);}get isWeekend(){return this.currentWeekDayNumber>=this.weekendStartDay}get currentWeekDayNumber(){return this.currentDate%this.weekLength+1}get currentDayName(){return this.getDayName?this.getDayName(this.currentWeekDayNumber-1):(console.warn("[NQTR] Week days names are not defined, so currentDayName will be empty"),"")}get currentTimeSlot(){if(this.timeSlots.length===0)return console.warn("[NQTR] Time slots are not defined"),0;for(let r=0;r<this.timeSlots.length;r++){let e=this.timeSlots[r];if(this.timeSlots.length>r+1&&this.nowIsBetween(e.startTime,this.timeSlots[r+1].startTime))return r}return this.timeSlots.length-1}increaseTime(r=this.defaultTimeSpent){let e=this.currentTime+r;return e>=this.dayEndTime&&(this.increaseDate(),e=this.dayStartTime+(e-this.dayEndTime)),this.currentTime=e,this.currentTime}increaseDate(r=1,e=this.dayStartTime){let t=this.currentDate+r;return this.currentDate=t,this.currentTime=e,this.currentDate}nowIsBetween(r,e){r===void 0&&(r=this.dayStartTime-1),e===void 0&&(e=this.dayEndTime+1);let t=this.currentTime;return r<e?t>=r&&t<e:t>=r||t<e}};var Oe=new L,qe=new q,Me=new Q,Ne=new M;var Le={...F,...oe,...de,handlers:K,registries:Qe},zr=Le;export{b as ActivityBaseModel,g as ActivityStoredClass,P as CommitmentBaseModel,y as CommitmentStoredClass,E as LocationBaseModel,S as LocationStoredClass,C as MapBaseModel,v as MapStoredClass,w as QuestBaseModel,_ as QuestStoredClass,D as RoomBaseModel,I as RoomStoredClass,O as StageBaseModel,x as StageStoredClass,zr as default};
package/dist/ink.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var handlers=require('@drincs/nqtr/handlers'),registries=require('@drincs/nqtr/registries');var n;(e=>(e.log=(o,...r)=>console.log(`[NQTR] ${o}`,...r),e.warn=(o,...r)=>console.warn(`[NQTR] ${o}`,...r),e.error=(o,...r)=>console.error(`[NQTR] ${o}`,...r),e.info=(o,...r)=>console.info(`[NQTR] ${o}`,...r)))(n||(n={}));function v(a){a||(a={hours:handlers.timeTracker.defaultTimeSpent}),typeof a=="number"&&(a={hours:a});let{hours:i,days:u}=a;u&&handlers.timeTracker.increaseDate(u,handlers.timeTracker.dayStartTime),i&&handlers.timeTracker.increaseTime(i);}var b=(a={})=>{let{timeConverter:i=e=>Number(e.replace(":",".")),dateConverter:u=e=>Number(e),wait:d=v}=a;return (e,o,r)=>{switch(e[1]){case "room":switch(e[0]){case "enter":if(e.length>2){let t=registries.RegisteredRooms.get(e[2]);return t?handlers.navigator.currentRoom=t:n.warn(`Room ${e[2]} not found`),true}break}break;case "time":switch(e[0]){case "set":if(e.length>2){let t=i("01:00".replace(":","."));return isNaN(t)?n.warn(`Invalid time format: ${e[2]}`):handlers.timeTracker.currentTime=t,true}break}break;case "date":switch(e[0]){case "set":if(e.length>2){let t=u(e[2]);return isNaN(t)?n.warn(`Invalid date format: ${e[2]}`):handlers.timeTracker.currentDate=t,true}break}break;case "activity":switch(e[0]){case "add":if(e.length==5){let t=registries.RegisteredActivities.get(e[2]);if(!t)return n.warn(`Activity ${e[2]} not found`),true;let{in:m}=r(e.slice(3)),f=registries.RegisteredRooms.get(m);return f?f.addActivity(t):n.warn(`Room ${m} not found`),true}case "remove":if(e.length==5){let t=registries.RegisteredActivities.get(e[2]);if(!t)return n.warn(`Activity ${e[2]} not found`),true;let{from:m}=r(e.slice(3)),f=registries.RegisteredRooms.get(m);return f?f.removeActivity(t):n.warn(`Room ${m} not found`),true}}break;case "routine":switch(e[0]){case "add":if(e.length==3){let t=registries.RegisteredCommitments.get(e[2]);return t?(handlers.routine.add(t),true):(n.warn(`Commitment ${e[2]} not found`),true)}case "remove":if(e.length==3){let t=registries.RegisteredCommitments.get(e[2]);return t?(handlers.routine.remove(t),true):(n.warn(`Commitment ${e[2]} not found`),true)}}break;case "quest":switch(e[0]){case "start":if(e.length==3){let t=registries.RegisteredQuests.get(e[2]);return t?(t.start(o),true):(n.warn(`Quest ${e[2]} not found`),true)}case "continue":if(e.length==3){let t=registries.RegisteredQuests.get(e[2]);return t?(t.continue(o),true):(n.warn(`Quest ${e[2]} not found`),true)}}break}switch(e[0]){case "wait":if(e.length==1)return d(),true;if(e.length==2){let t=i(e[1]);return isNaN(t)?n.warn(`Invalid time format: ${e[1]}`):d(t),true}else if(e.length>2){let t=r(e.slice(1));return t.hours!==void 0&&typeof t.hours=="string"&&(t.hours=i(t.hours)),t.days!==void 0&&typeof t.days=="string"&&(t.days=u(t.days)),d(t),true}break}return false}};exports.nqtrHandler=b;
1
+ 'use strict';var handlers=require('@drincs/nqtr/handlers'),registries=require('@drincs/nqtr/registries'),pixiVnInk=require('@drincs/pixi-vn-ink');var o;(e=>(e.log=(a,...n)=>console.log(`[NQTR] ${a}`,...n),e.warn=(a,...n)=>console.warn(`[NQTR] ${a}`,...n),e.error=(a,...n)=>console.error(`[NQTR] ${a}`,...n),e.info=(a,...n)=>console.info(`[NQTR] ${a}`,...n)))(o||(o={}));function k(i){i||(i={hours:handlers.timeTracker.defaultTimeSpent}),typeof i=="number"&&(i={hours:i});let{hours:u,days:f}=i;f&&handlers.timeTracker.increaseDate(f,handlers.timeTracker.dayStartTime),u&&handlers.timeTracker.increaseTime(u);}var b=(i={})=>{pixiVnInk.VariableGetter.add((e,a)=>{if(e&&typeof e=="object"&&"type"in e&&"key"in e&&"storageOperationType"in e&&"storageType"in e&&e.storageOperationType==="get"&&(e.storageType==="storage"||e.storageType==="tempstorage"||e.storageType==="flagStorage")){let n=e;if(n.key.endsWith("_currentStageIndex")){let t=n.key.replace("_currentStageIndex",""),r=registries.RegisteredQuests.get(t);return r?r.currentStageIndex:(o.warn(`Quest ${t} not found`),a(e))}else if(n.key.endsWith("_started")){let t=n.key.replace("_started",""),r=registries.RegisteredQuests.get(t);return r?r.started:(o.warn(`Quest ${t} not found`),a(e))}else if(n.key.endsWith("_completed")){let t=n.key.replace("_completed",""),r=registries.RegisteredQuests.get(t);return r?r.completed:(o.warn(`Quest ${t} not found`),a(e))}else if(n.key.endsWith("_failed")){let t=n.key.replace("_failed",""),r=registries.RegisteredQuests.get(t);return r?r.failed:(o.warn(`Quest ${t} not found`),a(e))}}return a(e)});let{timeConverter:u=e=>Number(e.replace(":",".")),dateConverter:f=e=>Number(e),wait:l=k}=i;return (e,a,n)=>{switch(e[1]){case "room":switch(e[0]){case "enter":if(e.length>2){let t=registries.RegisteredRooms.get(e[2]);return t?handlers.navigator.currentRoom=t:o.warn(`Room ${e[2]} not found`),true}break}break;case "time":switch(e[0]){case "set":if(e.length>2){let t=u(e[2]);return isNaN(t)?o.warn(`Invalid time format: ${e[2]}`):handlers.timeTracker.currentTime=t,true}break}break;case "date":switch(e[0]){case "set":if(e.length>2){let t=f(e[2]);return isNaN(t)?o.warn(`Invalid date format: ${e[2]}`):handlers.timeTracker.currentDate=t,true}break}break;case "activity":switch(e[0]){case "add":if(e.length==5){let t=registries.RegisteredActivities.get(e[2]);if(!t)return o.warn(`Activity ${e[2]} not found`),true;let{in:r}=n(e.slice(3)),s=registries.RegisteredRooms.get(r);return s?s.addActivity(t):o.warn(`Room ${r} not found`),true}case "remove":if(e.length==5){let t=registries.RegisteredActivities.get(e[2]);if(!t)return o.warn(`Activity ${e[2]} not found`),true;let{from:r}=n(e.slice(3)),s=registries.RegisteredRooms.get(r);return s?s.removeActivity(t):o.warn(`Room ${r} not found`),true}}break;case "routine":switch(e[0]){case "add":if(e.length==5){let t=registries.RegisteredCommitments.get(e[2]);if(!t)return o.warn(`Commitment ${e[2]} not found`),true;let{in:r}=n(e.slice(3)),s=registries.RegisteredRooms.get(r);return s?s.addCommitment(t):o.warn(`Room ${r} not found`),true}case "remove":if(e.length==3){let t=registries.RegisteredCommitments.get(e[2]);return t?(handlers.routine.remove(t),true):(o.warn(`Commitment ${e[2]} not found`),true)}}break;case "quest":switch(e[0]){case "start":if(e.length==3){let t=registries.RegisteredQuests.get(e[2]);return t?(t.start(a),true):(o.warn(`Quest ${e[2]} not found`),true)}case "continue":if(e.length==3){let t=registries.RegisteredQuests.get(e[2]);return t?(t.continue(a),true):(o.warn(`Quest ${e[2]} not found`),true)}}break}switch(e[0]){case "wait":if(e.length==1)return l(),true;if(e.length==2){let t=u(e[1]);return isNaN(t)?o.warn(`Invalid time format: ${e[1]}`):l(t),true}else if(e.length>2){let t=n(e.slice(1));return t.hours!==void 0&&typeof t.hours=="string"&&(t.hours=u(t.hours)),t.days!==void 0&&typeof t.days=="string"&&(t.days=f(t.days)),l(t),true}break}return false}};exports.nqtrHandler=b;
package/dist/ink.mjs CHANGED
@@ -1 +1 @@
1
- import {routine,timeTracker,navigator}from'@drincs/nqtr/handlers';import {RegisteredQuests,RegisteredCommitments,RegisteredActivities,RegisteredRooms}from'@drincs/nqtr/registries';var n;(e=>(e.log=(o,...r)=>console.log(`[NQTR] ${o}`,...r),e.warn=(o,...r)=>console.warn(`[NQTR] ${o}`,...r),e.error=(o,...r)=>console.error(`[NQTR] ${o}`,...r),e.info=(o,...r)=>console.info(`[NQTR] ${o}`,...r)))(n||(n={}));function v(a){a||(a={hours:timeTracker.defaultTimeSpent}),typeof a=="number"&&(a={hours:a});let{hours:i,days:u}=a;u&&timeTracker.increaseDate(u,timeTracker.dayStartTime),i&&timeTracker.increaseTime(i);}var b=(a={})=>{let{timeConverter:i=e=>Number(e.replace(":",".")),dateConverter:u=e=>Number(e),wait:d=v}=a;return (e,o,r)=>{switch(e[1]){case "room":switch(e[0]){case "enter":if(e.length>2){let t=RegisteredRooms.get(e[2]);return t?navigator.currentRoom=t:n.warn(`Room ${e[2]} not found`),true}break}break;case "time":switch(e[0]){case "set":if(e.length>2){let t=i("01:00".replace(":","."));return isNaN(t)?n.warn(`Invalid time format: ${e[2]}`):timeTracker.currentTime=t,true}break}break;case "date":switch(e[0]){case "set":if(e.length>2){let t=u(e[2]);return isNaN(t)?n.warn(`Invalid date format: ${e[2]}`):timeTracker.currentDate=t,true}break}break;case "activity":switch(e[0]){case "add":if(e.length==5){let t=RegisteredActivities.get(e[2]);if(!t)return n.warn(`Activity ${e[2]} not found`),true;let{in:m}=r(e.slice(3)),f=RegisteredRooms.get(m);return f?f.addActivity(t):n.warn(`Room ${m} not found`),true}case "remove":if(e.length==5){let t=RegisteredActivities.get(e[2]);if(!t)return n.warn(`Activity ${e[2]} not found`),true;let{from:m}=r(e.slice(3)),f=RegisteredRooms.get(m);return f?f.removeActivity(t):n.warn(`Room ${m} not found`),true}}break;case "routine":switch(e[0]){case "add":if(e.length==3){let t=RegisteredCommitments.get(e[2]);return t?(routine.add(t),true):(n.warn(`Commitment ${e[2]} not found`),true)}case "remove":if(e.length==3){let t=RegisteredCommitments.get(e[2]);return t?(routine.remove(t),true):(n.warn(`Commitment ${e[2]} not found`),true)}}break;case "quest":switch(e[0]){case "start":if(e.length==3){let t=RegisteredQuests.get(e[2]);return t?(t.start(o),true):(n.warn(`Quest ${e[2]} not found`),true)}case "continue":if(e.length==3){let t=RegisteredQuests.get(e[2]);return t?(t.continue(o),true):(n.warn(`Quest ${e[2]} not found`),true)}}break}switch(e[0]){case "wait":if(e.length==1)return d(),true;if(e.length==2){let t=i(e[1]);return isNaN(t)?n.warn(`Invalid time format: ${e[1]}`):d(t),true}else if(e.length>2){let t=r(e.slice(1));return t.hours!==void 0&&typeof t.hours=="string"&&(t.hours=i(t.hours)),t.days!==void 0&&typeof t.days=="string"&&(t.days=u(t.days)),d(t),true}break}return false}};export{b as nqtrHandler};
1
+ import {routine,timeTracker,navigator}from'@drincs/nqtr/handlers';import {RegisteredQuests,RegisteredCommitments,RegisteredRooms,RegisteredActivities}from'@drincs/nqtr/registries';import {VariableGetter}from'@drincs/pixi-vn-ink';var o;(e=>(e.log=(a,...n)=>console.log(`[NQTR] ${a}`,...n),e.warn=(a,...n)=>console.warn(`[NQTR] ${a}`,...n),e.error=(a,...n)=>console.error(`[NQTR] ${a}`,...n),e.info=(a,...n)=>console.info(`[NQTR] ${a}`,...n)))(o||(o={}));function k(i){i||(i={hours:timeTracker.defaultTimeSpent}),typeof i=="number"&&(i={hours:i});let{hours:u,days:f}=i;f&&timeTracker.increaseDate(f,timeTracker.dayStartTime),u&&timeTracker.increaseTime(u);}var b=(i={})=>{VariableGetter.add((e,a)=>{if(e&&typeof e=="object"&&"type"in e&&"key"in e&&"storageOperationType"in e&&"storageType"in e&&e.storageOperationType==="get"&&(e.storageType==="storage"||e.storageType==="tempstorage"||e.storageType==="flagStorage")){let n=e;if(n.key.endsWith("_currentStageIndex")){let t=n.key.replace("_currentStageIndex",""),r=RegisteredQuests.get(t);return r?r.currentStageIndex:(o.warn(`Quest ${t} not found`),a(e))}else if(n.key.endsWith("_started")){let t=n.key.replace("_started",""),r=RegisteredQuests.get(t);return r?r.started:(o.warn(`Quest ${t} not found`),a(e))}else if(n.key.endsWith("_completed")){let t=n.key.replace("_completed",""),r=RegisteredQuests.get(t);return r?r.completed:(o.warn(`Quest ${t} not found`),a(e))}else if(n.key.endsWith("_failed")){let t=n.key.replace("_failed",""),r=RegisteredQuests.get(t);return r?r.failed:(o.warn(`Quest ${t} not found`),a(e))}}return a(e)});let{timeConverter:u=e=>Number(e.replace(":",".")),dateConverter:f=e=>Number(e),wait:l=k}=i;return (e,a,n)=>{switch(e[1]){case "room":switch(e[0]){case "enter":if(e.length>2){let t=RegisteredRooms.get(e[2]);return t?navigator.currentRoom=t:o.warn(`Room ${e[2]} not found`),true}break}break;case "time":switch(e[0]){case "set":if(e.length>2){let t=u(e[2]);return isNaN(t)?o.warn(`Invalid time format: ${e[2]}`):timeTracker.currentTime=t,true}break}break;case "date":switch(e[0]){case "set":if(e.length>2){let t=f(e[2]);return isNaN(t)?o.warn(`Invalid date format: ${e[2]}`):timeTracker.currentDate=t,true}break}break;case "activity":switch(e[0]){case "add":if(e.length==5){let t=RegisteredActivities.get(e[2]);if(!t)return o.warn(`Activity ${e[2]} not found`),true;let{in:r}=n(e.slice(3)),s=RegisteredRooms.get(r);return s?s.addActivity(t):o.warn(`Room ${r} not found`),true}case "remove":if(e.length==5){let t=RegisteredActivities.get(e[2]);if(!t)return o.warn(`Activity ${e[2]} not found`),true;let{from:r}=n(e.slice(3)),s=RegisteredRooms.get(r);return s?s.removeActivity(t):o.warn(`Room ${r} not found`),true}}break;case "routine":switch(e[0]){case "add":if(e.length==5){let t=RegisteredCommitments.get(e[2]);if(!t)return o.warn(`Commitment ${e[2]} not found`),true;let{in:r}=n(e.slice(3)),s=RegisteredRooms.get(r);return s?s.addCommitment(t):o.warn(`Room ${r} not found`),true}case "remove":if(e.length==3){let t=RegisteredCommitments.get(e[2]);return t?(routine.remove(t),true):(o.warn(`Commitment ${e[2]} not found`),true)}}break;case "quest":switch(e[0]){case "start":if(e.length==3){let t=RegisteredQuests.get(e[2]);return t?(t.start(a),true):(o.warn(`Quest ${e[2]} not found`),true)}case "continue":if(e.length==3){let t=RegisteredQuests.get(e[2]);return t?(t.continue(a),true):(o.warn(`Quest ${e[2]} not found`),true)}}break}switch(e[0]){case "wait":if(e.length==1)return l(),true;if(e.length==2){let t=u(e[1]);return isNaN(t)?o.warn(`Invalid time format: ${e[1]}`):l(t),true}else if(e.length>2){let t=n(e.slice(1));return t.hours!==void 0&&typeof t.hours=="string"&&(t.hours=u(t.hours)),t.days!==void 0&&typeof t.days=="string"&&(t.days=f(t.days)),l(t),true}break}return false}};export{b as nqtrHandler};
@@ -1 +1 @@
1
- 'use strict';var pixiVn=require('@drincs/pixi-vn');var t;(n=>(n.log=(e,...r)=>console.log(`[NQTR] ${e}`,...r),n.warn=(e,...r)=>console.warn(`[NQTR] ${e}`,...r),n.error=(e,...r)=>console.error(`[NQTR] ${e}`,...r),n.info=(e,...r)=>console.info(`[NQTR] ${e}`,...r)))(t||(t={}));var s=new pixiVn.CachedMap({cacheSize:20}),l;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>n.add(r));return}s.set(e.id,e);}n.add=o;function a(e){try{let r=s.get(e);if(!r){console.warn(`[NQTR] Activity ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Activity ${e}`,r);return}}n.get=a;function i(){return Array.from(s.values())}n.values=i;function f(e){return s.has(e)}n.has=f;})(l||(l={}));var M=l;var c=new pixiVn.CachedMap({cacheSize:20}),$=new pixiVn.CachedMap({cacheSize:20}),g;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>n.add(r));return}c.set(e.id,e);}n.add=o;function a(e){try{let r=c.get(e);if(!r){console.warn(`[NQTR] Commitment ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Commitment ${e}`,r);return}}n.get=a;function i(){return Array.from(c.values())}n.values=i;function f(e){return c.has(e)}n.has=f;})(g||(g={}));var E=g;var u=new pixiVn.CachedMap({cacheSize:20}),y;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>o(r));return}u.set(e.id,e);}n.add=o;function a(e){try{let r=u.get(e);if(!r){console.warn(`[NQTR] Location ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Location ${e}`,r);return}}n.get=a;function i(){return Array.from(u.values())}n.values=i;function f(e){return u.has(e)}n.has=f;})(y||(y={}));var h=y;var m=new pixiVn.CachedMap({cacheSize:20}),x;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>o(r));return}m.set(e.id,e);}n.add=o;function a(e){try{let r=m.get(e);if(!r){console.warn(`[NQTR] Map ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Map ${e}`,r);return}}n.get=a;function i(){return Array.from(m.values())}n.values=i;function f(e){return m.has(e)}n.has=f;})(x||(x={}));var I=x;var p=new pixiVn.CachedMap({cacheSize:5}),A;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>n.add(r));return}p.set(e.id,e);}n.add=o;function a(e){try{let r=p.get(e);if(!r){console.warn(`[NQTR] Quest ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Quest ${e}`,r);return}}n.get=a;function i(){return Array.from(p.values())}n.values=i;function f(e){return p.has(e)}n.has=f;})(A||(A={}));var z=A;var d=new pixiVn.CachedMap({cacheSize:20}),w;(n=>{function o(e){if(Array.isArray(e)){e.forEach(C=>o(C));return}d.set(e.id,e);let r=e.location;h.add(r);let R=r?.map;R&&I.add(R);}n.add=o;function a(e){try{let r=d.get(e);if(!r){console.warn(`[NQTR] Room ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Room ${e}`,r);return}}n.get=a;function i(){return Array.from(d.values())}n.values=i;function f(e){return d.has(e)}n.has=f;})(w||(w={}));var b=w;exports.RegisteredActivities=M;exports.RegisteredCommitments=E;exports.RegisteredLocations=h;exports.RegisteredMaps=I;exports.RegisteredQuests=z;exports.RegisteredRooms=b;exports.fixedCommitments=$;exports.registeredCommitments=c;
1
+ 'use strict';var pixiVn=require('@drincs/pixi-vn');var t;(n=>(n.log=(e,...r)=>console.log(`[NQTR] ${e}`,...r),n.warn=(e,...r)=>console.warn(`[NQTR] ${e}`,...r),n.error=(e,...r)=>console.error(`[NQTR] ${e}`,...r),n.info=(e,...r)=>console.info(`[NQTR] ${e}`,...r)))(t||(t={}));var s=new pixiVn.CachedMap({cacheSize:20}),g;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>n.add(r));return}s.set(e.id,e);}n.add=o;function a(e){try{let r=s.get(e);if(!r){console.warn(`[NQTR] Activity ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Activity ${e}`,r);return}}n.get=a;function i(){return Array.from(s.values())}n.values=i;function f(e){return s.has(e)}n.has=f;})(g||(g={}));var M=g;var c=new pixiVn.CachedMap({cacheSize:20}),$=new pixiVn.CachedMap({cacheSize:20}),l;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>n.add(r));return}c.set(e.id,e);}n.add=o;function a(e){try{let r=c.get(e);if(!r){console.warn(`[NQTR] Commitment ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Commitment ${e}`,r);return}}n.get=a;function i(){return Array.from(c.values())}n.values=i;function f(e){return c.has(e)}n.has=f;})(l||(l={}));var E=l;var u=new pixiVn.CachedMap({cacheSize:20}),y;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>o(r));return}u.set(e.id,e);}n.add=o;function a(e){try{let r=u.get(e);if(!r){console.warn(`[NQTR] Location ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Location ${e}`,r);return}}n.get=a;function i(){return Array.from(u.values())}n.values=i;function f(e){return u.has(e)}n.has=f;})(y||(y={}));var h=y;var m=new pixiVn.CachedMap({cacheSize:20}),x;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>o(r));return}m.set(e.id,e);}n.add=o;function a(e){try{let r=m.get(e);if(!r){console.warn(`[NQTR] Map ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Map ${e}`,r);return}}n.get=a;function i(){return Array.from(m.values())}n.values=i;function f(e){return m.has(e)}n.has=f;})(x||(x={}));var I=x;var p=new pixiVn.CachedMap({cacheSize:5}),A;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>n.add(r));return}p.set(e.id,e);}n.add=o;function a(e){try{let r=p.get(e);if(!r){console.warn(`[NQTR] Quest ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Quest ${e}`,r);return}}n.get=a;function i(){return Array.from(p.values())}n.values=i;function f(e){return p.has(e)}n.has=f;})(A||(A={}));var z=A;var d=new pixiVn.CachedMap({cacheSize:20}),w;(n=>{function o(e){if(Array.isArray(e)){e.forEach(C=>o(C));return}d.set(e.id,e);let r=e.location;h.add(r);let R=r?.map;R&&I.add(R);}n.add=o;function a(e){try{let r=d.get(e);if(!r){console.warn(`[NQTR] Room ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Room ${e}`,r);return}}n.get=a;function i(){return Array.from(d.values())}n.values=i;function f(e){return d.has(e)}n.has=f;})(w||(w={}));var b=w;exports.RegisteredActivities=M;exports.RegisteredCommitments=E;exports.RegisteredLocations=h;exports.RegisteredMaps=I;exports.RegisteredQuests=z;exports.RegisteredRooms=b;exports.fixedCommitments=$;exports.registeredCommitments=c;
@@ -86,10 +86,6 @@ interface CommitmentBaseInternalInterface extends ActivityBaseInternalInterface
86
86
  * The character or characters that are in the commitment and so in the room.
87
87
  */
88
88
  readonly characters: CharacterInterface[];
89
- /**
90
- * The room where the commitment is.
91
- */
92
- readonly room: RoomInterface;
93
89
  /**
94
90
  * 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.
95
91
  * If you set "automatic" remember to remove the commitment when it is no longer needed, because otherwise it repeats itself every time.
@@ -109,22 +105,13 @@ interface NavigationAbstractInterface extends StoredClassModel {
109
105
  * @param options
110
106
  * @returns
111
107
  */
112
- addActivity(activity: ActivityInterface, options?: {
113
- /**
114
- * Time slot in which activity will be active.
115
- */
116
- timeSlot?: TimeSchedulingInterface;
117
- /**
118
- * Used to schedule what date it will be added and removed.
119
- */
120
- dateScheduling?: DateSchedulingInterface;
121
- }): void;
108
+ addActivity(activity: ActivityInterface, options?: ActiveScheduling): void;
122
109
  /**
123
110
  * Disconnects the activity from the class.
124
111
  * @param activity The activity to disconnect from the class.
125
112
  * @param options
126
113
  */
127
- removeActivity(activity: ActivityInterface | string, options?: Pick<DateSchedulingInterface, "to">): void;
114
+ removeActivity(activity: ActivityInterface | string): void;
128
115
  /**
129
116
  * Removes the useless activities.
130
117
  */
@@ -182,6 +169,19 @@ interface RoomBaseInternalInterface extends NavigationAbstractInterface {
182
169
  * The location where the room is.
183
170
  */
184
171
  readonly location: LocationInterface;
172
+ /**
173
+ * Connects the commitment to the class.
174
+ * @param commitment The commitment to connect to the class.
175
+ * @param options
176
+ * @returns
177
+ */
178
+ addCommitment(commitment: CommitmentInterface, options?: ActiveScheduling): void;
179
+ /**
180
+ * Disconnects the commitment from the class.
181
+ * @param commitment The commitment to disconnect from the class.
182
+ * @param options
183
+ */
184
+ removeCommitment(commitment: CommitmentInterface | string): void;
185
185
  /**
186
186
  * Get the character commitments of the room.
187
187
  */
@@ -385,7 +385,7 @@ declare namespace RegisteredActivities {
385
385
  * The key is the id of the commitment and the value is the commitment itself.
386
386
  */
387
387
  declare const registeredCommitments: CachedMap<string, CommitmentInterface>;
388
- declare const fixedCommitments: CachedMap<string, CommitmentInterface>;
388
+ declare const fixedCommitments: CachedMap<string, [CommitmentInterface, string]>;
389
389
  declare namespace RegisteredCommitments {
390
390
  /**
391
391
  * Save a commitment in the registered commitments. If the commitment already exists, it will be overwritten.
@@ -86,10 +86,6 @@ interface CommitmentBaseInternalInterface extends ActivityBaseInternalInterface
86
86
  * The character or characters that are in the commitment and so in the room.
87
87
  */
88
88
  readonly characters: CharacterInterface[];
89
- /**
90
- * The room where the commitment is.
91
- */
92
- readonly room: RoomInterface;
93
89
  /**
94
90
  * 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.
95
91
  * If you set "automatic" remember to remove the commitment when it is no longer needed, because otherwise it repeats itself every time.
@@ -109,22 +105,13 @@ interface NavigationAbstractInterface extends StoredClassModel {
109
105
  * @param options
110
106
  * @returns
111
107
  */
112
- addActivity(activity: ActivityInterface, options?: {
113
- /**
114
- * Time slot in which activity will be active.
115
- */
116
- timeSlot?: TimeSchedulingInterface;
117
- /**
118
- * Used to schedule what date it will be added and removed.
119
- */
120
- dateScheduling?: DateSchedulingInterface;
121
- }): void;
108
+ addActivity(activity: ActivityInterface, options?: ActiveScheduling): void;
122
109
  /**
123
110
  * Disconnects the activity from the class.
124
111
  * @param activity The activity to disconnect from the class.
125
112
  * @param options
126
113
  */
127
- removeActivity(activity: ActivityInterface | string, options?: Pick<DateSchedulingInterface, "to">): void;
114
+ removeActivity(activity: ActivityInterface | string): void;
128
115
  /**
129
116
  * Removes the useless activities.
130
117
  */
@@ -182,6 +169,19 @@ interface RoomBaseInternalInterface extends NavigationAbstractInterface {
182
169
  * The location where the room is.
183
170
  */
184
171
  readonly location: LocationInterface;
172
+ /**
173
+ * Connects the commitment to the class.
174
+ * @param commitment The commitment to connect to the class.
175
+ * @param options
176
+ * @returns
177
+ */
178
+ addCommitment(commitment: CommitmentInterface, options?: ActiveScheduling): void;
179
+ /**
180
+ * Disconnects the commitment from the class.
181
+ * @param commitment The commitment to disconnect from the class.
182
+ * @param options
183
+ */
184
+ removeCommitment(commitment: CommitmentInterface | string): void;
185
185
  /**
186
186
  * Get the character commitments of the room.
187
187
  */
@@ -385,7 +385,7 @@ declare namespace RegisteredActivities {
385
385
  * The key is the id of the commitment and the value is the commitment itself.
386
386
  */
387
387
  declare const registeredCommitments: CachedMap<string, CommitmentInterface>;
388
- declare const fixedCommitments: CachedMap<string, CommitmentInterface>;
388
+ declare const fixedCommitments: CachedMap<string, [CommitmentInterface, string]>;
389
389
  declare namespace RegisteredCommitments {
390
390
  /**
391
391
  * Save a commitment in the registered commitments. If the commitment already exists, it will be overwritten.
@@ -1 +1 @@
1
- import {CachedMap}from'@drincs/pixi-vn';var t;(n=>(n.log=(e,...r)=>console.log(`[NQTR] ${e}`,...r),n.warn=(e,...r)=>console.warn(`[NQTR] ${e}`,...r),n.error=(e,...r)=>console.error(`[NQTR] ${e}`,...r),n.info=(e,...r)=>console.info(`[NQTR] ${e}`,...r)))(t||(t={}));var s=new CachedMap({cacheSize:20}),l;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>n.add(r));return}s.set(e.id,e);}n.add=o;function a(e){try{let r=s.get(e);if(!r){console.warn(`[NQTR] Activity ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Activity ${e}`,r);return}}n.get=a;function i(){return Array.from(s.values())}n.values=i;function f(e){return s.has(e)}n.has=f;})(l||(l={}));var M=l;var c=new CachedMap({cacheSize:20}),$=new CachedMap({cacheSize:20}),g;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>n.add(r));return}c.set(e.id,e);}n.add=o;function a(e){try{let r=c.get(e);if(!r){console.warn(`[NQTR] Commitment ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Commitment ${e}`,r);return}}n.get=a;function i(){return Array.from(c.values())}n.values=i;function f(e){return c.has(e)}n.has=f;})(g||(g={}));var E=g;var u=new CachedMap({cacheSize:20}),y;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>o(r));return}u.set(e.id,e);}n.add=o;function a(e){try{let r=u.get(e);if(!r){console.warn(`[NQTR] Location ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Location ${e}`,r);return}}n.get=a;function i(){return Array.from(u.values())}n.values=i;function f(e){return u.has(e)}n.has=f;})(y||(y={}));var h=y;var m=new CachedMap({cacheSize:20}),x;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>o(r));return}m.set(e.id,e);}n.add=o;function a(e){try{let r=m.get(e);if(!r){console.warn(`[NQTR] Map ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Map ${e}`,r);return}}n.get=a;function i(){return Array.from(m.values())}n.values=i;function f(e){return m.has(e)}n.has=f;})(x||(x={}));var I=x;var p=new CachedMap({cacheSize:5}),A;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>n.add(r));return}p.set(e.id,e);}n.add=o;function a(e){try{let r=p.get(e);if(!r){console.warn(`[NQTR] Quest ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Quest ${e}`,r);return}}n.get=a;function i(){return Array.from(p.values())}n.values=i;function f(e){return p.has(e)}n.has=f;})(A||(A={}));var z=A;var d=new CachedMap({cacheSize:20}),w;(n=>{function o(e){if(Array.isArray(e)){e.forEach(C=>o(C));return}d.set(e.id,e);let r=e.location;h.add(r);let R=r?.map;R&&I.add(R);}n.add=o;function a(e){try{let r=d.get(e);if(!r){console.warn(`[NQTR] Room ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Room ${e}`,r);return}}n.get=a;function i(){return Array.from(d.values())}n.values=i;function f(e){return d.has(e)}n.has=f;})(w||(w={}));var b=w;export{M as RegisteredActivities,E as RegisteredCommitments,h as RegisteredLocations,I as RegisteredMaps,z as RegisteredQuests,b as RegisteredRooms,$ as fixedCommitments,c as registeredCommitments};
1
+ import {CachedMap}from'@drincs/pixi-vn';var t;(n=>(n.log=(e,...r)=>console.log(`[NQTR] ${e}`,...r),n.warn=(e,...r)=>console.warn(`[NQTR] ${e}`,...r),n.error=(e,...r)=>console.error(`[NQTR] ${e}`,...r),n.info=(e,...r)=>console.info(`[NQTR] ${e}`,...r)))(t||(t={}));var s=new CachedMap({cacheSize:20}),g;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>n.add(r));return}s.set(e.id,e);}n.add=o;function a(e){try{let r=s.get(e);if(!r){console.warn(`[NQTR] Activity ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Activity ${e}`,r);return}}n.get=a;function i(){return Array.from(s.values())}n.values=i;function f(e){return s.has(e)}n.has=f;})(g||(g={}));var M=g;var c=new CachedMap({cacheSize:20}),$=new CachedMap({cacheSize:20}),l;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>n.add(r));return}c.set(e.id,e);}n.add=o;function a(e){try{let r=c.get(e);if(!r){console.warn(`[NQTR] Commitment ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Commitment ${e}`,r);return}}n.get=a;function i(){return Array.from(c.values())}n.values=i;function f(e){return c.has(e)}n.has=f;})(l||(l={}));var E=l;var u=new CachedMap({cacheSize:20}),y;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>o(r));return}u.set(e.id,e);}n.add=o;function a(e){try{let r=u.get(e);if(!r){console.warn(`[NQTR] Location ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Location ${e}`,r);return}}n.get=a;function i(){return Array.from(u.values())}n.values=i;function f(e){return u.has(e)}n.has=f;})(y||(y={}));var h=y;var m=new CachedMap({cacheSize:20}),x;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>o(r));return}m.set(e.id,e);}n.add=o;function a(e){try{let r=m.get(e);if(!r){console.warn(`[NQTR] Map ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Map ${e}`,r);return}}n.get=a;function i(){return Array.from(m.values())}n.values=i;function f(e){return m.has(e)}n.has=f;})(x||(x={}));var I=x;var p=new CachedMap({cacheSize:5}),A;(n=>{function o(e){if(Array.isArray(e)){e.forEach(r=>n.add(r));return}p.set(e.id,e);}n.add=o;function a(e){try{let r=p.get(e);if(!r){console.warn(`[NQTR] Quest ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Quest ${e}`,r);return}}n.get=a;function i(){return Array.from(p.values())}n.values=i;function f(e){return p.has(e)}n.has=f;})(A||(A={}));var z=A;var d=new CachedMap({cacheSize:20}),w;(n=>{function o(e){if(Array.isArray(e)){e.forEach(C=>o(C));return}d.set(e.id,e);let r=e.location;h.add(r);let R=r?.map;R&&I.add(R);}n.add=o;function a(e){try{let r=d.get(e);if(!r){console.warn(`[NQTR] Room ${e} not found, you should register it first`);return}return r}catch(r){t.error(`Error while getting Room ${e}`,r);return}}n.get=a;function i(){return Array.from(d.values())}n.values=i;function f(e){return d.has(e)}n.has=f;})(w||(w={}));var b=w;export{M as RegisteredActivities,E as RegisteredCommitments,h as RegisteredLocations,I as RegisteredMaps,z as RegisteredQuests,b as RegisteredRooms,$ as fixedCommitments,c as registeredCommitments};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drincs/nqtr",
3
- "version": "0.7.2",
3
+ "version": "0.8.1",
4
4
  "description": "A complete system introducing the concepts of location, time and event, producing the framework of a not-quite-point-and-click adventure game.",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -62,7 +62,8 @@
62
62
  },
63
63
  "homepage": "https://pixi-vn.web.app/nqtr",
64
64
  "devDependencies": {
65
- "@drincs/pixi-vn-ink": "^0.11.2",
65
+ "@drincs/pixi-vn-ink": "^0.12.2",
66
+ "@drincs/pixi-vn-json": "^1.10.1",
66
67
  "jsdom": "^28.0.0",
67
68
  "ts-node": "^10.9.2",
68
69
  "tsup": "^8.5.1",
@@ -71,7 +72,13 @@
71
72
  "vitest": "^4.0.18"
72
73
  },
73
74
  "peerDependencies": {
74
- "@drincs/pixi-vn": ">=1.4.0"
75
+ "@drincs/pixi-vn": ">=1.5.17",
76
+ "@drincs/pixi-vn-ink": ">=0.12.2"
77
+ },
78
+ "peerDependenciesMeta": {
79
+ "@drincs/pixi-vn-ink": {
80
+ "optional": true
81
+ }
75
82
  },
76
83
  "keywords": [
77
84
  "game",