@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.93 kB
JavaScript
;var registries=require('@drincs/nqtr/registries'),storage=require('@drincs/pixi-vn/storage'),core=require('@drincs/pixi-vn/core');var N=Object.defineProperty;var k=(o,e,t)=>e in o?N(o,e,{enumerable:true,configurable:true,writable:true,value:t}):o[e]=t;var c=(o,e,t)=>k(o,typeof e!="symbol"?e+"":e,t);var d="___nqtr-time_manager_data___",I="___nqtr-current_room_memory___",v="___nqtr-last_event_memory___";function p(o){storage.storage.set(v,o);}var m;(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)))(m||(m={}));var g=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(I)}get currentRoom(){let e=this.currentRoomId;if(!e){m.error("The current room has not yet been set");return}let t=registries.RegisteredRooms.get(e);if(!t){m.error(`Current room ${e} not found`);return}return t}set currentRoom(e){if(typeof e!="string"&&(e=e.id),!registries.RegisteredRooms.get(e)){m.error(`The room ${e} is not registered, so it can't be set as current room`);return}let r=storage.storage.get(I);r!==e&&(p({type:"editroom",prev:r,value:e}),storage.storage.set(I,e));}get currentLocation(){return this.currentRoom?.location}get currentMap(){return this.currentRoom?.location.map}clearExpiredActivities(){registries.RegisteredRooms.values().forEach(e=>{e.clearExpiredActivities();});}};var y=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 w="___nqtr-temporary_commitment___",T=class{get temporaryRoutine(){let e=storage.storage.get(w);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 i=this.temporaryRoutine;e.forEach(a=>{registries.RegisteredCommitments.get(a.id)&&m.warn(`The commitment ${a.id} is already registered, it will be overwritten`),registries.RegisteredCommitments.add(a),i[a.id]={id:a.id,roomId:t,...r};}),storage.storage.set(w,i);}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]:m.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(w,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 i=registries.RegisteredCommitments.get(r),a=e[r],s=a?.roomId||registries.fixedCommitments.get(r)?.[1];return s&&i&&i.isActive(a)&&(i.characters.length>0?i.characters.every(f=>!t[f.id]||i.priority>t[f.id][0].priority)&&i.characters.forEach(f=>{t[f.id]=[i,s];}):m.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){return this.currentRoutine.find(t=>{if(t.characters.map(r=>r.id).includes(e.id))return t})}};var u=class u{};c(u,"dayStartTime",0),c(u,"dayEndTime",24),c(u,"defaultTimeSpent",1),c(u,"timeSlots",[]),c(u,"weekLength",7),c(u,"weekendStartDay",u.weekLength-1),c(u,"getDayName");var n=u;var _=class{initialize(e){let{dayStartTime:t=0,dayEndTime:r=24,defaultTimeSpent:i=1,timeSlots:a=[],weekLength:s=7,weekendStartDay:E=s-1,getDayName:f}=e;n.dayStartTime=t,n.dayEndTime=r,n.defaultTimeSpent=i,n.timeSlots=a,n.weekLength=s,E>=n.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${s}, so will be ignored`):n.weekendStartDay=E,n.getDayName=f;}get dayStartTime(){return n.dayStartTime}get dayEndTime(){return n.dayEndTime}get defaultTimeSpent(){return n.defaultTimeSpent}get timeSlots(){return n.timeSlots}get weekLength(){return n.weekLength}get weekendStartDay(){return n.weekendStartDay}get getDayName(){return n.getDayName}get currentTime(){let e=storage.storage.get(d)||{};return e.hasOwnProperty("currentTime")&&typeof e.currentTime=="number"?e.currentTime:this.dayStartTime}set currentTime(e){let t=storage.storage.get(d)||{},r={...t};typeof e=="number"?r.currentTime=e:delete r.currentTime,p({type:"edittime",prev:t,value:r}),storage.storage.set(d,r);}get currentDate(){let e=storage.storage.get(d)||{};return e.hasOwnProperty("currentDate")&&typeof e.currentDate=="number"?e.currentDate:0}set currentDate(e){let t=storage.storage.get(d)||{},r={...t};typeof e=="number"?r.currentDate=e:delete r.currentDate,p({type:"edittime",prev:t,value:r}),storage.storage.set(d,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 de=new _,fe=new g,le=new T,pe=new y;exports.navigator=fe;exports.questsNotebook=pe;exports.routine=le;exports.timeTracker=de;