@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 • 5.09 kB
JavaScript
'use strict';var pixiVn=require('@drincs/pixi-vn');var m="___nqtr-time_manager_data___";var o=class{static minDayHours=0;static maxDayHours=24;static defaultTimeSpent=1;static timeSlots=[];static weekLength=7;static weekendStartDay=this.weekLength-1;static weekDaysNames=[]};var g=class{initialize(e){let{minDayHours:t=0,maxDayHours:r=24,defaultTimeSpent:n=1,timeSlots:u=[],weekLength:a=7,weekendStartDay:C=a-1,weekDaysNames:v=[]}=e;o.minDayHours=t,o.maxDayHours=r,o.defaultTimeSpent=n,o.timeSlots=u,o.weekLength=a,C>=o.weekLength?console.warn(`[NQTR] Weekend start day should be less than week length ${a}, so will be ignored`):o.weekendStartDay=C,v.length!==a?console.warn(`[NQTR] Week days names should be equal to week length ${a}, so will be ignored`):o.weekDaysNames=v;}get minDayHours(){return o.minDayHours}get maxDayHours(){return o.maxDayHours}get defaultTimeSpent(){return o.defaultTimeSpent}get timeSlots(){return o.timeSlots}get weekLength(){return o.weekLength}get weekendStartDay(){return o.weekendStartDay}get weekDaysNames(){return o.weekDaysNames}get currentHour(){let e=pixiVn.storage.getVariable(m)||{};return e.hasOwnProperty("currentHour")&&typeof e.currentHour=="number"?e.currentHour:this.minDayHours}set currentHour(e){let t=pixiVn.storage.getVariable(m)||{};typeof e=="number"?t.currentHour=e:delete t.currentHour,pixiVn.storage.setVariable(m,t);}get currentDay(){let e=pixiVn.storage.getVariable(m)||{};return e.hasOwnProperty("currentDay")&&typeof e.currentDay=="number"?e.currentDay:0}set currentDay(e){let t=pixiVn.storage.getVariable(m)||{};typeof e=="number"?t.currentDay=e:delete t.currentDay,pixiVn.storage.setVariable(m,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 s=new g;var O="__nqtr-activity__",h=class extends pixiVn.StoredClassModel{constructor(t,r,n,u=O){super(u,t);this._onRun=r;this._fromHour=n.fromHour,this._toHour=n.toHour,this._fromDay=n.fromDay,this._toDay=n.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<=s.currentDay)}get isActive(){return !(this.fromDay&&this.fromDay>s.currentDay||this.toDay&&this.toDay<s.currentDay||!s.nowIsBetween(this.fromHour,this.toHour))}};var A="__nqtr-commitment__",p=class extends h{constructor(t,r,n,u,a){u=u||(()=>{});super(t,u,a,A);this._characters=r;this._room=n;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);}};var w=class extends p{constructor(e,t,r,n){super(e,t?Array.isArray(t)?t:[t]:[],r,n.onRun,{executionType:n.executionType,priority:n.priority,fromHour:n.fromHour,toHour:n.toHour,fromDay:n.fromDay,toDay:n.toDay}),this._name=n.name||"",this._image=n.image,this.defaultDisabled=n.disabled||false,this.defaultHidden=n.hidden||false,this._icon=n.icon;}_name;get name(){return this._name}_image;get image(){return this._image}_icon;get icon(){return this._icon}defaultDisabled;get disabled(){let e=this.getStorageProperty("disabled")||this.defaultDisabled;return typeof e=="string"?pixiVn.getFlag(e):e}set disabled(e){this.setStorageProperty("disabled",e);}defaultHidden;get hidden(){if(this.fromDay&&this.fromDay>s.currentDay||!s.nowIsBetween(this.fromHour,this.toHour)||!this.expired)return true;let e=this.getStorageProperty("hidden")||this.defaultHidden;return typeof e=="string"?pixiVn.getFlag(e):e}set hidden(e){this.setStorageProperty("hidden",e);}};module.exports=w;//# sourceMappingURL=CommitmentBaseModel.js.map
//# sourceMappingURL=CommitmentBaseModel.js.map