@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.
1 lines • 6.58 kB
JavaScript
;var storage=require('@drincs/pixi-vn/storage'),registries=require('@drincs/nqtr/registries'),core=require('@drincs/pixi-vn/core');var m="___nqtr-time_manager_data___",h="___nqtr-current_room_memory___",b="___nqtr-last_event_memory___";function f(u){storage.storage.set(b,u);}var a;(n=>(n.log=(o,...i)=>console.log(`[NQTR] ${o}`,...i),n.warn=(o,...i)=>console.warn(`[NQTR] ${o}`,...i),n.error=(o,...i)=>console.error(`[NQTR] ${o}`,...i),n.info=(o,...i)=>console.info(`[NQTR] ${o}`,...i)))(a||={});var p=class{get rooms(){return registries.RegisteredRooms.values()}get locations(){return registries.RegisteredLocations.values()}get maps(){return registries.RegisteredMaps.values()}get currentRoomId(){return storage.storage.get(h)}get currentRoom(){let e=this.currentRoomId;if(!e){a.error("The current room has not yet been set");return}let t=registries.RegisteredRooms.get(e);if(!t){a.error(`Current room ${e} not found`);return}return t}set currentRoom(e){if(typeof e!="string"&&(e=e.id),!registries.RegisteredRooms.get(e)){a.error(`The room ${e} is not registered, so it can't be set as current room`);return}let r=storage.storage.get(h);r!==e&&(f({type:"editroom",prev:r,value:e}),storage.storage.set(h,e));}get currentLocation(){return this.currentRoom?.location}get currentMap(){return this.currentRoom?.location.map}clearExpiredActivities(){registries.RegisteredRooms.values().forEach(e=>{e.clearExpiredActivities();});}};var g=class{get quests(){return registries.RegisteredQuests.values()}get startedQuests(){return this.quests.filter(e=>e.started)}get inProgressQuests(){return this.quests.filter(e=>e.inProgress)}get completedQuests(){return this.quests.filter(e=>e.completed)}get failedQuests(){return this.quests.filter(e=>e.failed)}get notStartedQuests(){return this.quests.filter(e=>!e.started)}find(e){return registries.RegisteredQuests.get(e)}async startsStageMustBeStarted(e){let t=this.quests.map(r=>r.currentStageMustStart?r.startCurrentStage(e):Promise.resolve());await Promise.all(t);}};var E="___nqtr-temporary_commitment___",y=class{get temporaryRoutine(){let e=storage.storage.get(E);if(e){if(Array.isArray(e)){if(e.length>0)throw new core.PixiError("obsolete_save","The save you loaded is not compatible with the current version of NQTR. Please delete the save and start a new game.");return {}}}else return {};return e}get commitmentsIds(){return [...registries.fixedCommitments.keys(),...Object.keys(this.temporaryRoutine)]}add(e,t,r={}){Array.isArray(e)||(e=[e]);let n=this.temporaryRoutine;e.forEach(o=>{let i=typeof o=="string"?o:o.id;n[i]={id:i,roomId:t,...r};}),storage.storage.set(E,n);}find(e){return registries.RegisteredCommitments.get(e)}remove(e,t){typeof e!="string"&&(e=e.id);let r=this.temporaryRoutine;r[e]?(!t||r[e].roomId===t)&&delete r[e]:a.warn(`The commitment ${e} was not found in the temporary routine, so it will be ignored. If you want to remove a fixed commitment, you can add it to the temporary routine with a same character.`),storage.storage.set(E,r);}clearExpiredRoutine(){registries.RegisteredCommitments.values().forEach(e=>{e.expired&&this.remove(e);});}get characterCommitments(){let e=this.temporaryRoutine;return this.commitmentsIds.reduce((t,r)=>{let n=registries.RegisteredCommitments.get(r),o=e[r],i=o?.roomId||registries.fixedCommitments.get(r);return i&&n?.isActive(o)&&(n.characters.length>0?n.characters.every(c=>!t[c.id]||n.priority>t[c.id][0].priority)&&n.characters.forEach(c=>{t[c.id]=[n,i];}):a.error(`The commitment ${n.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(n=>n.id).includes(t))return r})}};var M={dayStartTime:0,dayEndTime:24,defaultTimeSpent:1,timeSlots:[],weekLength:7,weekendStartDay:6,getDayName:void 0},s=M;var l=class{initialize(e){let{dayStartTime:t=0,dayEndTime:r=24,defaultTimeSpent:n=1,timeSlots:o=[],weekLength:i=7,weekendStartDay:I=i-1,getDayName:c}=e;s.dayStartTime=t,s.dayEndTime=r,s.defaultTimeSpent=n,s.timeSlots=o,s.weekLength=i,I>=s.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${i}, so will be ignored`):s.weekendStartDay=I,s.getDayName=c;}get dayStartTime(){return s.dayStartTime}get dayEndTime(){return s.dayEndTime}get defaultTimeSpent(){return s.defaultTimeSpent}get timeSlots(){return s.timeSlots}get weekLength(){return s.weekLength}get weekendStartDay(){return s.weekendStartDay}get getDayName(){return s.getDayName}get currentTime(){let e=storage.storage.get(m)||{};return Object.hasOwn(e,"currentTime")&&typeof e.currentTime=="number"?e.currentTime:this.dayStartTime}set currentTime(e){let t=storage.storage.get(m)||{},r={...t};typeof e=="number"?r.currentTime=e:delete r.currentTime,f({type:"edittime",prev:t,value:r}),storage.storage.set(m,r);}get currentDate(){let e=storage.storage.get(m)||{};return Object.hasOwn(e,"currentDate")&&typeof e.currentDate=="number"?e.currentDate:0}set currentDate(e){let t=storage.storage.get(m)||{},r={...t};typeof e=="number"?r.currentDate=e:delete r.currentDate,f({type:"edittime",prev:t,value:r}),storage.storage.set(m,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 se=new l,ae=new p,me=new y,ue=new g;exports.navigator=ae;exports.questsNotebook=ue;exports.routine=me;exports.timeTracker=se;