@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.54 kB
JavaScript
import {StoredClassModel}from'@drincs/pixi-vn';var o="__nqtr-quest__",n=class extends StoredClassModel{constructor(t,e,r={}){super(o,t);this._stages=e;this._onStart=r.onStart,this._onNextStage=r.onNextStage;}get stages(){return this._stages}get currentStageIndex(){return this.getStorageProperty("currentStageIndex")}set currentStageIndex(t){this.setStorageProperty("currentStageIndex",t);}get currentStage(){let t=this.currentStageIndex;if(!(t===undefined||t>=this.stages.length))return this.stages[t]}get started(){return this.currentStageIndex!==undefined}get completed(){return this.currentStageIndex===undefined?false:this.currentStageIndex>this.stages.length-1}get failed(){return this.getStorageProperty("failed")||false}set failed(t){this.setStorageProperty("failed",t);}_onStart;get onStart(){return this._onStart}_onNextStage;get onNextStage(){return this._onNextStage}start(t){if(this.started){console.warn(`[NQTR] Quest ${this.id} is already started`);return}if(this.stages.length===0){console.error(`[NQTR] Quest ${this.id} has no stages`);return}this.currentStageIndex=0;let e=this.currentStage;if(e&&e.start)return this.onStart&&this.onStart(this,t),e.start(t);console.error(`[NQTR] Quest ${this.id} has no start stage`);}tryToGoNextStage(t){if(!this.started||this.completed)return false;let e=this.currentStage;return e?e.completed?this.goNextStage(t):false:(console.error(`[NQTR] Quest ${this.id} has no current stage`),false)}completeCurrentStageAndGoNext(t){let e=this.currentStage;return e?(e.completed=true,this.goNextStage(t)):(console.error(`[NQTR] Quest ${this.id} has no current stage`),false)}goNextStage(t){if(!this.started)return console.warn(`[NQTR] Quest ${this.id} is not started`),false;if(this.completed)return console.warn(`[NQTR] Quest ${this.id} is already completed`),false;let e=this.currentStage,r=this.currentStageIndex;if(!e||r===undefined)return console.error(`[NQTR] Quest ${this.id} has no current stage`),false;this.currentStageIndex=r+1,this.onNextStage&&this.onNextStage(this,t),e&&e.onEnd&&e.onEnd(e,t);let s=this.currentStage;return s&&(s.inizialize(),this.currentStageMustStart&&this.startCurrentStage(t)),true}get currentStageMustStart(){let t=this.currentStage;return t?!t.started&&t.canStart&&!t.completed:false}startCurrentStage(t){let e=this.currentStage;e&&this.currentStageMustStart?e.start(t):console.warn(`[NQTR] Quest ${this.id} can't start the current stage`);}};export{n as default};//# sourceMappingURL=QuestStoredClass.mjs.map
//# sourceMappingURL=QuestStoredClass.mjs.map