@drincs/nqtr 0.8.2 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -21
- package/dist/StageInterface-BN_O8nDA.d.mts +363 -0
- package/dist/StageInterface-BN_O8nDA.d.ts +363 -0
- package/dist/handlers.cjs +1 -1
- package/dist/handlers.d.mts +6 -617
- package/dist/handlers.d.ts +6 -617
- package/dist/handlers.mjs +1 -1
- package/dist/index-CtxMgD9N.d.ts +270 -0
- package/dist/index-D0T0L2IE.d.mts +270 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.mts +62 -660
- package/dist/index.d.ts +62 -660
- package/dist/index.mjs +1 -1
- package/dist/ink.cjs +1 -1
- package/dist/ink.d.mts +58 -10
- package/dist/ink.d.ts +58 -10
- package/dist/ink.mjs +1 -1
- package/dist/registries.cjs +1 -1
- package/dist/registries.d.mts +143 -366
- package/dist/registries.d.ts +143 -366
- package/dist/registries.mjs +1 -1
- package/dist/vite.cjs +2 -0
- package/dist/vite.d.mts +160 -0
- package/dist/vite.d.ts +160 -0
- package/dist/vite.mjs +2 -0
- package/package.json +37 -12
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {timeTracker,navigator,routine}from'@drincs/nqtr/handlers';export*from'@drincs/nqtr/handlers';import*as Ne from'@drincs/nqtr/registries';import {fixedCommitments,RegisteredRooms,RegisteredLocations,RegisteredMaps,RegisteredQuests,RegisteredCommitments,RegisteredActivities}from'@drincs/nqtr/registries';export{RegisteredActivities,RegisteredCommitments,RegisteredLocations,RegisteredMaps,RegisteredQuests,RegisteredRooms}from'@drincs/nqtr/registries';import {StoredClassModel,storage}from'@drincs/pixi-vn/storage';import {narration}from'@drincs/pixi-vn/narration';import {PixiError}from'@drincs/pixi-vn/core';var U=Object.defineProperty;var me=(o,r,e)=>r in o?U(o,r,{enumerable:true,configurable:true,writable:true,value:e}):o[r]=e;var W=(o,r)=>{for(var e in r)U(o,e,{get:r[e],enumerable:true});};var n=(o,r,e)=>me(o,typeof r!="symbol"?r+"":r,e);var F={};W(F,{ActivityBaseModel:()=>b,ActivityStoredClass:()=>g,CommitmentBaseModel:()=>P,CommitmentStoredClass:()=>y,LocationBaseModel:()=>E,LocationStoredClass:()=>S,MapBaseModel:()=>C,MapStoredClass:()=>v,QuestBaseModel:()=>w,QuestStoredClass:()=>_,RoomBaseModel:()=>D,RoomStoredClass:()=>I,StageBaseModel:()=>O,StageStoredClass:()=>T});var ge="__nqtr-activity__",g=class extends StoredClassModel{constructor(e,t,i,a=ge){super(a,e);this._onRun=t;n(this,"_timeSlot");n(this,"_dateScheduling");this._timeSlot=i.timeSlot,this._dateScheduling=i.dateScheduling;}_onRun;get timeSlot(){return this._timeSlot}get dateScheduling(){return this._dateScheduling}addTempHistoryItem(){narration.addCurrentStepToHistory();}get run(){return async e=>(this.addTempHistoryItem(),await this._onRun(this,e))}get expired(){return !!(this.dateScheduling?.to&&this.dateScheduling.to<=timeTracker.currentDate)}isActive(e={}){let{timeSlot:t=this.timeSlot,dateScheduling:i=this.dateScheduling}=e;if(i?.from!=null&&i.from>timeTracker.currentDate||i?.to!=null&&i.to<timeTracker.currentDate)return false;t&&!Array.isArray(t)&&(t=[t]);for(let a of t||[])if(!timeTracker.nowIsBetween(a?.from,a?.to))return false;return true}};var b=class extends g{constructor(e,t,i){super(e,t,{dateScheduling:i.dateScheduling,timeSlot:i.timeSlot});n(this,"defaultName");n(this,"defaultDisabled");n(this,"defaultHidden");n(this,"_icon");this.defaultName=i.name||"",this.defaultDisabled=i.disabled||false,this.defaultHidden=i.hidden||false,this._icon=i.renderIcon;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}get icon(){return this._icon}};var m="___nqtr-time_manager_data___",p="___nqtr-current_room_memory___",Y="___nqtr-last_event_memory___";function R(o){storage.set(Y,o);}function J(){return storage.get(Y)}var pe="__nqtr-commitment__",y=class extends g{constructor(e,t,i,a){i=i||(()=>{});super(e,i,a,pe);this._characters=t;n(this,"defaultExecutionType");n(this,"defaultPriority");this.defaultExecutionType=a.executionType||"interaction",this.defaultPriority=a.priority;}_characters;get characters(){return this._characters}get executionType(){return this.getStorageProperty("executionType")||this.defaultExecutionType}set executionType(e){this.setStorageProperty("executionType",e);}get priority(){return this.getStorageProperty("priority")||this.defaultPriority||0}set priority(e){this.setStorageProperty("priority",e);}addTempHistoryItem(){let e=navigator.currentRoom;if(!e||this.executionType!=="automatic")return super.addTempHistoryItem();let t=J();switch(t?.type){case "editroom":storage.set(p,t.prev),super.addTempHistoryItem(),storage.set(p,e.id);break;case "edittime":let i=storage.get(m)||{};storage.set(m,t.prev),super.addTempHistoryItem(),storage.set(m,i);break}}};var P=class extends y{constructor(e,t,i){super(e,t?Array.isArray(t)?t:[t]:[],i.onRun,{executionType:i.executionType,priority:i.priority,timeSlot:i.timeSlot,dateScheduling:i.dateScheduling});n(this,"_name");n(this,"_image");n(this,"_icon");n(this,"defaultDisabled");n(this,"defaultHidden");this._name=i.name||"",this._image=i.image,this.defaultDisabled=i.disabled||false,this.defaultHidden=i.hidden||false,this._icon=i.icon;}get name(){return this._name}get image(){return this._image}get icon(){return this._icon}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}};var d;(i=>(i.log=(a,...s)=>console.log(`[NQTR] ${a}`,...s),i.warn=(a,...s)=>console.warn(`[NQTR] ${a}`,...s),i.error=(a,...s)=>console.error(`[NQTR] ${a}`,...s),i.info=(a,...s)=>console.info(`[NQTR] ${a}`,...s)))(d||(d={}));var h=class extends StoredClassModel{constructor(e,t,i=[]){super(e,t);this.defaultActivities=i;}defaultActivities;get defaultActivitiesIds(){return this.defaultActivities.map(e=>e.id)}get activeActivityScheduling(){return this.getStorageProperty("activeActivityScheduling")||{}}get excludedActivitiesScheduling(){return this.getStorageProperty("excludedActivitiesScheduling")||{}}removeActivityScheduling(e){let t=this.activeActivityScheduling;delete t[e],this.setStorageProperty("activeActivityScheduling",t);let i=this.excludedActivitiesScheduling;delete i[e],this.setStorageProperty("excludedActivitiesScheduling",i);}editActivityScheduling(e,t){this.removeActivityScheduling(e);let i=this.activeActivityScheduling;i[e]=t,this.setStorageProperty("activeActivityScheduling",i);}editExcludedActivityScheduling(e,t){this.removeActivityScheduling(e);let i=this.excludedActivitiesScheduling;i[e]=t,this.setStorageProperty("excludedActivitiesScheduling",i);}get additionalActivitiesIds(){return this.getStorageProperty("additionalActivitiesIds")||[]}get excludedActivitiesIds(){return this.getStorageProperty("excludedActivitiesIds")||[]}get activitiesIds(){return this.additionalActivitiesIds.concat(this.defaultActivitiesIds)}addActivity(e,t={}){let{timeSlot:i,dateScheduling:a}=t;if(i&&!Array.isArray(i)&&(i=[i]),i?.forEach(c=>{let{to:l=timeTracker.dayEndTime+1}=c||{};if(c&&c.from>=l)throw d.error("The from time must be less than the to time."),new PixiError("invalid_usage","The from time must be less than the to time.")}),a?.from!==void 0&&a?.to!==void 0&&a?.from>=a?.to)throw d.error("The from day/date must be less than the to day/date."),new PixiError("invalid_usage","The from day/date must be less than the to day/date.");let s=this.additionalActivitiesIds;this.defaultActivitiesIds.includes(e.id)||s.includes(e.id)?d.info(`Activity with id ${e.id} already exists in the ${this.id}, so it will be updated with the new scheduling options if they are provided.`):(s.push(e.id),this.setStorageProperty("additionalActivitiesIds",s)),this.excludedActivitiesIds.includes(e.id)&&(this.removeActivityScheduling(e.id),d.log(`Activity with id ${e.id} was excluded from the ${this.id}, but now it will be added again with the new scheduling options. So it will be removed from the excluded activities list.`)),(i||a)&&this.editActivityScheduling(e.id,{timeSlot:i,dateScheduling:a});}removeActivity(e){let t=typeof e=="string"?e:e.id,i=this.additionalActivitiesIds;if(i.includes(t))i=i.filter(a=>a!==t),this.setStorageProperty("additionalActivitiesIds",i);else if(this.defaultActivitiesIds.includes(t)){let a=this.excludedActivitiesIds;a.push(t),this.setStorageProperty("excludedActivitiesIds",a);}else d.warn(`Activity with id ${t} not found, so it will be ignored.`);}clearExpiredActivities(){let e=this.activeActivityScheduling,t=this.excludedActivitiesScheduling,i=this.additionalActivitiesIds,a=this.excludedActivitiesIds;i.forEach(s=>{if(s in e){let{to:c}=e[s].dateScheduling||{};c&&c<timeTracker.currentDate&&(this.removeActivityScheduling(s),i=i.filter(l=>l!==s));}}),a.forEach(s=>{s in t&&t[s]&&(this.removeActivityScheduling(s),a=a.filter(c=>c!==s));});}get activities(){return [...new Set([...this.additionalActivitiesIds,...this.defaultActivitiesIds])].reduce((e,t)=>{let i=RegisteredActivities.get(t);return i&&i.isActive(this.activeActivityScheduling[t])&&!this.excludedActivitiesScheduling[t]&&e.push(i),e},[])}};var Ie="__nqtr-location__",S=class extends h{constructor(e,t,i=[]){super(Ie,e,i);this._map=t;}_map;get map(){return this._map}get rooms(){return navigator.rooms.filter(e=>e.location.id===this.id)}};var E=class extends S{constructor(e,t,i={}){super(e,t,i.activities||[]);n(this,"defaultName");n(this,"defaultDisabled");n(this,"defaultHidden");n(this,"_icon");this.defaultName=i.name||"",this.defaultDisabled=i.disabled||false,this.defaultHidden=i.hidden||false,this._icon=i.icon;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}get icon(){return this._icon}};var Te="__nqtr-map__",v=class extends h{constructor(r,e=[]){super(Te,r,e);}get locations(){return navigator.locations.filter(r=>r.map.id===this.id)}};var C=class extends v{constructor(e,t={}){super(e,t.activities||[]);n(this,"defaultName");n(this,"_image");this.defaultName=t.name||"",this._image=t.image;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get image(){return this._image}};var ie="__nqtr-room__",I=class extends h{constructor(e,t,i=[]){var r=(...Qt)=>(super(...Qt),this._location=t,this);Array.isArray(i)?r(ie,e,i):(r(ie,e,i.activities),i.routine.forEach(a=>fixedCommitments.set(a.id,[a,e])));}_location;get routine(){return routine.roomCommitments[this.id]||[]}addCommitment(e,t={}){let{timeSlot:i,dateScheduling:a}=t;if(i&&!Array.isArray(i)&&(i=[i]),i?.forEach(s=>{let{to:c=timeTracker.dayEndTime+1}=s||{};if(s&&s.from>=c)throw d.error("The from time must be less than the to time."),new PixiError("invalid_usage","The from time must be less than the to time.")}),a?.from!==void 0&&a?.to!==void 0&&a?.from>=a?.to)throw d.error("The from day/date must be less than the to day/date."),new PixiError("invalid_usage","The from day/date must be less than the to day/date.");routine.add(e,this.id,{timeSlot:i,dateScheduling:a});}removeCommitment(e){routine.remove(e,this.id);}get location(){return this._location}get characters(){return this.routine.reduce((e,t)=>(e.push(...t.characters),e),[])}get automaticFunctions(){return this.routine.reduce((e,t)=>{if(t.executionType==="automatic"&&t.run){let i=async a=>{await t.run(a);};e.push(i);}return e},[])}};var D=class extends I{constructor(e,t,i={}){super(e,t,{activities:i.activities||[],routine:i.routine||[]});n(this,"defaultName");n(this,"_image");n(this,"defaultDisabled");n(this,"defaultHidden");n(this,"_icon");this.defaultName=i.name||"",this._image=i.image,this.defaultDisabled=i.disabled||false,this.defaultHidden=i.hidden||false,this._icon=i.icon;}get name(){return this.getStorageProperty("name")||this.defaultName}set name(e){this.setStorageProperty("name",e);}get image(){return this._image}get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?storage.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}get hidden(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}get icon(){return this._icon}};var Ae="__nqtr-quest__",_=class extends StoredClassModel{constructor(e,t,i={}){super(Ae,e);this._stages=t;n(this,"_onStart");n(this,"_onContinue");this._onStart=i.onStart,this._onContinue=i.onContinue||i.onNextStage;}_stages;get stages(){return this._stages}get currentStageIndex(){return this.getStorageProperty("currentStageIndex")}set currentStageIndex(e){this.setStorageProperty("currentStageIndex",e);}get currentStage(){let e=this.currentStageIndex;if(!(e===void 0||e>=this.stages.length))return this.stages[e]}get started(){return this.currentStageIndex!==void 0}get completed(){return this.currentStageIndex===void 0?false:this.currentStageIndex>this.stages.length-1}get inProgress(){return this.completed||this.failed?false:this.started}get failed(){return this.getStorageProperty("failed")||false}set failed(e){this.setStorageProperty("failed",e);}get onStart(){return this._onStart}get onContinue(){return this._onContinue}get onNextStage(){return this._onContinue}async start(e){if(this.started){console.warn(`[NQTR] Quest ${this.id} is already started`);return}if(this.stages.length===0){d.error(`Quest ${this.id} has no stages`);return}this.currentStageIndex=0;let t=this.currentStage;if(t&&t.start)return this.onStart&&await this.onStart(this,e),await t.start(e);d.error(`Quest ${this.id} has no start stage`);}async goNextIfCompleted(e){return await this.advanceIfCompleted(e)}async advanceIfCompleted(e){if(!this.inProgress)return false;let t=this.currentStage;return t?t.completed?await this.advanceUnconditionally(e):false:(d.error(`Quest ${this.id} has no current stage`),false)}async goNext(e){return await this.continue(e)}async continue(e){let t=this.currentStage;return t?(t.completed=true,await this.advanceUnconditionally(e)):(d.error(`Quest ${this.id} has no current stage`),false)}async forceGoNext(e){return await this.advanceUnconditionally(e)}async advanceUnconditionally(e){if(!this.inProgress)return console.warn(`[NQTR] Quest ${this.id} is not in progress`),false;let t=this.currentStage,i=this.currentStageIndex;if(!t||i===void 0)return d.error(`Quest ${this.id} has no current stage`),false;this.currentStageIndex=i+1,this.onContinue&&await this.onContinue(this,e),t&&t.onEnd&&await t.onEnd(t,e);let a=this.currentStage;return a&&(a.inizialize(),this.currentStageMustStart&&await this.startCurrentStage(e)),true}get currentStageMustStart(){let e=this.currentStage;return e?!e.started&&e.canStart&&!e.completed:false}async startCurrentStage(e){let t=this.currentStage;t&&this.currentStageMustStart?await t.start(e):console.warn(`[NQTR] Quest ${this.id} can't start the current stage`);}};var w=class extends _{constructor(e,t,i){super(e,t,{onStart:i.onStart,onContinue:i.onContinue||i.onNextStage});n(this,"_name");n(this,"_description");n(this,"_icon");n(this,"_image");n(this,"_inDevelopment");this._name=i.name||"",this._description=i.description||"",this._icon=i.icon,this._image=i.image,this._inDevelopment=i.inDevelopment||false;}get name(){return this._name}get description(){return this._description}get icon(){return this._icon}get image(){return this._image}get inDevelopment(){return this._inDevelopment}};var Ee="__nqtr-stage__",T=class extends StoredClassModel{constructor(e,t={}){super(Ee,e);n(this,"_onStart");n(this,"_onEnd");n(this,"_deltaDateRequired");n(this,"_questsRequired");this._onStart=t.onStart,this._onEnd=t.onEnd,this._deltaDateRequired=t.deltaDateRequired,this._questsRequired=t.questsRequired||[];}get onStart(){return this._onStart}get onEnd(){return this._onEnd}get completed(){return this.getStorageProperty("completed")||false}set completed(e){this.setStorageProperty("completed",e);}get started(){return this.getStorageProperty("started")||false}set started(e){this.setStorageProperty("started",e);}get inizializeDate(){return this.getStorageProperty("inizializeDate")}set inizializeDate(e){this.setStorageProperty("inizializeDate",e);}get startDate(){let e=this.inizializeDate;if(e!==void 0)return e+this.deltaDateRequired}get canStart(){let e=this.deltaDateRequired;if(e>0){let t=this.inizializeDate;if(t===void 0||t+e>timeTracker.currentDate)return false}return !(this.questsRequired.length>0&&!this.questsRequired.every(t=>t.quest.currentStageIndex&&t.quest.currentStageIndex>=t.stageNumber))}inizialize(){this.deltaDateRequired>0&&(this.inizializeDate=timeTracker.currentDate,console.log(`[NQTR] Stage ${this.id} will start on date ${this.startDate}`));}async start(e){this.canStart?(this.started=true,this.onStart&&await this.onStart(this,e)):console.warn(`[NQTR] Stage ${this.id} can't start`);}get deltaDateRequired(){return this._deltaDateRequired||0}get questsRequired(){return this._questsRequired||[]}};var O=class extends T{constructor(e,t){super(e,{onStart:t.onStart,onEnd:t.onEnd,deltaDateRequired:t.deltaDateRequired,questsRequired:t.questsRequired});n(this,"_name");n(this,"_description");n(this,"_adviceDescription");n(this,"_image");n(this,"_flags");n(this,"_flagsRequired");n(this,"_requestDescriptionToStart");this._name=t.name||"",this._flags=t.flags||[],this._description=t.description||"",this._adviceDescription=t.adviceDescription||"",this._image=t.image,this._flagsRequired=t.flagsRequired||[],this._requestDescriptionToStart=t.requestDescriptionToStart||"";}get name(){return this._name}get description(){return this._description}get adviceDescription(){return this._adviceDescription}get image(){return this._image}get flags(){return this._flags}get flagsRequired(){return this._flagsRequired}get requestDescriptionToStart(){return this._requestDescriptionToStart}get completed(){return super.completed?true:this.flags.length>0?!!this.flags.every(e=>storage.getFlag(e.flag)):false}set completed(e){super.completed=e;}get canStart(){return this.flagsRequired.length>0&&!this.flagsRequired.every(e=>storage.getFlag(e.flag))?false:super.canStart}};var oe={};var de={};var K={};W(K,{navigator:()=>qe,questsNotebook:()=>Qe,routine:()=>Me,timeTracker:()=>Oe});var q=class{get rooms(){return RegisteredRooms.values()}get locations(){return RegisteredLocations.values()}get maps(){return RegisteredMaps.values()}get currentRoomId(){return storage.get(p)}get currentRoom(){let r=this.currentRoomId;if(!r){d.error("The current room has not yet been set");return}let e=RegisteredRooms.get(r);if(!e){d.error(`Current room ${r} not found`);return}return e}set currentRoom(r){if(typeof r!="string"&&(r=r.id),!RegisteredRooms.get(r)){d.error(`The room ${r} is not registered, so it can't be set as current room`);return}let t=storage.get(p);t!==r&&(R({type:"editroom",prev:t,value:r}),storage.set(p,r));}get currentLocation(){return this.currentRoom?.location}get currentMap(){return this.currentRoom?.location.map}clearExpiredActivities(){RegisteredRooms.values().forEach(r=>{r.clearExpiredActivities();});}};var M=class{get quests(){return RegisteredQuests.values()}get startedQuests(){return this.quests.filter(r=>r.started)}get inProgressQuests(){return this.quests.filter(r=>r.inProgress)}get completedQuests(){return this.quests.filter(r=>r.completed)}get failedQuests(){return this.quests.filter(r=>r.failed)}get notStartedQuests(){return this.quests.filter(r=>!r.started)}find(r){return RegisteredQuests.get(r)}async startsStageMustBeStarted(r){let e=this.quests.map(t=>t.currentStageMustStart?t.startCurrentStage(r):Promise.resolve());await Promise.all(e);}};var H="___nqtr-temporary_commitment___",N=class{get temporaryRoutine(){let r=storage.get(H);if(r){if(Array.isArray(r)){if(r.length>0)throw new PixiError("obsolete_save","The save you loaded is not compatible with the current version of NQTR. Please delete the save and start a new game.");return {}}}else return {};return r}get commitmentsIds(){return [...fixedCommitments.keys(),...Object.keys(this.temporaryRoutine)]}add(r,e,t={}){Array.isArray(r)||(r=[r]);let i=this.temporaryRoutine;r.forEach(a=>{RegisteredCommitments.get(a.id)&&d.warn(`The commitment ${a.id} is already registered, it will be overwritten`),RegisteredCommitments.add(a),i[a.id]={id:a.id,roomId:e,...t};}),storage.set(H,i);}find(r){return RegisteredCommitments.get(r)}remove(r,e){typeof r!="string"&&(r=r.id);let t=this.temporaryRoutine;t[r]?(!e||t[r].roomId===e)&&delete t[r]:d.warn(`The commitment ${r} was not found in the temporary routine, so it will be ignored. If you want to remove a fixed commitment, you can add it to the temporary routine with a same character.`),storage.set(H,t);}clearExpiredRoutine(){RegisteredCommitments.values().forEach(r=>{r.expired&&this.remove(r);});}get characterCommitments(){let r=this.temporaryRoutine;return this.commitmentsIds.reduce((e,t)=>{let i=RegisteredCommitments.get(t),a=r[t],s=a?.roomId||fixedCommitments.get(t)?.[1];return s&&i&&i.isActive(a)&&(i.characters.length>0?i.characters.every(l=>!e[l.id]||i.priority>e[l.id][0].priority)&&i.characters.forEach(l=>{e[l.id]=[i,s];}):d.error(`The commitment ${i.id} has no characters assigned`)),e},{})}get currentRoutine(){return Object.values(this.characterCommitments).map(([r])=>r)}get roomCommitments(){return Object.values(this.characterCommitments).reduce((r,e)=>{let t=e[1];return r[t]||(r[t]=[]),r[t].push(e[0]),r},{})}getCommitmentByCharacter(r){return this.currentRoutine.find(e=>{if(e.characters.map(t=>t.id).includes(r.id))return e})}};var f=class f{};n(f,"dayStartTime",0),n(f,"dayEndTime",24),n(f,"defaultTimeSpent",1),n(f,"timeSlots",[]),n(f,"weekLength",7),n(f,"weekendStartDay",f.weekLength-1),n(f,"getDayName");var u=f;var L=class{initialize(r){let{dayStartTime:e=0,dayEndTime:t=24,defaultTimeSpent:i=1,timeSlots:a=[],weekLength:s=7,weekendStartDay:c=s-1,getDayName:l}=r;u.dayStartTime=e,u.dayEndTime=t,u.defaultTimeSpent=i,u.timeSlots=a,u.weekLength=s,c>=u.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${s}, so will be ignored`):u.weekendStartDay=c,u.getDayName=l;}get dayStartTime(){return u.dayStartTime}get dayEndTime(){return u.dayEndTime}get defaultTimeSpent(){return u.defaultTimeSpent}get timeSlots(){return u.timeSlots}get weekLength(){return u.weekLength}get weekendStartDay(){return u.weekendStartDay}get getDayName(){return u.getDayName}get currentTime(){let r=storage.get(m)||{};return r.hasOwnProperty("currentTime")&&typeof r.currentTime=="number"?r.currentTime:this.dayStartTime}set currentTime(r){let e=storage.get(m)||{},t={...e};typeof r=="number"?t.currentTime=r:delete t.currentTime,R({type:"edittime",prev:e,value:t}),storage.set(m,t);}get currentDate(){let r=storage.get(m)||{};return r.hasOwnProperty("currentDate")&&typeof r.currentDate=="number"?r.currentDate:0}set currentDate(r){let e=storage.get(m)||{},t={...e};typeof r=="number"?t.currentDate=r:delete t.currentDate,R({type:"edittime",prev:e,value:t}),storage.set(m,t);}get isWeekend(){return this.currentWeekDayNumber>=this.weekendStartDay}get currentWeekDayNumber(){return this.currentDate%this.weekLength+1}get currentDayName(){return this.getDayName?this.getDayName(this.currentWeekDayNumber-1):(console.warn("[NQTR] Week days names are not defined, so currentDayName will be empty"),"")}get currentTimeSlot(){if(this.timeSlots.length===0)return console.warn("[NQTR] Time slots are not defined"),0;for(let r=0;r<this.timeSlots.length;r++){let e=this.timeSlots[r];if(this.timeSlots.length>r+1&&this.nowIsBetween(e.startTime,this.timeSlots[r+1].startTime))return r}return this.timeSlots.length-1}increaseTime(r=this.defaultTimeSpent){let e=this.currentTime+r;return e>=this.dayEndTime&&(this.increaseDate(),e=this.dayStartTime+(e-this.dayEndTime)),this.currentTime=e,this.currentTime}increaseDate(r=1,e=this.dayStartTime){let t=this.currentDate+r;return this.currentDate=t,this.currentTime=e,this.currentDate}nowIsBetween(r,e){r===void 0&&(r=this.dayStartTime-1),e===void 0&&(e=this.dayEndTime+1);let t=this.currentTime;return r<e?t>=r&&t<e:t>=r||t<e}};var Oe=new L,qe=new q,Me=new N,Qe=new M;var Le={...F,...oe,...de,handlers:K,registries:Ne},zr=Le;export{b as ActivityBaseModel,g as ActivityStoredClass,P as CommitmentBaseModel,y as CommitmentStoredClass,E as LocationBaseModel,S as LocationStoredClass,C as MapBaseModel,v as MapStoredClass,w as QuestBaseModel,_ as QuestStoredClass,D as RoomBaseModel,I as RoomStoredClass,O as StageBaseModel,T as StageStoredClass,zr as default};
|
|
1
|
+
import {timeTracker,navigator,routine}from'@drincs/nqtr/handlers';export*from'@drincs/nqtr/handlers';import*as Qe from'@drincs/nqtr/registries';import {fixedCommitments,RegisteredRooms,RegisteredLocations,RegisteredMaps,RegisteredQuests,RegisteredCommitments,RegisteredActivities}from'@drincs/nqtr/registries';export{RegisteredActivities,RegisteredCommitments,RegisteredLocations,RegisteredMaps,RegisteredQuests,RegisteredRooms}from'@drincs/nqtr/registries';import {narration}from'@drincs/pixi-vn/narration';import {StoredClassModel,storage}from'@drincs/pixi-vn/storage';import {RegisteredCharacters}from'@drincs/pixi-vn/characters';import {PixiError}from'@drincs/pixi-vn/core';var ce=Object.defineProperty;var K=(s,e)=>{for(var t in e)ce(s,t,{get:e[t],enumerable:true});};var $={};K($,{ActivityBaseModel:()=>_,ActivityStoredClass:()=>m,CommitmentBaseModel:()=>A,CommitmentStoredClass:()=>p,LocationBaseModel:()=>b,LocationStoredClass:()=>h,MapBaseModel:()=>C,MapStoredClass:()=>y,QuestBaseModel:()=>P,QuestStoredClass:()=>v,RoomBaseModel:()=>E,RoomStoredClass:()=>S,StageBaseModel:()=>D,StageStoredClass:()=>I});var fe="__nqtr-activity__",m=class extends StoredClassModel{constructor(t,r,i,n=fe){super(n,t);this._onRun=r;this._timeSlot=i.timeSlot,this._dateScheduling=i.dateScheduling;}_onRun;_timeSlot;get timeSlot(){return this._timeSlot}_dateScheduling;get dateScheduling(){return this._dateScheduling}addTempHistoryItem(){return narration.addCurrentStepToHistory()}get run(){return async t=>(this.addTempHistoryItem(),await this._onRun(this,t))}get expired(){return !!(this.dateScheduling?.to&&this.dateScheduling.to<=timeTracker.currentDate)}isActive(t={}){let{timeSlot:r=this.timeSlot,dateScheduling:i=this.dateScheduling}=t;if(i?.from!=null&&i.from>timeTracker.currentDate||i?.to!=null&&i.to<timeTracker.currentDate)return false;r&&!Array.isArray(r)&&(r=[r]);for(let n of r||[])if(!timeTracker.nowIsBetween(n?.from,n?.to))return false;return true}};var _=class extends m{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 u="___nqtr-time_manager_data___",g="___nqtr-current_room_memory___",L="___nqtr-last_event_memory___";function R(s){storage.set(L,s);}function j(){return storage.get(L)}var he="__nqtr-commitment__",p=class extends m{constructor(e,t,r,i){r=r||(()=>{}),super(e,r,i,he),this.defaultExecutionType=i.executionType||"interaction",this.defaultPriority=i.priority,this.characters=t.reduce((n,a)=>{if(typeof a=="string"){let c=RegisteredCharacters.get(a);c?n.push(c):console.warn(`Character with id ${a} not found for commitment ${e}`);}else n.push(a);return n},[]);}defaultExecutionType;defaultPriority;characters;get executionType(){return this.getStorageProperty("executionType")||this.defaultExecutionType}set executionType(e){this.setStorageProperty("executionType",e);}get priority(){return this.getStorageProperty("priority")||this.defaultPriority||0}set priority(e){this.setStorageProperty("priority",e);}addTempHistoryItem(){let e=navigator.currentRoom;if(!e||this.executionType!=="automatic")return super.addTempHistoryItem();let t=j();switch(t?.type){case "editroom":storage.set(g,t.prev),super.addTempHistoryItem(),storage.set(g,e.id);break;case "edittime":{let r=storage.get(u)||{};storage.set(u,t.prev),super.addTempHistoryItem(),storage.set(u,r);break}}}runOptions;get run(){return async(e,t)=>{let r=t?.removeFromRoutine??this.executionType==="automatic";return this.addTempHistoryItem(),r&&routine.remove(this.id),await this._onRun(this,e)}}};var A=class extends p{constructor(e,t,r){super(e,t?Array.isArray(t)?t:[t]:[],r.onRun,{executionType:r.executionType,priority:r.priority,timeSlot:r.timeSlot,dateScheduling:r.dateScheduling}),this._name=r.name||"",this._image=r.image,this.defaultDisabled=r.disabled||false,this.defaultHidden=r.hidden||false,this._icon=r.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(){let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?storage.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}};var o;(i=>(i.log=(n,...a)=>console.log(`[NQTR] ${n}`,...a),i.warn=(n,...a)=>console.warn(`[NQTR] ${n}`,...a),i.error=(n,...a)=>console.error(`[NQTR] ${n}`,...a),i.info=(n,...a)=>console.info(`[NQTR] ${n}`,...a)))(o||={});var f=class extends StoredClassModel{constructor(e,t,r=[]){super(e,t),this.defaultActivitiesIds=r.map(i=>typeof i=="string"?i:i.id);}defaultActivitiesIds;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 r=this.excludedActivitiesScheduling;delete r[e],this.setStorageProperty("excludedActivitiesScheduling",r);}editActivityScheduling(e,t){this.removeActivityScheduling(e);let r=this.activeActivityScheduling;r[e]=t,this.setStorageProperty("activeActivityScheduling",r);}editExcludedActivityScheduling(e,t){this.removeActivityScheduling(e);let r=this.excludedActivitiesScheduling;r[e]=t,this.setStorageProperty("excludedActivitiesScheduling",r);}get additionalActivitiesIds(){return this.getStorageProperty("additionalActivitiesIds")||[]}get excludedActivitiesIds(){return this.getStorageProperty("excludedActivitiesIds")||[]}get activitiesIds(){return this.additionalActivitiesIds.concat(this.defaultActivitiesIds)}addActivity(e,t={}){let r=typeof e=="string"?RegisteredActivities.get(e):e;if(!r)throw o.error(`Activity with id ${e} not found.`),new PixiError("unknown_element",`Activity with id ${e} not found.`);let{timeSlot:i,dateScheduling:n}=t;if(i&&!Array.isArray(i)&&(i=[i]),i?.forEach(c=>{let{to:l=timeTracker.dayEndTime+1}=c||{};if(c&&c.from>=l)throw o.error("The from time must be less than the to time."),new PixiError("invalid_usage","The from time must be less than the to time.")}),n?.from!==void 0&&n?.to!==void 0&&n?.from>=n?.to)throw o.error("The from day/date must be less than the to day/date."),new PixiError("invalid_usage","The from day/date must be less than the to day/date.");let a=this.additionalActivitiesIds;this.defaultActivitiesIds.includes(r.id)||a.includes(r.id)?o.info(`Activity with id ${r.id} already exists in the ${this.id}, so it will be updated with the new scheduling options if they are provided.`):(a.push(r.id),this.setStorageProperty("additionalActivitiesIds",a)),this.excludedActivitiesIds.includes(r.id)&&(this.removeActivityScheduling(r.id),o.log(`Activity with id ${r.id} was excluded from the ${this.id}, but now it will be added again with the new scheduling options. So it will be removed from the excluded activities list.`)),(i||n)&&this.editActivityScheduling(r.id,{timeSlot:i,dateScheduling:n});}removeActivity(e){let t=typeof e=="string"?e:e.id,r=this.additionalActivitiesIds;if(r.includes(t))r=r.filter(i=>i!==t),this.setStorageProperty("additionalActivitiesIds",r);else if(this.defaultActivitiesIds.includes(t)){let i=this.excludedActivitiesIds;i.push(t),this.setStorageProperty("excludedActivitiesIds",i);}else o.warn(`Activity with id ${t} not found, so it will be ignored.`);}clearExpiredActivities(){let e=this.activeActivityScheduling,t=this.excludedActivitiesScheduling,r=this.additionalActivitiesIds,i=this.excludedActivitiesIds;r.forEach(n=>{if(n in e){let{to:a}=e[n].dateScheduling||{};a&&a<timeTracker.currentDate&&(this.removeActivityScheduling(n),r=r.filter(c=>c!==n));}}),i.forEach(n=>{n in t&&t[n]&&(this.removeActivityScheduling(n),i=i.filter(a=>a!==n));});}get activities(){return [...new Set([...this.additionalActivitiesIds,...this.defaultActivitiesIds])].reduce((e,t)=>{let r=RegisteredActivities.get(t);return r?.isActive(this.activeActivityScheduling[t])&&!this.excludedActivitiesScheduling[t]&&e.push(r),e},[])}};var ve="__nqtr-location__",h=class extends f{constructor(t,r,i=[]){super(ve,t,i);this._map=r;}_map;get map(){return this._map}get rooms(){return navigator.rooms.filter(t=>t.location.id===this.id)}};var b=class extends h{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 Te="__nqtr-map__",y=class extends f{constructor(e,t=[]){super(Te,e,t);}get locations(){return navigator.locations.filter(e=>e.map.id===this.id)}};var C=class extends y{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 te="__nqtr-room__",S=class extends f{_location;constructor(e,t,r=[]){Array.isArray(r)?super(te,e,r):(super(te,e,r.activities),r.routine.forEach(i=>{let n=typeof i=="string"?i:i.id;fixedCommitments.set(n,e);})),this._location=t;}get routine(){return routine.roomCommitments[this.id]||[]}addCommitment(e,t={}){let{timeSlot:r,dateScheduling:i}=t;if(r&&!Array.isArray(r)&&(r=[r]),r?.forEach(n=>{let{to:a=timeTracker.dayEndTime+1}=n||{};if(n&&n.from>=a)throw o.error("The from time must be less than the to time."),new PixiError("invalid_usage","The from time must be less than the to time.")}),i?.from!==void 0&&i?.to!==void 0&&i?.from>=i?.to)throw o.error("The from day/date must be less than the to day/date."),new PixiError("invalid_usage","The from day/date must be less than the to day/date.");routine.add(e,this.id,{timeSlot:r,dateScheduling:i});}removeCommitment(e){routine.remove(e,this.id);}get location(){return this._location}get characters(){return this.routine.reduce((e,t)=>(e.push(...t.characters),e),[])}get automaticFunctions(){return this.routine.reduce((e,t)=>{if(t.executionType==="automatic"&&t.run){let r=async i=>{await t.run(i);};e.push(r);}return e},[])}};var E=class extends S{constructor(e,t,r={}){super(e,t,{activities:r.activities||[],routine:r.routine||[]}),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 Ae="__nqtr-quest__",v=class extends StoredClassModel{constructor(t,r,i={}){super(Ae,t);this._stages=r;this._onStart=i.onStart,this._onContinue=i.onContinue||i.onNextStage;}_stages;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}_onContinue;get onContinue(){return this._onContinue}get onNextStage(){return this._onContinue}async start(t){if(this.started){console.warn(`[NQTR] Quest ${this.id} is already started`);return}if(this.stages.length===0){o.error(`Quest ${this.id} has no stages`);return}this.currentStageIndex=0;let r=this.currentStage;if(r?.start)return this.onStart&&await this.onStart(this,t),await r.start(t);o.error(`Quest ${this.id} has no start stage`);}async goNextIfCompleted(t){return await this.advanceIfCompleted(t)}async advanceIfCompleted(t){if(!this.inProgress)return false;let r=this.currentStage;return r?r.completed?await this.advanceUnconditionally(t):false:(o.error(`Quest ${this.id} has no current stage`),false)}async goNext(t){return await this.continue(t)}async continue(t){let r=this.currentStage;return r?(r.completed=true,await this.advanceUnconditionally(t)):(o.error(`Quest ${this.id} has no current stage`),false)}async forceGoNext(t){return await this.advanceUnconditionally(t)}async advanceUnconditionally(t){if(!this.inProgress)return console.warn(`[NQTR] Quest ${this.id} is not in progress`),false;let r=this.currentStage,i=this.currentStageIndex;if(!r||i===void 0)return o.error(`Quest ${this.id} has no current stage`),false;this.currentStageIndex=i+1,this.onContinue&&await this.onContinue(this,t),r?.onEnd&&await r.onEnd(r,t);let n=this.currentStage;return n&&(n.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 P=class extends v{constructor(e,t,r){super(e,t,{onStart:r.onStart,onContinue:r.onContinue||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 Ce="__nqtr-stage__",I=class extends StoredClassModel{constructor(e,t={}){super(Ce,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>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`);}_deltaDateRequired;get deltaDateRequired(){return this._deltaDateRequired||0}_questsRequired;get questsRequired(){return this._questsRequired||[]}};var D=class extends I{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 ae={};var oe={};var G={};K(G,{navigator:()=>qe,questsNotebook:()=>Ne,routine:()=>Me,timeTracker:()=>Oe});var w=class{get rooms(){return RegisteredRooms.values()}get locations(){return RegisteredLocations.values()}get maps(){return RegisteredMaps.values()}get currentRoomId(){return storage.get(g)}get currentRoom(){let e=this.currentRoomId;if(!e){o.error("The current room has not yet been set");return}let t=RegisteredRooms.get(e);if(!t){o.error(`Current room ${e} not found`);return}return t}set currentRoom(e){if(typeof e!="string"&&(e=e.id),!RegisteredRooms.get(e)){o.error(`The room ${e} is not registered, so it can't be set as current room`);return}let r=storage.get(g);r!==e&&(R({type:"editroom",prev:r,value:e}),storage.set(g,e));}get currentLocation(){return this.currentRoom?.location}get currentMap(){return this.currentRoom?.location.map}clearExpiredActivities(){RegisteredRooms.values().forEach(e=>{e.clearExpiredActivities();});}};var O=class{get quests(){return RegisteredQuests.values()}get startedQuests(){return this.quests.filter(e=>e.started)}get inProgressQuests(){return this.quests.filter(e=>e.inProgress)}get completedQuests(){return this.quests.filter(e=>e.completed)}get failedQuests(){return this.quests.filter(e=>e.failed)}get notStartedQuests(){return this.quests.filter(e=>!e.started)}find(e){return RegisteredQuests.get(e)}async startsStageMustBeStarted(e){let t=this.quests.map(r=>r.currentStageMustStart?r.startCurrentStage(e):Promise.resolve());await Promise.all(t);}};var H="___nqtr-temporary_commitment___",q=class{get temporaryRoutine(){let e=storage.get(H);if(e){if(Array.isArray(e)){if(e.length>0)throw new PixiError("obsolete_save","The save you loaded is not compatible with the current version of NQTR. Please delete the save and start a new game.");return {}}}else return {};return e}get commitmentsIds(){return [...fixedCommitments.keys(),...Object.keys(this.temporaryRoutine)]}add(e,t,r={}){Array.isArray(e)||(e=[e]);let i=this.temporaryRoutine;e.forEach(n=>{let a=typeof n=="string"?n:n.id;i[a]={id:a,roomId:t,...r};}),storage.set(H,i);}find(e){return RegisteredCommitments.get(e)}remove(e,t){typeof e!="string"&&(e=e.id);let r=this.temporaryRoutine;r[e]?(!t||r[e].roomId===t)&&delete r[e]:o.warn(`The commitment ${e} was not found in the temporary routine, so it will be ignored. If you want to remove a fixed commitment, you can add it to the temporary routine with a same character.`),storage.set(H,r);}clearExpiredRoutine(){RegisteredCommitments.values().forEach(e=>{e.expired&&this.remove(e);});}get characterCommitments(){let e=this.temporaryRoutine;return this.commitmentsIds.reduce((t,r)=>{let i=RegisteredCommitments.get(r),n=e[r],a=n?.roomId||fixedCommitments.get(r);return a&&i?.isActive(n)&&(i.characters.length>0?i.characters.every(l=>!t[l.id]||i.priority>t[l.id][0].priority)&&i.characters.forEach(l=>{t[l.id]=[i,a];}):o.error(`The commitment ${i.id} has no characters assigned`)),t},{})}get currentRoutine(){return Object.values(this.characterCommitments).map(([e])=>e)}get roomCommitments(){return Object.values(this.characterCommitments).reduce((e,t)=>{let r=t[1];return e[r]||(e[r]=[]),e[r].push(t[0]),e},{})}getCommitmentByCharacter(e){let t=typeof e=="string"?e:e.id;return this.currentRoutine.find(r=>{if(r.characters.map(i=>i.id).includes(t))return r})}};var we={dayStartTime:0,dayEndTime:24,defaultTimeSpent:1,timeSlots:[],weekLength:7,weekendStartDay:6,getDayName:void 0},d=we;var M=class{initialize(e){let{dayStartTime:t=0,dayEndTime:r=24,defaultTimeSpent:i=1,timeSlots:n=[],weekLength:a=7,weekendStartDay:c=a-1,getDayName:l}=e;d.dayStartTime=t,d.dayEndTime=r,d.defaultTimeSpent=i,d.timeSlots=n,d.weekLength=a,c>=d.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${a}, so will be ignored`):d.weekendStartDay=c,d.getDayName=l;}get dayStartTime(){return d.dayStartTime}get dayEndTime(){return d.dayEndTime}get defaultTimeSpent(){return d.defaultTimeSpent}get timeSlots(){return d.timeSlots}get weekLength(){return d.weekLength}get weekendStartDay(){return d.weekendStartDay}get getDayName(){return d.getDayName}get currentTime(){let e=storage.get(u)||{};return Object.hasOwn(e,"currentTime")&&typeof e.currentTime=="number"?e.currentTime:this.dayStartTime}set currentTime(e){let t=storage.get(u)||{},r={...t};typeof e=="number"?r.currentTime=e:delete r.currentTime,R({type:"edittime",prev:t,value:r}),storage.set(u,r);}get currentDate(){let e=storage.get(u)||{};return Object.hasOwn(e,"currentDate")&&typeof e.currentDate=="number"?e.currentDate:0}set currentDate(e){let t=storage.get(u)||{},r={...t};typeof e=="number"?r.currentDate=e:delete r.currentDate,R({type:"edittime",prev:t,value:r}),storage.set(u,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 Oe=new M,qe=new w,Me=new q,Ne=new O;var Le={...$,...ae,...oe,handlers:G,registries:Qe},wr=Le;export{_ as ActivityBaseModel,m as ActivityStoredClass,A as CommitmentBaseModel,p as CommitmentStoredClass,b as LocationBaseModel,h as LocationStoredClass,C as MapBaseModel,y as MapStoredClass,P as QuestBaseModel,v as QuestStoredClass,E as RoomBaseModel,S as RoomStoredClass,D as StageBaseModel,I as StageStoredClass,wr as default};
|
package/dist/ink.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var handlers=require('@drincs/nqtr/handlers'),registries=require('@drincs/nqtr/registries'),pixiVnInk=require('@drincs/pixi-vn-ink');var
|
|
1
|
+
'use strict';var handlers=require('@drincs/nqtr/handlers'),registries=require('@drincs/nqtr/registries'),pixiVnInk=require('@drincs/pixi-vn-ink'),zod=require('zod');var d;(s=>(s.log=(t,...r)=>console.log(`[NQTR] ${t}`,...r),s.warn=(t,...r)=>console.warn(`[NQTR] ${t}`,...r),s.error=(t,...r)=>console.error(`[NQTR] ${t}`,...r),s.info=(t,...r)=>console.info(`[NQTR] ${t}`,...r)))(d||={});function N(a){a||(a={hours:handlers.timeTracker.defaultTimeSpent}),typeof a=="number"&&(a={hours:a});let{hours:c,days:l}=a;l&&handlers.timeTracker.increaseDate(l,handlers.timeTracker.dayStartTime),c&&handlers.timeTracker.increaseTime(c);}function I(a={}){let{timeConverter:c=t=>Number(t.replace(":",".")),dateConverter:l=t=>Number(t),wait:y=N}=a;function s(t){return t&&t.length>0?zod.z.enum(Object.fromEntries(t.map(r=>[r,r]))):zod.z.string()}pixiVnInk.VariableGetter.add((t,r)=>{if(t&&typeof t=="object"&&"type"in t&&"key"in t&&"storageOperationType"in t&&"storageType"in t&&t.storageOperationType==="get"&&(t.storageType==="storage"||t.storageType==="tempstorage"||t.storageType==="flagStorage")){let o=t;if(o.key.endsWith("_currentStageIndex")){let n=o.key.replace("_currentStageIndex",""),i=registries.RegisteredQuests.get(n);return i?i.currentStageIndex:(d.warn(`Quest ${n} not found`),r(t))}else if(o.key.endsWith("_started")){let n=o.key.replace("_started",""),i=registries.RegisteredQuests.get(n);return i?i.started:(d.warn(`Quest ${n} not found`),r(t))}else if(o.key.endsWith("_completed")){let n=o.key.replace("_completed",""),i=registries.RegisteredQuests.get(n);return i?i.completed:(d.warn(`Quest ${n} not found`),r(t))}else if(o.key.endsWith("_failed")){let n=o.key.replace("_failed",""),i=registries.RegisteredQuests.get(n);return i?i.failed:(d.warn(`Quest ${n} not found`),r(t))}}return r(t)}),pixiVnInk.HashtagCommands.add(t=>{let r=registries.RegisteredRooms.get(t[2]);return r?handlers.navigator.currentRoom=r:d.warn(`Room ${t[2]} not found`),true},{name:"Enter room",description:"Enter a room by its ID. This command sets the current room in the navigator to the specified room.\n\n```ink\n# enter room <roomId>\n```",validation:zod.z.tuple([zod.z.literal("enter"),zod.z.literal("room"),s(a.roomIds)])}),pixiVnInk.HashtagCommands.add(t=>{let r=c(t[2]);return Number.isNaN(r)?d.warn(`Invalid time format: ${t[2]}`):handlers.timeTracker.currentTime=r,true},{name:"Set time",description:'Set the current time in the time tracker. The time should be provided in a valid format (e.g., "HH:MM").\n\n```ink\n# set time <time>\n```',validation:zod.z.tuple([zod.z.literal("set"),zod.z.literal("time"),zod.z.string()])}),pixiVnInk.HashtagCommands.add(t=>{let r=l(t[2]);return Number.isNaN(r)?d.warn(`Invalid date format: ${t[2]}`):handlers.timeTracker.currentDate=r,true},{name:"Set date",description:'Set the current date in the time tracker. The date should be provided in a valid format (e.g., "YYYY-MM-DD").\n\n```ink\n# set date <date>\n```',validation:zod.z.tuple([zod.z.literal("set"),zod.z.literal("date"),zod.z.string()])}),pixiVnInk.HashtagCommands.add(t=>{let r=c(t[1]);return Number.isNaN(r)?d.warn(`Invalid time format: ${t[1]}`):y(r),true},{name:"Wait for time",description:'Wait for a specified amount of time. The time should be provided in a valid format (e.g., "HH:MM").\n\n```ink\n# wait <time>\n```',validation:zod.z.tuple([zod.z.literal("wait"),zod.z.string()])}),pixiVnInk.HashtagCommands.add(t=>(y(),true),{name:"Wait",description:"Wait for the default amount of time specified in the time tracker.\n\n```ink\n# wait\n```",validation:zod.z.tuple([zod.z.literal("wait")])}),pixiVnInk.HashtagCommands.add((t,r,o)=>{let n=false,i=o(t.slice(1));return i.hours!==void 0&&typeof i.hours=="string"&&(i.hours=c(i.hours),n=true),i.days!==void 0&&typeof i.days=="string"&&(i.days=l(i.days),n=true),n&&y(i),n},{name:"Wait with options",description:'Wait for a specified amount of time and/or days. You can provide options for hours and days in the format "hours=<time>" and "days=<date>".\n\n```ink\n# wait hours <time> days <date>\n```',validation:zod.z.tuple([zod.z.literal("wait"),zod.z.string(),zod.z.string()]).rest(zod.z.string())}),pixiVnInk.HashtagCommands.add((t,r,o)=>{let n=registries.RegisteredActivities.get(t[2]);if(!n)return d.warn(`Activity ${t[2]} not found`),true;let{in:i}=o(t.slice(3)),u=registries.RegisteredRooms.get(i);return u?u.addActivity(n):d.warn(`Room ${i} not found`),true},{name:"Add activity to room",description:"Add an activity to a specified room. You need to provide the activity ID and the room ID.\n\n```ink\n# add activity <activityId> in <roomId>\n```",validation:zod.z.tuple([zod.z.literal("add"),zod.z.literal("activity"),s(a.activityIds),zod.z.literal("in"),s(a.roomIds)])}),pixiVnInk.HashtagCommands.add((t,r,o)=>{let n=registries.RegisteredActivities.get(t[2]);if(!n)return d.warn(`Activity ${t[2]} not found`),true;let{from:i}=o(t.slice(3)),u=registries.RegisteredRooms.get(i);return u?u.removeActivity(n):d.warn(`Room ${i} not found`),true},{name:"Remove activity from room",description:"Remove an activity from a specified room. You need to provide the activity ID and the room ID.\n\n```ink\n# remove activity <activityId> from <roomId>\n```",validation:zod.z.tuple([zod.z.literal("remove"),zod.z.literal("activity"),s(a.activityIds),zod.z.literal("from"),s(a.roomIds)])}),pixiVnInk.HashtagCommands.add((t,r,o)=>{let n=registries.RegisteredCommitments.get(t[2]);if(!n)return d.warn(`Commitment ${t[2]} not found`),true;let{in:i}=o(t.slice(3)),u=registries.RegisteredRooms.get(i);return u?u.addCommitment(n):d.warn(`Room ${i} not found`),true},{name:"Add commitment to room",description:"Add a commitment to a specified room. You need to provide the commitment ID and the room ID.\n\n```ink\n# add routine <commitmentId> in <roomId>\n```",validation:zod.z.tuple([zod.z.literal("add"),zod.z.literal("routine"),s(a.commitmentIds),zod.z.literal("in"),s(a.roomIds)])}),pixiVnInk.HashtagCommands.add(t=>{let r=registries.RegisteredCommitments.get(t[2]);return r?(handlers.routine.remove(r),true):(d.warn(`Commitment ${t[2]} not found`),true)},{name:"Remove commitment from room",description:"Remove a commitment from the routine. You need to provide the commitment ID.\n\n```ink\n# remove routine <commitmentId>\n```",validation:zod.z.tuple([zod.z.literal("remove"),zod.z.literal("routine"),s(a.commitmentIds)])}),pixiVnInk.HashtagCommands.add((t,r)=>{let o=registries.RegisteredQuests.get(t[2]);return o?(o.start(r),true):(d.warn(`Quest ${t[2]} not found`),true)},{name:"Start quest",description:"Start a quest by its ID. This command will initiate the quest and set it as started.\n\n```ink\n# start quest <questId>\n```",validation:zod.z.tuple([zod.z.literal("start"),zod.z.literal("quest"),s(a.questIds)])}),pixiVnInk.HashtagCommands.add((t,r)=>{let o=registries.RegisteredQuests.get(t[2]);return o?(o.continue(r),true):(d.warn(`Quest ${t[2]} not found`),true)},{name:"Continue quest",description:"Continue a quest by its ID. This command will proceed with the quest if it has been started.\n\n```ink\n# continue quest <questId>\n```",validation:zod.z.tuple([zod.z.literal("continue"),zod.z.literal("quest"),s(a.questIds)])});}function b(a){I(a);}exports.createNqtrHandler=I;exports.nqtrHandler=b;
|
package/dist/ink.d.mts
CHANGED
|
@@ -1,17 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
interface WaitOptions {
|
|
2
|
+
hours?: number;
|
|
3
|
+
days?: number;
|
|
4
|
+
}
|
|
5
|
+
interface NqtrHandlerOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Custom time converter function to convert time strings to numbers. The default implementation converts "HH:MM" format to hours as a number (e.g. "01:30" => 1.5).
|
|
8
|
+
* @default (time: string) => Number(time.replace(":", "."))
|
|
9
|
+
* @param time Time string in the format "HH:MM"
|
|
10
|
+
* @returns Time in hours as a number (e.g. "01:30" => 1.5)
|
|
11
|
+
*/
|
|
12
|
+
timeConverter?: (time: string) => number;
|
|
13
|
+
/**
|
|
14
|
+
* Custom date converter function to convert date strings to numbers. The default implementation converts a string to a number using `Number()`.
|
|
15
|
+
* @default (date: string) => Number(date)
|
|
16
|
+
* @param date Date string
|
|
17
|
+
* @returns Date as a number
|
|
18
|
+
*/
|
|
19
|
+
dateConverter?: (date: string) => number;
|
|
20
|
+
/**
|
|
21
|
+
* Custom wait function to replace the default time and date increasing logic. The default implementation increases time and date based on the provided delta or default values.
|
|
22
|
+
* @default waitInternal
|
|
23
|
+
* @param delta An object containing hours and/or days to increase, or a number representing hours to increase.
|
|
24
|
+
*/
|
|
25
|
+
wait?: (delta?: WaitOptions | number) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Known activity IDs — e.g. `nqtrActivityIds` from the file generated by the Vite plugin.
|
|
28
|
+
* When provided, the Ink hashtag validation does a runtime membership check instead of accepting any string.
|
|
29
|
+
*/
|
|
30
|
+
activityIds?: readonly string[];
|
|
31
|
+
/**
|
|
32
|
+
* Known commitment IDs — e.g. `nqtrCommitmentIds` from the file generated by the Vite plugin.
|
|
33
|
+
* When provided, the Ink hashtag validation does a runtime membership check instead of accepting any string.
|
|
34
|
+
*/
|
|
35
|
+
commitmentIds?: readonly string[];
|
|
36
|
+
/**
|
|
37
|
+
* Known quest IDs — e.g. `nqtrQuestIds` from the file generated by the Vite plugin.
|
|
38
|
+
* When provided, the Ink hashtag validation does a runtime membership check instead of accepting any string.
|
|
39
|
+
*/
|
|
40
|
+
questIds?: readonly string[];
|
|
41
|
+
/**
|
|
42
|
+
* Known room IDs — e.g. `nqtrRoomIds` from the file generated by the Vite plugin.
|
|
43
|
+
* When provided, the Ink hashtag validation does a runtime membership check instead of accepting any string.
|
|
44
|
+
*/
|
|
45
|
+
roomIds?: readonly string[];
|
|
46
|
+
}
|
|
3
47
|
/**
|
|
4
|
-
*
|
|
48
|
+
* Registers all NQTR-specific Ink hashtag command handlers for managing rooms, time, date,
|
|
49
|
+
* activities, routines, and quests. Supports commands like `enter room`, `set time`, `set date`,
|
|
50
|
+
* `add/remove activity`, `add/remove routine`, `start/continue quest`, and `wait`.
|
|
5
51
|
* @example
|
|
6
52
|
* ```ts
|
|
7
|
-
* import {
|
|
8
|
-
* import { HashtagCommands } from '@drincs/pixi-vn-ink';
|
|
53
|
+
* import { createNqtrHandler } from '@drincs/nqtr/ink';
|
|
9
54
|
*
|
|
10
|
-
*
|
|
55
|
+
* createNqtrHandler();
|
|
11
56
|
* ```
|
|
12
|
-
* @param options
|
|
13
|
-
|
|
57
|
+
* @param options Optional configuration for time/date conversion, wait logic, and known entity IDs.
|
|
58
|
+
*/
|
|
59
|
+
declare function createNqtrHandler(options?: NqtrHandlerOptions): void;
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated Use {@link createNqtrHandler} instead.
|
|
14
62
|
*/
|
|
15
|
-
declare
|
|
63
|
+
declare function nqtrHandler(options?: NqtrHandlerOptions): void;
|
|
16
64
|
|
|
17
|
-
export { nqtrHandler };
|
|
65
|
+
export { createNqtrHandler, nqtrHandler };
|
package/dist/ink.d.ts
CHANGED
|
@@ -1,17 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
interface WaitOptions {
|
|
2
|
+
hours?: number;
|
|
3
|
+
days?: number;
|
|
4
|
+
}
|
|
5
|
+
interface NqtrHandlerOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Custom time converter function to convert time strings to numbers. The default implementation converts "HH:MM" format to hours as a number (e.g. "01:30" => 1.5).
|
|
8
|
+
* @default (time: string) => Number(time.replace(":", "."))
|
|
9
|
+
* @param time Time string in the format "HH:MM"
|
|
10
|
+
* @returns Time in hours as a number (e.g. "01:30" => 1.5)
|
|
11
|
+
*/
|
|
12
|
+
timeConverter?: (time: string) => number;
|
|
13
|
+
/**
|
|
14
|
+
* Custom date converter function to convert date strings to numbers. The default implementation converts a string to a number using `Number()`.
|
|
15
|
+
* @default (date: string) => Number(date)
|
|
16
|
+
* @param date Date string
|
|
17
|
+
* @returns Date as a number
|
|
18
|
+
*/
|
|
19
|
+
dateConverter?: (date: string) => number;
|
|
20
|
+
/**
|
|
21
|
+
* Custom wait function to replace the default time and date increasing logic. The default implementation increases time and date based on the provided delta or default values.
|
|
22
|
+
* @default waitInternal
|
|
23
|
+
* @param delta An object containing hours and/or days to increase, or a number representing hours to increase.
|
|
24
|
+
*/
|
|
25
|
+
wait?: (delta?: WaitOptions | number) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Known activity IDs — e.g. `nqtrActivityIds` from the file generated by the Vite plugin.
|
|
28
|
+
* When provided, the Ink hashtag validation does a runtime membership check instead of accepting any string.
|
|
29
|
+
*/
|
|
30
|
+
activityIds?: readonly string[];
|
|
31
|
+
/**
|
|
32
|
+
* Known commitment IDs — e.g. `nqtrCommitmentIds` from the file generated by the Vite plugin.
|
|
33
|
+
* When provided, the Ink hashtag validation does a runtime membership check instead of accepting any string.
|
|
34
|
+
*/
|
|
35
|
+
commitmentIds?: readonly string[];
|
|
36
|
+
/**
|
|
37
|
+
* Known quest IDs — e.g. `nqtrQuestIds` from the file generated by the Vite plugin.
|
|
38
|
+
* When provided, the Ink hashtag validation does a runtime membership check instead of accepting any string.
|
|
39
|
+
*/
|
|
40
|
+
questIds?: readonly string[];
|
|
41
|
+
/**
|
|
42
|
+
* Known room IDs — e.g. `nqtrRoomIds` from the file generated by the Vite plugin.
|
|
43
|
+
* When provided, the Ink hashtag validation does a runtime membership check instead of accepting any string.
|
|
44
|
+
*/
|
|
45
|
+
roomIds?: readonly string[];
|
|
46
|
+
}
|
|
3
47
|
/**
|
|
4
|
-
*
|
|
48
|
+
* Registers all NQTR-specific Ink hashtag command handlers for managing rooms, time, date,
|
|
49
|
+
* activities, routines, and quests. Supports commands like `enter room`, `set time`, `set date`,
|
|
50
|
+
* `add/remove activity`, `add/remove routine`, `start/continue quest`, and `wait`.
|
|
5
51
|
* @example
|
|
6
52
|
* ```ts
|
|
7
|
-
* import {
|
|
8
|
-
* import { HashtagCommands } from '@drincs/pixi-vn-ink';
|
|
53
|
+
* import { createNqtrHandler } from '@drincs/nqtr/ink';
|
|
9
54
|
*
|
|
10
|
-
*
|
|
55
|
+
* createNqtrHandler();
|
|
11
56
|
* ```
|
|
12
|
-
* @param options
|
|
13
|
-
|
|
57
|
+
* @param options Optional configuration for time/date conversion, wait logic, and known entity IDs.
|
|
58
|
+
*/
|
|
59
|
+
declare function createNqtrHandler(options?: NqtrHandlerOptions): void;
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated Use {@link createNqtrHandler} instead.
|
|
14
62
|
*/
|
|
15
|
-
declare
|
|
63
|
+
declare function nqtrHandler(options?: NqtrHandlerOptions): void;
|
|
16
64
|
|
|
17
|
-
export { nqtrHandler };
|
|
65
|
+
export { createNqtrHandler, nqtrHandler };
|
package/dist/ink.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {navigator,timeTracker,routine}from'@drincs/nqtr/handlers';import {RegisteredQuests,RegisteredRooms,RegisteredActivities,RegisteredCommitments}from'@drincs/nqtr/registries';import {VariableGetter,HashtagCommands}from'@drincs/pixi-vn-ink';import {z}from'zod';var d;(s=>(s.log=(t,...r)=>console.log(`[NQTR] ${t}`,...r),s.warn=(t,...r)=>console.warn(`[NQTR] ${t}`,...r),s.error=(t,...r)=>console.error(`[NQTR] ${t}`,...r),s.info=(t,...r)=>console.info(`[NQTR] ${t}`,...r)))(d||={});function N(a){a||(a={hours:timeTracker.defaultTimeSpent}),typeof a=="number"&&(a={hours:a});let{hours:c,days:l}=a;l&&timeTracker.increaseDate(l,timeTracker.dayStartTime),c&&timeTracker.increaseTime(c);}function I(a={}){let{timeConverter:c=t=>Number(t.replace(":",".")),dateConverter:l=t=>Number(t),wait:y=N}=a;function s(t){return t&&t.length>0?z.enum(Object.fromEntries(t.map(r=>[r,r]))):z.string()}VariableGetter.add((t,r)=>{if(t&&typeof t=="object"&&"type"in t&&"key"in t&&"storageOperationType"in t&&"storageType"in t&&t.storageOperationType==="get"&&(t.storageType==="storage"||t.storageType==="tempstorage"||t.storageType==="flagStorage")){let o=t;if(o.key.endsWith("_currentStageIndex")){let n=o.key.replace("_currentStageIndex",""),i=RegisteredQuests.get(n);return i?i.currentStageIndex:(d.warn(`Quest ${n} not found`),r(t))}else if(o.key.endsWith("_started")){let n=o.key.replace("_started",""),i=RegisteredQuests.get(n);return i?i.started:(d.warn(`Quest ${n} not found`),r(t))}else if(o.key.endsWith("_completed")){let n=o.key.replace("_completed",""),i=RegisteredQuests.get(n);return i?i.completed:(d.warn(`Quest ${n} not found`),r(t))}else if(o.key.endsWith("_failed")){let n=o.key.replace("_failed",""),i=RegisteredQuests.get(n);return i?i.failed:(d.warn(`Quest ${n} not found`),r(t))}}return r(t)}),HashtagCommands.add(t=>{let r=RegisteredRooms.get(t[2]);return r?navigator.currentRoom=r:d.warn(`Room ${t[2]} not found`),true},{name:"Enter room",description:"Enter a room by its ID. This command sets the current room in the navigator to the specified room.\n\n```ink\n# enter room <roomId>\n```",validation:z.tuple([z.literal("enter"),z.literal("room"),s(a.roomIds)])}),HashtagCommands.add(t=>{let r=c(t[2]);return Number.isNaN(r)?d.warn(`Invalid time format: ${t[2]}`):timeTracker.currentTime=r,true},{name:"Set time",description:'Set the current time in the time tracker. The time should be provided in a valid format (e.g., "HH:MM").\n\n```ink\n# set time <time>\n```',validation:z.tuple([z.literal("set"),z.literal("time"),z.string()])}),HashtagCommands.add(t=>{let r=l(t[2]);return Number.isNaN(r)?d.warn(`Invalid date format: ${t[2]}`):timeTracker.currentDate=r,true},{name:"Set date",description:'Set the current date in the time tracker. The date should be provided in a valid format (e.g., "YYYY-MM-DD").\n\n```ink\n# set date <date>\n```',validation:z.tuple([z.literal("set"),z.literal("date"),z.string()])}),HashtagCommands.add(t=>{let r=c(t[1]);return Number.isNaN(r)?d.warn(`Invalid time format: ${t[1]}`):y(r),true},{name:"Wait for time",description:'Wait for a specified amount of time. The time should be provided in a valid format (e.g., "HH:MM").\n\n```ink\n# wait <time>\n```',validation:z.tuple([z.literal("wait"),z.string()])}),HashtagCommands.add(t=>(y(),true),{name:"Wait",description:"Wait for the default amount of time specified in the time tracker.\n\n```ink\n# wait\n```",validation:z.tuple([z.literal("wait")])}),HashtagCommands.add((t,r,o)=>{let n=false,i=o(t.slice(1));return i.hours!==void 0&&typeof i.hours=="string"&&(i.hours=c(i.hours),n=true),i.days!==void 0&&typeof i.days=="string"&&(i.days=l(i.days),n=true),n&&y(i),n},{name:"Wait with options",description:'Wait for a specified amount of time and/or days. You can provide options for hours and days in the format "hours=<time>" and "days=<date>".\n\n```ink\n# wait hours <time> days <date>\n```',validation:z.tuple([z.literal("wait"),z.string(),z.string()]).rest(z.string())}),HashtagCommands.add((t,r,o)=>{let n=RegisteredActivities.get(t[2]);if(!n)return d.warn(`Activity ${t[2]} not found`),true;let{in:i}=o(t.slice(3)),u=RegisteredRooms.get(i);return u?u.addActivity(n):d.warn(`Room ${i} not found`),true},{name:"Add activity to room",description:"Add an activity to a specified room. You need to provide the activity ID and the room ID.\n\n```ink\n# add activity <activityId> in <roomId>\n```",validation:z.tuple([z.literal("add"),z.literal("activity"),s(a.activityIds),z.literal("in"),s(a.roomIds)])}),HashtagCommands.add((t,r,o)=>{let n=RegisteredActivities.get(t[2]);if(!n)return d.warn(`Activity ${t[2]} not found`),true;let{from:i}=o(t.slice(3)),u=RegisteredRooms.get(i);return u?u.removeActivity(n):d.warn(`Room ${i} not found`),true},{name:"Remove activity from room",description:"Remove an activity from a specified room. You need to provide the activity ID and the room ID.\n\n```ink\n# remove activity <activityId> from <roomId>\n```",validation:z.tuple([z.literal("remove"),z.literal("activity"),s(a.activityIds),z.literal("from"),s(a.roomIds)])}),HashtagCommands.add((t,r,o)=>{let n=RegisteredCommitments.get(t[2]);if(!n)return d.warn(`Commitment ${t[2]} not found`),true;let{in:i}=o(t.slice(3)),u=RegisteredRooms.get(i);return u?u.addCommitment(n):d.warn(`Room ${i} not found`),true},{name:"Add commitment to room",description:"Add a commitment to a specified room. You need to provide the commitment ID and the room ID.\n\n```ink\n# add routine <commitmentId> in <roomId>\n```",validation:z.tuple([z.literal("add"),z.literal("routine"),s(a.commitmentIds),z.literal("in"),s(a.roomIds)])}),HashtagCommands.add(t=>{let r=RegisteredCommitments.get(t[2]);return r?(routine.remove(r),true):(d.warn(`Commitment ${t[2]} not found`),true)},{name:"Remove commitment from room",description:"Remove a commitment from the routine. You need to provide the commitment ID.\n\n```ink\n# remove routine <commitmentId>\n```",validation:z.tuple([z.literal("remove"),z.literal("routine"),s(a.commitmentIds)])}),HashtagCommands.add((t,r)=>{let o=RegisteredQuests.get(t[2]);return o?(o.start(r),true):(d.warn(`Quest ${t[2]} not found`),true)},{name:"Start quest",description:"Start a quest by its ID. This command will initiate the quest and set it as started.\n\n```ink\n# start quest <questId>\n```",validation:z.tuple([z.literal("start"),z.literal("quest"),s(a.questIds)])}),HashtagCommands.add((t,r)=>{let o=RegisteredQuests.get(t[2]);return o?(o.continue(r),true):(d.warn(`Quest ${t[2]} not found`),true)},{name:"Continue quest",description:"Continue a quest by its ID. This command will proceed with the quest if it has been started.\n\n```ink\n# continue quest <questId>\n```",validation:z.tuple([z.literal("continue"),z.literal("quest"),s(a.questIds)])});}function b(a){I(a);}export{I as createNqtrHandler,b as nqtrHandler};
|
package/dist/registries.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var pixiVn=require('@drincs/pixi-vn');var
|
|
1
|
+
'use strict';var pixiVn=require('@drincs/pixi-vn');var o;(i=>(i.log=(r,...t)=>console.log(`[NQTR] ${r}`,...t),i.warn=(r,...t)=>console.warn(`[NQTR] ${r}`,...t),i.error=(r,...t)=>console.error(`[NQTR] ${r}`,...t),i.info=(r,...t)=>console.info(`[NQTR] ${r}`,...t)))(o||={});var f=new pixiVn.CachedMap({cacheSize:20}),h;(r=>{function n(...t){for(let e of t){if(Array.isArray(e)){n(...e);continue}f.set(e.id,e);}}r.add=n;function a(t){try{let e=f.get(t);if(!e){console.warn(`[NQTR] Activity ${t} not found, you should register it first`);return}return e}catch(e){o.error(`Error while getting Activity ${t}`,e);return}}r.get=a;function c(){return Array.from(f.values())}r.values=c;function s(t){return f.has(t)}r.has=s;function i(){f.clear();}r.clear=i;})(h||={});var T=h;var m=new pixiVn.CachedMap({cacheSize:20}),A=new pixiVn.CachedMap({cacheSize:20}),R;(r=>{function n(...t){for(let e of t){if(Array.isArray(e)){n(...e);return}m.set(e.id,e);}}r.add=n;function a(t){try{let e=m.get(t);if(!e){console.warn(`[NQTR] Commitment ${t} not found, you should register it first`);return}return e}catch(e){o.error(`Error while getting Commitment ${t}`,e);return}}r.get=a;function c(){return Array.from(m.values())}r.values=c;function s(t){return m.has(t)}r.has=s;function i(){m.clear(),A.clear();}r.clear=i;})(R||={});var $=R;var u=new pixiVn.CachedMap({cacheSize:20}),Q;(r=>{function n(...t){for(let e of t){if(Array.isArray(e)){n(...e);return}u.set(e.id,e);}}r.add=n;function a(t){try{let e=u.get(t);if(!e){console.warn(`[NQTR] Location ${t} not found, you should register it first`);return}return e}catch(e){o.error(`Error while getting Location ${t}`,e);return}}r.get=a;function c(){return Array.from(u.values())}r.values=c;function s(t){return u.has(t)}r.has=s;function i(){u.clear();}r.clear=i;})(Q||={});var l=Q;var p=new pixiVn.CachedMap({cacheSize:20}),w;(r=>{function n(...t){for(let e of t){if(Array.isArray(e)){n(...e);return}p.set(e.id,e);}}r.add=n;function a(t){try{let e=p.get(t);if(!e){console.warn(`[NQTR] Map ${t} not found, you should register it first`);return}return e}catch(e){o.error(`Error while getting Map ${t}`,e);return}}r.get=a;function c(){return Array.from(p.values())}r.values=c;function s(t){return p.has(t)}r.has=s;function i(){p.clear();}r.clear=i;})(w||={});var y=w;var d=new pixiVn.CachedMap({cacheSize:5}),C;(r=>{function n(...t){for(let e of t){if(Array.isArray(e)){n(...e);return}d.set(e.id,e);}}r.add=n;function a(t){try{let e=d.get(t);if(!e){console.warn(`[NQTR] Quest ${t} not found, you should register it first`);return}return e}catch(e){o.error(`Error while getting Quest ${t}`,e);return}}r.get=a;function c(){return Array.from(d.values())}r.values=c;function s(t){return d.has(t)}r.has=s;function i(){d.clear();}r.clear=i;})(C||={});var S=C;var g=new pixiVn.CachedMap({cacheSize:20}),M;(r=>{function n(...t){for(let e of t){if(Array.isArray(e)){n(...e);return}g.set(e.id,e);let x=e.location;l.add(x);let I=x?.map;I&&y.add(I);}}r.add=n;function a(t){try{let e=g.get(t);if(!e){console.warn(`[NQTR] Room ${t} not found, you should register it first`);return}return e}catch(e){o.error(`Error while getting Room ${t}`,e);return}}r.get=a;function c(){return Array.from(g.values())}r.values=c;function s(t){return g.has(t)}r.has=s;function i(){g.clear();}r.clear=i;})(M||={});var E=M;exports.RegisteredActivities=T;exports.RegisteredCommitments=$;exports.RegisteredLocations=l;exports.RegisteredMaps=y;exports.RegisteredQuests=S;exports.RegisteredRooms=E;exports.fixedCommitments=A;exports.registeredActivities=f;exports.registeredCommitments=m;exports.registeredLocations=u;exports.registeredMaps=p;exports.registeredQuests=d;exports.registeredRooms=g;
|