@drincs/nqtr 0.4.0 → 0.4.2
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/dist/classes/index.cjs +1 -1
- package/dist/classes/index.cjs.map +1 -1
- package/dist/classes/index.mjs +1 -1
- package/dist/classes/index.mjs.map +1 -1
- package/dist/decorators/index.cjs +1 -1
- package/dist/decorators/index.cjs.map +1 -1
- package/dist/decorators/index.d.mts +56 -3
- package/dist/decorators/index.d.ts +56 -3
- package/dist/decorators/index.mjs +1 -1
- package/dist/decorators/index.mjs.map +1 -1
- package/dist/{index-B8-yQhYT.d.ts → index-B-x-OmU2.d.ts} +0 -2
- package/dist/{index-knrOEAIO.d.mts → index-k8ho_YWr.d.mts} +0 -2
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/managers/index.cjs +1 -1
- package/dist/managers/index.cjs.map +1 -1
- package/dist/managers/index.d.mts +1 -1
- package/dist/managers/index.d.ts +1 -1
- package/dist/managers/index.mjs +1 -1
- package/dist/managers/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/classes/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var pixiVn=require('@drincs/pixi-vn');var l="___nqtr-time_manager_data___",p="___nqtr-current_room_memory___",J="___nqtr-last_event_memory___";var u;(n=>(n.log=(i,...a)=>console.log(`[NQTR] ${i}`,...a),n.warn=(i,...a)=>console.warn(`[NQTR] ${i}`,...a),n.error=(i,...a)=>console.error(`[NQTR] ${i}`,...a),n.info=(i,...a)=>console.info(`[NQTR] ${i}`,...a)))(u||={});var H=new pixiVn.CachedMap({cacheSize:20}),te;(n=>{function o(i){if(Array.isArray(i)){i.forEach(a=>n.add(a));return}H.set(i.id,i);}n.add=o;function e(i){try{let a=H.get(i);if(!a){console.warn(`[NQTR] Activity ${i} not found, you should register it first`);return}return a}catch(a){u.error(`Error while getting Activity ${i}`,a);return}}n.get=e;function t(){return Array.from(H.values())}n.values=t;function r(i){return H.has(i)}n.has=r;})(te||={});var O=te;var S=new pixiVn.CachedMap({cacheSize:20}),M=new pixiVn.CachedMap({cacheSize:20}),ie;(n=>{function o(i){if(Array.isArray(i)){i.forEach(a=>n.add(a));return}console.warn(`[NQTR] Registering commitment ${i.id}`,i),S.set(i.id,i);}n.add=o;function e(i){try{let a=S.get(i);if(!a){console.warn(`[NQTR] Commitment ${i} not found, you should register it first`);return}return a}catch(a){u.error(`Error while getting Commitment ${i}`,a);return}}n.get=e;function t(){return Array.from(S.values())}n.values=t;function r(i){return S.has(i)}n.has=r;})(ie||={});var v=ie;var q=new pixiVn.CachedMap({cacheSize:5}),ne;(n=>{function o(i){if(Array.isArray(i)){i.forEach(a=>n.add(a));return}q.set(i.id,i);}n.add=o;function e(i){try{let a=q.get(i);if(!a){console.warn(`[NQTR] Quest ${i} not found, you should register it first`);return}return a}catch(a){u.error(`Error while getting Quest ${i}`,a);return}}n.get=e;function t(){return Array.from(q.values())}n.values=t;function r(i){return q.has(i)}n.has=r;})(ne||={});var E=new pixiVn.CachedMap({cacheSize:20}),L=new pixiVn.CachedMap({cacheSize:20}),$=new pixiVn.CachedMap({cacheSize:20}),ae;(n=>{function o(i){if(Array.isArray(i)){i.forEach(m=>o(m));return}E.has(i.id)&&console.warn(`[NQTR] Room id ${i.id} already exists, it will be overwritten`),E.set(i.id,i);let a=i.location;L.set(a.id,a);let s=a?.map;s&&$.set(s.id,s);}n.add=o;function e(i){try{let a=E.get(i);if(!a){console.warn(`[NQTR] Room ${i} not found, you should register it first`);return}return a}catch(a){u.error(`Error while getting Room ${i}`,a);return}}n.get=e;function t(){return Array.from(E.values())}n.values=t;function r(i){return E.has(i)}n.has=r;})(ae||={});var I=ae;var w=class{get rooms(){return I.values()}get locations(){return Array.from(L.values())}getLocationById(e){return L.get(e)}get maps(){return Array.from($.values())}getMapById(e){return $.get(e)}get currentRoomId(){return pixiVn.storage.getVariable(p)}get currentRoom(){let e=this.currentRoomId;if(!e){u.error("The current room has not yet been set");return}let t=I.get(e);if(!t){u.error(`Current room ${e} not found`);return}return t}set currentRoom(e){if(typeof e!="string"&&(e=e.id),!I.get(e)){u.error(`The room ${e} is not registered, so it can't be set as current room`);return}let r=pixiVn.storage.getVariable(p);r!==e&&(C({type:"editroom",prev:r,value:e}),pixiVn.storage.setVariable(p,e));}get currentLocation(){return this.currentRoom?.location}get currentMap(){return this.currentRoom?.location.map}clearExpiredActivities(){I.values().forEach(e=>{e.clearExpiredActivities();});}};var Y="___nqtr-temporary_commitment___",N=class{get fixedRoutine(){return [...M.values()]}set fixedRoutine(e){e.forEach(t=>{M.has(t.id)&&console.warn(`[NQTR] Commitment id ${t.id} already exists, it will be overwritten`),M.set(t.id,t);});}get temporaryRoutine(){let e=pixiVn.storage.getVariable(Y);return e?e.map(r=>v.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(!v.get(r.id)){console.warn(`[NQTR] Commitment ${r.id} not found, it will be ignored`);return}return r.id}).filter(r=>r!==void 0);pixiVn.storage.setVariable(Y,t);}find(e){return v.get(e)}remove(e){Array.isArray(e)||(e=[e]);let t=e.map(n=>n.id),r=pixiVn.storage.getVariable(Y);r&&(r=r.filter(n=>!t.includes(n)),pixiVn.storage.setVariable(Y,r));}clearExpiredRoutine(){v.values().forEach(e=>{e.expired&&S.delete(e.id);});}get currentRoutine(){let e={};return [...this.fixedRoutine,...this.temporaryRoutine].forEach(t=>{t.isActive&&(t.characters.length>0?t.characters.every(n=>!e[n.id]||t.priority>e[n.id].priority)&&t.characters.forEach(n=>{e[n.id]=t;}):u.error(`The commitment ${t.id} has no characters assigned`));}),Object.values(e)}get currentRoomRoutine(){return g.currentRoom?.routine||[]}getCommitmentByCharacter(e){this.currentRoutine.forEach(t=>{if(t.characters.map(r=>r.id).includes(e.id))return t});}};var d=class{static minDayHours=0;static maxDayHours=24;static defaultTimeSpent=1;static timeSlots=[];static weekLength=7;static weekendStartDay=this.weekLength-1;static weekDaysNames=[]};var Q=class{initialize(e){let{minDayHours:t=0,maxDayHours:r=24,defaultTimeSpent:n=1,timeSlots:i=[],weekLength:a=7,weekendStartDay:s=a-1,weekDaysNames:m=[]}=e;d.minDayHours=t,d.maxDayHours=r,d.defaultTimeSpent=n,d.timeSlots=i,d.weekLength=a,s>=d.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${a}, so will be ignored`):d.weekendStartDay=s,m.length!==a?console.warn(`[NQTR] Week days names should be equal to week length ${a}, so will be ignored`):d.weekDaysNames=m;}get minDayHours(){return d.minDayHours}get maxDayHours(){return d.maxDayHours}get defaultTimeSpent(){return d.defaultTimeSpent}get timeSlots(){return d.timeSlots}get weekLength(){return d.weekLength}get weekendStartDay(){return d.weekendStartDay}get weekDaysNames(){return d.weekDaysNames}get currentHour(){let e=pixiVn.storage.getVariable(l)||{};return e.hasOwnProperty("currentHour")&&typeof e.currentHour=="number"?e.currentHour:this.minDayHours}set currentHour(e){let t=pixiVn.storage.getVariable(l)||{},r={...t};typeof e=="number"?r.currentHour=e:delete r.currentHour,C({type:"edittime",prev:t,value:r}),pixiVn.storage.setVariable(l,r);}get currentDay(){let e=pixiVn.storage.getVariable(l)||{};return e.hasOwnProperty("currentDay")&&typeof e.currentDay=="number"?e.currentDay:0}set currentDay(e){let t=pixiVn.storage.getVariable(l)||{},r={...t};typeof e=="number"?r.currentDay=e:delete r.currentDay,C({type:"edittime",prev:t,value:r}),pixiVn.storage.setVariable(l,r);}get isWeekend(){return this.currentWeekDayNumber>=this.weekendStartDay}get currentWeekDayNumber(){return this.currentDay%this.weekLength+1}get currentDayName(){let e=this.currentWeekDayNumber-1;return e>=this.weekDaysNames.length?(console.warn(`[NQTR] Week day name is not defined for day ${e}`,this.weekDaysNames),""):this.weekDaysNames[e]}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.startHour,this.timeSlots[e+1].startHour))return e}return this.timeSlots.length-1}increaseHour(e=this.defaultTimeSpent){let t=this.currentHour+e;return t>=this.maxDayHours&&(this.increaseDay(),t=this.minDayHours+(t-this.maxDayHours)),this.currentHour=t,this.currentHour}increaseDay(e=this.minDayHours,t=1){let r=this.currentDay+t;return this.currentDay=r,this.currentHour=e,this.currentDay}nowIsBetween(e,t){e===void 0&&(e=this.minDayHours-1),t===void 0&&(t=this.maxDayHours+1);let r=this.currentHour;return e<t?r>=e&&r<t:r>=e||r<t}};var c=new Q,g=new w,V=new N;function C(o){pixiVn.storage.setVariable(J,o);}function he(){return pixiVn.storage.getVariable(J)}function oe(){let o=he(),e=g.currentRoom;if(!e||!e.automaticFunction){pixiVn.narration.addCurrentStepToHistory();return}switch(o?.type){case "editroom":pixiVn.storage.setVariable(p,o.prev),pixiVn.narration.addCurrentStepToHistory(),pixiVn.storage.setVariable(p,e.id);break;case "edittime":let t=pixiVn.storage.getVariable(l)||{};pixiVn.storage.setVariable(l,o.prev),pixiVn.narration.addCurrentStepToHistory(),pixiVn.storage.setVariable(l,t);break}}var ye="__nqtr-activity__",h=class extends pixiVn.StoredClassModel{constructor(t,r,n,i=ye){super(i,t);this._onRun=r;this._fromHour=n.fromHour,this._toHour=n.toHour,this._fromDay=n.fromDay,this._toDay=n.toDay;}_fromHour;get fromHour(){return this._fromHour}_toHour;get toHour(){return this._toHour}_fromDay;get fromDay(){return this._fromDay}_toDay;get toDay(){return this._toDay}get run(){return async t=>(oe(),await this._onRun(this,t))}get expired(){return !!(this.toDay&&this.toDay<=c.currentDay)}get isActive(){return !(this.fromDay&&this.fromDay>c.currentDay||this.toDay&&this.toDay<c.currentDay||!c.nowIsBetween(this.fromHour,this.toHour))}};var F=class extends h{constructor(e,t,r){super(e,t,{fromHour:r.fromHour,toHour:r.toHour,fromDay:r.fromDay,toDay:r.toDay}),this.defaultName=r.name||"",this.defaultDisabled=r.disabled||false,this.defaultHidden=r.hidden||false,this._icon=r.renderIcon;}defaultName;get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}defaultDisabled;get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?pixiVn.storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}defaultHidden;get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?pixiVn.storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}_icon;get icon(){return this._icon}};var Se="__nqtr-commitment__",_=class extends h{constructor(t,r,n,i,a){i=i||(()=>{});super(t,i,a,Se);this._characters=r;this._room=n;this.defaultExecutionType=a.executionType||"interaction",this.defaultPriority=a.priority;}defaultExecutionType;defaultPriority;get characters(){return this._characters}get room(){return this._room}get executionType(){return this.getStorageProperty("executionType")||this.defaultExecutionType}set executionType(t){this.setStorageProperty("executionType",t);}get priority(){return this.getStorageProperty("priority")||this.defaultPriority||0}set priority(t){this.setStorageProperty("priority",t);}};var z=class extends _{constructor(e,t,r,n){super(e,t?Array.isArray(t)?t:[t]:[],r,n.onRun,{executionType:n.executionType,priority:n.priority,fromHour:n.fromHour,toHour:n.toHour,fromDay:n.fromDay,toDay:n.toDay}),this._name=n.name||"",this._image=n.image,this.defaultDisabled=n.disabled||false,this.defaultHidden=n.hidden||false,this._icon=n.icon;}_name;get name(){return this._name}_image;get image(){return this._image}_icon;get icon(){return this._icon}defaultDisabled;get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?pixiVn.storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}defaultHidden;get hidden(){if(this.fromDay&&this.fromDay>c.currentDay||!c.nowIsBetween(this.fromHour,this.toHour)||!this.expired)return true;let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?pixiVn.storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}};var f=class extends pixiVn.StoredClassModel{constructor(t,r,n=[]){super(t,r);this.defaultActivities=n;}get defaultActivitiesIds(){return this.defaultActivities.map(t=>t.id)}get activeActivityScheduling(){return this.getStorageProperty("activeActivityScheduling")||{}}get excludedActivitiesScheduling(){return this.getStorageProperty("excludedActivitiesScheduling")||{}}removeActivityScheduling(t){let r=this.activeActivityScheduling;delete r[t],this.setStorageProperty("activeActivityScheduling",r);let n=this.excludedActivitiesScheduling;delete n[t],this.setStorageProperty("excludedActivitiesScheduling",n);}editActivityScheduling(t,r){this.removeActivityScheduling(t);let n=this.activeActivityScheduling;n[t]=r,this.setStorageProperty("activeActivityScheduling",n);}editExcludedActivityScheduling(t,r){this.removeActivityScheduling(t);let n=this.excludedActivitiesScheduling;n[t]=r,this.setStorageProperty("excludedActivitiesScheduling",n);}get additionalActivitiesIds(){return this.getStorageProperty("additionalActivitiesIds")||[]}get excludedActivitiesIds(){return this.getStorageProperty("excludedActivitiesIds")||[]}addActivity(t,r={}){let{hours:n,fromDay:i,toDay:a}=r,s={};if(n){if(n.from>=n.to)throw new Error("[NQTR] The from hour must be less than the to hour.");s.fromHour=n.from;}if(i===0&&console.warn("[NQTR] The from day must be greater than 0, so it will be ignored."),a===0&&console.warn("[NQTR] The to day must be greater than 0, so it will be ignored."),i&&a&&i>=a)throw new Error("[NQTR] The from day must be less than the to day.");if(i&&(s.fromDay=i),a&&(s.toDay=a),this.defaultActivitiesIds.includes(t.id)){console.warn(`[NQTR] Activity with id ${t.id} already exists, so it will be ignored.`);return}let m=this.additionalActivitiesIds;if(m.includes(t.id)){if(Object.keys(s).length){this.editActivityScheduling(t.id,s);return}else if(this.excludedActivitiesIds.includes(t.id)){this.removeActivityScheduling(t.id),console.log(`[NQTR] Activity with id ${t.id} was excluded, so it will be associated with this class again.`);return}console.warn(`[NQTR] Activity with id ${t.id} already exists, so it will be ignored.`);return}m.push(t.id),this.setStorageProperty("additionalActivitiesIds",m),Object.keys(s).length&&this.editActivityScheduling(t.id,s);}removeActivity(t,r={}){let{toDay:n}=r,i={};n===0&&console.warn("[NQTR] The to day must be greater than 0, so it will be ignored."),n&&(i.toDay=n);let a=this.additionalActivitiesIds;if(a.includes(t.id)){if(Object.keys(i).length){this.editExcludedActivityScheduling(t.id,i);return}a=a.filter(s=>s!==t.id),this.setStorageProperty("additionalActivitiesIds",a);}else if(this.defaultActivitiesIds.includes(t.id)){if(Object.keys(i).length){this.editExcludedActivityScheduling(t.id,i);return}let s=this.excludedActivitiesIds;s.push(t.id),this.setStorageProperty("excludedActivitiesIds",s);}else console.warn(`[NQTR] Activity with id ${t.id} not found, so it will be ignored.`);}clearExpiredActivities(){let t=this.activeActivityScheduling,r=this.excludedActivitiesScheduling,n=this.additionalActivitiesIds,i=this.excludedActivitiesIds;n.forEach(a=>{if(a in t){let{toDay:s}=t[a];s&&s<c.currentDay&&(this.removeActivityScheduling(a),n=n.filter(m=>m!==a));}}),i.forEach(a=>{if(a in r){let{toDay:s}=r[a];s&&s<c.currentDay&&(this.removeActivityScheduling(a),i=i.filter(m=>m!==a));}});}get activities(){let t=[];return Object.entries(this.activeActivityScheduling).forEach(([r,n])=>{let i=O.get(r),{fromDay:a=i?.fromDay,fromHour:s=i?.fromHour,toDay:m=i?.toDay,toHour:le=i?.toHour}=n;i&&c.nowIsBetween(s,le)&&!(a&&a>c.currentDay)&&!(m&&m<c.currentDay)&&t.push(i);}),Object.entries(this.excludedActivitiesScheduling).forEach(([r,n])=>{let i=O.get(r);i&&i.isActive&&!(n.toDay&&n.toDay>=c.currentDay)&&t.push(i);}),this.defaultActivities.forEach(r=>{r.isActive&&!t.find(n=>n.id===r.id)&&t.push(r);}),t}};var Ie="__nqtr-location__",x=class extends f{constructor(t,r,n=[]){super(Ie,t,n);this._map=r;}get map(){return this._map}get rooms(){return g.rooms.filter(t=>t.location.id===this.id)}};var G=class extends x{constructor(e,t,r={}){super(e,t,r.activities||[]),this.defaultName=r.name||"",this.defaultDisabled=r.disabled||false,this.defaultHidden=r.hidden||false,this._icon=r.icon;}defaultName;get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}defaultDisabled;get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?pixiVn.storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}defaultHidden;get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?pixiVn.storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}_icon;get icon(){return this._icon}};var be="__nqtr-map__",R=class extends f{constructor(e,t=[]){super(be,e,t);}get locations(){return g.locations.filter(e=>e.map.id===this.id)}};var K=class extends R{constructor(e,t={}){super(e,t.activities||[]),this.defaultName=t.name||"",this._image=t.image;}defaultName;get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}_image;get image(){return this._image}};var _e="__nqtr-room__",T=class extends f{constructor(t,r,n=[]){super(_e,t,n);this._location=r;}get routine(){return V.currentRoutine.filter(t=>t.room.id===this.id)}get location(){return this._location}get characters(){let t=[];return this.routine.forEach(r=>{t.push(...r.characters);}),t}get automaticFunction(){let t=this.routine.find(r=>r.executionType==="automatic")?.run;if(t)return async r=>{await t(r);}}};var j=class extends T{constructor(e,t,r={}){super(e,t,r.activities||[]),this.defaultName=r.name||"",this._image=r.image,this.defaultDisabled=r.disabled||false,this.defaultHidden=r.hidden||false,this._icon=r.icon;}defaultName;get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}_image;get image(){return this._image}defaultDisabled;get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?pixiVn.storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}defaultHidden;get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?pixiVn.storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}_icon;get icon(){return this._icon}get routine(){return V.currentRoutine.filter(e=>e.room.id===this.id)}};var Re="__nqtr-quest__",A=class extends pixiVn.StoredClassModel{constructor(t,r,n={}){super(Re,t);this._stages=r;this._onStart=n.onStart,this._onNextStage=n.onNextStage;}get stages(){return this._stages}get currentStageIndex(){return this.getStorageProperty("currentStageIndex")}set currentStageIndex(t){this.setStorageProperty("currentStageIndex",t);}get currentStage(){let t=this.currentStageIndex;if(!(t===void 0||t>=this.stages.length))return this.stages[t]}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(t){this.setStorageProperty("failed",t);}_onStart;get onStart(){return this._onStart}_onNextStage;get onNextStage(){return this._onNextStage}async start(t){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 r=this.currentStage;if(r&&r.start)return this.onStart&&await this.onStart(this,t),await r.start(t);u.error(`Quest ${this.id} has no start stage`);}async tryToGoNextStage(t){if(!this.inProgress)return false;let r=this.currentStage;return r?r.completed?await this.goNextStage(t):false:(u.error(`Quest ${this.id} has no current stage`),false)}async completeCurrentStageAndGoNext(t){let r=this.currentStage;return r?(r.completed=true,await this.goNextStage(t)):(u.error(`Quest ${this.id} has no current stage`),false)}async goNextStage(t){if(!this.inProgress)return console.warn(`[NQTR] Quest ${this.id} is not in progress`),false;let r=this.currentStage,n=this.currentStageIndex;if(!r||n===void 0)return u.error(`Quest ${this.id} has no current stage`),false;this.currentStageIndex=n+1,this.onNextStage&&await this.onNextStage(this,t),r&&r.onEnd&&await r.onEnd(r,t);let i=this.currentStage;return i&&(i.inizialize(),this.currentStageMustStart&&await this.startCurrentStage(t)),true}get currentStageMustStart(){let t=this.currentStage;return t?!t.started&&t.canStart&&!t.completed:false}async startCurrentStage(t){let r=this.currentStage;r&&this.currentStageMustStart?await r.start(t):console.warn(`[NQTR] Quest ${this.id} can't start the current stage`);}};var W=class extends A{constructor(e,t,r){super(e,t,{onStart:r.onStart,onNextStage:r.onNextStage}),this._name=r.name||"",this._description=r.description||"",this._icon=r.icon,this._image=r.image,this._inDevelopment=r.inDevelopment||false;}_name;get name(){return this._name}_description;get description(){return this._description}_icon;get icon(){return this._icon}_image;get image(){return this._image}_inDevelopment;get inDevelopment(){return this._inDevelopment}};var Ae="__nqtr-stage__",D=class extends pixiVn.StoredClassModel{constructor(e,t={}){super(Ae,e),this._onStart=t.onStart,this._onEnd=t.onEnd,this._daysRequiredToStart=t.daysRequiredToStart,this._questsRequiredToStart=t.questsRequiredToStart||[];}_onStart;get onStart(){return this._onStart}_onEnd;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 prevStageEndDay(){return this.getStorageProperty("prevStageEndDay")}set prevStageEndDay(e){this.setStorageProperty("prevStageEndDay",e);}get startDay(){let e=this.prevStageEndDay;if(e!==void 0)return e+this.daysRequiredToStart}get canStart(){let e=this.daysRequiredToStart;if(e>0){let t=this.prevStageEndDay;if(t===void 0||t+e>c.currentDay)return false}return !(this.questsRequiredToStart.length>0&&!this.questsRequiredToStart.every(t=>t.quest.currentStageIndex&&t.quest.currentStageIndex>=t.stageNumber))}inizialize(){this.daysRequiredToStart>0&&(this.prevStageEndDay=c.currentDay,console.log(`[NQTR] Stage ${this.id} will start on day ${this.startDay}`));}async start(e){this.canStart?(this.started=true,this.onStart&&await this.onStart(this,e)):console.warn(`[NQTR] Stage ${this.id} can't start`);}_daysRequiredToStart;get daysRequiredToStart(){return this._daysRequiredToStart||0}_questsRequiredToStart;get questsRequiredToStart(){return this._questsRequiredToStart||[]}};var U=class extends D{constructor(e,t){super(e,{onStart:t.onStart,onEnd:t.onEnd,daysRequiredToStart:t.daysRequiredToStart,questsRequiredToStart:t.questsRequiredToStart}),this._name=t.name||"",this._flags=t.flags||[],this._description=t.description||"",this._adviceDescription=t.adviceDescription||"",this._image=t.image,this._flagsRequiredToStart=t.flagsRequiredToStart||[],this._requestDescriptionToStart=t.requestDescriptionToStart||"";}_name;get name(){return this._name}_description;get description(){return this._description}_adviceDescription;get adviceDescription(){return this._adviceDescription}_image;get image(){return this._image}_flags;get flags(){return this._flags}_flagsRequiredToStart;get flagsRequiredToStart(){return this._flagsRequiredToStart}_requestDescriptionToStart;get requestDescriptionToStart(){return this._requestDescriptionToStart}get completed(){return super.completed?true:this.flags.length>0?!!this.flags.every(e=>pixiVn.storage.getFlag(e.flag)):false}set completed(e){super.completed=e;}get canStart(){return this.flagsRequiredToStart.length>0&&!this.flagsRequiredToStart.every(e=>pixiVn.storage.getFlag(e.flag))?false:super.canStart}};exports.ActivityBaseModel=F;exports.ActivityStoredClass=h;exports.CommitmentBaseModel=z;exports.CommitmentStoredClass=_;exports.LocationBaseModel=G;exports.LocationStoredClass=x;exports.MapBaseModel=K;exports.MapStoredClass=R;exports.QuestBaseModel=W;exports.QuestStoredClass=A;exports.RoomBaseModel=j;exports.RoomStoredClass=T;exports.StageBaseModel=U;exports.StageStoredClass=D;//# sourceMappingURL=index.cjs.map
|
|
1
|
+
'use strict';var pixiVn=require('@drincs/pixi-vn');var f="___nqtr-time_manager_data___",p="___nqtr-current_room_memory___",Z="___nqtr-last_event_memory___";var u;(a=>(a.log=(i,...n)=>console.log(`[NQTR] ${i}`,...n),a.warn=(i,...n)=>console.warn(`[NQTR] ${i}`,...n),a.error=(i,...n)=>console.error(`[NQTR] ${i}`,...n),a.info=(i,...n)=>console.info(`[NQTR] ${i}`,...n)))(u||={});var q=new pixiVn.CachedMap({cacheSize:20}),re;(a=>{function o(i){if(Array.isArray(i)){i.forEach(n=>a.add(n));return}q.set(i.id,i);}a.add=o;function e(i){try{let n=q.get(i);if(!n){console.warn(`[NQTR] Activity ${i} not found, you should register it first`);return}return n}catch(n){u.error(`Error while getting Activity ${i}`,n);return}}a.get=e;function t(){return Array.from(q.values())}a.values=t;function r(i){return q.has(i)}a.has=r;})(re||={});var L=re;var S=new pixiVn.CachedMap({cacheSize:20}),k=new pixiVn.CachedMap({cacheSize:20}),ne;(a=>{function o(i){if(Array.isArray(i)){i.forEach(n=>a.add(n));return}console.warn(`[NQTR] Registering commitment ${i.id}`,i),S.set(i.id,i);}a.add=o;function e(i){try{let n=S.get(i);if(!n){console.warn(`[NQTR] Commitment ${i} not found, you should register it first`);return}return n}catch(n){u.error(`Error while getting Commitment ${i}`,n);return}}a.get=e;function t(){return Array.from(S.values())}a.values=t;function r(i){return S.has(i)}a.has=r;})(ne||={});var v=ne;var E=new pixiVn.CachedMap({cacheSize:20}),ae;(a=>{function o(i){if(Array.isArray(i)){i.forEach(n=>o(n));return}E.has(i.id)&&console.warn(`[NQTR] Location id ${i.id} already exists, it will be overwritten`),E.set(i.id,i);}a.add=o;function e(i){try{let n=E.get(i);if(!n){console.warn(`[NQTR] Location ${i} not found, you should register it first`);return}return n}catch(n){u.error(`Error while getting Location ${i}`,n);return}}a.get=e;function t(){return Array.from(E.values())}a.values=t;function r(i){return E.has(i)}a.has=r;})(ae||={});var w=ae;var C=new pixiVn.CachedMap({cacheSize:20}),oe;(a=>{function o(i){if(Array.isArray(i)){i.forEach(n=>o(n));return}C.has(i.id)&&console.warn(`[NQTR] Map id ${i.id} already exists, it will be overwritten`),C.set(i.id,i);}a.add=o;function e(i){try{let n=C.get(i);if(!n){console.warn(`[NQTR] Map ${i} not found, you should register it first`);return}return n}catch(n){u.error(`Error while getting Map ${i}`,n);return}}a.get=e;function t(){return Array.from(C.values())}a.values=t;function r(i){return C.has(i)}a.has=r;})(oe||={});var P=oe;var $=new pixiVn.CachedMap({cacheSize:5}),se;(a=>{function o(i){if(Array.isArray(i)){i.forEach(n=>a.add(n));return}$.set(i.id,i);}a.add=o;function e(i){try{let n=$.get(i);if(!n){console.warn(`[NQTR] Quest ${i} not found, you should register it first`);return}return n}catch(n){u.error(`Error while getting Quest ${i}`,n);return}}a.get=e;function t(){return Array.from($.values())}a.values=t;function r(i){return $.has(i)}a.has=r;})(se||={});var Y=new pixiVn.CachedMap({cacheSize:20}),ue;(a=>{function o(i){if(Array.isArray(i)){i.forEach(m=>o(m));return}Y.set(i.id,i);let n=i.location;w.add(n);let s=n?.map;s&&P.add(s);}a.add=o;function e(i){try{let n=Y.get(i);if(!n){console.warn(`[NQTR] Room ${i} not found, you should register it first`);return}return n}catch(n){u.error(`Error while getting Room ${i}`,n);return}}a.get=e;function t(){return Array.from(Y.values())}a.values=t;function r(i){return Y.has(i)}a.has=r;})(ue||={});var I=ue;var N=class{get rooms(){return I.values()}get locations(){return w.values()}get maps(){return P.values()}get currentRoomId(){return pixiVn.storage.getVariable(p)}get currentRoom(){let e=this.currentRoomId;if(!e){u.error("The current room has not yet been set");return}let t=I.get(e);if(!t){u.error(`Current room ${e} not found`);return}return t}set currentRoom(e){if(typeof e!="string"&&(e=e.id),!I.get(e)){u.error(`The room ${e} is not registered, so it can't be set as current room`);return}let r=pixiVn.storage.getVariable(p);r!==e&&(Q({type:"editroom",prev:r,value:e}),pixiVn.storage.setVariable(p,e));}get currentLocation(){return this.currentRoom?.location}get currentMap(){return this.currentRoom?.location.map}clearExpiredActivities(){I.values().forEach(e=>{e.clearExpiredActivities();});}};var F="___nqtr-temporary_commitment___",H=class{get fixedRoutine(){return [...k.values()]}set fixedRoutine(e){e.forEach(t=>{k.has(t.id)&&console.warn(`[NQTR] Commitment id ${t.id} already exists, it will be overwritten`),k.set(t.id,t);});}get temporaryRoutine(){let e=pixiVn.storage.getVariable(F);return e?e.map(r=>v.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(!v.get(r.id)){console.warn(`[NQTR] Commitment ${r.id} not found, it will be ignored`);return}return r.id}).filter(r=>r!==void 0);pixiVn.storage.setVariable(F,t);}find(e){return v.get(e)}remove(e){Array.isArray(e)||(e=[e]);let t=e.map(a=>a.id),r=pixiVn.storage.getVariable(F);r&&(r=r.filter(a=>!t.includes(a)),pixiVn.storage.setVariable(F,r));}clearExpiredRoutine(){v.values().forEach(e=>{e.expired&&S.delete(e.id);});}get currentRoutine(){let e={};return [...this.fixedRoutine,...this.temporaryRoutine].forEach(t=>{t.isActive&&(t.characters.length>0?t.characters.every(a=>!e[a.id]||t.priority>e[a.id].priority)&&t.characters.forEach(a=>{e[a.id]=t;}):u.error(`The commitment ${t.id} has no characters assigned`));}),Object.values(e)}get currentRoomRoutine(){return g.currentRoom?.routine||[]}getCommitmentByCharacter(e){this.currentRoutine.forEach(t=>{if(t.characters.map(r=>r.id).includes(e.id))return t});}};var d=class{static minDayHours=0;static maxDayHours=24;static defaultTimeSpent=1;static timeSlots=[];static weekLength=7;static weekendStartDay=this.weekLength-1;static weekDaysNames=[]};var O=class{initialize(e){let{minDayHours:t=0,maxDayHours:r=24,defaultTimeSpent:a=1,timeSlots:i=[],weekLength:n=7,weekendStartDay:s=n-1,weekDaysNames:m=[]}=e;d.minDayHours=t,d.maxDayHours=r,d.defaultTimeSpent=a,d.timeSlots=i,d.weekLength=n,s>=d.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${n}, so will be ignored`):d.weekendStartDay=s,m.length!==n?console.warn(`[NQTR] Week days names should be equal to week length ${n}, so will be ignored`):d.weekDaysNames=m;}get minDayHours(){return d.minDayHours}get maxDayHours(){return d.maxDayHours}get defaultTimeSpent(){return d.defaultTimeSpent}get timeSlots(){return d.timeSlots}get weekLength(){return d.weekLength}get weekendStartDay(){return d.weekendStartDay}get weekDaysNames(){return d.weekDaysNames}get currentHour(){let e=pixiVn.storage.getVariable(f)||{};return e.hasOwnProperty("currentHour")&&typeof e.currentHour=="number"?e.currentHour:this.minDayHours}set currentHour(e){let t=pixiVn.storage.getVariable(f)||{},r={...t};typeof e=="number"?r.currentHour=e:delete r.currentHour,Q({type:"edittime",prev:t,value:r}),pixiVn.storage.setVariable(f,r);}get currentDay(){let e=pixiVn.storage.getVariable(f)||{};return e.hasOwnProperty("currentDay")&&typeof e.currentDay=="number"?e.currentDay:0}set currentDay(e){let t=pixiVn.storage.getVariable(f)||{},r={...t};typeof e=="number"?r.currentDay=e:delete r.currentDay,Q({type:"edittime",prev:t,value:r}),pixiVn.storage.setVariable(f,r);}get isWeekend(){return this.currentWeekDayNumber>=this.weekendStartDay}get currentWeekDayNumber(){return this.currentDay%this.weekLength+1}get currentDayName(){let e=this.currentWeekDayNumber-1;return e>=this.weekDaysNames.length?(console.warn(`[NQTR] Week day name is not defined for day ${e}`,this.weekDaysNames),""):this.weekDaysNames[e]}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.startHour,this.timeSlots[e+1].startHour))return e}return this.timeSlots.length-1}increaseHour(e=this.defaultTimeSpent){let t=this.currentHour+e;return t>=this.maxDayHours&&(this.increaseDay(),t=this.minDayHours+(t-this.maxDayHours)),this.currentHour=t,this.currentHour}increaseDay(e=this.minDayHours,t=1){let r=this.currentDay+t;return this.currentDay=r,this.currentHour=e,this.currentDay}nowIsBetween(e,t){e===void 0&&(e=this.minDayHours-1),t===void 0&&(t=this.maxDayHours+1);let r=this.currentHour;return e<t?r>=e&&r<t:r>=e||r<t}};var c=new O,g=new N,z=new H;function Q(o){pixiVn.storage.setVariable(Z,o);}function be(){return pixiVn.storage.getVariable(Z)}function de(){let o=be(),e=g.currentRoom;if(!e||!e.automaticFunction){pixiVn.narration.addCurrentStepToHistory();return}switch(o?.type){case "editroom":pixiVn.storage.setVariable(p,o.prev),pixiVn.narration.addCurrentStepToHistory(),pixiVn.storage.setVariable(p,e.id);break;case "edittime":let t=pixiVn.storage.getVariable(f)||{};pixiVn.storage.setVariable(f,o.prev),pixiVn.narration.addCurrentStepToHistory(),pixiVn.storage.setVariable(f,t);break}}var _e="__nqtr-activity__",h=class extends pixiVn.StoredClassModel{constructor(t,r,a,i=_e){super(i,t);this._onRun=r;this._fromHour=a.fromHour,this._toHour=a.toHour,this._fromDay=a.fromDay,this._toDay=a.toDay;}_fromHour;get fromHour(){return this._fromHour}_toHour;get toHour(){return this._toHour}_fromDay;get fromDay(){return this._fromDay}_toDay;get toDay(){return this._toDay}get run(){return async t=>(de(),await this._onRun(this,t))}get expired(){return !!(this.toDay&&this.toDay<=c.currentDay)}get isActive(){return !(this.fromDay&&this.fromDay>c.currentDay||this.toDay&&this.toDay<c.currentDay||!c.nowIsBetween(this.fromHour,this.toHour))}};var G=class extends h{constructor(e,t,r){super(e,t,{fromHour:r.fromHour,toHour:r.toHour,fromDay:r.fromDay,toDay:r.toDay}),this.defaultName=r.name||"",this.defaultDisabled=r.disabled||false,this.defaultHidden=r.hidden||false,this._icon=r.renderIcon;}defaultName;get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}defaultDisabled;get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?pixiVn.storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}defaultHidden;get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?pixiVn.storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}_icon;get icon(){return this._icon}};var Re="__nqtr-commitment__",x=class extends h{constructor(t,r,a,i,n){i=i||(()=>{});super(t,i,n,Re);this._characters=r;this._room=a;this.defaultExecutionType=n.executionType||"interaction",this.defaultPriority=n.priority;}defaultExecutionType;defaultPriority;get characters(){return this._characters}get room(){return this._room}get executionType(){return this.getStorageProperty("executionType")||this.defaultExecutionType}set executionType(t){this.setStorageProperty("executionType",t);}get priority(){return this.getStorageProperty("priority")||this.defaultPriority||0}set priority(t){this.setStorageProperty("priority",t);}};var K=class extends x{constructor(e,t,r,a){super(e,t?Array.isArray(t)?t:[t]:[],r,a.onRun,{executionType:a.executionType,priority:a.priority,fromHour:a.fromHour,toHour:a.toHour,fromDay:a.fromDay,toDay:a.toDay}),this._name=a.name||"",this._image=a.image,this.defaultDisabled=a.disabled||false,this.defaultHidden=a.hidden||false,this._icon=a.icon;}_name;get name(){return this._name}_image;get image(){return this._image}_icon;get icon(){return this._icon}defaultDisabled;get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?pixiVn.storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}defaultHidden;get hidden(){if(this.fromDay&&this.fromDay>c.currentDay||!c.nowIsBetween(this.fromHour,this.toHour)||!this.expired)return true;let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?pixiVn.storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}};var l=class extends pixiVn.StoredClassModel{constructor(t,r,a=[]){super(t,r);this.defaultActivities=a;}get defaultActivitiesIds(){return this.defaultActivities.map(t=>t.id)}get activeActivityScheduling(){return this.getStorageProperty("activeActivityScheduling")||{}}get excludedActivitiesScheduling(){return this.getStorageProperty("excludedActivitiesScheduling")||{}}removeActivityScheduling(t){let r=this.activeActivityScheduling;delete r[t],this.setStorageProperty("activeActivityScheduling",r);let a=this.excludedActivitiesScheduling;delete a[t],this.setStorageProperty("excludedActivitiesScheduling",a);}editActivityScheduling(t,r){this.removeActivityScheduling(t);let a=this.activeActivityScheduling;a[t]=r,this.setStorageProperty("activeActivityScheduling",a);}editExcludedActivityScheduling(t,r){this.removeActivityScheduling(t);let a=this.excludedActivitiesScheduling;a[t]=r,this.setStorageProperty("excludedActivitiesScheduling",a);}get additionalActivitiesIds(){return this.getStorageProperty("additionalActivitiesIds")||[]}get excludedActivitiesIds(){return this.getStorageProperty("excludedActivitiesIds")||[]}addActivity(t,r={}){let{hours:a,fromDay:i,toDay:n}=r,s={};if(a){if(a.from>=a.to)throw new Error("[NQTR] The from hour must be less than the to hour.");s.fromHour=a.from;}if(i===0&&console.warn("[NQTR] The from day must be greater than 0, so it will be ignored."),n===0&&console.warn("[NQTR] The to day must be greater than 0, so it will be ignored."),i&&n&&i>=n)throw new Error("[NQTR] The from day must be less than the to day.");if(i&&(s.fromDay=i),n&&(s.toDay=n),this.defaultActivitiesIds.includes(t.id)){console.warn(`[NQTR] Activity with id ${t.id} already exists, so it will be ignored.`);return}let m=this.additionalActivitiesIds;if(m.includes(t.id)){if(Object.keys(s).length){this.editActivityScheduling(t.id,s);return}else if(this.excludedActivitiesIds.includes(t.id)){this.removeActivityScheduling(t.id),console.log(`[NQTR] Activity with id ${t.id} was excluded, so it will be associated with this class again.`);return}console.warn(`[NQTR] Activity with id ${t.id} already exists, so it will be ignored.`);return}m.push(t.id),this.setStorageProperty("additionalActivitiesIds",m),Object.keys(s).length&&this.editActivityScheduling(t.id,s);}removeActivity(t,r={}){let{toDay:a}=r,i={};a===0&&console.warn("[NQTR] The to day must be greater than 0, so it will be ignored."),a&&(i.toDay=a);let n=this.additionalActivitiesIds;if(n.includes(t.id)){if(Object.keys(i).length){this.editExcludedActivityScheduling(t.id,i);return}n=n.filter(s=>s!==t.id),this.setStorageProperty("additionalActivitiesIds",n);}else if(this.defaultActivitiesIds.includes(t.id)){if(Object.keys(i).length){this.editExcludedActivityScheduling(t.id,i);return}let s=this.excludedActivitiesIds;s.push(t.id),this.setStorageProperty("excludedActivitiesIds",s);}else console.warn(`[NQTR] Activity with id ${t.id} not found, so it will be ignored.`);}clearExpiredActivities(){let t=this.activeActivityScheduling,r=this.excludedActivitiesScheduling,a=this.additionalActivitiesIds,i=this.excludedActivitiesIds;a.forEach(n=>{if(n in t){let{toDay:s}=t[n];s&&s<c.currentDay&&(this.removeActivityScheduling(n),a=a.filter(m=>m!==n));}}),i.forEach(n=>{if(n in r){let{toDay:s}=r[n];s&&s<c.currentDay&&(this.removeActivityScheduling(n),i=i.filter(m=>m!==n));}});}get activities(){let t=[],r=this.activeActivityScheduling;return this.additionalActivitiesIds.concat(this.defaultActivitiesIds).forEach(a=>{let i=L.get(a),{fromDay:n=i?.fromDay,fromHour:s=i?.fromHour,toDay:m=i?.toDay,toHour:he=i?.toHour}=r[a]||{};i&&c.nowIsBetween(s,he)&&!(n&&n>c.currentDay)&&!(m&&m<c.currentDay)&&t.push(i);}),Object.entries(this.excludedActivitiesScheduling).forEach(([a,i])=>{let n=L.get(a);n&&n.isActive&&!(i.toDay&&i.toDay>=c.currentDay)&&t.push(n);}),this.defaultActivities.forEach(a=>{a.isActive&&!t.find(i=>i.id===a.id)&&t.push(a);}),t}};var Ae="__nqtr-location__",_=class extends l{constructor(t,r,a=[]){super(Ae,t,a);this._map=r;}get map(){return this._map}get rooms(){return g.rooms.filter(t=>t.location.id===this.id)}};var W=class extends _{constructor(e,t,r={}){super(e,t,r.activities||[]),this.defaultName=r.name||"",this.defaultDisabled=r.disabled||false,this.defaultHidden=r.hidden||false,this._icon=r.icon;}defaultName;get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}defaultDisabled;get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?pixiVn.storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}defaultHidden;get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?pixiVn.storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}_icon;get icon(){return this._icon}};var De="__nqtr-map__",R=class extends l{constructor(e,t=[]){super(De,e,t);}get locations(){return g.locations.filter(e=>e.map.id===this.id)}};var j=class extends R{constructor(e,t={}){super(e,t.activities||[]),this.defaultName=t.name||"",this._image=t.image;}defaultName;get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}_image;get image(){return this._image}};var Ee="__nqtr-room__",T=class extends l{constructor(t,r,a=[]){super(Ee,t,a);this._location=r;}get routine(){return z.currentRoutine.filter(t=>t.room.id===this.id)}get location(){return this._location}get characters(){let t=[];return this.routine.forEach(r=>{t.push(...r.characters);}),t}get automaticFunction(){let t=this.routine.find(r=>r.executionType==="automatic")?.run;if(t)return async r=>{await t(r);}}};var U=class extends T{constructor(e,t,r={}){super(e,t,r.activities||[]),this.defaultName=r.name||"",this._image=r.image,this.defaultDisabled=r.disabled||false,this.defaultHidden=r.hidden||false,this._icon=r.icon;}defaultName;get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}_image;get image(){return this._image}defaultDisabled;get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?pixiVn.storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}defaultHidden;get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?pixiVn.storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}_icon;get icon(){return this._icon}get routine(){return z.currentRoutine.filter(e=>e.room.id===this.id)}};var Ce="__nqtr-quest__",A=class extends pixiVn.StoredClassModel{constructor(t,r,a={}){super(Ce,t);this._stages=r;this._onStart=a.onStart,this._onNextStage=a.onNextStage;}get stages(){return this._stages}get currentStageIndex(){return this.getStorageProperty("currentStageIndex")}set currentStageIndex(t){this.setStorageProperty("currentStageIndex",t);}get currentStage(){let t=this.currentStageIndex;if(!(t===void 0||t>=this.stages.length))return this.stages[t]}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(t){this.setStorageProperty("failed",t);}_onStart;get onStart(){return this._onStart}_onNextStage;get onNextStage(){return this._onNextStage}async start(t){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 r=this.currentStage;if(r&&r.start)return this.onStart&&await this.onStart(this,t),await r.start(t);u.error(`Quest ${this.id} has no start stage`);}async tryToGoNextStage(t){if(!this.inProgress)return false;let r=this.currentStage;return r?r.completed?await this.goNextStage(t):false:(u.error(`Quest ${this.id} has no current stage`),false)}async completeCurrentStageAndGoNext(t){let r=this.currentStage;return r?(r.completed=true,await this.goNextStage(t)):(u.error(`Quest ${this.id} has no current stage`),false)}async goNextStage(t){if(!this.inProgress)return console.warn(`[NQTR] Quest ${this.id} is not in progress`),false;let r=this.currentStage,a=this.currentStageIndex;if(!r||a===void 0)return u.error(`Quest ${this.id} has no current stage`),false;this.currentStageIndex=a+1,this.onNextStage&&await this.onNextStage(this,t),r&&r.onEnd&&await r.onEnd(r,t);let i=this.currentStage;return i&&(i.inizialize(),this.currentStageMustStart&&await this.startCurrentStage(t)),true}get currentStageMustStart(){let t=this.currentStage;return t?!t.started&&t.canStart&&!t.completed:false}async startCurrentStage(t){let r=this.currentStage;r&&this.currentStageMustStart?await r.start(t):console.warn(`[NQTR] Quest ${this.id} can't start the current stage`);}};var J=class extends A{constructor(e,t,r){super(e,t,{onStart:r.onStart,onNextStage:r.onNextStage}),this._name=r.name||"",this._description=r.description||"",this._icon=r.icon,this._image=r.image,this._inDevelopment=r.inDevelopment||false;}_name;get name(){return this._name}_description;get description(){return this._description}_icon;get icon(){return this._icon}_image;get image(){return this._image}_inDevelopment;get inDevelopment(){return this._inDevelopment}};var Ne="__nqtr-stage__",D=class extends pixiVn.StoredClassModel{constructor(e,t={}){super(Ne,e),this._onStart=t.onStart,this._onEnd=t.onEnd,this._daysRequiredToStart=t.daysRequiredToStart,this._questsRequiredToStart=t.questsRequiredToStart||[];}_onStart;get onStart(){return this._onStart}_onEnd;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 prevStageEndDay(){return this.getStorageProperty("prevStageEndDay")}set prevStageEndDay(e){this.setStorageProperty("prevStageEndDay",e);}get startDay(){let e=this.prevStageEndDay;if(e!==void 0)return e+this.daysRequiredToStart}get canStart(){let e=this.daysRequiredToStart;if(e>0){let t=this.prevStageEndDay;if(t===void 0||t+e>c.currentDay)return false}return !(this.questsRequiredToStart.length>0&&!this.questsRequiredToStart.every(t=>t.quest.currentStageIndex&&t.quest.currentStageIndex>=t.stageNumber))}inizialize(){this.daysRequiredToStart>0&&(this.prevStageEndDay=c.currentDay,console.log(`[NQTR] Stage ${this.id} will start on day ${this.startDay}`));}async start(e){this.canStart?(this.started=true,this.onStart&&await this.onStart(this,e)):console.warn(`[NQTR] Stage ${this.id} can't start`);}_daysRequiredToStart;get daysRequiredToStart(){return this._daysRequiredToStart||0}_questsRequiredToStart;get questsRequiredToStart(){return this._questsRequiredToStart||[]}};var X=class extends D{constructor(e,t){super(e,{onStart:t.onStart,onEnd:t.onEnd,daysRequiredToStart:t.daysRequiredToStart,questsRequiredToStart:t.questsRequiredToStart}),this._name=t.name||"",this._flags=t.flags||[],this._description=t.description||"",this._adviceDescription=t.adviceDescription||"",this._image=t.image,this._flagsRequiredToStart=t.flagsRequiredToStart||[],this._requestDescriptionToStart=t.requestDescriptionToStart||"";}_name;get name(){return this._name}_description;get description(){return this._description}_adviceDescription;get adviceDescription(){return this._adviceDescription}_image;get image(){return this._image}_flags;get flags(){return this._flags}_flagsRequiredToStart;get flagsRequiredToStart(){return this._flagsRequiredToStart}_requestDescriptionToStart;get requestDescriptionToStart(){return this._requestDescriptionToStart}get completed(){return super.completed?true:this.flags.length>0?!!this.flags.every(e=>pixiVn.storage.getFlag(e.flag)):false}set completed(e){super.completed=e;}get canStart(){return this.flagsRequiredToStart.length>0&&!this.flagsRequiredToStart.every(e=>pixiVn.storage.getFlag(e.flag))?false:super.canStart}};exports.ActivityBaseModel=G;exports.ActivityStoredClass=h;exports.CommitmentBaseModel=K;exports.CommitmentStoredClass=x;exports.LocationBaseModel=W;exports.LocationStoredClass=_;exports.MapBaseModel=j;exports.MapStoredClass=R;exports.QuestBaseModel=J;exports.QuestStoredClass=A;exports.RoomBaseModel=U;exports.RoomStoredClass=T;exports.StageBaseModel=X;exports.StageStoredClass=D;//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|