@drincs/nqtr
Version:
A complete system introducing the concepts of location, time and event, producing the framework of a not-quite-point-and-click adventure game.
2 lines • 6.25 kB
JavaScript
;var pixiVn=require('@drincs/pixi-vn');var s={};function R(i){try{let e=s[i];if(!e){console.error(`[NQTR] Room ${i} not found`);return}return e}catch(e){console.error(`[NQTR] Error while getting Room ${i}`,e);return}}var _="___nqtr-current_room_memory___",c=class{get rooms(){return Object.values(s)}get locations(){let e={};return Object.values(s).forEach(t=>{e[t.location.id]=t.location;}),Object.values(e)}get maps(){let e={};return Object.values(s).forEach(t=>{e[t.location.map.id]=t.location.map;}),Object.values(e)}get currentRoom(){let e=pixiVn.storage.getVariable(_);if(!e){console.error("[NQTR] The current room has not yet been set");return}let t=R(e);if(!t){console.error(`[NQTR] Current room ${e} not found`);return}return t}set currentRoom(e){if(typeof e!="string"&&(e=e.id),!R(e)){console.error(`[NQTR] The room ${e} is not registered, so it can't be set as current room`);return}pixiVn.storage.setVariable(_,e);}get currentLocation(){return this.currentRoom?.location}get currentMap(){return this.currentRoom?.location.map}clearExpiredActivities(){Object.entries(s).forEach(([e,t])=>{t.clearExpiredActivities();});}};var g={};function Q(i){try{let e=g[i];if(!e){console.error(`[NQTR] Quest ${i} not found`);return}return e}catch(e){console.error(`[NQTR] Error while getting Quest ${i}`,e);return}}var f=class{get quests(){return Object.values(g)}get startedQuests(){return this.quests.filter(e=>e.started)}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 Q(e)}startsStageMustBeStarted(e){Object.values(g).forEach(t=>{t.currentStageMustStart&&t.startCurrentStage(e);});}};var y={},h={};function p(i){try{let e=y[i];if(!e){console.error(`[NQTR] Commitment ${i} not found`);return}return e}catch(e){console.error(`[NQTR] Error while getting Commitment ${i}`,e);return}}var I="___nqtr-temporary_commitment___",l=class{get fixedRoutine(){return Object.values(h)}set fixedRoutine(e){e.forEach(t=>{h[t.id]&&console.warn(`[NQTR] Commitment id ${t.id} already exists, it will be overwritten`),h[t.id]=t;});}get temporaryRoutine(){let e=pixiVn.storage.getVariable(I);return e?e.map(r=>p(r)).filter(r=>r!==undefined):[]}get allRoutine(){return [...this.fixedRoutine,...this.temporaryRoutine]}add(e){Array.isArray(e)||(e=[e]);let t=e.map(r=>{if(!p(r.id)){console.warn(`[NQTR] Commitment ${r.id} not found, it will be ignored`);return}return r.id}).filter(r=>r!==undefined);pixiVn.storage.setVariable(I,t);}find(e){return p(e)}remove(e){Array.isArray(e)||(e=[e]);let t=e.map(o=>o.id),r=pixiVn.storage.getVariable(I);r&&(r=r.filter(o=>!t.includes(o)),pixiVn.storage.setVariable(I,r));}clearExpiredRoutine(){Object.values(y).forEach(e=>{e.expired&&delete y[e.id];});}get currentRoutine(){let e={};return [...this.temporaryRoutine,...this.fixedRoutine].reverse().forEach(t=>{t.isActive&&(t.characters.length>0?t.characters.every(o=>!e[o.id]||t.priority>e[o.id].priority)&&t.characters.forEach(o=>{e[o.id]=t;}):console.error(`[NQTR] The commitment ${t.id} has no characters assigned`));}),Object.values(e)}get currentRoomRoutine(){return C.currentRoom?.routine||[]}getCommitmentByCharacter(e){this.currentRoutine.forEach(t=>{if(t.characters.map(r=>r.id).includes(e.id))return t});}};var a="___nqtr-time_manager_data___";var n=class{static minDayHours=0;static maxDayHours=24;static defaultTimeSpent=1;static timeSlots=[];static weekLength=7;static weekendStartDay=this.weekLength-1;static weekDaysNames=[]};var d=class{initialize(e){let{minDayHours:t=0,maxDayHours:r=24,defaultTimeSpent:o=1,timeSlots:x=[],weekLength:u=7,weekendStartDay:T=u-1,weekDaysNames:w=[]}=e;n.minDayHours=t,n.maxDayHours=r,n.defaultTimeSpent=o,n.timeSlots=x,n.weekLength=u,T>=n.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${u}, so will be ignored`):n.weekendStartDay=T,w.length!==u?console.warn(`[NQTR] Week days names should be equal to week length ${u}, so will be ignored`):n.weekDaysNames=w;}get minDayHours(){return n.minDayHours}get maxDayHours(){return n.maxDayHours}get defaultTimeSpent(){return n.defaultTimeSpent}get timeSlots(){return n.timeSlots}get weekLength(){return n.weekLength}get weekendStartDay(){return n.weekendStartDay}get weekDaysNames(){return n.weekDaysNames}get currentHour(){let e=pixiVn.storage.getVariable(a)||{};return e.hasOwnProperty("currentHour")&&typeof e.currentHour=="number"?e.currentHour:this.minDayHours}set currentHour(e){let t=pixiVn.storage.getVariable(a)||{};typeof e=="number"?t.currentHour=e:delete t.currentHour,pixiVn.storage.setVariable(a,t);}get currentDay(){let e=pixiVn.storage.getVariable(a)||{};return e.hasOwnProperty("currentDay")&&typeof e.currentDay=="number"?e.currentDay:0}set currentDay(e){let t=pixiVn.storage.getVariable(a)||{};typeof e=="number"?t.currentDay=e:delete t.currentDay,pixiVn.storage.setVariable(a,t);}get isWeekend(){return this.currentWeekDayNumber>=this.weekendStartDay}get currentWeekDayNumber(){return this.currentDay%this.weekLength+1}get currentDayName(){let e=this.currentWeekDayNumber-1;return e>=this.weekDaysNames.length?(console.warn(`[NQTR] Week day name is not defined for day ${e}`,this.weekDaysNames),""):this.weekDaysNames[e]}get currentTimeSlot(){if(this.timeSlots.length===0)return console.warn("[NQTR] Time slots are not defined"),0;for(let e=0;e<this.timeSlots.length;e++){let t=this.timeSlots[e];if(this.timeSlots.length>e+1&&this.nowIsBetween(t.startHour,this.timeSlots[e+1].startHour))return e}return this.timeSlots.length-1}increaseHour(e=this.defaultTimeSpent){let t=this.currentHour+e;return t>=this.maxDayHours&&(this.increaseDay(),t=this.minDayHours+(t-this.maxDayHours)),this.currentHour=t,this.currentHour}increaseDay(e=this.minDayHours,t=1){let r=this.currentDay+t;return this.currentDay=r,this.currentHour=e,this.currentDay}nowIsBetween(e,t){e===undefined&&(e=this.minDayHours-1),t===undefined&&(t=this.maxDayHours+1);let r=this.currentHour;return e<t?r>=e&&r<t:r>=e||r<t}};var J=new d,C=new c,X=new l,Z=new f;exports.navigator=C;exports.questsNotebook=Z;exports.routine=X;exports.timeTracker=J;//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map