@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 • 4.11 kB
JavaScript
import {StoredClassModel,storage}from'@drincs/pixi-vn';var u="___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 y=class{initialize(e){let{minDayHours:t=0,maxDayHours:r=24,defaultTimeSpent:o=1,timeSlots:s=[],weekLength:a=7,weekendStartDay:x=a-1,weekDaysNames:C=[]}=e;n.minDayHours=t,n.maxDayHours=r,n.defaultTimeSpent=o,n.timeSlots=s,n.weekLength=a,x>=n.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${a}, so will be ignored`):n.weekendStartDay=x,C.length!==a?console.warn(`[NQTR] Week days names should be equal to week length ${a}, so will be ignored`):n.weekDaysNames=C;}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=storage.getVariable(u)||{};return e.hasOwnProperty("currentHour")&&typeof e.currentHour=="number"?e.currentHour:this.minDayHours}set currentHour(e){let t=storage.getVariable(u)||{};typeof e=="number"?t.currentHour=e:delete t.currentHour,storage.setVariable(u,t);}get currentDay(){let e=storage.getVariable(u)||{};return e.hasOwnProperty("currentDay")&&typeof e.currentDay=="number"?e.currentDay:0}set currentDay(e){let t=storage.getVariable(u)||{};typeof e=="number"?t.currentDay=e:delete t.currentDay,storage.setVariable(u,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 g=new y;var N="__nqtr-activity__",p=class extends StoredClassModel{constructor(t,r,o,s=N){super(s,t);this._onRun=r;this._fromHour=o.fromHour,this._toHour=o.toHour,this._fromDay=o.fromDay,this._toDay=o.toDay;}_fromHour;get fromHour(){return this._fromHour}_toHour;get toHour(){return this._toHour}_fromDay;get fromDay(){return this._fromDay}_toDay;get toDay(){return this._toDay}get run(){return t=>this._onRun(this,t)}get expired(){return !!(this.toDay&&this.toDay<=g.currentDay)}get isActive(){return !(this.fromDay&&this.fromDay>g.currentDay||this.toDay&&this.toDay<g.currentDay||!g.nowIsBetween(this.fromHour,this.toHour))}};var k="__nqtr-commitment__",w=class extends p{constructor(t,r,o,s,a){s=s||(()=>{});super(t,s,a,k);this._characters=r;this._room=o;this.defaultExecutionType=a.executionType||"interaction",this.defaultPriority=a.priority;}defaultExecutionType;defaultPriority;get characters(){return this._characters}get room(){return this._room}get executionType(){return this.getStorageProperty("executionType")||this.defaultExecutionType}set executionType(t){this.setStorageProperty("executionType",t);}get priority(){return this.getStorageProperty("priority")||this.defaultPriority||0}set priority(t){this.setStorageProperty("priority",t);}};export{w as default};//# sourceMappingURL=CommitmentStoredClass.mjs.map
//# sourceMappingURL=CommitmentStoredClass.mjs.map