@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 • 2.86 kB
JavaScript
'use strict';var pixiVn=require('@drincs/pixi-vn');var a="___nqtr-time_manager_data___";var r=class{static minDayHours=0;static maxDayHours=24;static defaultTimeSpent=1;static timeSlots=[];static weekLength=7;static weekendStartDay=this.weekLength-1;static weekDaysNames=[]};var u=class{initialize(e){let{minDayHours:t=0,maxDayHours:n=24,defaultTimeSpent:y=1,timeSlots:D=[],weekLength:s=7,weekendStartDay:m=s-1,weekDaysNames:o=[]}=e;r.minDayHours=t,r.maxDayHours=n,r.defaultTimeSpent=y,r.timeSlots=D,r.weekLength=s,m>=r.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${s}, so will be ignored`):r.weekendStartDay=m,o.length!==s?console.warn(`[NQTR] Week days names should be equal to week length ${s}, so will be ignored`):r.weekDaysNames=o;}get minDayHours(){return r.minDayHours}get maxDayHours(){return r.maxDayHours}get defaultTimeSpent(){return r.defaultTimeSpent}get timeSlots(){return r.timeSlots}get weekLength(){return r.weekLength}get weekendStartDay(){return r.weekendStartDay}get weekDaysNames(){return r.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 n=this.currentDay+t;return this.currentDay=n,this.currentHour=e,this.currentDay}nowIsBetween(e,t){e===undefined&&(e=this.minDayHours-1),t===undefined&&(t=this.maxDayHours+1);let n=this.currentHour;return e<t?n>=e&&n<t:n>=e||n<t}};module.exports=u;//# sourceMappingURL=TimeManager.js.map
//# sourceMappingURL=TimeManager.js.map