@drincs/nqtr 0.5.7 → 0.7.0
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/LICENSE +479 -649
- package/dist/handlers.cjs +1 -0
- package/dist/handlers.d.mts +606 -0
- package/dist/handlers.d.ts +606 -0
- package/dist/handlers.mjs +1 -0
- package/dist/index.cjs +1 -2
- package/dist/index.d.mts +1391 -22
- package/dist/index.d.ts +1391 -22
- package/dist/index.mjs +1 -2
- package/dist/ink.cjs +1 -0
- package/dist/ink.mjs +0 -0
- package/dist/registries.cjs +1 -0
- package/dist/registries.d.mts +516 -0
- package/dist/registries.d.ts +516 -0
- package/dist/registries.mjs +1 -0
- package/package.json +43 -10
- package/dist/RoomInterface-COSoQndi.d.mts +0 -181
- package/dist/RoomInterface-VyDG8FVX.d.ts +0 -181
- package/dist/StageInterface-v96_K9Tg.d.mts +0 -188
- package/dist/StageInterface-v96_K9Tg.d.ts +0 -188
- package/dist/classes/index.cjs +0 -2
- package/dist/classes/index.cjs.map +0 -1
- package/dist/classes/index.d.mts +0 -514
- package/dist/classes/index.d.ts +0 -514
- package/dist/classes/index.mjs +0 -2
- package/dist/classes/index.mjs.map +0 -1
- package/dist/decorators/index.cjs +0 -2
- package/dist/decorators/index.cjs.map +0 -1
- package/dist/decorators/index.d.mts +0 -163
- package/dist/decorators/index.d.ts +0 -163
- package/dist/decorators/index.mjs +0 -2
- package/dist/decorators/index.mjs.map +0 -1
- package/dist/index-BrR28W31.d.mts +0 -269
- package/dist/index-CKbOHqkF.d.ts +0 -269
- package/dist/index-DQXOfV1Z.d.ts +0 -199
- package/dist/index-jntH7-J_.d.mts +0 -199
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/interface/index.cjs +0 -2
- package/dist/interface/index.cjs.map +0 -1
- package/dist/interface/index.d.mts +0 -5
- package/dist/interface/index.d.ts +0 -5
- package/dist/interface/index.mjs +0 -2
- package/dist/interface/index.mjs.map +0 -1
- package/dist/managers/index.cjs +0 -2
- package/dist/managers/index.cjs.map +0 -1
- package/dist/managers/index.d.mts +0 -6
- package/dist/managers/index.d.ts +0 -6
- package/dist/managers/index.mjs +0 -2
- package/dist/managers/index.mjs.map +0 -1
- package/dist/types/index.cjs +0 -2
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.d.mts +0 -65
- package/dist/types/index.d.ts +0 -65
- package/dist/types/index.mjs +0 -2
- package/dist/types/index.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import {CachedMap,storage,StoredClassModel,narration}from'@drincs/pixi-vn';var Te=Object.defineProperty;var X=(o,e)=>{for(var t in e)Te(o,t,{get:e[t],enumerable:true});};var ne={};X(ne,{ActivityBaseModel:()=>q,ActivityStoredClass:()=>f,CommitmentBaseModel:()=>$,CommitmentStoredClass:()=>v,LocationBaseModel:()=>B,LocationStoredClass:()=>I,MapBaseModel:()=>k,MapStoredClass:()=>x,QuestBaseModel:()=>Y,QuestStoredClass:()=>_,RoomBaseModel:()=>z,RoomStoredClass:()=>R,StageBaseModel:()=>F,StageStoredClass:()=>T});var ie={};X(ie,{navigator:()=>y,questsNotebook:()=>Ce,routine:()=>re,timeTracker:()=>d});var l="___nqtr-time_manager_data___",p="___nqtr-current_room_memory___",Z="___nqtr-last_event_memory___";var ee={};X(ee,{RegisteredActivities:()=>D,RegisteredCommitments:()=>h,RegisteredLocations:()=>A,RegisteredMaps:()=>E,RegisteredQuests:()=>C,RegisteredRooms:()=>S});var s;(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)))(s||={});var V=new CachedMap({cacheSize:20}),oe;(n=>{function o(i){if(Array.isArray(i)){i.forEach(a=>n.add(a));return}V.set(i.id,i);}n.add=o;function e(i){try{let a=V.get(i);if(!a){console.warn(`[NQTR] Activity ${i} not found, you should register it first`);return}return a}catch(a){s.error(`Error while getting Activity ${i}`,a);return}}n.get=e;function t(){return Array.from(V.values())}n.values=t;function r(i){return V.has(i)}n.has=r;})(oe||={});var D=oe;var b=new CachedMap({cacheSize:20}),H=new CachedMap({cacheSize:20}),ue;(n=>{function o(i){if(Array.isArray(i)){i.forEach(a=>n.add(a));return}b.set(i.id,i);}n.add=o;function e(i){try{let a=b.get(i);if(!a){console.warn(`[NQTR] Commitment ${i} not found, you should register it first`);return}return a}catch(a){s.error(`Error while getting Commitment ${i}`,a);return}}n.get=e;function t(){return Array.from(b.values())}n.values=t;function r(i){return b.has(i)}n.has=r;})(ue||={});var h=ue;var G=new CachedMap({cacheSize:20}),de;(n=>{function o(i){if(Array.isArray(i)){i.forEach(a=>o(a));return}G.set(i.id,i);}n.add=o;function e(i){try{let a=G.get(i);if(!a){console.warn(`[NQTR] Location ${i} not found, you should register it first`);return}return a}catch(a){s.error(`Error while getting Location ${i}`,a);return}}n.get=e;function t(){return Array.from(G.values())}n.values=t;function r(i){return G.has(i)}n.has=r;})(de||={});var A=de;var K=new CachedMap({cacheSize:20}),ce;(n=>{function o(i){if(Array.isArray(i)){i.forEach(a=>o(a));return}K.set(i.id,i);}n.add=o;function e(i){try{let a=K.get(i);if(!a){console.warn(`[NQTR] Map ${i} not found, you should register it first`);return}return a}catch(a){s.error(`Error while getting Map ${i}`,a);return}}n.get=e;function t(){return Array.from(K.values())}n.values=t;function r(i){return K.has(i)}n.has=r;})(ce||={});var E=ce;var W=new CachedMap({cacheSize:5}),le;(n=>{function o(i){if(Array.isArray(i)){i.forEach(a=>n.add(a));return}W.set(i.id,i);}n.add=o;function e(i){try{let a=W.get(i);if(!a){console.warn(`[NQTR] Quest ${i} not found, you should register it first`);return}return a}catch(a){s.error(`Error while getting Quest ${i}`,a);return}}n.get=e;function t(){return Array.from(W.values())}n.values=t;function r(i){return W.has(i)}n.has=r;})(le||={});var C=le;var U=new CachedMap({cacheSize:20}),me;(n=>{function o(i){if(Array.isArray(i)){i.forEach(m=>o(m));return}U.set(i.id,i);let a=i.location;A.add(a);let u=a?.map;u&&E.add(u);}n.add=o;function e(i){try{let a=U.get(i);if(!a){console.warn(`[NQTR] Room ${i} not found, you should register it first`);return}return a}catch(a){s.error(`Error while getting Room ${i}`,a);return}}n.get=e;function t(){return Array.from(U.values())}n.values=t;function r(i){return U.has(i)}n.has=r;})(me||={});var S=me;function w(o){storage.setVariable(Z,o);}function ge(){return storage.getVariable(Z)}var N=class{get rooms(){return S.values()}get locations(){return A.values()}get maps(){return E.values()}get currentRoomId(){return storage.getVariable(p)}get currentRoom(){let e=this.currentRoomId;if(!e){s.error("The current room has not yet been set");return}let t=S.get(e);if(!t){s.error(`Current room ${e} not found`);return}return t}set currentRoom(e){if(typeof e!="string"&&(e=e.id),!S.get(e)){s.error(`The room ${e} is not registered, so it can't be set as current room`);return}let r=storage.getVariable(p);r!==e&&(w({type:"editroom",prev:r,value:e}),storage.setVariable(p,e));}get currentLocation(){return this.currentRoom?.location}get currentMap(){return this.currentRoom?.location.map}clearExpiredActivities(){S.values().forEach(e=>{e.clearExpiredActivities();});}};var M=class{get quests(){return C.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 C.get(e)}async startsStageMustBeStarted(e){let t=this.quests.map(r=>r.currentStageMustStart?r.startCurrentStage(e):Promise.resolve());await Promise.all(t);}};var J="___nqtr-temporary_commitment___",Q=class{get fixedRoutine(){return [...H.values()]}set fixedRoutine(e){e.forEach(t=>{H.has(t.id)&&console.warn(`[NQTR] Commitment id ${t.id} already exists, it will be overwritten`),H.set(t.id,t);});}get temporaryRoutine(){let e=storage.getVariable(J);return e?e.map(r=>h.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(!h.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.setVariable(J,t);}find(e){return h.get(e)}remove(e){Array.isArray(e)||(e=[e]);let t=e.map(n=>n.id),r=storage.getVariable(J);r&&(r=r.filter(n=>!t.includes(n)),storage.setVariable(J,r));}clearExpiredRoutine(){h.values().forEach(e=>{e.expired&&b.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;}):s.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 c=class{static dayStartTime=0;static dayEndTime=24;static defaultTimeSpent=1;static timeSlots=[];static weekLength=7;static weekendStartDay=this.weekLength-1;static getDayName};var O=class{initialize(e){let{dayStartTime:t=0,dayEndTime:r=24,defaultTimeSpent:n=1,timeSlots:i=[],weekLength:a=7,weekendStartDay:u=a-1,getDayName:m}=e;c.dayStartTime=t,c.dayEndTime=r,c.defaultTimeSpent=n,c.timeSlots=i,c.weekLength=a,u>=c.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${a}, so will be ignored`):c.weekendStartDay=u,c.getDayName=m;}get dayStartTime(){return c.dayStartTime}get dayEndTime(){return c.dayEndTime}get defaultTimeSpent(){return c.defaultTimeSpent}get timeSlots(){return c.timeSlots}get weekLength(){return c.weekLength}get weekendStartDay(){return c.weekendStartDay}get getDayName(){return c.getDayName}get currentTime(){let e=storage.getVariable(l)||{};return e.hasOwnProperty("currentTime")&&typeof e.currentTime=="number"?e.currentTime:this.dayStartTime}set currentTime(e){let t=storage.getVariable(l)||{},r={...t};typeof e=="number"?r.currentTime=e:delete r.currentTime,w({type:"edittime",prev:t,value:r}),storage.setVariable(l,r);}get currentDate(){let e=storage.getVariable(l)||{};return e.hasOwnProperty("currentDate")&&typeof e.currentDate=="number"?e.currentDate:0}set currentDate(e){let t=storage.getVariable(l)||{},r={...t};typeof e=="number"?r.currentDate=e:delete r.currentDate,w({type:"edittime",prev:t,value:r}),storage.setVariable(l,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 d=new O,y=new N,re=new Q,Ce=new M;var Me="__nqtr-activity__",f=class extends StoredClassModel{constructor(t,r,n,i=Me){super(i,t);this._onRun=r;this._timeSlot=n.timeSlot,this._dateScheduling=n.dateScheduling;}_timeSlot;get timeSlot(){return this._timeSlot}_dateScheduling;get dateScheduling(){return this._dateScheduling}addTempHistoryItem(){narration.addCurrentStepToHistory();}get run(){return async t=>(this.addTempHistoryItem(),await this._onRun(this,t))}get expired(){return !!(this.dateScheduling?.to&&this.dateScheduling.to<=d.currentDate)}get isActive(){return !(this.dateScheduling?.from&&this.dateScheduling.from>d.currentDate||this.dateScheduling?.to&&this.dateScheduling.to<d.currentDate||!d.nowIsBetween(this.timeSlot?.from,this.timeSlot?.to))}};var q=class extends f{constructor(e,t,r){super(e,t,{dateScheduling:r.dateScheduling,timeSlot:r.timeSlot}),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"?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"?storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}_icon;get icon(){return this._icon}};var Qe="__nqtr-commitment__",v=class extends f{constructor(t,r,n,i,a){i=i||(()=>{});super(t,i,a,Qe);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);}addTempHistoryItem(){let t=y.currentRoom;if(!t||this.executionType!=="automatic")return super.addTempHistoryItem();let r=ge();switch(r?.type){case "editroom":storage.setVariable(p,r.prev),super.addTempHistoryItem(),storage.setVariable(p,t.id);break;case "edittime":let n=storage.getVariable(l)||{};storage.setVariable(l,r.prev),super.addTempHistoryItem(),storage.setVariable(l,n);break}}};var $=class extends v{constructor(e,t,r,n){super(e,t?Array.isArray(t)?t:[t]:[],r,n.onRun,{executionType:n.executionType,priority:n.priority,timeSlot:n.timeSlot,dateScheduling:n.dateScheduling}),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"?storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}defaultHidden;get hidden(){if(this.dateScheduling?.from&&this.dateScheduling.from>d.currentDate||!d.nowIsBetween(this.timeSlot?.from,this.timeSlot?.to)||!this.expired)return true;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(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")||[]}get activitiesIds(){return this.additionalActivitiesIds.concat(this.defaultActivitiesIds)}addActivity(t,r={}){let{timeSlot:n,dateScheduling:i}=r,{to:a=d.dayEndTime+1}=n||{};if(n&&n.from>=a)throw new Error("[NQTR] The from time must be less than the to time.");if(i?.from!==void 0&&i?.to!==void 0&&i?.from>=i?.to)throw new Error("[NQTR] The from day/date must be less than the to day/date.");if(this.defaultActivitiesIds.includes(t.id)){console.warn(`[NQTR] Activity with id ${t.id} already exists, so it will be ignored.`);return}let u=this.additionalActivitiesIds;u.includes(t.id)?console.warn(`[NQTR] Activity with id ${t.id} already exists, so it will be ignored.`):(u.push(t.id),this.setStorageProperty("additionalActivitiesIds",u)),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.`)),(n||i)&&this.editActivityScheduling(t.id,{timeSlot:n,dateScheduling:i});}removeActivity(t,r={}){let{to:n}=r,i=typeof t=="string"?t:t.id,a=this.additionalActivitiesIds;if(a.includes(i)){if(n!==void 0){this.editExcludedActivityScheduling(i,{dateScheduling:{to:n}});return}a=a.filter(u=>u!==i),this.setStorageProperty("additionalActivitiesIds",a),this.removeActivityScheduling(i);}else if(this.defaultActivitiesIds.includes(i)){if(n!==void 0){this.editExcludedActivityScheduling(i,{dateScheduling:{to:n}});return}let u=this.excludedActivitiesIds;u.push(i),this.setStorageProperty("excludedActivitiesIds",u);}else console.warn(`[NQTR] Activity with id ${i} 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{to:u}=t[a].dateScheduling||{};u&&u<d.currentDate&&(this.removeActivityScheduling(a),n=n.filter(m=>m!==a));}}),i.forEach(a=>{if(a in r){let{to:u}=r[a].dateScheduling||{};u&&u<d.currentDate&&(this.removeActivityScheduling(a),i=i.filter(m=>m!==a));}});}get activities(){let t=[],r=this.activeActivityScheduling;return this.additionalActivitiesIds.concat(this.defaultActivitiesIds).forEach(n=>{let i=D.get(n),{dateScheduling:a,timeSlot:u}=r[n]||{},{from:m=i?.dateScheduling?.from,to:ae=i?.dateScheduling?.to}=a||{},{from:Re=i?.timeSlot?.from,to:_e=i?.timeSlot?.to}=u||{};i&&d.nowIsBetween(Re,_e)&&!(m&&m>d.currentDate)&&!(ae&&ae<d.currentDate)&&t.push(i);}),Object.entries(this.excludedActivitiesScheduling).forEach(([n,i])=>{let a=D.get(n);a&&a.isActive&&!(i.dateScheduling&&i.dateScheduling.to!==void 0&&i.dateScheduling.to>=d.currentDate)&&t.push(a);}),this.defaultActivities.forEach(n=>{n.isActive&&!t.find(i=>i.id===n.id)&&t.push(n);}),t}};var qe="__nqtr-location__",I=class extends g{constructor(t,r,n=[]){super(qe,t,n);this._map=r;}get map(){return this._map}get rooms(){return y.rooms.filter(t=>t.location.id===this.id)}};var B=class extends I{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"?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"?storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}_icon;get icon(){return this._icon}};var Le="__nqtr-map__",x=class extends g{constructor(e,t=[]){super(Le,e,t);}get locations(){return y.locations.filter(e=>e.map.id===this.id)}};var k=class extends x{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__",R=class extends g{constructor(t,r,n=[]){super($e,t,n);this._location=r;}get routine(){return re.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 automaticFunctions(){return this.routine.filter(t=>t.executionType==="automatic"&&t.run).map(t=>async n=>{await t.run(n);})}};var z=class extends R{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"?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"?storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}_icon;get icon(){return this._icon}};var ke="__nqtr-quest__",_=class extends StoredClassModel{constructor(t,r,n={}){super(ke,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){s.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);s.error(`Quest ${this.id} has no start stage`);}tryToGoNextStage(t){return this.goNextIfCompleted(t)}async goNextIfCompleted(t){if(!this.inProgress)return false;let r=this.currentStage;return r?r.completed?await this.forceGoNext(t):false:(s.error(`Quest ${this.id} has no current stage`),false)}completeCurrentStageAndGoNext(t){return this.goNext(t)}async goNext(t){let r=this.currentStage;return r?(r.completed=true,await this.forceGoNext(t)):(s.error(`Quest ${this.id} has no current stage`),false)}goNextStage(t){return this.forceGoNext(t)}async forceGoNext(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 s.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 Y=class extends _{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 Ye="__nqtr-stage__",T=class extends StoredClassModel{constructor(e,t={}){super(Ye,e),this._onStart=t.onStart,this._onEnd=t.onEnd,this._deltaDateRequired=t.deltaDateRequired,this._questsRequired=t.questsRequired||[];}_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 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>d.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=d.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`);}_deltaDateRequired;get deltaDateRequired(){return this._deltaDateRequired||0}_questsRequired;get questsRequired(){return this._questsRequired||[]}};var F=class extends T{constructor(e,t){super(e,{onStart:t.onStart,onEnd:t.onEnd,deltaDateRequired:t.deltaDateRequired,questsRequired:t.questsRequired}),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||"";}_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}_flagsRequired;get flagsRequired(){return this._flagsRequired}_requestDescriptionToStart;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 Ie={};var xe={};var Fe={...ne,...ee,...Ie,...ie,...xe},ai=Fe;export{q as ActivityBaseModel,f as ActivityStoredClass,$ as CommitmentBaseModel,v as CommitmentStoredClass,B as LocationBaseModel,I as LocationStoredClass,k as MapBaseModel,x as MapStoredClass,Y as QuestBaseModel,_ as QuestStoredClass,D as RegisteredActivities,h as RegisteredCommitments,A as RegisteredLocations,E as RegisteredMaps,C as RegisteredQuests,S as RegisteredRooms,z as RoomBaseModel,R as RoomStoredClass,F as StageBaseModel,T as StageStoredClass,ai as default,y as navigator,Ce as questsNotebook,re as routine,d as timeTracker};//# sourceMappingURL=index.mjs.map
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
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 V=Object.defineProperty;var me=(o,r,e)=>r in o?V(o,r,{enumerable:true,configurable:true,writable:true,value:e}):o[r]=e;var j=(o,r)=>{for(var e in r)V(o,e,{get:r[e],enumerable:true});};var a=(o,r,e)=>me(o,typeof r!="symbol"?r+"":r,e);var G={};j(G,{ActivityBaseModel:()=>b,ActivityStoredClass:()=>f,CommitmentBaseModel:()=>P,CommitmentStoredClass:()=>S,LocationBaseModel:()=>D,LocationStoredClass:()=>v,MapBaseModel:()=>C,MapStoredClass:()=>I,QuestBaseModel:()=>q,QuestStoredClass:()=>x,RoomBaseModel:()=>w,RoomStoredClass:()=>_,StageBaseModel:()=>O,StageStoredClass:()=>R});var pe="__nqtr-activity__",f=class extends StoredClassModel{constructor(e,t,i,n=pe){super(n,e);this._onRun=t;a(this,"_timeSlot");a(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)}get isActive(){return !(this.dateScheduling?.from&&this.dateScheduling.from>timeTracker.currentDate||this.dateScheduling?.to&&this.dateScheduling.to<timeTracker.currentDate||!timeTracker.nowIsBetween(this.timeSlot?.from,this.timeSlot?.to))}};var b=class extends f{constructor(e,t,i){super(e,t,{dateScheduling:i.dateScheduling,timeSlot:i.timeSlot});a(this,"defaultName");a(this,"defaultDisabled");a(this,"defaultHidden");a(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___",h="___nqtr-current_room_memory___",F="___nqtr-last_event_memory___";function A(o){storage.set(F,o);}function Z(){return storage.get(F)}var Se="__nqtr-commitment__",S=class extends f{constructor(e,t,i,n,s){n=n||(()=>{});super(e,n,s,Se);this._characters=t;this._room=i;a(this,"defaultExecutionType");a(this,"defaultPriority");this.defaultExecutionType=s.executionType||"interaction",this.defaultPriority=s.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=Z();switch(t?.type){case "editroom":storage.set(h,t.prev),super.addTempHistoryItem(),storage.set(h,e.id);break;case "edittime":let i=storage.get(l)||{};storage.set(l,t.prev),super.addTempHistoryItem(),storage.set(l,i);break}}};var P=class extends S{constructor(e,t,i,n){super(e,t?Array.isArray(t)?t:[t]:[],i,n.onRun,{executionType:n.executionType,priority:n.priority,timeSlot:n.timeSlot,dateScheduling:n.dateScheduling});a(this,"_name");a(this,"_image");a(this,"_icon");a(this,"defaultDisabled");a(this,"defaultHidden");this._name=n.name||"",this._image=n.image,this.defaultDisabled=n.disabled||false,this.defaultHidden=n.hidden||false,this._icon=n.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(){if(this.dateScheduling?.from&&this.dateScheduling.from>timeTracker.currentDate||!timeTracker.nowIsBetween(this.timeSlot?.from,this.timeSlot?.to)||!this.expired)return true;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:n}=t,{to:s=timeTracker.dayEndTime+1}=i||{};if(i&&i.from>=s)throw new Error("[NQTR] The from time must be less than the to time.");if(n?.from!==void 0&&n?.to!==void 0&&n?.from>=n?.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 d=this.additionalActivitiesIds;d.includes(e.id)?console.warn(`[NQTR] Activity with id ${e.id} already exists, so it will be ignored.`):(d.push(e.id),this.setStorageProperty("additionalActivitiesIds",d)),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||n)&&this.editActivityScheduling(e.id,{timeSlot:i,dateScheduling:n});}removeActivity(e,t={}){let{to:i}=t,n=typeof e=="string"?e:e.id,s=this.additionalActivitiesIds;if(s.includes(n)){if(i!==void 0){this.editExcludedActivityScheduling(n,{dateScheduling:{to:i}});return}s=s.filter(d=>d!==n),this.setStorageProperty("additionalActivitiesIds",s),this.removeActivityScheduling(n);}else if(this.defaultActivitiesIds.includes(n)){if(i!==void 0){this.editExcludedActivityScheduling(n,{dateScheduling:{to:i}});return}let d=this.excludedActivitiesIds;d.push(n),this.setStorageProperty("excludedActivitiesIds",d);}else console.warn(`[NQTR] Activity with id ${n} not found, so it will be ignored.`);}clearExpiredActivities(){let e=this.activeActivityScheduling,t=this.excludedActivitiesScheduling,i=this.additionalActivitiesIds,n=this.excludedActivitiesIds;i.forEach(s=>{if(s in e){let{to:d}=e[s].dateScheduling||{};d&&d<timeTracker.currentDate&&(this.removeActivityScheduling(s),i=i.filter(p=>p!==s));}}),n.forEach(s=>{if(s in t){let{to:d}=t[s].dateScheduling||{};d&&d<timeTracker.currentDate&&(this.removeActivityScheduling(s),n=n.filter(p=>p!==s));}});}get activities(){let e=[],t=this.activeActivityScheduling;return this.additionalActivitiesIds.concat(this.defaultActivitiesIds).forEach(i=>{let n=RegisteredActivities.get(i),{dateScheduling:s,timeSlot:d}=t[i]||{},{from:p=n?.dateScheduling?.from,to:W=n?.dateScheduling?.to}=s||{},{from:ce=n?.timeSlot?.from,to:le=n?.timeSlot?.to}=d||{};n&&timeTracker.nowIsBetween(ce,le)&&!(p&&p>timeTracker.currentDate)&&!(W&&W<timeTracker.currentDate)&&e.push(n);}),Object.entries(this.excludedActivitiesScheduling).forEach(([i,n])=>{let s=RegisteredActivities.get(i);s&&s.isActive&&!(n.dateScheduling&&n.dateScheduling.to!==void 0&&n.dateScheduling.to>=timeTracker.currentDate)&&e.push(s);}),this.defaultActivities.forEach(i=>{i.isActive&&!e.find(n=>n.id===i.id)&&e.push(i);}),e}};var Ie="__nqtr-location__",v=class extends g{constructor(e,t,i=[]){super(Ie,e,i);this._map=t;}get map(){return this._map}get rooms(){return navigator.rooms.filter(e=>e.location.id===this.id)}};var D=class extends v{constructor(e,t,i={}){super(e,t,i.activities||[]);a(this,"defaultName");a(this,"defaultDisabled");a(this,"defaultHidden");a(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__",I=class extends g{constructor(r,e=[]){super(xe,r,e);}get locations(){return navigator.locations.filter(r=>r.map.id===this.id)}};var C=class extends I{constructor(e,t={}){super(e,t.activities||[]);a(this,"defaultName");a(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 Te="__nqtr-room__",_=class extends g{constructor(e,t,i=[]){super(Te,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 w=class extends _{constructor(e,t,i={}){super(e,t,i.activities||[]);a(this,"defaultName");a(this,"_image");a(this,"defaultDisabled");a(this,"defaultHidden");a(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 c;(i=>(i.log=(n,...s)=>console.log(`[NQTR] ${n}`,...s),i.warn=(n,...s)=>console.warn(`[NQTR] ${n}`,...s),i.error=(n,...s)=>console.error(`[NQTR] ${n}`,...s),i.info=(n,...s)=>console.info(`[NQTR] ${n}`,...s)))(c||(c={}));var Ae="__nqtr-quest__",x=class extends StoredClassModel{constructor(e,t,i={}){super(Ae,e);this._stages=t;a(this,"_onStart");a(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){c.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);c.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:(c.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)):(c.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 c.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 n=this.currentStage;return n&&(n.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 q=class extends x{constructor(e,t,i){super(e,t,{onStart:i.onStart,onNextStage:i.onNextStage});a(this,"_name");a(this,"_description");a(this,"_icon");a(this,"_image");a(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 Pe="__nqtr-stage__",R=class extends StoredClassModel{constructor(e,t={}){super(Pe,e);a(this,"_onStart");a(this,"_onEnd");a(this,"_deltaDateRequired");a(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 R{constructor(e,t){super(e,{onStart:t.onStart,onEnd:t.onEnd,deltaDateRequired:t.deltaDateRequired,questsRequired:t.questsRequired});a(this,"_name");a(this,"_description");a(this,"_adviceDescription");a(this,"_image");a(this,"_flags");a(this,"_flagsRequired");a(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 U={};j(U,{navigator:()=>Oe,questsNotebook:()=>Me,routine:()=>Ne,timeTracker:()=>qe});var N=class{get rooms(){return RegisteredRooms.values()}get locations(){return RegisteredLocations.values()}get maps(){return RegisteredMaps.values()}get currentRoomId(){return storage.get(h)}get currentRoom(){let r=this.currentRoomId;if(!r){c.error("The current room has not yet been set");return}let e=RegisteredRooms.get(r);if(!e){c.error(`Current room ${r} not found`);return}return e}set currentRoom(r){if(typeof r!="string"&&(r=r.id),!RegisteredRooms.get(r)){c.error(`The room ${r} is not registered, so it can't be set as current room`);return}let t=storage.get(h);t!==r&&(A({type:"editroom",prev:t,value:r}),storage.set(h,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 z="___nqtr-temporary_commitment___",Q=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(z);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(z,e);}find(r){return RegisteredCommitments.get(r)}remove(r){Array.isArray(r)||(r=[r]);let e=r.map(i=>i.id),t=storage.get(z);t&&(t=t.filter(i=>!e.includes(i)),storage.set(z,t));}clearExpiredRoutine(){RegisteredCommitments.values().forEach(r=>{r.expired&®isteredCommitments.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;}):c.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{};a(m,"dayStartTime",0),a(m,"dayEndTime",24),a(m,"defaultTimeSpent",1),a(m,"timeSlots",[]),a(m,"weekLength",7),a(m,"weekendStartDay",m.weekLength-1),a(m,"getDayName");var u=m;var L=class{initialize(r){let{dayStartTime:e=0,dayEndTime:t=24,defaultTimeSpent:i=1,timeSlots:n=[],weekLength:s=7,weekendStartDay:d=s-1,getDayName:p}=r;u.dayStartTime=e,u.dayEndTime=t,u.defaultTimeSpent=i,u.timeSlots=n,u.weekLength=s,d>=u.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${s}, so will be ignored`):u.weekendStartDay=d,u.getDayName=p;}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(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,A({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,A({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 qe=new L,Oe=new N,Ne=new Q,Me=new M;var Le={...G,...oe,...de,handlers:U,registries:Qe},Lr=Le;export{b as ActivityBaseModel,f as ActivityStoredClass,P as CommitmentBaseModel,S as CommitmentStoredClass,D as LocationBaseModel,v as LocationStoredClass,C as MapBaseModel,I as MapStoredClass,q as QuestBaseModel,x as QuestStoredClass,w as RoomBaseModel,_ as RoomStoredClass,O as StageBaseModel,R as StageStoredClass,Lr as default};
|
package/dist/ink.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';
|
package/dist/ink.mjs
ADDED
|
File without changes
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
import { OnRunProps as OnRunProps$1, ActivityInterface as ActivityInterface$1, CommitmentInterface as CommitmentInterface$1, LocationInterface as LocationInterface$1, MapInterface as MapInterface$1, RoomInterface as RoomInterface$1, QuestInterface as QuestInterface$1, StageInterface as StageInterface$1 } from '@drincs/nqtr';
|
|
2
|
+
import { CharacterInterface, CachedMap } from '@drincs/pixi-vn';
|
|
3
|
+
import { StoredClassModel } from '@drincs/pixi-vn/storage';
|
|
4
|
+
|
|
5
|
+
type ExecutionType = "automatic" | "interaction";
|
|
6
|
+
|
|
7
|
+
type OnRunProps = OnRunProps$1;
|
|
8
|
+
/**
|
|
9
|
+
* The function that is called when the class is runned.
|
|
10
|
+
*/
|
|
11
|
+
type OnRunEvent<T> = (item: T, props: OnRunProps) => any | Promise<any>;
|
|
12
|
+
type OnRunAsyncFunction = (props: OnRunProps) => Promise<any>;
|
|
13
|
+
|
|
14
|
+
type QuestsRequiredType = {
|
|
15
|
+
quest: QuestInterface;
|
|
16
|
+
stageNumber: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
interface DateSchedulingInterface {
|
|
20
|
+
/**
|
|
21
|
+
* The start date. If the item hasn't started yet, it will be hidden.
|
|
22
|
+
* If you set it to 3, the item will be hidden on dates 1 and 2 and will be shown starting on date 3.
|
|
23
|
+
*/
|
|
24
|
+
from: number;
|
|
25
|
+
/**
|
|
26
|
+
* The date when the item ends. If the item is ended yet, it will be deleted or hidden.
|
|
27
|
+
* If you set { from: 0, to: 3 }, the item will be shown into dates 1 and 2 and will be deleted or hidden from date 3.
|
|
28
|
+
* @default undefined
|
|
29
|
+
*/
|
|
30
|
+
to?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface TimeSchedulingInterface {
|
|
34
|
+
/**
|
|
35
|
+
* The time when the item starts. If the item is not started yet, it will be hidden.
|
|
36
|
+
* If you set 3, the item will be hidden into times 1 and 2, and will be shown from time 3.
|
|
37
|
+
*/
|
|
38
|
+
from: number;
|
|
39
|
+
/**
|
|
40
|
+
* The time when the item ends. If the item is ended yet, it will be hidden.
|
|
41
|
+
* If you set 3, the item will be shown into times 1 and 2 and will be hidden from time 3.
|
|
42
|
+
* @default timeTracker.dayEndTime + 1
|
|
43
|
+
*/
|
|
44
|
+
to?: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface ActivityInterface extends ActivityBaseInternalInterface, ActivityInterface$1 {
|
|
48
|
+
}
|
|
49
|
+
interface ActivityBaseInternalInterface {
|
|
50
|
+
/**
|
|
51
|
+
* The id of the activity/commitment.
|
|
52
|
+
*/
|
|
53
|
+
readonly id: string;
|
|
54
|
+
/**
|
|
55
|
+
* Time slot in which activity/commitment will be active.
|
|
56
|
+
*/
|
|
57
|
+
readonly timeSlot: TimeSchedulingInterface | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Used to schedule what date it will be added and removed.
|
|
60
|
+
*/
|
|
61
|
+
readonly dateScheduling: DateSchedulingInterface | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* The function that is called when the activity/commitment is runned.
|
|
64
|
+
*/
|
|
65
|
+
readonly run: OnRunAsyncFunction;
|
|
66
|
+
/**
|
|
67
|
+
* Whether the activity/commitment is a deadline, so it will then be removed or hidden.
|
|
68
|
+
*
|
|
69
|
+
* It **depends only on the date**, not the time. So if you set { dateScheduling: { from: 0, to: 3 }, timeSlot { from: 10, to: 20 } } the activity/commitment hidden or deleted on date 3 at 0.
|
|
70
|
+
*/
|
|
71
|
+
readonly expired: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Whether the activity/commitment is active.
|
|
74
|
+
*/
|
|
75
|
+
readonly isActive: boolean;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface CommitmentInterface extends CommitmentBaseInternalInterface, CommitmentInterface$1 {
|
|
79
|
+
}
|
|
80
|
+
interface CommitmentBaseInternalInterface extends ActivityBaseInternalInterface {
|
|
81
|
+
/**
|
|
82
|
+
* The character or characters that are in the commitment and so in the room.
|
|
83
|
+
*/
|
|
84
|
+
readonly characters: CharacterInterface[];
|
|
85
|
+
/**
|
|
86
|
+
* The room where the commitment is.
|
|
87
|
+
*/
|
|
88
|
+
readonly room: RoomInterface;
|
|
89
|
+
/**
|
|
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.
|
|
91
|
+
* If you set "automatic" remember to remove the commitment when it is no longer needed, because otherwise it repeats itself every time.
|
|
92
|
+
*/
|
|
93
|
+
executionType: ExecutionType;
|
|
94
|
+
/**
|
|
95
|
+
* The priority. The higher the number, the higher the priority.
|
|
96
|
+
* To ensure that a character is not in 2 places at the same time, if there are 2 or more valid commits at the same time and with the same character, the one with the highest priority will be chosen.
|
|
97
|
+
*/
|
|
98
|
+
priority: number;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
interface NavigationAbstractInterface extends StoredClassModel {
|
|
102
|
+
/**
|
|
103
|
+
* Connects the activity to the class.
|
|
104
|
+
* @param activity The activity to connect to the class.
|
|
105
|
+
* @param options
|
|
106
|
+
* @returns
|
|
107
|
+
*/
|
|
108
|
+
addActivity(activity: ActivityInterface, options?: {
|
|
109
|
+
/**
|
|
110
|
+
* Time slot in which activity will be active.
|
|
111
|
+
*/
|
|
112
|
+
timeSlot?: TimeSchedulingInterface;
|
|
113
|
+
/**
|
|
114
|
+
* Used to schedule what date it will be added and removed.
|
|
115
|
+
*/
|
|
116
|
+
dateScheduling?: DateSchedulingInterface;
|
|
117
|
+
}): void;
|
|
118
|
+
/**
|
|
119
|
+
* Disconnects the activity from the class.
|
|
120
|
+
* @param activity The activity to disconnect from the class.
|
|
121
|
+
* @param options
|
|
122
|
+
*/
|
|
123
|
+
removeActivity(activity: ActivityInterface | string, options?: Pick<DateSchedulingInterface, "to">): void;
|
|
124
|
+
/**
|
|
125
|
+
* Removes the useless activities.
|
|
126
|
+
*/
|
|
127
|
+
clearExpiredActivities(): void;
|
|
128
|
+
/**
|
|
129
|
+
* All the ids of the activities associated with this class. Compared to {@link activities}, they are not filtered based on their scheduling.
|
|
130
|
+
*/
|
|
131
|
+
readonly activitiesIds: string[];
|
|
132
|
+
/**
|
|
133
|
+
* The activities associated with this class, filtered based on their scheduling.
|
|
134
|
+
*/
|
|
135
|
+
activities: ActivityInterface[];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
interface LocationInterface extends LocationInternalInterface, LocationInterface$1 {
|
|
139
|
+
}
|
|
140
|
+
interface LocationInternalInterface extends NavigationAbstractInterface {
|
|
141
|
+
/**
|
|
142
|
+
* The id of the location.
|
|
143
|
+
*/
|
|
144
|
+
readonly id: string;
|
|
145
|
+
/**
|
|
146
|
+
* The map where the location is.
|
|
147
|
+
*/
|
|
148
|
+
readonly map: MapInterface;
|
|
149
|
+
/**
|
|
150
|
+
* Get all rooms in the location.
|
|
151
|
+
* @returns The rooms in the location.
|
|
152
|
+
*/
|
|
153
|
+
readonly rooms: RoomInterface[];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
interface MapInterface extends MapBaseInternalInterface, MapInterface$1 {
|
|
157
|
+
}
|
|
158
|
+
interface MapBaseInternalInterface extends NavigationAbstractInterface {
|
|
159
|
+
/**
|
|
160
|
+
* The id of the map.
|
|
161
|
+
*/
|
|
162
|
+
readonly id: string;
|
|
163
|
+
/**
|
|
164
|
+
* Get all locations in the map.
|
|
165
|
+
* @returns The locations in the map.
|
|
166
|
+
*/
|
|
167
|
+
readonly locations: LocationInterface[];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
interface RoomInterface extends RoomBaseInternalInterface, RoomInterface$1 {
|
|
171
|
+
}
|
|
172
|
+
interface RoomBaseInternalInterface extends NavigationAbstractInterface {
|
|
173
|
+
/**
|
|
174
|
+
* The id of the room.
|
|
175
|
+
*/
|
|
176
|
+
readonly id: string;
|
|
177
|
+
/**
|
|
178
|
+
* The location where the room is.
|
|
179
|
+
*/
|
|
180
|
+
readonly location: LocationInterface;
|
|
181
|
+
/**
|
|
182
|
+
* Get the character commitments of the room.
|
|
183
|
+
*/
|
|
184
|
+
readonly routine: CommitmentInterface[];
|
|
185
|
+
/**
|
|
186
|
+
* Get the characters in the room.
|
|
187
|
+
*/
|
|
188
|
+
readonly characters: CharacterInterface[];
|
|
189
|
+
/**
|
|
190
|
+
* Get the functions that will be executed when the room is visited.
|
|
191
|
+
*/
|
|
192
|
+
readonly automaticFunctions: OnRunAsyncFunction[];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
interface QuestInterface extends QuestBaseInternalInterface, QuestInterface$1 {
|
|
196
|
+
}
|
|
197
|
+
interface QuestBaseInternalInterface {
|
|
198
|
+
/**
|
|
199
|
+
* The id of the quest.
|
|
200
|
+
*/
|
|
201
|
+
readonly id: string;
|
|
202
|
+
/**
|
|
203
|
+
* The stages of the quest.
|
|
204
|
+
*/
|
|
205
|
+
readonly stages: StageInterface[];
|
|
206
|
+
/**
|
|
207
|
+
* The index of the current stage.
|
|
208
|
+
*/
|
|
209
|
+
currentStageIndex?: number;
|
|
210
|
+
/**
|
|
211
|
+
* The current stage.
|
|
212
|
+
*/
|
|
213
|
+
readonly currentStage?: StageInterface;
|
|
214
|
+
/**
|
|
215
|
+
* If the quest is started.
|
|
216
|
+
*/
|
|
217
|
+
readonly started: boolean;
|
|
218
|
+
/**
|
|
219
|
+
* If the quest is started and not completed and not failed.
|
|
220
|
+
*/
|
|
221
|
+
readonly inProgress: boolean;
|
|
222
|
+
/**
|
|
223
|
+
* If the quest is completed.
|
|
224
|
+
*/
|
|
225
|
+
readonly completed: boolean;
|
|
226
|
+
/**
|
|
227
|
+
* If the quest is failed.
|
|
228
|
+
*/
|
|
229
|
+
readonly failed: boolean;
|
|
230
|
+
/**
|
|
231
|
+
* The function that will be called when the quest starts.
|
|
232
|
+
*/
|
|
233
|
+
readonly onStart?: OnRunEvent<QuestInterface>;
|
|
234
|
+
/**
|
|
235
|
+
* The function that will be called when the quest goes to the next stage.
|
|
236
|
+
*/
|
|
237
|
+
readonly onNextStage?: OnRunEvent<QuestInterface>;
|
|
238
|
+
/**
|
|
239
|
+
* Start the quest.
|
|
240
|
+
* @param props The properties for the start stage. If you not want to pass any property, you can pass an {}.
|
|
241
|
+
* @returns
|
|
242
|
+
*/
|
|
243
|
+
start(props: OnRunProps$1): Promise<void>;
|
|
244
|
+
/**
|
|
245
|
+
* Go to the next stage if the current stage is completed.
|
|
246
|
+
* If you want to force the change of stage, use {@link advanceUnconditionally}.
|
|
247
|
+
* @param props The properties. If you not want to pass any property, you can pass an {}.
|
|
248
|
+
* @returns true if the stage was changed, false otherwise.
|
|
249
|
+
*/
|
|
250
|
+
advanceIfCompleted(props: OnRunProps$1): Promise<boolean>;
|
|
251
|
+
/**
|
|
252
|
+
* Complete the current stage and go to the next stage with {@link advanceUnconditionally}.
|
|
253
|
+
* If you want to go to the next stage only if the current stage is completed, use {@link advanceIfCompleted}.
|
|
254
|
+
* @param props The properties. If you not want to pass any property, you can pass an {}.
|
|
255
|
+
* @returns true if the stage was changed, false otherwise.
|
|
256
|
+
*/
|
|
257
|
+
continue(props: OnRunProps$1): Promise<boolean>;
|
|
258
|
+
/**
|
|
259
|
+
* Ignore the completed state of the current stage and go to the next stage without checking if the current stage is completed.
|
|
260
|
+
* If you want to go to the next stage only if the current stage is completed, use {@link advanceIfCompleted}.
|
|
261
|
+
* @param props The properties. If you not want to pass any property, you can pass an {}.
|
|
262
|
+
* @returns returns true if the stage was changed, false otherwise.
|
|
263
|
+
*/
|
|
264
|
+
advanceUnconditionally(props: OnRunProps$1): Promise<boolean>;
|
|
265
|
+
/**
|
|
266
|
+
* If the current stage must start. It is true if the current stage is not started, can start and not completed.
|
|
267
|
+
*/
|
|
268
|
+
readonly currentStageMustStart: boolean;
|
|
269
|
+
/**
|
|
270
|
+
* Start the current stage. This is a system function, do not use it directly.
|
|
271
|
+
* @param props The properties for the start stage. If you not want to pass any property, you can pass an {}.
|
|
272
|
+
*/
|
|
273
|
+
startCurrentStage(props: OnRunProps$1): Promise<void>;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
interface StageInterface extends StageBaseInternalInterface, StageInterface$1 {
|
|
277
|
+
}
|
|
278
|
+
interface StageBaseInternalInterface {
|
|
279
|
+
/**
|
|
280
|
+
* The id of the stage.
|
|
281
|
+
*/
|
|
282
|
+
readonly id: string;
|
|
283
|
+
/**
|
|
284
|
+
* The function that will be called when the stage starts.
|
|
285
|
+
*/
|
|
286
|
+
readonly onStart?: OnRunEvent<StageInterface>;
|
|
287
|
+
/**
|
|
288
|
+
* The function that will be called when the stage ends.
|
|
289
|
+
*/
|
|
290
|
+
readonly onEnd?: OnRunEvent<StageInterface>;
|
|
291
|
+
/**
|
|
292
|
+
* Check if the flag and goals are completed.
|
|
293
|
+
* You can force the completion of the stage by setting the completed property to true.
|
|
294
|
+
* @example
|
|
295
|
+
* ```ts
|
|
296
|
+
* export default class Stage extends StageStoredClass {
|
|
297
|
+
* override get completed(): boolean {
|
|
298
|
+
* if (super.completed) {
|
|
299
|
+
* return true;
|
|
300
|
+
* }
|
|
301
|
+
* if (this.flags.length > 0) {
|
|
302
|
+
* if (!this.flags.every((flag) => storage.getFlag(flag.flag))) {
|
|
303
|
+
* return false;
|
|
304
|
+
* }
|
|
305
|
+
* return true;
|
|
306
|
+
* }
|
|
307
|
+
* return false;
|
|
308
|
+
* }
|
|
309
|
+
* override set completed(value: boolean) {
|
|
310
|
+
* super.completed = value;
|
|
311
|
+
* }
|
|
312
|
+
* }
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
completed: boolean;
|
|
316
|
+
/**
|
|
317
|
+
* If the stage is started.
|
|
318
|
+
*/
|
|
319
|
+
started: boolean;
|
|
320
|
+
/**
|
|
321
|
+
* The date when the stage starts.
|
|
322
|
+
*/
|
|
323
|
+
readonly startDate?: number;
|
|
324
|
+
/**
|
|
325
|
+
* Check if the stage can start.
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* export default class Stage extends StageStoredClass {
|
|
329
|
+
* override get canStart(): boolean {
|
|
330
|
+
* if (this.flagsRequired.length > 0 && !this.flagsRequired.every((flag) => storage.getFlag(flag.flag))) {
|
|
331
|
+
* return false;
|
|
332
|
+
* }
|
|
333
|
+
* return super.canStart;
|
|
334
|
+
* }
|
|
335
|
+
* }
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
338
|
+
readonly canStart: boolean;
|
|
339
|
+
/**
|
|
340
|
+
* The function that will be called when the stage starts.
|
|
341
|
+
*/
|
|
342
|
+
start(props: OnRunProps$1): Promise<void>;
|
|
343
|
+
/**
|
|
344
|
+
* The number of day/date required to start the stage.
|
|
345
|
+
*/
|
|
346
|
+
readonly deltaDateRequired: number;
|
|
347
|
+
/**
|
|
348
|
+
* The list of quests required to start the stage.
|
|
349
|
+
*/
|
|
350
|
+
readonly questsRequired: QuestsRequiredType[];
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
declare namespace RegisteredActivities {
|
|
354
|
+
/**
|
|
355
|
+
* Save an activity in the registered activities. If the activity already exists, it will be overwritten.
|
|
356
|
+
* @param activity The activity to save.
|
|
357
|
+
* @returns
|
|
358
|
+
*/
|
|
359
|
+
function add(activities: ActivityInterface | ActivityInterface[]): void;
|
|
360
|
+
/**
|
|
361
|
+
* Get an activity by its id.
|
|
362
|
+
* @param id The id of the activity.
|
|
363
|
+
* @returns The activity or undefined if not found.
|
|
364
|
+
*/
|
|
365
|
+
function get(id: string): ActivityInterface | undefined;
|
|
366
|
+
/**
|
|
367
|
+
* Get a list of all activities registered.
|
|
368
|
+
* @returns An array of activities.
|
|
369
|
+
*/
|
|
370
|
+
function values(): ActivityInterface[];
|
|
371
|
+
/**
|
|
372
|
+
* Check if an activity is registered.
|
|
373
|
+
* @param id The id of the activity.
|
|
374
|
+
* @returns True if the activity is registered, false otherwise.
|
|
375
|
+
*/
|
|
376
|
+
function has(id: string): boolean;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* A Map that contains all commitments registered and available to be used.
|
|
381
|
+
* The key is the id of the commitment and the value is the commitment itself.
|
|
382
|
+
*/
|
|
383
|
+
declare const registeredCommitments: CachedMap<string, CommitmentInterface>;
|
|
384
|
+
declare const fixedCommitments: CachedMap<string, CommitmentInterface>;
|
|
385
|
+
declare namespace RegisteredCommitments {
|
|
386
|
+
/**
|
|
387
|
+
* Save a commitment in the registered commitments. If the commitment already exists, it will be overwritten.
|
|
388
|
+
* @param commitment The commitment to save.
|
|
389
|
+
* @returns
|
|
390
|
+
*/
|
|
391
|
+
function add(commitments: CommitmentInterface | CommitmentInterface[]): void;
|
|
392
|
+
/**
|
|
393
|
+
* Get a commitment by its id.
|
|
394
|
+
* @param id The id of the commitment.
|
|
395
|
+
* @returns The commitment or undefined if not found.
|
|
396
|
+
*/
|
|
397
|
+
function get(id: string): CommitmentInterface | undefined;
|
|
398
|
+
/**
|
|
399
|
+
* Get a list of all commitments registered.
|
|
400
|
+
* @returns An array of commitments.
|
|
401
|
+
*/
|
|
402
|
+
function values(): CommitmentInterface[];
|
|
403
|
+
/**
|
|
404
|
+
* Check if a commitment is registered.
|
|
405
|
+
* @param id The id of the commitment.
|
|
406
|
+
* @returns True if the commitment is registered, false otherwise.
|
|
407
|
+
*/
|
|
408
|
+
function has(id: string): boolean;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
declare namespace RegisteredLocations {
|
|
412
|
+
/**
|
|
413
|
+
* Save a location in the registered locations. If the location already exists, it will be overwritten.
|
|
414
|
+
* @param location The location to save.
|
|
415
|
+
* @returns
|
|
416
|
+
*/
|
|
417
|
+
function add(location: LocationInterface | LocationInterface[]): void;
|
|
418
|
+
/**
|
|
419
|
+
* Get a location by its id.
|
|
420
|
+
* @param id The id of the location.
|
|
421
|
+
* @returns The location or undefined if not found.
|
|
422
|
+
*/
|
|
423
|
+
function get(id: string): LocationInterface | undefined;
|
|
424
|
+
/**
|
|
425
|
+
* Get a list of all locations registered.
|
|
426
|
+
* @returns An array of locations.
|
|
427
|
+
*/
|
|
428
|
+
function values(): LocationInterface[];
|
|
429
|
+
/**
|
|
430
|
+
* Check if a location is registered.
|
|
431
|
+
* @param id The id of the location.
|
|
432
|
+
* @returns True if the location is registered, false otherwise.
|
|
433
|
+
*/
|
|
434
|
+
function has(id: string): boolean;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
declare namespace RegisteredMaps {
|
|
438
|
+
/**
|
|
439
|
+
* Save a map in the registered maps. If the map already exists, it will be overwritten.
|
|
440
|
+
* @param map The map to save.
|
|
441
|
+
* @returns
|
|
442
|
+
*/
|
|
443
|
+
function add(map: MapInterface | MapInterface[]): void;
|
|
444
|
+
/**
|
|
445
|
+
* Get a map by its id.
|
|
446
|
+
* @param id The id of the map.
|
|
447
|
+
* @returns The map or undefined if not found.
|
|
448
|
+
*/
|
|
449
|
+
function get(id: string): MapInterface | undefined;
|
|
450
|
+
/**
|
|
451
|
+
* Get a list of all maps registered.
|
|
452
|
+
* @returns An array of maps.
|
|
453
|
+
*/
|
|
454
|
+
function values(): MapInterface[];
|
|
455
|
+
/**
|
|
456
|
+
* Check if a map is registered.
|
|
457
|
+
* @param id The id of the map.
|
|
458
|
+
* @returns True if the map is registered, false otherwise.
|
|
459
|
+
*/
|
|
460
|
+
function has(id: string): boolean;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
declare namespace RegisteredQuest {
|
|
464
|
+
/**
|
|
465
|
+
* Save a quest in the registered quests. If the quest already exists, it will be overwritten.
|
|
466
|
+
* @param quest The quest to save.
|
|
467
|
+
* @returns
|
|
468
|
+
*/
|
|
469
|
+
function add(quests: QuestInterface | QuestInterface[]): void;
|
|
470
|
+
/**
|
|
471
|
+
* Get a quest by its id.
|
|
472
|
+
* @param id The id of the quest.
|
|
473
|
+
* @returns The quest or undefined if not found.
|
|
474
|
+
*/
|
|
475
|
+
function get(id: string): QuestInterface | undefined;
|
|
476
|
+
/**
|
|
477
|
+
* Get a list of all quests registered.
|
|
478
|
+
* @returns An array of quests.
|
|
479
|
+
*/
|
|
480
|
+
function values(): QuestInterface[];
|
|
481
|
+
/**
|
|
482
|
+
* Check if a quest is registered.
|
|
483
|
+
* @param id The id of the quest.
|
|
484
|
+
* @returns True if the quest is registered, false otherwise.
|
|
485
|
+
*/
|
|
486
|
+
function has(id: string): boolean;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
declare namespace RegisteredRooms {
|
|
490
|
+
/**
|
|
491
|
+
* Save a room in the registered rooms, and their location and map if they are not already registered.
|
|
492
|
+
* If the room already exists, it will be overwritten.
|
|
493
|
+
* @param room The room to save.
|
|
494
|
+
* @returns
|
|
495
|
+
*/
|
|
496
|
+
function add(room: RoomInterface | RoomInterface[]): void;
|
|
497
|
+
/**
|
|
498
|
+
* Get a room by its id.
|
|
499
|
+
* @param id The id of the room.
|
|
500
|
+
* @returns The room or undefined if not found.
|
|
501
|
+
*/
|
|
502
|
+
function get(id: string): RoomInterface | undefined;
|
|
503
|
+
/**
|
|
504
|
+
* Get a list of all rooms registered.
|
|
505
|
+
* @returns An array of rooms.
|
|
506
|
+
*/
|
|
507
|
+
function values(): RoomInterface[];
|
|
508
|
+
/**
|
|
509
|
+
* Check if a room is registered.
|
|
510
|
+
* @param id The id of the room.
|
|
511
|
+
* @returns True if the room is registered, false otherwise.
|
|
512
|
+
*/
|
|
513
|
+
function has(id: string): boolean;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
export { RegisteredActivities, RegisteredCommitments, RegisteredLocations, RegisteredMaps, RegisteredQuest as RegisteredQuests, RegisteredRooms, fixedCommitments, registeredCommitments };
|