narrat 2.2.3 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/narrat.es.js +1 -1
- package/dist/narrat.es.js.map +1 -1
- package/dist/narrat.umd.js +1 -1
- package/dist/narrat.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/narrat.umd.js
CHANGED
|
@@ -181,5 +181,5 @@ This will fail in production.`);s=Pl,s._s.has(r)||(i?Fg(r,e,o,s):X7(r,o,s),proce
|
|
|
181
181
|
Label: ${((r=n.currentFrame)==null?void 0:r.label)||"none"}`)}}async function kU(t,e){const n=t.command,r=ar.commands[n.commandType];if(r){const o={args:[],options:{},operator:n.operator,staticOptions:n.staticOptions,code:t.code,commandType:n.commandType,fileName:t.fileName,line:t.line},i=r.argTypes;o.options={};for(const[a,s]of n.args.entries()){let u;if(b8(s))u=await Qg(s,e);else if(typeof s=="string")if(s.search(m8)===0)u=s.substring(3);else if(k8(s)){const l=cu(),f=cU(l,s.substring(1));if(f){const[c,d]=f;u=c[d]}else u=s}else u=s;else u=s;if(o.args.push(u),Array.isArray(i)&&i.length>a){const l=i[a];u!==null&&(o.options[l.name]=u)}}return o}else throw new Error(`${n.commandType} is not a valid command`)}async function Qg(t,e){const n=await kU(t,e),r=ar.commands[n.commandType];if(r)return await r.run(n,e);throw new Error(`${n.commandType} is not a valid command`)}async function wU(t){El("onPlayerAnswered");const e=fn(),n=e.popAnswerQueue(),r=e.currentLine;try{if(n){const o=ar.commands[n.commandType];if(o)return await o.processPlayerAnswer(n,t)}}catch(o){console.error(o),Kn(`Error after player answer at ${r.fileName}:${r.line+1} (${r.code}<br /> - Error: ${o}`)}}const fu=Ko("rendering",{state:()=>({screenHeight:window.innerHeight,screenWidth:window.innerWidth,canvasWidth:window.innerWidth,canvasHeight:window.innerHeight,renderRatio:1,topOffset:0,leftOffset:0,layoutMode:"horizontal"}),actions:{updateScreenSize(t,e,n){this.screenHeight=e,this.screenWidth=t,this.renderRatio=1,this.topOffset=0,this.leftOffset=0,t<jt().layout.verticalLayoutThreshold?this.layoutMode="vertical":this.layoutMode="horizontal"}}}),kn=Ko("main",{state:()=>({ready:!1,playing:!1,errors:[],playTime:{start:0,previousPlaytime:0},saveSlot:0,options:{logging:!1,debug:!1},flowState:"menu",modal:!1,paused:!1}),actions:{async setup(t,e){var s;$r().setMasterVolume((s=e.audioOptions.volume)!=null?s:1),e.audioOptions.defaultMusic&&$r().playChannel("music",e.audioOptions.defaultMusic,0),await fn().loadScripts(t),$i().setButtons(e),cr().setupSkills(e.skills),Wi().setupHudStats(e.hudStats),Or().setupItems(e.items),Vr().setupQuests(e.quests)},startMachine(){$r().stopAll(),fn().start(),this.ready=!0,this.startPlaying(),ar.callHook("onGameStart"),this.setFlowState("playing")},setSaveSlot(t){this.saveSlot=t,NW(t)},async startGame(t){this.setSaveSlot(t),this.startMachine(),await this.saveGame(),fn().runGame()},async loadGame(t,e){this.setSaveSlot(e),this.startMachine(),t&&(this.setLoadedData(t),$r().reloadAudio(t.audio),fn().runLabel(t.vm.lastLabel))},playerAnswered(t){wU(t)},menuReturn(){this.reset(),this.setFlowState("menu"),jt().audioOptions.defaultMusic&&$r().playChannel("music",jt().audioOptions.defaultMusic,0)},createError(t){this.errors.push({text:t})},clearErrors(){this.errors=[]},setFlowState(t){this.flowState=t},openModal(t){this.modal=t},closeModal(){this.modal=!1},toggleMenu(){this.modal?this.modal=!1:this.modal="menu"},pause(){this.paused=!0},unpause(){this.paused=!1},setOptions(t){this.options=t},startPlaying(){this.playing=!0,this.playTime.start=Date.now()},reset(){this.ready=!1,this.errors=[],this.modal=!1,this.paused=!1,fn().reset(),$r().reset(),this.playing=!1,this.ready=!0},generateSaveData(){return{playTime:qd(this.playTime.start,this.playTime.previousPlaytime)}},loadSaveData(t){this.playTime.previousPlaytime=t.playTime},saveGame(){const t=$i(),e=cr(),n=co(),r=fn(),o=kn(),i=Wi(),a=$r(),s=Or(),u={version:n8,screen:t.generateSaveData(),skills:e.generateSaveData(),dialog:n.generateSaveData(),vm:r.generateSaveData(),main:o.generateSaveData(),hud:i.generateSaveData(),audio:a.generateSaveData(),inventory:s.generateSaveData(),quests:Vr().generateSaveData(),metadata:{saveDate:new Date().toISOString()}};IW(u,this.saveSlot)},setLoadedData(t){const e=$i(),n=cr(),r=co(),o=fn(),i=kn(),a=Wi(),s=$r(),u=Or();e.loadSaveData(t.screen),n.loadSaveData(t.skills),r.loadSaveData(t.dialog),o.loadSaveData(t.vm),i.loadSaveData(t.main),a.loadSaveData(t.hud),s.loadSaveData(t.audio),u.loadSaveData(t.inventory),Vr().loadSaveData(t.quests)},getAllStates(){return{main:this,screens:$i(),skills:cr(),dialog:co(),vm:fn(),hud:Wi(),audio:$r(),rendering:fu(),notifications:Co(),inventory:Or(),quests:Vr()}},overrideStates(t){const e=this.getAllStates();for(const n in t){const r=t[n];Object.assign(e[n],r)}}},getters:{isInGame(t){return t.flowState==="playing"}}});function jU(t,e,n){console.error(`Parser error: ${t.fileName}:${t.currentLine}`,n);const r=`[Parser Error] in <span class="error-filename">${t.fileName}:${e+1}</span> - <b>${n}</b>`;Kn(r)}function Kn(t){const e=kn();console.error(t),t=t.replace(/[\r\n]/g,`
|
|
182
182
|
<br />`),e.createError(`\u274C ${t}`)}const cr=Ko("skills",{state:()=>({skillChecks:{},skills:{}}),actions:{setupSkillCheck(t,e){this.skillChecks[e]=t},passSkillCheck(t,e){this.skillChecks[t].happened=!0,this.skillChecks[t].succeeded=!0,e&&(this.skillChecks[t].hidden=!0)},failSkillCheck(t,e){this.skillChecks[t].happened=!0,this.skillChecks[t].succeeded=!1,e&&(this.skillChecks[t].hidden=!0)},generateSaveData(){return{skillChecks:this.skillChecks,skills:this.skills}},getSkillCheck(t){return this.skillChecks[t]||this.setupSkillCheck(this.createSkillCheckState(),t),this.skillChecks[t]},createSkillCheckState(){return{happened:!1,succeeded:!1,hidden:!1}},loadSaveData(t){this.skillChecks=Md(this.skillChecks,t.skillChecks),this.skills=Md(this.skills,t.skills)},setupSkills(t){for(const e in t)this.skills[e]={id:e,level:t[e].startingLevel||0,xp:0}},getSkill(t){return this.skills[t]},getSkillLevel(t){return this.getSkill(t).level},getSkillXp(t){return this.getSkill(t).xp},addXp(t,e){const n=this.getSkill(t);n||Kn(`Skill ${t} doesn't exist`),n.xp+=e,n.xp>=jt().skillOptions.xpPerLevel&&(n.xp=0,n.level++,this.levelledUp(t))},setSkillLevel(t,e){const n=this.getSkill(t);n||Kn(`Skill ${t} doesn't exist`),n.level=e,this.levelledUp(t)},incrementSkill(t,e){this.getSkill(t).level+=e,this.levelledUp(t)},levelledUp(t){const e=jt().skills[t].name,n=this.skills[t].level;jt().skillOptions.notifyLevelUp&&Co().addNotification(`Your skill in ${e} is now level ${n}`)}}});let x8;const xU=j.defineComponent({components:{Modal:ds},setup(){const t=cr(),e=j.computed(()=>t.skills),n=j.computed(()=>t.skillChecks);return{skills:e,skillChecks:n}},data(){return{showDebug:!1,jumping:!1,searchString:"",matches:[],matchCursor:0}},mounted(){window.addEventListener("keydown",t=>{if(this.jumping||(t.key==="d"&&this.toggle(),t.key==="j"&&this.jump()),t.key==="ArrowDown"&&(t.preventDefault(),this.matches.length>this.matchCursor+1?this.matchCursor+=1:this.matchCursor=0),t.key==="ArrowUp"&&(t.preventDefault(),this.matchCursor>0?this.matchCursor-=1:this.matchCursor=this.matches.length-1),t.key==="Escape"&&(this.finishJumping(),this.showDebug=!1),this.jumping&&t.key==="Enter"&&this.matchCursor<this.matches.length){const e=this.matches[this.matchCursor];fn().runLabel(e),this.finishJumping()}})},methods:{finishJumping(){this.jumping=!1,this.matches=[],this.searchString=""},labelSelected(t){const e=t.target.value;fn().runLabel(e),this.close()},close(){this.showDebug=!1},closeErrors(){kn().clearErrors()},open(){this.showDebug=!0;const t=fn(),e=kn(),n=Vr(),r=Or(),o=cr();this.$nextTick(()=>{new _7({target:this.$refs.variablesViewer,props:{content:{text:void 0,json:{data:this.variables,quests:n.quests,items:r.items,skills:o.skills,skillChecks:o.skillChecks}},onChange:i=>{t.overrideData(i.json.data),n.quests=i.json.quests,r.items=i.json.items,o.skills=i.json.skills,o.skillChecks=i.json.skillChecks}}}),new _7({target:this.$refs.stateViewer,props:{content:{text:void 0,json:e.getAllStates()},onChange:i=>{e.overrideStates(i.json)}}})})},toggle(){this.showDebug?this.showDebug=!1:this.jumping?this.finishJumping():this.open()},jump(){x8=new hs(this.labels,{includeScore:!0}),this.jumping=!0,setTimeout(()=>{this.$nextTick(()=>{this.$refs.search.focus()})},10),this.matchCursor=0,this.matches=this.labels},getMatchResultStyle(t){if(t===this.matchCursor)return{background:"var(--light-background)"}},onSearchInput(){const t=this.searchString;console.log(t);const e=x8.search(t);this.matches=e.map(n=>n.item),this.matches.length>0&&this.matchCursor>this.matches.length-1&&(this.matchCursor=this.matches.length-1)},save(){kn().saveGame()},wordCount(){const e=Object.values(this.script).reduce((n,r)=>(Po.log(n),n+this.countWordsInScriptBranch(r.branch)),0);alert(`You have ${e} words`)},countWordsInScriptLine(t){if(t.command.commandType==="talk"&&typeof t.command.args[2]=="string")return this.countWordsInString(t.command.args[2]);if(t.command.commandType==="text")return this.countWordsInString(t.code);if(t.command.commandType==="choice"){const e=t.command.staticOptions;let n=this.countWordsInScriptLine(e.prompt);return n+=e.choices.reduce((o,i)=>o+this.countWordsInString(i.prompt.code),0),e.choices.reduce((o,i)=>i.branch?o+this.countWordsInScriptBranch(i.branch):o,n)}if(t.command.commandType==="if"){const e=t.command.staticOptions;return[e.success,e.failure].reduce((r,o)=>o?r+this.countWordsInScriptBranch(o):r,0)}return 0},countWordsInString(t){return t.split(" ").length},countWordsInScriptBranch(t){return t.reduce((e,n)=>n?e+this.countWordsInScriptLine(n):e,0)},getPlayTimeString(){const t=qd(this.playTime.start,this.playTime.previousPlaytime);return Hd(t/1e3)}},computed:{...Ci(fn,["script","data"]),...Ci(kn,["playTime","errors","playing","flowState"]),labels(){const t=this.script;return Object.keys(t).sort()},variables(){return this.data}}}),rY="",_U={class:"debug-menu"},SU={key:0,class:"debug-info"},CU=[j.createElementVNode("h3",null,"Debug mode is ON",-1),j.createElementVNode("ul",null,[j.createElementVNode("li",null,[j.createElementVNode("b",null,"j"),j.createTextVNode(": Quick Label Jump")]),j.createElementVNode("li",null,[j.createElementVNode("b",null,"d"),j.createTextVNode(": Debug Menu")]),j.createElementVNode("li",null,[j.createElementVNode("b",null,"Escape"),j.createTextVNode(": Toggle Menu")])],-1)],$U=j.createElementVNode("h3",{class:"title"},"Jump to label",-1),OU={key:0,class:"search-results"},AU={key:1},EU=[j.createElementVNode("h3",null,"No matches found",-1)],PU=j.createElementVNode("h3",{class:"title"},"Error(s)",-1),TU=j.createTextVNode(" There are errors in your dialogue scripts. Open the developer console for more details. "),MU=["innerHTML"],IU=j.createElementVNode("h3",{class:"title"},"Debug Menu!",-1),NU={class:"container"},LU=j.createTextVNode(" Hello this is the debug menu. "),RU=j.createElementVNode("option",{class:"option",selected:"",disabled:""},"Jump to a label",-1),DU=["value"],BU={class:"grid grid-cols-3 gap-4"},zU=j.createElementVNode("h2",null,"Variables Editor",-1),VU={ref:"variablesViewer"},FU=j.createElementVNode("h2",null,"Skill Checks",-1),qU={class:"table-auto"},HU=j.createElementVNode("thead",null,[j.createElementVNode("tr",null,[j.createElementVNode("th",null,"Skill Check"),j.createElementVNode("th",null,"Happened"),j.createElementVNode("th",null,"Succeeded")])],-1),WU=j.createElementVNode("h2",null,"App State editor (entire app and engine",-1),UU=j.createElementVNode("h3",{style:{color:"pink"}}," Use for debugging, editing some of those things can cause issues ",-1),JU={ref:"stateViewer"};function GU(t,e,n,r,o,i){const a=j.resolveComponent("modal");return j.openBlock(),j.createElementBlock("div",_U,[j.createElementVNode("button",{onClick:e[0]||(e[0]=(...s)=>t.open&&t.open(...s)),class:"button debug-button"},"Debug Menu"),!t.playing&&t.flowState==="menu"?(j.openBlock(),j.createElementBlock("div",SU,CU)):j.createCommentVNode("",!0),t.jumping?(j.openBlock(),j.createBlock(a,{key:1,onClose:t.finishJumping,containerCssClass:"jump-menu-container"},{header:j.withCtx(()=>[$U]),body:j.withCtx(()=>[j.withDirectives(j.createElementVNode("input",{type:"text",class:"label-input input",ref:"search","onUpdate:modelValue":e[1]||(e[1]=s=>t.searchString=s),onInput:e[2]||(e[2]=(...s)=>t.onSearchInput&&t.onSearchInput(...s))},null,544),[[j.vModelText,t.searchString]]),t.matches.length>0?(j.openBlock(),j.createElementBlock("div",OU,[(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(t.matches,(s,u)=>(j.openBlock(),j.createElementBlock("div",{class:"search-result",style:j.normalizeStyle(t.getMatchResultStyle(u)),key:u},j.toDisplayString(s),5))),128))])):(j.openBlock(),j.createElementBlock("div",AU,EU))]),_:1},8,["onClose"])):j.createCommentVNode("",!0),t.errors.length>0?(j.openBlock(),j.createBlock(a,{key:2,onClose:t.closeErrors,containerCssClass:"debug-menu-container"},{header:j.withCtx(()=>[PU]),body:j.withCtx(()=>[TU,j.createElementVNode("ul",null,[(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(t.errors,(s,u)=>(j.openBlock(),j.createElementBlock("li",{key:u,class:"error-message list-disc",innerHTML:s.text},null,8,MU))),128))])]),_:1},8,["onClose"])):j.createCommentVNode("",!0),t.showDebug?(j.openBlock(),j.createBlock(a,{key:3,onClose:t.close,containerCssClass:"debug-menu-container"},{header:j.withCtx(()=>[IU]),body:j.withCtx(()=>[j.createElementVNode("div",NU,[LU,j.createElementVNode("select",{class:"select",name:"label-selector",onChange:e[3]||(e[3]=s=>t.labelSelected(s))},[RU,(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(t.labels,s=>(j.openBlock(),j.createElementBlock("option",{class:"option",value:s,key:s},j.toDisplayString(s),9,DU))),128))],32),j.createElementVNode("div",BU,[j.createElementVNode("button",{onClick:e[4]||(e[4]=(...s)=>t.wordCount&&t.wordCount(...s)),class:"button"},"Word Count"),j.createElementVNode("button",{onClick:e[5]||(e[5]=(...s)=>t.save&&t.save(...s)),class:"button"},"Save Game")]),j.createElementVNode("h3",null,"Play time: "+j.toDisplayString(t.getPlayTimeString()),1),zU,j.createElementVNode("div",VU,null,512),FU,j.createElementVNode("table",qU,[HU,j.createElementVNode("tbody",null,[(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(t.skillChecks,(s,u)=>(j.openBlock(),j.createElementBlock("tr",{key:u},[j.createElementVNode("td",null,j.toDisplayString(u),1),j.createElementVNode("td",null,j.toDisplayString(s.happened?"\u2705":"\u274C"),1),j.createElementVNode("td",null,j.toDisplayString(s.happened?s.succeeded?"\u2705":"\u274C":"NA"),1)]))),128))])]),WU,UU,j.createElementVNode("div",JU,null,512)])]),_:1},8,["onClose"])):j.createCommentVNode("",!0)])}const KU=qr(xU,[["render",GU]]),QU=j.defineComponent({data(){return{}},methods:{getStatImage(t){return Al(this.statsConfig[t].icon)}},computed:{...Ci(Wi,["hudStats"]),...Ci(fu,["layoutMode"]),statsConfig(){return jt().hudStats},stats(){return this.hudStats},hudStyle(){let t="0";return this.layoutMode==="horizontal"&&(t=`${jt().layout.minTextWidth}px`),{right:t}}}}),sY="",YU=["src"],XU={class:"bold hud-text"},ZU=j.createTextVNode(": ");function eJ(t,e,n,r,o,i){return j.openBlock(),j.createElementBlock("div",{class:"hud",style:j.normalizeStyle(t.hudStyle)},[(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(t.stats,(a,s)=>(j.openBlock(),j.createElementBlock("div",{key:s,class:"hud-stat"},[j.createElementVNode("img",{class:"hud-icon",src:t.getStatImage(s)},null,8,YU),j.createElementVNode("span",XU,j.toDisplayString(t.statsConfig[s].name),1),ZU,j.createElementVNode("span",null,j.toDisplayString(Math.floor(a.value*100)/100),1)]))),128))],4)}const tJ=qr(QU,[["render",eJ]]),nJ=j.defineComponent({props:{percentage:Number,step:String},methods:{loadingStyle(){return{width:`${this.percentage*40}vw`}}},computed:{}}),uY="",rJ={id:"loading-bar"},oJ={id:"loading-text"};function iJ(t,e,n,r,o,i){return j.openBlock(),j.createElementBlock("div",rJ,[j.createElementVNode("div",{id:"inner-loading-bar",style:j.normalizeStyle(t.loadingStyle())},null,4),j.createElementVNode("div",oJ,[j.createElementVNode("h3",null,"Loading "+j.toDisplayString(Math.floor(t.percentage*100))+"% - "+j.toDisplayString(t.step),1)])])}const aJ=qr(nJ,[["render",iJ]]),sJ=j.defineComponent({data(){},methods:{},computed:{...Ci(Co,["notifications"])}}),lY="",uJ=["innerHTML"];function lJ(t,e,n,r,o,i){return j.openBlock(),j.createBlock(j.TransitionGroup,{name:"notification",tag:"div",class:"notifications-holder"},{default:j.withCtx(()=>[(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(t.notifications,(a,s)=>(j.openBlock(),j.createElementBlock("div",{class:"notification",key:s},[j.createElementVNode("h3",{innerHTML:a.text},null,8,uJ)]))),128))]),_:1})}const cJ=qr(sJ,[["render",lJ]]);let Yg;function fJ(t){Yg=t}function Xg(t){return Yg.characters[t]}function dJ(t,e){const n=Xg(t);if(e||(e="default"),n.sprites)return`${Yg.config.imagesPath}${n.sprites[e]}`}function Id(t){return t?Xg(t).style||{}:{}}function _8(t,e,n,r){const o=t/n,i=e/r;return Math.min(o,i)}let S8=0,C8=0;function hJ(t){return Po.log("Loading images"),new Promise((e,n)=>{if(Object.keys(t.images).length<1){e();return}for(const r in t.images){const o=t.images[r];pJ(r,o,e,n)}})}function pJ(t,e,n,r){S8++,Po.log(`Loading image ${t} at ${e}`);const o=new Image;o.onload=()=>{C8+=1,Po.log(`Loaded image ${t} successfully`),C8>=S8&&(Po.log("All images loaded"),n())},o.onerror=i=>{console.error(`Error loading image ${t}`),r(i)},o.src=e}function $8(t,e=50,n={}){var c,d;let r;const o=(c=n.isImmediate)!=null?c:!1,i=(d=n.callback)!=null?d:!1,a=n.maxWait;let s=Date.now(),u=[];function l(){if(console.log("wait: ",e),a!==void 0){const h=Date.now()-s;if(h+e>=a)return a-h}return e}const f=function(...h){const p=this;return new Promise((v,g)=>{const m=function(){if(r=void 0,s=Date.now(),!o){const k=t.apply(p,h);i&&i(k),u.forEach(({resolve:w})=>w(k)),u=[]}};console.log("should call now? ",o,r);const y=o&&r===void 0;r!==void 0&&(console.log("clearing timeout"),clearTimeout(r));const b=l();if(console.log(`nextInvoke: ${b}`),r=setTimeout(m,b),y){console.log("calling");const k=t.apply(p,h);return i&&i(k),v(k)}u.push({resolve:v,reject:g})})};return f.cancel=function(h){r!==void 0&&clearTimeout(r),u.forEach(({reject:p})=>p(h)),u=[]},f}const vJ=j.defineComponent({data(){return{muted:!1,volumes:[],modeNames:{master:"Master volume:",music:"Music:",ambiant:"Ambiant:",sound:"Sound effects:"}}},mounted(){const t=$r(),e=ja.Howler.volume();this.volumes.push({mode:"master",volume:e}),t.modes.forEach((n,r)=>{this.volumes.push({mode:r,volume:t.modes.get(r).options.volume})})},methods:{changeVolume(t,e){const n=e.target;t==="master"?$r().setMasterVolume(n.value):$r().setModeVolume(t,n.value)},toggleMute(){this.muted?(ja.Howler.mute(!1),this.muted=!1):(ja.Howler.mute(!0),this.muted=!0)}}}),cY="",mJ={class:"volume-controls"},gJ=j.createElementVNode("h3",{class:"subtitle"},"Volume",-1),yJ={for:"volume",class:"volume-label"},bJ=["onUpdate:modelValue","onChange"];function kJ(t,e,n,r,o,i){return j.openBlock(),j.createElementBlock("div",mJ,[gJ,(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(t.volumes,(a,s)=>(j.openBlock(),j.createElementBlock("div",{class:"volume-control",key:a.mode},[j.createElementVNode("label",yJ,j.toDisplayString(t.modeNames[a.mode]),1),j.withDirectives(j.createElementVNode("input",{ref_for:!0,ref:"slider",class:"volume-slider",type:"range",id:"volume",name:"volume",min:"0",max:"1",step:"0.1","onUpdate:modelValue":u=>t.volumes[s].volume=u,onChange:u=>t.changeVolume(a.mode,u)},null,40,bJ),[[j.vModelText,t.volumes[s].volume]])]))),128))])}const wJ=qr(vJ,[["render",kJ]]),jJ=j.defineComponent({components:{Modal:ds,VolumeControls:wJ},data(){return{}},mounted(){},methods:{quit(){window.close()},mainMenu(){kn().menuReturn(),this.closeMenu()},closeMenu(){this.$emit("close")},getPlayTimeString(){const t=qd(this.playTime.start,this.playTime.previousPlaytime);return Hd(t/1e3)}},computed:{...Ci(kn,["playTime"])}}),fY="",xJ=j.createElementVNode("h3",{class:"title"},"Menu",-1),_J={class:"menu-content"};function SJ(t,e,n,r,o,i){const a=j.resolveComponent("VolumeControls"),s=j.resolveComponent("modal");return j.openBlock(),j.createBlock(s,{class:"menu",onClose:e[2]||(e[2]=u=>t.$emit("close")),containerCssClass:"main-menu-modal"},{header:j.withCtx(()=>[xJ]),body:j.withCtx(()=>[j.createElementVNode("div",_J,[j.createElementVNode("h3",null,"Play time: "+j.toDisplayString(t.getPlayTimeString()),1),j.createVNode(a),j.createElementVNode("button",{class:"button title quit-button",onClick:e[0]||(e[0]=(...u)=>t.mainMenu&&t.mainMenu(...u))}," Main Menu "),j.createElementVNode("button",{class:"button title quit-button",onClick:e[1]||(e[1]=(...u)=>t.quit&&t.quit(...u))},"Exit")])]),_:1})}const CJ=qr(jJ,[["render",SJ]]),$J=j.defineComponent({setup(){const t=cr();return{skills:j.computed(()=>t.skills)}},components:{Modal:ds},data(){return{chosenSkill:!1}},mounted(){},methods:{getSkillStyle(t){return{backgroundImage:`url(${this.skillConf[t].icon})`}},getSkillName(t){return this.skillConf[t].name},clickSkill(t){this.chosenSkill=t},closeSkill(){this.chosenSkill=!1},xpBarWidth(t){return{width:`${Math.floor(t/this.xpPerLevel*100)}%`}}},computed:{skillsToDisplay(){const t={};for(const e in this.skills)this.skillConf[e].hidden&&this.skills[e].level<1||(t[e]=this.skills[e]);return t},skillConf(){return jt().skills},xpPerLevel(){return jt().skillOptions.xpPerLevel}}}),dY="",OJ=j.createElementVNode("h3",{class:"title"},"Skills",-1),AJ={key:0,class:"skills-container"},EJ=["onClick"],PJ={class:"skill-title"},TJ={class:"skill-xp-container"},MJ={class:"skill-xp-text"},IJ={class:"skill-level"},NJ={key:1},LJ={class:"flex flex-row skill-description-container"},RJ={class:"flex skill-left"},DJ={class:"flex skill-right"},BJ=j.createElementVNode("hr",{class:"hr-solid"},null,-1);function zJ(t,e,n,r,o,i){const a=j.resolveComponent("modal");return j.openBlock(),j.createBlock(a,{class:"menu",onClose:e[1]||(e[1]=s=>t.$emit("close")),containerCssClass:"skills-modal"},{header:j.withCtx(()=>[OJ]),body:j.withCtx(()=>[t.chosenSkill?typeof t.chosenSkill=="string"?(j.openBlock(),j.createElementBlock("div",NJ,[j.createElementVNode("div",LJ,[j.createElementVNode("div",RJ,[j.createElementVNode("div",{class:"skill-display",style:j.normalizeStyle(t.getSkillStyle(t.chosenSkill))},null,4)]),j.createElementVNode("div",DJ,[j.createElementVNode("h2",null,j.toDisplayString(t.getSkillName(t.chosenSkill)),1),BJ,j.createElementVNode("h3",null,"Level: "+j.toDisplayString(t.skills[t.chosenSkill].level),1),j.createElementVNode("p",null,j.toDisplayString(t.skillConf[t.chosenSkill].description),1)])]),j.createElementVNode("button",{class:"button",onClick:e[0]||(e[0]=(...s)=>t.closeSkill&&t.closeSkill(...s))},j.toDisplayString("<--"))])):j.createCommentVNode("",!0):(j.openBlock(),j.createElementBlock("div",AJ,[(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(t.skillsToDisplay,s=>(j.openBlock(),j.createElementBlock("button",{onClick:()=>t.clickSkill(s.id),class:"skill-display",style:j.normalizeStyle(t.getSkillStyle(s.id)),key:s.id},[j.createElementVNode("h3",PJ,j.toDisplayString(t.getSkillName(s.id)),1),j.createElementVNode("div",TJ,[j.createElementVNode("div",{class:"skill-xp-bar",style:j.normalizeStyle(t.xpBarWidth(s.xp))},null,4),j.createElementVNode("h3",MJ,j.toDisplayString(s.xp)+" / "+j.toDisplayString(t.xpPerLevel)+" XP",1)]),j.createElementVNode("h3",IJ,j.toDisplayString(s.level),1)],12,EJ))),128))]))]),_:1})}const VJ=qr($J,[["render",zJ]]),FJ=j.defineComponent({setup(){const t=Or(),e=co(),n=j.computed(()=>t.items),r=j.computed(()=>e.currentDialog.choices);return{items:n,currentlyChoosing:r}},components:{Modal:ds},data(){return{chosenId:!1}},mounted(){},methods:{close(){this.$emit("close")},getItemStyle(t){return{backgroundImage:`url(${this.itemConf[t].icon})`}},getItemName(t){return this.itemConf[t].name},getItemConf(t){return this.itemConf[t]},clickItem(t){this.chosenId=t},closeItem(){this.chosenId=!1},useItem(){if(this.chosenItem&&this.canUseChosenItem&&this.chosenItemConf){const t=this.chosenItemConf.onUse;this.close(),t.action==="jump"?fn().runLabel(t.label):t.action==="run"?fn().runLabelFunction(t.label,!0):Kn(`Unknown action ${t.action}`)}},canUseItem(t){const e=this.itemConf[t.id];return!!(e&&e.onUse&&!Or().isInteractionTagBlocked(e.tag)&&!this.currentlyChoosing)}},computed:{itemsToDisplay(){const t={};for(const e in this.items)this.items[e].amount>0&&(t[e]=this.items[e]);return t},chosenItem(){return this.chosenId?this.items[this.chosenId]:null},canUseChosenItem(){return this.canUseItem(this.chosenItem)},chosenItemConf(){return this.chosenId?this.itemConf[this.chosenId]:null},itemConf(){return jt().items}}}),hY="",qJ=j.createElementVNode("h3",{class:"title"},"Inventory",-1),HJ={key:0,class:"inventory-container"},WJ=["onClick"],UJ={class:"item-title"},JJ={class:"item-amount"},GJ={key:1},KJ={class:"flex flex-row item-description-container"},QJ={class:"flex item-left"},YJ={class:"flex item-right"},XJ=j.createElementVNode("hr",{class:"hr-solid"},null,-1),ZJ={key:2},eG=[j.createElementVNode("h2",null,"The inventory is empty!",-1)];function tG(t,e,n,r,o,i){const a=j.resolveComponent("modal");return j.openBlock(),j.createBlock(a,{class:"menu",onClose:t.close,containerCssClass:"inventory-modal"},{header:j.withCtx(()=>[qJ]),body:j.withCtx(()=>[!t.chosenItem&&Object.keys(t.itemsToDisplay).length>0?(j.openBlock(),j.createElementBlock("div",HJ,[(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(t.itemsToDisplay,s=>(j.openBlock(),j.createElementBlock("button",{onClick:()=>t.clickItem(s.id),class:"item-display",style:j.normalizeStyle(t.getItemStyle(s.id)),key:s.id},[j.createElementVNode("h3",UJ,j.toDisplayString(t.getItemName(s.id)),1),j.createElementVNode("h3",JJ,j.toDisplayString(s.amount),1)],12,WJ))),128))])):typeof t.chosenId=="string"?(j.openBlock(),j.createElementBlock("div",GJ,[j.createElementVNode("div",KJ,[j.createElementVNode("div",QJ,[j.createElementVNode("div",{class:"item-display",style:j.normalizeStyle(t.getItemStyle(t.chosenId))},null,4)]),j.createElementVNode("div",YJ,[j.createElementVNode("h2",null,j.toDisplayString(t.getItemName(t.chosenId)),1),XJ,j.createElementVNode("h3",null,"Amount: "+j.toDisplayString(t.chosenItem.amount),1),j.createElementVNode("p",null,j.toDisplayString(t.chosenItemConf.description),1),j.createElementVNode("button",{onClick:e[0]||(e[0]=(...s)=>t.useItem&&t.useItem(...s)),class:j.normalizeClass(["button",t.canUseChosenItem?"":"disabled"])}," Use ",2)])]),j.createElementVNode("button",{class:"button",onClick:e[1]||(e[1]=(...s)=>t.closeItem&&t.closeItem(...s))},j.toDisplayString("<--"))])):(j.openBlock(),j.createElementBlock("div",ZJ,eG))]),_:1},8,["onClose"])}const nG=qr(FJ,[["render",tG]]),rG=j.defineComponent({props:{pictureUrl:String},computed:{...Ci(fu,["layoutMode"]),boxStyle(){const t=jt().layout;let e=0,n=0;return this.layoutMode==="vertical"?(e="50%",n=`${t.mobileDialogHeightPercentage-5}%`):(e=`${t.minTextWidth-10}px`,n="20%"),{right:e,bottom:n,width:`${t.portraits.width}px`,height:`${t.portraits.height}px`}}}}),vY="",oG=["src"];function iG(t,e,n,r,o,i){return j.openBlock(),j.createElementBlock("div",{class:"dialog-picture override",style:j.normalizeStyle(t.boxStyle)},[j.createElementVNode("img",{src:t.pictureUrl,class:"picture override"},null,8,oG)],4)}const aG=qr(rG,[["render",iG]]);class sG{constructor(){Eo(this,"listeners",{})}on(e,n){return this.listeners[e]||this.addEventToMap(e),this.listeners[e].add(n),n}off(e,n){return this.listeners[e]&&this.listeners[e].delete(n),n}once(e,n){const r=(...o)=>{this.off(e,r),n(...o)};return this.on(e,r)}emit(e,...n){this.listeners[e]&&this.listeners[e].forEach(r=>r(...n))}clear(){Object.keys(this.listeners).forEach(e=>{delete this.listeners[e]})}addEventToMap(e){this.listeners[e]=new Set}}class uG extends sG{setup(e=!1){const r=e?"keydown":"keyup",o=$8(i=>{Il.emit("debouncedKeydown",i)},10,{isImmediate:!0,maxWait:10});document.addEventListener("keydown",i=>{Il.emit("keydown",i)}),document.addEventListener(r,i=>{o(i)})}}const Il=new uG,lG=j.defineComponent({data(){return{playerText:"",passed:!1,listener:null,timeout:null}},props:{options:{type:Object,required:!0},active:Boolean},mounted(){if(this.canInteract){const t=e=>{if(this.canInteract&&this.options.textField&&e.key==="Enter"&&this.submitText(),this.canInteract&&!this.options.textField){let n=-1;if(e.key===" ")n=0;else switch(e.key){case" ":n=0;break;case"1":n=0;break;case"2":n=1;break;case"3":n=2;break;case"4":n=3;break;case"5":n=4;break;case"6":n=5;break;case"7":n=6;break;case"8":n=7;break}n!==-1&&(this.choices&&n<this.choices.length?this.chooseOption(this.choices[n]):this.chooseOption(n))}};this.listener=Il.on("debouncedKeydown",t),this.timeout=setTimeout(()=>{this.options.textField&&this.$refs.playerInput.focus()},10)}},unmounted(){this.clearListeners()},computed:{...Ci(kn,["paused"]),preText(){return this.options.title?" \u2013 ":""},style(){return Id(this.options.styleId)},dialogBoxStyle(){const t=Id(this.options.styleId),e={opacity:this.options.old?"0.7":"1"};return this.options.title||(e.marginTop="-20px"),{...t.boxCss,...e}},titleStyle(){const t=Id(this.options.styleId);return{color:t.color,...t.nameCss}},textStyle(){return Id(this.options.styleId).textCss},choices(){if(this.options.choices)return this.options.choices},canInteract(){return this.active&&!this.passed&&this.options.interactive&&!this.paused}},methods:{clearListeners(){this.listener&&(Il.off("keydown",this.listener),this.listener=null),this.timeout&&(clearTimeout(this.timeout),this.timeout=null)},chooseOption(t){this.finishLine();let e;typeof t=="object"?e=t.originalIndex:e=t,kn().playerAnswered(e)},finishLine(){this.clearListeners(),this.passed=!0},dialogStyle(t){const e={};return t.allowed||(e.pointerEvents="none",e.textDecoration="line-through"),e},dialogClass(t){if(!t.allowed)return"strike-anim"},submitText(){const t=this.playerText;kn().playerAnswered(t)}}}),mY="",cG={class:"dialog-content"},fG=["innerHTML"],dG=["innerHTML"],hG=["innerHTML"],pG={key:1,class:"dialog-choices"},vG=["onClick","innerHTML"],mG={key:2},gG={key:3,class:"buttons-container"};function yG(t,e,n,r,o,i){return j.openBlock(),j.createElementBlock("div",{class:"dialog-box w-full override",style:j.normalizeStyle(t.dialogBoxStyle)},[j.createElementVNode("div",cG,[t.options.title?(j.openBlock(),j.createElementBlock("span",{key:0,class:"dialog-title override",style:j.normalizeStyle(t.titleStyle),innerHTML:t.options.title},null,12,fG)):j.createCommentVNode("",!0),j.createElementVNode("span",{class:"dialog-text dialog-separator override",style:j.normalizeStyle(t.textStyle),innerHTML:t.preText},null,12,dG),j.createElementVNode("span",{class:j.normalizeClass(["dialog-text override",t.options.cssClass]),style:j.normalizeStyle(t.textStyle),innerHTML:t.options.text},null,14,hG),t.canInteract&&t.choices?(j.openBlock(),j.createElementBlock("div",pG,[(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(t.choices,(a,s)=>(j.openBlock(),j.createElementBlock("p",{key:s,style:j.normalizeStyle(t.dialogStyle(a)),class:j.normalizeClass([t.dialogClass(a),"dialog-choice override"]),onClick:u=>t.chooseOption(a),innerHTML:`${s+1}. \u2013\xA0 ${a.choice}`},null,14,vG))),128))])):t.canInteract&&t.options.textField?(j.openBlock(),j.createElementBlock("div",mG,[j.withDirectives(j.createElementVNode("input",{type:"text",class:"label-input input",ref:"playerInput",id:"player-input-field","onUpdate:modelValue":e[0]||(e[0]=a=>t.playerText=a)},null,512),[[j.vModelText,t.playerText]]),j.createElementVNode("button",{onClick:e[1]||(e[1]=(...a)=>t.submitText&&t.submitText(...a)),class:"button",id:"player-input-submit"}," Submit ")])):t.canInteract?(j.openBlock(),j.createElementBlock("div",gG,[j.createElementVNode("div",{onClick:e[2]||(e[2]=a=>t.chooseOption(0)),class:"interact-button button override"}," Continue ")])):j.createCommentVNode("",!0)])],4)}const bG=qr(lG,[["render",yG]]),kG=j.createElementVNode("div",{class:"anchor"},null,-1),wG=j.defineComponent({__name:"game-dialog",props:{layoutMode:String,inGame:Boolean},setup(t){const e=t,n=fn(),r=j.computed(()=>n.stack),o=co(),i=j.computed(()=>o.dialog),a=j.ref(null),s=j.computed(()=>e.layoutMode==="vertical"?{}:{paddingBottom:`${jt().layout.dialogBottomPadding}px`}),u=j.computed(()=>{if(i.value.length>0)return i.value[i.value.length-1]}),l=j.computed(()=>{if(u.value)return dJ(u.value.speaker,u.value.pose)}),f=j.computed(()=>jt().layout.minTextWidth),c=j.computed(()=>{let p;const v="100%";return e.layoutMode,{width:e.layoutMode==="horizontal"?`${f.value}px`:"100%",height:v,transform:p,transformOrigin:"right"}});function d(p,v){let m=Xg(p.speaker).name;return v>=1&&i.value[v-1].speaker===p.speaker&&(m=void 0),p.choices&&p.choices.forEach(y=>{y.choice=Gg(y.choice)}),{title:m!=null?m:"",text:p.text,cssClass:p.cssClass,styleId:p.speaker,choices:p.choices,old:v<i.value.length-1,interactive:p.interactive,textField:p.textField}}function h(p){return p===o.dialog.length-1&&r.value.length>0}return j.watch(i.value,p=>{if(a.value){const v=a.value;v.scrollTop=v.scrollHeight+1e8}}),(p,v)=>(j.openBlock(),j.createElementBlock(j.Fragment,null,[j.createVNode(j.Transition,{name:"fade"},{default:j.withCtx(()=>[j.unref(l)?(j.openBlock(),j.createBlock(aG,{key:0,pictureUrl:j.unref(l)},null,8,["pictureUrl"])):j.createCommentVNode("",!0)]),_:1}),t.inGame?(j.openBlock(),j.createElementBlock("div",{key:0,class:"dialog override",ref_key:"dialogRef",ref:a,style:j.normalizeStyle(j.unref(c))},[j.createVNode(j.TransitionGroup,{name:"list",tag:"div",class:"dialog-container w-full override",style:j.normalizeStyle(j.unref(s))},{default:j.withCtx(()=>[(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(j.unref(i),(g,m)=>(j.openBlock(),j.createBlock(bG,{key:g.id,options:d(g,m),active:h(m)},null,8,["options","active"]))),128))]),_:1},8,["style"]),kG],4)):j.createCommentVNode("",!0)],64))}}),gY="",jG=j.defineComponent({setup(){const t=Vr();return{quests:j.computed(()=>t.quests)}},computed:{questsToDisplay(){return t8(this.quests,t=>t.state!=="hidden")}},methods:{close(){this.$emit("close")},getQuestData(t){return Sd(t)},getObjectiveData(t,e){return Mg(t,e)},getDisplayTextForQuestState(t){switch(t.state){case"hidden":return" Hidden";case"unlocked":return"";case"completed":return" (Completed)";default:return" Unknown"}},getQuestDescription(t){return t.ending?t.ending:this.getQuestData(t.id).description},getAvailableObjectives(t){return t8(t.objectives,e=>e.state!=="hidden")}},components:{Modal:ds}}),yY="",xG=j.createElementVNode("h3",{class:"title"},"Quests",-1),_G={key:0,class:"quests-container"},SG={class:"quest-title"},CG={class:"quest-description"},$G={key:0,class:"quest-objectives-container list-disc"},OG={key:1,class:"menu-container"},AG=[j.createElementVNode("h2",{class:"title"},"There are no quests!",-1)];function EG(t,e,n,r,o,i){const a=j.resolveComponent("modal");return j.openBlock(),j.createBlock(a,{class:"quests",onClose:t.close,containerCssClass:"quests-modal"},{header:j.withCtx(()=>[xG]),body:j.withCtx(()=>[Object.keys(t.questsToDisplay).length>0?(j.openBlock(),j.createElementBlock("div",_G,[(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(t.questsToDisplay,s=>(j.openBlock(),j.createElementBlock("div",{class:"quest-display",key:s.id},[j.createElementVNode("div",{class:j.normalizeClass(["quest-header",s.state==="completed"?"quest-completed":"quest-in-progress"])},[j.createElementVNode("h3",SG,j.toDisplayString(t.getQuestData(s.id).title)+" "+j.toDisplayString(t.getDisplayTextForQuestState(s)),1)],2),j.createElementVNode("p",CG,j.toDisplayString(t.getQuestDescription(s)),1),s.state!=="completed"?(j.openBlock(),j.createElementBlock("ul",$G,[(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(t.getAvailableObjectives(s),u=>(j.openBlock(),j.createElementBlock("li",{class:"quest-objective-display",key:u.id},[j.createElementVNode("p",{class:j.normalizeClass(["quest-objective-description",u.state==="completed"?"quest-objective-completed":"quest-objctive-in-progress"])},j.toDisplayString(t.getObjectiveData(s.id,u.id).description),3)]))),128))])):j.createCommentVNode("",!0)]))),128))])):(j.openBlock(),j.createElementBlock("div",OG,AG))]),_:1},8,["onClose"])}const PG=qr(jG,[["render",EG]]),TG=j.defineComponent({data(){return{buttons:[{id:"menu",cssId:"menu-button",text:"Menu"},{id:"skills",cssId:"skills-menu-button",text:"Skills",condition:()=>this.showSkills},{id:"inventory",cssId:"inventory-menu-button",text:"Items",condition:()=>this.showInventory},{id:"quests",cssId:"quests-menu-button",text:"Quests",condition:()=>this.showQuests}],activeMenu:!1}},mounted(){document.addEventListener("keydown",t=>{t.key==="Escape"&&this.toggleMenu()}),ar.callHook("onGameMounted")},unmounted(){ar.callHook("onGameUnmounted")},methods:{buttonClick(t){t.onClick?t.onClick():kn().openModal(t.id)},openMenu(){kn().openModal("menu")},openSkills(){kn().openModal("skills")},openInventory(){kn().openModal("inventory")},openQuests(){kn().openModal("quests")},closeMenu(){kn().closeModal()},toggleMenu(){kn().toggleMenu()}},computed:{buttonsToShow(){return this.buttons.map(t=>{const e=jt().menuButtons[t.id]||{};return{...t,...e}}).filter(t=>t.condition?t.condition():!0)},showSkills(){return Object.entries(jt().skills).length>0},showInventory(){return Object.entries(jt().items).length>0},showQuests(){return Object.entries(jt().quests).length>0}}}),kY="",MG={class:"menu-container"},IG=["onClick","id"];function NG(t,e,n,r,o,i){return j.openBlock(),j.createElementBlock("div",MG,[(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(t.buttonsToShow,a=>(j.openBlock(),j.createElementBlock("button",{key:a.id,onClick:s=>t.buttonClick(a),id:a.cssId,class:"button menu-toggle-button"},j.toDisplayString(a.text),9,IG))),128))])}const LG=qr(TG,[["render",NG]]),RG=["id"],DG=["id","onClick"],BG=j.defineComponent({__name:"screen-layer",props:{layer:String},setup(t){const e=t,n=fn(),r=kn(),o=$i(),i=j.computed(()=>e.layer),a=j.computed(()=>o.buttons),s=j.computed(()=>{const p=jt().screens[i.value];if(!p)throw new Error(`Screen ${i.value} doesn't have a config`);return p}),u=j.computed(()=>s.value.buttons||[]),l=j.computed(()=>r.isInGame);function f(p){const g=_d(p).background;if(!!g)return P7(g)}function c(p){const v=_d(p),g={};v.position.width&&(g.width=`${v.position.width}px`),v.position.height&&(g.height=`${v.position.height}px`),v.background&&(g.backgroundImage=`url(${f(p)})`);const m=a.value[p].state;m==="greyed"?(g.opacity=.3,g.pointerEvents="none"):(m==="hidden"||m===!1)&&(g.display="none");let y=v.position.left,b=v.position.top;return v.anchor&&(y=v.position.left-v.position.width*v.anchor.x,b=v.position.top-v.position.height*v.anchor.y),{...g,left:`${y}px`,top:`${b}px`}}function d(p){const v=_d(p);if(a.value[p].state===!0){const m=v.action;v.actionType==="run"?n.runLabelFunction(m):n.runLabel(m)}}const h=j.computed(()=>({backgroundImage:`url(${P7(s.value.background)})`}));return(p,v)=>j.unref(l)?(j.openBlock(),j.createElementBlock("div",{key:0,class:"viewport-layer",id:`viewport-layer-${j.unref(i)}`,style:j.normalizeStyle(j.unref(h))},[(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(j.unref(u),(g,m)=>(j.openBlock(),j.createElementBlock("button",{key:m,class:"viewport-button",id:`viewport-button-${g}`,onClick:y=>d(g),style:j.normalizeStyle(c(g))},j.toDisplayString(j.unref(_d)(g).text),13,DG))),128))],12,RG)):j.createCommentVNode("",!0)}}),wY="",zG=j.defineComponent({__name:"screens",setup(t){const e=fu(),n=kn(),r=$i(),o=j.computed(()=>r.layers.filter(f=>f)),i=j.computed(()=>e.layoutMode),a=j.computed(()=>jt().layout.backgrounds.width),s=j.computed(()=>jt().layout.backgrounds.height),u=j.computed(()=>n.isInGame),l=j.computed(()=>{const f=`${a.value}px`;let c=`${s.value}px`;return i.value==="vertical"&&(c=`${100-jt().layout.mobileDialogHeightPercentage}%`),{height:c,width:f}});return(f,c)=>j.unref(u)?(j.openBlock(),j.createElementBlock("div",{key:0,class:"viewport",id:"narrat-viewport",style:j.normalizeStyle(j.unref(l))},[(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(j.unref(o),(d,h)=>(j.openBlock(),j.createBlock(BG,{key:h,layer:d},null,8,["layer"]))),128))],4)):j.createCommentVNode("",!0)}}),jY="",VG=j.createElementVNode("h3",{class:"title"},"Choose a save file",-1),FG={class:"saves-container flex flex-col"},qG={key:0,class:"empty-save-slot flex flex-row justify-around items-center grow"},HG=["onClick"],WG=[j.createElementVNode("h3",null,"Create a new save slot",-1)],UG={key:1,class:"used-save-slot flex flex-row justify-between items-center grow"},JG={class:"flex flex-col"},GG={class:"flex flex-col"},KG={class:"flex flex-row"},QG=["onClick"],YG=[j.createElementVNode("h3",null,"Load",-1)],XG=["onClick"],ZG=[j.createElementVNode("h3",null,"Delete",-1)],eK=j.defineComponent({__name:"save-slots",emits:["chosen","close"],setup(t,{emit:e}){const n=j.reactive([]);j.onMounted(()=>{r8().slots.forEach((s,u)=>{n[u]=s}),n.push(null)});function r(a){const s={saveData:n[a],slot:a};e("chosen",s)}function o(a){DW(a),n[a]=null}function i(a){return Hd(a.main.playTime)}return(a,s)=>(j.openBlock(),j.createBlock(ds,{onClose:s[0]||(s[0]=u=>a.$emit("close")),containerCssClass:"save-modal"},{header:j.withCtx(()=>[VG]),body:j.withCtx(()=>[j.createElementVNode("div",FG,[(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(n,(u,l)=>(j.openBlock(),j.createElementBlock("div",{class:"save-slot flex flex-row",key:l},[u==null?(j.openBlock(),j.createElementBlock("div",qG,[j.createElementVNode("button",{class:"button",onClick:f=>r(l)},WG,8,HG)])):(j.openBlock(),j.createElementBlock("div",UG,[j.createElementVNode("div",JG,[j.createElementVNode("h3",null,"Slot "+j.toDisplayString(l+1),1),j.createElementVNode("div",GG,[j.createElementVNode("p",null,"Play time: "+j.toDisplayString(i(u)),1),j.createElementVNode("p",null," Last save: "+j.toDisplayString(new Date(u.metadata.saveDate).toLocaleString()),1)])]),j.createElementVNode("div",KG,[j.createElementVNode("button",{class:"button",onClick:f=>r(l)},YG,8,QG),j.createElementVNode("button",{class:"button",onClick:f=>o(l)},ZG,8,XG)])]))]))),128))])]),_:1}))}}),CY="",tK={id:"game-menu",style:{height:"100%",padding:"20px"}},nK={id:"game-header",class:"flex flex-col justify-between items-center"},rK={id:"game-title-container"},oK={id:"game-title-text"},iK={class:"flex flex-col start-menu-buttons-container"},aK=j.defineComponent({__name:"StartMenu",setup(t){const e=j.ref(!1),n=j.ref(null),r=j.ref(-1),o=j.ref(!1);async function i(){El("onPressStart");const c=kn();r.value===-1&&(r.value=LW()),await c.startGame(r.value)}async function a(){El("onPressStart");const c=RW(r.value);if(!c){Kn("No save file found");return}kn().loadGame(c,r.value)}function s(){typeof n.value=="number"&&(r.value=n.value,a())}function u(){o.value=!0}function l({saveData:c,slot:d}){r.value=d,c?a():i()}j.onMounted(()=>{const c=r8();c.slots.length>0&&(e.value=!0),c.lastSaveSlot&&c.slots.length>c.lastSaveSlot&&c.slots[c.lastSaveSlot]&&(n.value=c.lastSaveSlot)});const f=j.computed(()=>jt().gameTitle);return(c,d)=>(j.openBlock(),j.createElementBlock("div",tK,[o.value?(j.openBlock(),j.createBlock(eK,{key:0,onChosen:l,onClose:d[0]||(d[0]=h=>o.value=!1)})):j.createCommentVNode("",!0),j.createElementVNode("div",nK,[j.createElementVNode("div",rK,[j.createElementVNode("h1",oK,j.toDisplayString(j.unref(f)),1)]),j.createElementVNode("div",iK,[n.value?(j.openBlock(),j.createElementBlock("button",{key:0,class:"button menu-button main-menu-button large continue-button override",onClick:s}," Continue ")):j.createCommentVNode("",!0),j.createElementVNode("button",{class:"button menu-button main-menu-button large start-button override",onClick:i}," New Game "),e.value?(j.openBlock(),j.createElementBlock("button",{key:1,class:"button menu-button main-menu-button large continue-button override",onClick:u}," Load Game ")):j.createCommentVNode("",!0)])])]))}}),$Y="",sK=j.defineComponent({setup(){const t=co(),e=fn(),n=kn();return{dialog:j.computed(()=>t.dialog),stack:j.computed(()=>e.stack),modal:j.computed(()=>n.modal),flowState:j.computed(()=>n.flowState)}},$refs:{dialogContainer:HTMLInputElement},inject:["mq"],components:{DebugMenu:KU,LoadingBar:aJ,NotificationToast:cJ,Hud:tJ,MainMenu:CJ,Skills:VJ,InventoryUi:nG,GameDialog:wG,QuestsUi:PG,MenuButtons:LG,Screens:zG,StartMenu:aK},data(){return{lineTitle:"title",lineText:"hello",gameLoaded:!1,loadingStep:"Loading",loadingPercentage:.1}},props:{config:Object,options:Object},async mounted(){ar.callHook("onAppMounted"),this.loadingStep="Characters";const t=await Hg(this.config.charactersPath);await fJ(JSON.parse(t)),this.loadingPercentage=.2,this.loadingStep="Data",this.loadingPercentage=.3,this.loadingStep="Images",await hJ(jt()),this.loadingPercentage=.7,this.loadingStep="Audio",await rW(jt()),ar.callHook("onAssetsLoaded"),this.loadingPercentage=.95,this.loadingStep="Starting...",await this.setupMachine(),ar.callHook("onGameSetup"),this.loadingPercentage=.1,this.gameLoaded=!0,window.addEventListener("resize",$8(()=>{this.updateScreenSize()},100,{maxWait:200})),Il.setup(this.options.debug),setTimeout(()=>{this.updateScreenSize()},50)},computed:{...Ci(fu,["screenWidth","screenHeight","canvasWidth","canvasHeight","topOffset","leftOffset","layoutMode"]),...Ci(fn,["currentLine"]),backgroundStyle(){let t;return this.layoutMode==="vertical"&&(t=`${100-jt().layout.mobileDialogHeightPercentage}%`),{backgroundColor:"red",height:t}},layoutWidth(){return jt().layout.backgrounds.width},inGame(){return this.flowState==="playing"},layoutHeight(){return jt().layout.backgrounds.height},backgroundSize(){return{width:this.canvasWidth,height:this.canvasHeight,top:this.topOffset,left:this.leftOffset}},gameWidth(){const t=jt();return this.layoutMode==="vertical"?window.innerWidth:t.layout.backgrounds.width+t.layout.minTextWidth},gameHeight(){const t=jt();return this.layoutMode==="vertical"?window.innerHeight:t.layout.backgrounds.height},appStyle(){const t=jt();if(this.screenWidth&&this.screenHeight&&t&&this.layoutMode==="horizontal"){const e=_8(this.screenWidth,this.screenHeight,this.gameWidth,this.gameHeight);return{transform:`scale(${e}, ${e})`,width:`${this.gameWidth}px`,height:`${this.gameHeight}px`}}return{}},gameStyle(){let t="row";return this.layoutMode==="vertical"&&(t="column"),{flexDirection:t}},screenRatio(){const t=jt(),e=t.layout.minTextWidth+t.layout.backgrounds.width;return this.screenWidth/e}},methods:{async setupMachine(){const t=jt().scripts;return kn().setup(t,jt())},updateScreenSize(){fu().updateScreenSize(window.innerWidth,window.innerHeight,this.layoutMode==="horizontal"?jt().layout.minTextWidth*this.screenRatio:0)},closeModal(){kn().closeModal()}}}),OY="",uK={key:3};function lK(t,e,n,r,o,i){const a=j.resolveComponent("Hud"),s=j.resolveComponent("MenuButtons"),u=j.resolveComponent("Skills"),l=j.resolveComponent("InventoryUi"),f=j.resolveComponent("QuestsUi"),c=j.resolveComponent("MainMenu"),d=j.resolveComponent("Screens"),h=j.resolveComponent("GameDialog"),p=j.resolveComponent("StartMenu"),v=j.resolveComponent("LoadingBar"),g=j.resolveComponent("DebugMenu"),m=j.resolveComponent("NotificationToast");return j.openBlock(),j.createElementBlock("div",{id:"app",style:j.normalizeStyle(t.appStyle)},[t.inGame?(j.openBlock(),j.createBlock(a,{key:0})):j.createCommentVNode("",!0),t.inGame?(j.openBlock(),j.createElementBlock("div",{key:1,class:"game",style:j.normalizeStyle(t.gameStyle)},[j.createVNode(s,{class:"menu-toggle"}),t.modal==="skills"?(j.openBlock(),j.createBlock(u,{key:0,onClose:t.closeModal},null,8,["onClose"])):j.createCommentVNode("",!0),t.modal==="inventory"?(j.openBlock(),j.createBlock(l,{key:1,onClose:t.closeModal},null,8,["onClose"])):j.createCommentVNode("",!0),t.modal==="quests"?(j.openBlock(),j.createBlock(f,{key:2,onClose:t.closeModal},null,8,["onClose"])):j.createCommentVNode("",!0),t.modal==="menu"?(j.openBlock(),j.createBlock(c,{key:3,onClose:t.closeModal},null,8,["onClose"])):j.createCommentVNode("",!0),j.createVNode(d),j.createVNode(h,{inGame:t.inGame,layoutMode:t.layoutMode},null,8,["inGame","layoutMode"])],4)):t.gameLoaded?(j.openBlock(),j.createBlock(p,{key:2})):(j.openBlock(),j.createElementBlock("div",uK,[j.createVNode(v,{percentage:t.loadingPercentage,step:t.loadingStep},null,8,["percentage","step"])])),t.options.debug?(j.openBlock(),j.createBlock(g,{key:4})):j.createCommentVNode("",!0),j.createVNode(m)],4)}const cK=qr(sK,[["render",lK]]);function dn(t,e){console.error("Runtime error ========================="),console.error(`Command: ${t.commandType}`),console.error("Args: ",t.args),console.error("Options: ",t.options),Kn(`Runtime error at ${t.fileName}:${t.line} (${t.commandType}) ${t.code}. -
|
|
183
183
|
<br />
|
|
184
|
-
Error: ${e}`),console.error("============================")}function fK(t,...e){console.log(`[${t.fileName}:${t.line}] log: `,...e)}class Ze{constructor(e,n,r,o){Eo(this,"keyword");Eo(this,"runner");Eo(this,"argTypes");Eo(this,"parser");Eo(this,"onPlayerAnswered");Eo(this,"returnAfterPlayerAnswer");this.keyword=e,this.runner=r,this.argTypes=n,o?this.parser=o:this.parser=Nl(this.keyword,this.argTypes),this.returnAfterPlayerAnswer=!1}async run(e,n){let r=await this.runner(e,n);return this.returnAfterPlayerAnswer&&(r=await new Promise((o,i)=>{fn().waitForPlayerAnswer(e),e.finishCommand=o})),r}async processPlayerAnswer(e,n){let r=n;return this.onPlayerAnswered&&(r=await this.onPlayerAnswered(e,n)),this.returnAfterPlayerAnswer&&e.finishCommand&&e.finishCommand(r),r}static FromOptions(e){var r;const n=new Ze(e.keyword,e.argTypes,e.runner,e.parser);return n.onPlayerAnswered=e.onPlayerAnswered,n.returnAfterPlayerAnswer=(r=e.returnAfterPlayerAnswer)!=null?r:!1,n}}function Nl(t,e){let n=[];if(e!=="any"){n=[e.length];const r=e.reduce((o,i)=>i.optional?o+1:o,0);if(r>1)throw new Error(`Only one optional argument is allowed for commands but ${t} has multiple ones`);r===1&&n.push(e.length-1)}return(r,o)=>{const i={newLine:r.currentLine+1},a=o.command.args;return e!=="any"&&!n.includes(a.length)?(console.log("Error details"),console.log(o.command),console.log(a),r.parserContext.error(r.line.line,`Command ${t}: Expected ${n.join(" or ")} arguments but got ${a.length}`),i):(o.command.commandType=t,e!=="any"&&o.command.args.forEach((s,u)=>{const l=e[u];!b8(s)&&!k8(s)&&(l.type==="any"||typeof s===l.type||r.parserContext.error(r.line.line,`Command ${t}: Argument #${u+1} (${l.name}) should be a ${l.type}, but got type ${typeof s}: ${JSON.stringify(s)}`))}),{newLine:r.currentLine+1})}}const dK=new Ze("add_level",[{name:"skillKey",type:"string"},{name:"amount",type:"number"}],async t=>{let{skillKey:e,amount:n}=t.options;if((!e||!n)&&dn(t,"add_level command needs a skill id and a value as parameters"),!Number.isInteger(n)){const r=n;n=Math.round(n),console.warn(`add_level expects a level to be an integer. Auto Rounding ${r} to ${n}`)}cr().incrementSkill(e,n)}),hK=Ze.FromOptions({keyword:"set_level",argTypes:[{name:"skill",type:"string"},{name:"level",type:"number"}],runner:async t=>{let{skill:e,level:n}=t.options;if((!e||!n)&&dn(t,"set_level command needs a skill id and a value as parameters"),!Number.isInteger(n)){const r=n;n=Math.round(n),console.warn(`set_level expects a level to be an integer. Auto Rounding ${r} to ${n}`)}cr().setSkillLevel(e,n)}}),pK=new Ze("add_xp",[{name:"xpKey",type:"string"},{name:"xpToAdd",type:"number"}],async t=>{const{xpKey:e,xpToAdd:n}=t.options;(!e||!n)&&dn(t,"add_xp command needs a skill id and a value as parameters"),cr().addXp(e,n)}),vK=new Ze("get_level",[{name:"skillKey",type:"string"}],async t=>{const{skillKey:e}=t.options;e||dn(t,"get_level command needs a skill id as parameter");const n=cr().getSkill(e);return n||dn(t,`Skill ${e} not found`),n.level}),mK=new Ze("get_xp",[{name:"xpKey",type:"string"}],async t=>{const{xpKey:e}=t.options;e||dn(t,"get_xp command needs a skill id as parameter");const n=cr().getSkillXp(e);return n||dn(t,`XP ${e} not found`),n}),gK=new Ze("roll",[{name:"id",type:"string"},{name:"skill",type:"string"},{name:"value",type:"number"},{name:"hideAfterRoll",type:"boolean",optional:!0}],async t=>{const{id:e,skill:n,value:r,hideAfterRoll:o}=t.options;return y8({id:e,skill:n,value:r,hideAfterRoll:o}).succeeded}),yK=new Ze("add_stat",[{name:"statKey",type:"string"},{name:"amountToAdd",type:"number"}],async t=>{const{statKey:e,amountToAdd:n}=t.options;(!e||typeof n!="number")&&dn(t,"add_stat command needs a stat id and a value as parameters"),Wi().addStat(e,n)}),bK=new Ze("set_stat",[{name:"statKey",type:"string"},{name:"value",type:"number"}],async t=>{const{statKey:e,value:n}=t.options;(!e||typeof n!="number")&&dn(t,"set_stat command needs a stat id and a value as parameters"),Wi().setStat(e,n)}),kK=new Ze("get_stat_value",[{name:"statKey",type:"string"}],async t=>{const{statKey:e}=t.options;return e||dn(t,"get_stat_value command needs a stat id as parameter"),Wi().getStatValue(e)}),wK=Ze.FromOptions({keyword:"jump",argTypes:"any",runner:async t=>{(t.args.length<1||typeof t.args[0]!="string")&&dn(t,"requires a label argument");const e=t.args[0],n=fn(),r={branchData:n.script[e],label:e,args:t.args.splice(1),currentIndex:0};return n.jumpTarget=r,await kn().saveGame(),Cd}}),jK=Ze.FromOptions({keyword:"run",argTypes:"any",runner:async t=>{(t.args.length<1||typeof t.args[0]!="string")&&dn(t,"run command needs a label to argument run");const e=t.args[0];return await fn().runLabelFunction(e,...t.args.slice(1))}}),xK=Ze.FromOptions({keyword:"var",argTypes:[{name:"name",type:"string"},{name:"value",type:"any"}],runner:async t=>{const{name:e,value:n}=t.options;fn().addScopedVariable(e,n)}}),_K=Ze.FromOptions({keyword:"return",argTypes:[{name:"value",type:"any"}],runner:async t=>{const{value:e}=t.options;return fn().setReturnValue(e),Ig}}),SK=Ze.FromOptions({keyword:"log",argTypes:"any",runner:async t=>{fK(t,...t.args)}}),CK=[{name:"mode",type:"string"},{name:"audio",type:"string"},{name:"channel",type:"number",optional:!0}],$K=new Ze("play",CK,async t=>{const e=$r(),{mode:n,audio:r,channel:o}=t.options,i=Zg(t,n);i&&e.playChannel(i,r,o!=null?o:0)}),OK=new Ze("pause",[{name:"mode",type:"string"},{name:"channel",type:"number",optional:!0}],async t=>{const e=$r(),{mode:n,channel:r}=t.options,o=Zg(t,n);o&&e.pauseChannel(o,r!=null?r:0)}),AK=new Ze("stop",[{name:"mode",type:"string"},{name:"channel",type:"number",optional:!0}],async t=>{const e=$r(),{mode:n,channel:r}=t.options,o=Zg(t,n);o&&e.stopChannel(o,r!=null?r:0)});function Zg(t,e){return EK(e)?e:(dn(t,`${e} is not a valid audio mode.`),!1)}function EK(t){return!!Z7.includes(t)}const PK=new Ze("set",[{name:"key",type:"string"},{name:"value",type:"any"}],async t=>{const e=cu();p8(e,t.options.key,t.options.value)}),TK=new Ze("add",[{name:"key",type:"string"},{name:"value",type:"any"}],async t=>{const e=cu();v8(e,t.options.key,t.options.value)}),MK=new Ze("set_screen",[{name:"screen",type:"string"},{name:"layer",type:"number",optional:!0}],async t=>{$i().setScreen(t.options.screen,t.options.layer)}),IK=new Ze("empty_layer",[{name:"layer",type:"number"}],async t=>{$i().emptyLayer(t.options.layer)}),NK=new Ze("set_button",[{name:"buttonId",type:"string"},{name:"state",type:"any"}],async t=>{const{buttonId:e,state:n}=t.options;$i().changeButton(e,n)}),LK=Ze.FromOptions({keyword:"talk",argTypes:[{name:"speaker",type:"string"},{name:"pose",type:"string"},{name:"text",type:"string"}],runner:async(t,e)=>{await Kg({speaker:t.options.speaker,pose:t.options.pose,cssClass:"talk-command",text:`"${t.options.text}"`,choices:e,interactive:!0})},returnAfterPlayerAnswer:!0}),RK=Ze.FromOptions({keyword:"think",argTypes:[{name:"speaker",type:"string"},{name:"pose",type:"string"},{name:"text",type:"string"}],runner:async(t,e)=>{await Kg({speaker:t.options.speaker,pose:t.options.pose,cssClass:"think-command",text:`${t.options.text}`,choices:e,interactive:!1})}}),DK=()=>{const t=Nl("text",[]);return(e,n)=>{const r=t(e,n);return n.command.staticOptions={text:n.code.substring(1,n.code.length-1)},r}},BK=Ze.FromOptions({keyword:"text",argTypes:[],runner:async(t,e)=>{await Kg({speaker:"game",cssClass:"text-command",text:t.staticOptions.text,choices:e,interactive:!0})},parser:DK(),returnAfterPlayerAnswer:!0}),zK=new Ze("add_item",[{name:"id",type:"string"},{name:"amount",type:"number"}],async t=>{const{id:e,amount:n}=t.options;Or().add({id:e,amount:n})}),VK=new Ze("remove_item",[{name:"id",type:"string"},{name:"amount",type:"number"}],async t=>{const{id:e,amount:n}=t.options;Or().remove({id:e,amount:n})}),FK=new Ze("has_item?",[{name:"id",type:"string"},{name:"amount",type:"number",optional:!0}],async t=>{const{id:e,amount:n}=t.options;return Or().hasItem(e,n)}),qK=new Ze("item_amount?",[{name:"id",type:"string"}],async t=>{const{id:e}=t.options;return Or().getItemAmount(e)}),HK=new Ze("enable_interaction",[{name:"tag",type:"string"}],async t=>{const e=t.options.tag;Or().enableInteraction(e)}),WK=new Ze("disable_interaction",[{name:"tag",type:"string"}],async t=>{const e=t.options.tag;Or().disableInteraction(e)}),UK=new Ze("start_quest",[{name:"questId",type:"string"}],async t=>{const e=t.options.questId;Vr().startQuest(e)}),JK=new Ze("start_objective",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;Vr().startObjective(e,n)}),GK=new Ze("complete_objective",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;Vr().completeObjective(e,n)}),KK=new Ze("complete_quest",[{name:"questId",type:"string"},{name:"ending",type:"string",optional:!0}],async t=>{const{questId:e,ending:n}=t.options;Vr().completeQuest(e,n)}),QK=new Ze("quest_completed?",[{name:"questId",type:"string"}],async t=>{const{questId:e}=t.options;return Vr().isQuestCompleted(e)}),YK=new Ze("objective_completed?",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;return Vr().isObjectiveCompleted(e,n)}),XK=new Ze("quest_started?",[{name:"questId",type:"string"}],async t=>{const{questId:e}=t.options;return Vr().isQuestStarted(e)}),ZK=new Ze("objective_started?",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;return Vr().isObjectiveStarted(e,n)}),eQ=Ze.FromOptions({keyword:"wait",argTypes:[{name:"duration",type:"number"}],runner:async t=>{await $d(t.options.duration)}}),tQ=new Ze("notify",[{name:"text",type:"string"}],async t=>{const{text:e}=t.options;Co().addNotification(e)}),nQ=new Ze("disable_notifications",[],async t=>{Co().disableNotifications()}),rQ=new Ze("enable_notifications",[],async t=>{Co().enableNotifications()}),oQ=new Ze("clear_dialog",[],async t=>{co().clearDialog()}),iQ=new Ze("if",[{name:"condition",type:"boolean"}],async t=>{const e=gU(t),n=fn();if(e){const r={branchData:{branch:e},currentIndex:0};return n.addAndRunBlock(r)}},(t,e)=>{let n=t.currentLine;Nl("if",[{name:"condition",type:"string"}])(t,e);const{lines:o,currentLine:i,line:a}=t,s=e.command;let u;const l=yU(o,i+1);return l&&l.code==="else:"&&(u=t.processCommandsFunction(t.parserContext,l.branch,a),n++),s.staticOptions={success:t.processCommandsFunction(t.parserContext,a.branch,a),failure:u},n++,{newLine:n}}),aQ=new Ze("==","any",async t=>{t.args.length<2&&dn(t,"requires at least two arguments");let e=t.args[0],n=!0;for(const r of t.args)if(r!=e){n=!1;break}else e=r;return n}),sQ=new Ze(">",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e>n}),uQ=new Ze("<",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e<n}),lQ=new Ze(">=",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e>=n}),cQ=new Ze("<=",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e<=n}),fQ=new Ze("!=",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e!=n}),dQ=new Ze("!",[{name:"a",type:"any"}],async t=>{const{a:e}=t.options;return!e}),hQ=new Ze("&&","any",async t=>{const e=t.args;return t.args.length<2&&dn(t,"requires at least two arguments"),e.reduce((n,r)=>n&&r,!0)}),pQ=new Ze("||","any",async t=>(t.args.length<2&&dn(t,"requires at least two arguments"),t.args.reduce((e,n)=>e||n,!1))),vQ=new Ze("?",[{name:"a",type:"any"},{name:"b",type:"any"},{name:"c",type:"any"}],async t=>{const{a:e,b:n,c:r}=t.options;return e?n:r}),mQ=new Ze("+","any",async t=>(t.args.length<2&&dn(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="number"?e+n:(dn(t,"requires all arguments to be numbers"),e),0))),gQ=new Ze("-","any",async t=>(t.args.length<2&&dn(t,"requires at least two arguments"),t.args.slice(1).reduce((e,n)=>typeof n=="number"?e-n:(dn(t,"requires all arguments to be numbers"),e),t.args[0]))),yQ=new Ze("neg",[{name:"a",type:"number"}],async t=>(t.args.length!==1&&dn(t,"requires one argument"),-t.options.a)),bQ=new Ze("abs",[{name:"a",type:"number"}],async t=>(t.args.length!==1&&dn(t,"requires one argument"),Math.abs(t.options.a))),kQ=new Ze("*","any",async t=>(t.args.length<2&&dn(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="number"?e*n:(dn(t,"requires all arguments to be numbers"),e),1))),wQ=new Ze("/","any",async t=>{t.args.length<2&&dn(t,"requires at least two arguments");const e=t.args[0]/t.args[1];return t.args.slice(2).reduce((n,r)=>typeof r=="number"?n/r:(dn(t,"requires all arguments to be numbers"),n),e)}),jQ=async t=>{const{prompt:e,choices:n}=t.staticOptions,r=[];for(const[,a]of n.entries()){const s=await Qg(a.prompt);r.push(s)}t.options.choiceResults=r;const o=r.map((a,s)=>{var f,c;let u=!0;return a.skillCheck&&(u=(c=(f=a.skillCheck)==null?void 0:f.allowed)!=null?c:!1),{choice:a.text,originalIndex:s,allowed:u}}).filter(a=>a.choice),i=await j8(e,o);return await CQ(t,i)};function xQ(t,e){e.branch||t.parserContext.error(e.line,`Choice option doesn't have any branch to go to (${e.code} - ${e.line})`);let n,r;const o=e.branch;return e.expression[1]==="roll"?((!o[0].branch||!o[1].branch)&&t.parserContext.error(e.line,`Choice option with a skill roll needs success and failure branches (${e.code} - ${e.line})`),n={success:t.processCommandsFunction(t.parserContext,o[0].branch,e),failure:t.processCommandsFunction(t.parserContext,o[1].branch,e)}):r=t.processCommandsFunction(t.parserContext,o,e),{prompt:t.processCommandsFunction(t.parserContext,[e],e)[0],branch:r,skillBranches:n}}const _Q=(t,e)=>{let n=t.currentLine;Nl("choice",[]);const{line:r}=t,o=e.command;(!r.branch||r.branch.length<2)&&t.parserContext.error(r.line,"Choice menu needs to have at least one option");const i=r.branch[0];i||t.parserContext.error(t.line.line,"Choice prompt is missing ");const s=r.branch.slice(1).map((u,l)=>(u.branch||t.parserContext.error(u.line,`Choice option doesn't have any branch to go to (${u.code})`),u=$Q(t.parserContext,u),xQ(t,u)));return o.staticOptions={prompt:t.processCommandsFunction(t.parserContext,[i],r)[0],choices:s},n++,{newLine:n}},SQ=Ze.FromOptions({keyword:"choice",argTypes:[],runner:jQ,parser:_Q}),CQ=async(t,e)=>{const n=e,r=fn(),{choices:o}=t.staticOptions,i=o[n],a=t.options.choiceResults[n];let s=a.text,u;if(a.skillCheck?(s=null,y8({skill:a.skillCheck.skillId,value:a.skillCheck.difficulty,id:a.skillCheck.skillCheckId,hideAfterRoll:a.skillCheck.hideAfterRoll}).succeeded?u=i.skillBranches.success:u=i.skillBranches.failure):u=i.branch,s){const l={speaker:"player",text:s,interactive:!1};co().addDialog(l)}if(u){const l={currentIndex:0,branchData:{branch:u}};return await r.addAndRunBlock(l)}};function $Q(t,e){return{code:`choicePrompt ${e.code}`,indentation:e.indentation,line:e.line,branch:e.branch,expression:["choicePrompt",...e.expression]}}const OQ=new Ze("choicePrompt","any",async t=>{const e=t.args;if(e[0]==="roll"){const n=e[1],r=e[2],o=e[3],i=e[4],a=e.length>5?e[5]:!1,s=cr().getSkillCheck(n);if(s.hidden)return{text:null};const u=s.happened&&!s.succeeded,{difficultyText:l}=hU({skill:r,skillCheckId:n,value:o});return{text:`${l} ${i}`,skillCheck:{allowed:!u,skillId:r,skillCheckId:n,difficulty:o,hideAfterRoll:a}}}else if(e.length>1&&e[1]==="if"){const n=e[0];let r=!0;return e.length>2&&(r=e[2]),r?{text:n}:{text:null}}else return{text:e[0]}}),O8=Ze.FromOptions({keyword:"text_field",argTypes:[{name:"prompt",type:"string"}],returnAfterPlayerAnswer:!0,runner:async t=>{const e={speaker:"game",text:t.options.prompt,textField:!0,interactive:!0};co().addDialog(e)}});O8.onPlayerAnswered=async(t,e)=>(typeof e!="string"&&dn(t,"The player's answer should be a string"),e);const AQ=Ze.FromOptions({keyword:"text_field_prompt",argTypes:[{name:"prompt",type:"string"}],runner:async t=>{const e={speaker:"game",text:t.options.prompt,textField:!0,interactive:!0};co().addDialog(e)}}),EQ=new Ze("random",[{name:"a",type:"number"},{name:"b",type:"number"}],async t=>{const{a:e,b:n}=t.options;return typeof e!="number"||typeof n!="number"?(dn(t,"random command needs two numbers as parameters"),0):Math.floor(Math.random()*(n-e+1))+e}),PQ=new Ze("random_float",[{name:"a",type:"number"},{name:"b",type:"number"}],async t=>{const{a:e,b:n}=t.options;return typeof e!="number"||typeof n!="number"?(dn(t,"random_float command needs two numbers as parameters"),0):Math.random()*(n-e)+e}),TQ=new Ze("random_from_args",[],async t=>{const e=t.args;return!e||!e.length?(dn(t,"random_from_args command needs at least one argument"),0):e[Math.floor(Math.random()*e.length)]}),MQ=new Ze("concat","any",async t=>(t.args.length<2&&dn(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="string"?`${e}${n}`:(dn(t,"requires all arguments to be strings"),e),""))),IQ=new Ze("join","any",async t=>{const e=t.args[0];return t.args.length<3&&dn(t,"requires at least 3 arguments"),t.args.slice(1).reduce((n,r)=>typeof r=="string"?`${n}${e}${r}`:(dn(t,"requires all arguments to be strings"),n),"")}),NQ=Ze.FromOptions({keyword:"min",argTypes:[{name:"min",type:"number"},{name:"value",type:"number"}],runner:async t=>{const{min:e,value:n}=t.options;return n<e?n:e}}),LQ=Ze.FromOptions({keyword:"max",argTypes:[{name:"max",type:"number"},{name:"value",type:"number"}],runner:async t=>{const{max:e,value:n}=t.options;return n>e?n:e}}),RQ=Ze.FromOptions({keyword:"clamp",argTypes:[{name:"min",type:"number"},{name:"max",type:"number"},{name:"value",type:"number"}],runner:async t=>{const{min:e,max:n,value:r}=t.options;return r<e?e:r>n?n:r}}),DQ=Ze.FromOptions({keyword:"floor",argTypes:[{name:"value",type:"number"}],runner:async t=>{const{value:e}=t.options;return Math.floor(e)}}),BQ=Ze.FromOptions({keyword:"ceil",argTypes:[{name:"value",type:"number"}],runner:async t=>{const{value:e}=t.options;return Math.ceil(e)}}),zQ=Ze.FromOptions({keyword:"round",argTypes:[{name:"value",type:"number"}],runner:async t=>{const{value:e}=t.options;return Math.round(e)}}),VQ=Ze.FromOptions({keyword:"sqrt",argTypes:[{name:"value",type:"number"}],runner:async t=>{const{value:e}=t.options;return Math.sqrt(e)}}),FQ=Ze.FromOptions({keyword:"^",argTypes:[{name:"base",type:"number"},{name:"exponent",type:"number"}],runner:async t=>{const{base:e,exponent:n}=t.options;return Math.pow(e,n)}});function qQ(t){t.addCommand(SQ),t.addCommand(OQ),t.addCommand(iQ),t.addCommand(yK),t.addCommand(bK),t.addCommand(kK),t.addCommand(oQ),t.addCommand(tQ),t.addCommand(nQ),t.addCommand(rQ),t.addCommand(OK),t.addCommand($K),t.addCommand(AK),t.addCommand(NK),t.addCommand(MK),t.addCommand(IK),t.addCommand(eQ),t.addCommand(aQ),t.addCommand(sQ),t.addCommand(uQ),t.addCommand(lQ),t.addCommand(cQ),t.addCommand(fQ),t.addCommand(dQ),t.addCommand(hQ),t.addCommand(pQ),t.addCommand(vQ),t.addCommand(mQ),t.addCommand(gQ),t.addCommand(kQ),t.addCommand(wQ),t.addCommand(yQ),t.addCommand(bQ),t.addCommand(TK),t.addCommand(PK),t.addCommand(BK),t.addCommand(LK),t.addCommand(RK),t.addCommand(wK),t.addCommand(jK),t.addCommand(xK),t.addCommand(_K),t.addCommand(SK),t.addCommand(UK),t.addCommand(JK),t.addCommand(GK),t.addCommand(KK),t.addCommand(XK),t.addCommand(ZK),t.addCommand(QK),t.addCommand(YK),t.addCommand(zK),t.addCommand(VK),t.addCommand(HK),t.addCommand(WK),t.addCommand(FK),t.addCommand(qK),t.addCommand(dK),t.addCommand(hK),t.addCommand(pK),t.addCommand(gK),t.addCommand(vK),t.addCommand(mK),t.addCommand(O8),t.addCommand(AQ),t.addCommand(EQ),t.addCommand(PQ),t.addCommand(TQ),t.addCommand(MQ),t.addCommand(IQ),t.addCommand(NQ),t.addCommand(LQ),t.addCommand(RQ),t.addCommand(DQ),t.addCommand(zQ),t.addCommand(BQ),t.addCommand(VQ),t.addCommand(FQ)}let Ll;ar.callHook("onPageLoaded");async function HQ(t,e){const n=await Hg(t.configPath);eW(JSON.parse(n)),t.baseAssetsPath&&(jt().baseAssetsPath=t.baseAssetsPath),Ll=j.createApp(cK,{config:t,options:e});const r=EW();if(Ll.use(r),kn().setOptions(e),Ll.use(N8,{breakpoints:{s:0,m:800,l:1200}}),qQ(ar),d0.setupDebugger(e.debug),console.log("%c Narrat game engine \u2013 [VI]{version} - {date}[/VI]","background: #222; color: #bada55"),ar.callHook("onNarratSetup"),Ll.mount("#game-holder"),e.debug){const o={app:Ll,vm:ar,jump:i=>{fn().runLabel(i)}};window.narrat=o}}class WQ{onPageLoaded(){}onNarratSetup(){}onAppMounted(){}onAssetsLoaded(){}onGameSetup(){}onGameStart(){}onGameMounted(){}onGameDismounted(){}}function UQ(t){ar.addPlugin(t)}function JQ(t){ar.addCommand(t)}sn.CommandPlugin=Ze,sn.NarratPlugin=WQ,sn.addCommand=JQ,sn.aspectRatioFit=_8,sn.generateParser=Nl,sn.getConfig=jt,sn.registerPlugin=UQ,sn.startApp=HQ,Object.defineProperties(sn,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
184
|
+
Error: ${e}`),console.error("============================")}function fK(t,...e){console.log(`[${t.fileName}:${t.line}] log: `,...e)}class Ze{constructor(e,n,r,o){Eo(this,"keyword");Eo(this,"runner");Eo(this,"argTypes");Eo(this,"parser");Eo(this,"onPlayerAnswered");Eo(this,"returnAfterPlayerAnswer");this.keyword=e,this.runner=r,this.argTypes=n,o?this.parser=o:this.parser=Nl(this.keyword,this.argTypes),this.returnAfterPlayerAnswer=!1}async run(e,n){let r=await this.runner(e,n);return this.returnAfterPlayerAnswer&&(r=await new Promise((o,i)=>{fn().waitForPlayerAnswer(e),e.finishCommand=o})),r}async processPlayerAnswer(e,n){let r=n;return this.onPlayerAnswered&&(r=await this.onPlayerAnswered(e,n)),this.returnAfterPlayerAnswer&&e.finishCommand&&e.finishCommand(r),r}static FromOptions(e){var r;const n=new Ze(e.keyword,e.argTypes,e.runner,e.parser);return n.onPlayerAnswered=e.onPlayerAnswered,n.returnAfterPlayerAnswer=(r=e.returnAfterPlayerAnswer)!=null?r:!1,n}}function Nl(t,e){let n=[];if(e!=="any"){n=[e.length];const r=e.reduce((o,i)=>i.optional?o+1:o,0);if(r>1)throw new Error(`Only one optional argument is allowed for commands but ${t} has multiple ones`);r===1&&n.push(e.length-1)}return(r,o)=>{const i={newLine:r.currentLine+1},a=o.command.args;return e!=="any"&&!n.includes(a.length)?(console.log("Error details"),console.log(o.command),console.log(a),r.parserContext.error(r.line.line,`Command ${t}: Expected ${n.join(" or ")} arguments but got ${a.length}`),i):(o.command.commandType=t,e!=="any"&&o.command.args.forEach((s,u)=>{const l=e[u];!b8(s)&&!k8(s)&&(l.type==="any"||typeof s===l.type||r.parserContext.error(r.line.line,`Command ${t}: Argument #${u+1} (${l.name}) should be a ${l.type}, but got type ${typeof s}: ${JSON.stringify(s)}`))}),{newLine:r.currentLine+1})}}const dK=new Ze("add_level",[{name:"skillKey",type:"string"},{name:"amount",type:"number"}],async t=>{let{skillKey:e,amount:n}=t.options;if((!e||!n)&&dn(t,"add_level command needs a skill id and a value as parameters"),!Number.isInteger(n)){const r=n;n=Math.round(n),console.warn(`add_level expects a level to be an integer. Auto Rounding ${r} to ${n}`)}cr().incrementSkill(e,n)}),hK=Ze.FromOptions({keyword:"set_level",argTypes:[{name:"skill",type:"string"},{name:"level",type:"number"}],runner:async t=>{let{skill:e,level:n}=t.options;if((!e||!n)&&dn(t,"set_level command needs a skill id and a value as parameters"),!Number.isInteger(n)){const r=n;n=Math.round(n),console.warn(`set_level expects a level to be an integer. Auto Rounding ${r} to ${n}`)}cr().setSkillLevel(e,n)}}),pK=new Ze("add_xp",[{name:"xpKey",type:"string"},{name:"xpToAdd",type:"number"}],async t=>{const{xpKey:e,xpToAdd:n}=t.options;(!e||!n)&&dn(t,"add_xp command needs a skill id and a value as parameters"),cr().addXp(e,n)}),vK=new Ze("get_level",[{name:"skillKey",type:"string"}],async t=>{const{skillKey:e}=t.options;e||dn(t,"get_level command needs a skill id as parameter");const n=cr().getSkill(e);return n||dn(t,`Skill ${e} not found`),n.level}),mK=new Ze("get_xp",[{name:"xpKey",type:"string"}],async t=>{const{xpKey:e}=t.options;e||dn(t,"get_xp command needs a skill id as parameter");const n=cr().getSkillXp(e);return n||dn(t,`XP ${e} not found`),n}),gK=new Ze("roll",[{name:"id",type:"string"},{name:"skill",type:"string"},{name:"value",type:"number"},{name:"hideAfterRoll",type:"boolean",optional:!0}],async t=>{const{id:e,skill:n,value:r,hideAfterRoll:o}=t.options;return y8({id:e,skill:n,value:r,hideAfterRoll:o}).succeeded}),yK=new Ze("add_stat",[{name:"statKey",type:"string"},{name:"amountToAdd",type:"number"}],async t=>{const{statKey:e,amountToAdd:n}=t.options;(!e||typeof n!="number")&&dn(t,"add_stat command needs a stat id and a value as parameters"),Wi().addStat(e,n)}),bK=new Ze("set_stat",[{name:"statKey",type:"string"},{name:"value",type:"number"}],async t=>{const{statKey:e,value:n}=t.options;(!e||typeof n!="number")&&dn(t,"set_stat command needs a stat id and a value as parameters"),Wi().setStat(e,n)}),kK=new Ze("get_stat_value",[{name:"statKey",type:"string"}],async t=>{const{statKey:e}=t.options;return e||dn(t,"get_stat_value command needs a stat id as parameter"),Wi().getStatValue(e)}),wK=Ze.FromOptions({keyword:"jump",argTypes:"any",runner:async t=>{(t.args.length<1||typeof t.args[0]!="string")&&dn(t,"requires a label argument");const e=t.args[0],n=fn(),r={branchData:n.script[e],label:e,args:t.args.splice(1),currentIndex:0};return n.jumpTarget=r,await kn().saveGame(),Cd}}),jK=Ze.FromOptions({keyword:"run",argTypes:"any",runner:async t=>{(t.args.length<1||typeof t.args[0]!="string")&&dn(t,"run command needs a label to argument run");const e=t.args[0];return await fn().runLabelFunction(e,...t.args.slice(1))}}),xK=Ze.FromOptions({keyword:"var",argTypes:[{name:"name",type:"string"},{name:"value",type:"any"}],runner:async t=>{const{name:e,value:n}=t.options;fn().addScopedVariable(e,n)}}),_K=Ze.FromOptions({keyword:"return",argTypes:[{name:"value",type:"any"}],runner:async t=>{const{value:e}=t.options;return fn().setReturnValue(e),Ig}}),SK=Ze.FromOptions({keyword:"log",argTypes:"any",runner:async t=>{fK(t,...t.args)}}),CK=[{name:"mode",type:"string"},{name:"audio",type:"string"},{name:"channel",type:"number",optional:!0}],$K=new Ze("play",CK,async t=>{const e=$r(),{mode:n,audio:r,channel:o}=t.options,i=Zg(t,n);i&&e.playChannel(i,r,o!=null?o:0)}),OK=new Ze("pause",[{name:"mode",type:"string"},{name:"channel",type:"number",optional:!0}],async t=>{const e=$r(),{mode:n,channel:r}=t.options,o=Zg(t,n);o&&e.pauseChannel(o,r!=null?r:0)}),AK=new Ze("stop",[{name:"mode",type:"string"},{name:"channel",type:"number",optional:!0}],async t=>{const e=$r(),{mode:n,channel:r}=t.options,o=Zg(t,n);o&&e.stopChannel(o,r!=null?r:0)});function Zg(t,e){return EK(e)?e:(dn(t,`${e} is not a valid audio mode.`),!1)}function EK(t){return!!Z7.includes(t)}const PK=new Ze("set",[{name:"key",type:"string"},{name:"value",type:"any"}],async t=>{const e=cu();p8(e,t.options.key,t.options.value)}),TK=new Ze("add",[{name:"key",type:"string"},{name:"value",type:"any"}],async t=>{const e=cu();v8(e,t.options.key,t.options.value)}),MK=new Ze("set_screen",[{name:"screen",type:"string"},{name:"layer",type:"number",optional:!0}],async t=>{$i().setScreen(t.options.screen,t.options.layer)}),IK=new Ze("empty_layer",[{name:"layer",type:"number"}],async t=>{$i().emptyLayer(t.options.layer)}),NK=new Ze("set_button",[{name:"buttonId",type:"string"},{name:"state",type:"any"}],async t=>{const{buttonId:e,state:n}=t.options;$i().changeButton(e,n)}),LK=Ze.FromOptions({keyword:"talk",argTypes:[{name:"speaker",type:"string"},{name:"pose",type:"string"},{name:"text",type:"string"}],runner:async(t,e)=>{await Kg({speaker:t.options.speaker,pose:t.options.pose,cssClass:"talk-command",text:`"${t.options.text}"`,choices:e,interactive:!0})},returnAfterPlayerAnswer:!0}),RK=Ze.FromOptions({keyword:"think",argTypes:[{name:"speaker",type:"string"},{name:"pose",type:"string"},{name:"text",type:"string"}],runner:async(t,e)=>{await Kg({speaker:t.options.speaker,pose:t.options.pose,cssClass:"think-command",text:`${t.options.text}`,choices:e,interactive:!0})}}),DK=()=>{const t=Nl("text",[]);return(e,n)=>{const r=t(e,n);return n.command.staticOptions={text:n.code.substring(1,n.code.length-1)},r}},BK=Ze.FromOptions({keyword:"text",argTypes:[],runner:async(t,e)=>{await Kg({speaker:"game",cssClass:"text-command",text:t.staticOptions.text,choices:e,interactive:!0})},parser:DK(),returnAfterPlayerAnswer:!0}),zK=new Ze("add_item",[{name:"id",type:"string"},{name:"amount",type:"number"}],async t=>{const{id:e,amount:n}=t.options;Or().add({id:e,amount:n})}),VK=new Ze("remove_item",[{name:"id",type:"string"},{name:"amount",type:"number"}],async t=>{const{id:e,amount:n}=t.options;Or().remove({id:e,amount:n})}),FK=new Ze("has_item?",[{name:"id",type:"string"},{name:"amount",type:"number",optional:!0}],async t=>{const{id:e,amount:n}=t.options;return Or().hasItem(e,n)}),qK=new Ze("item_amount?",[{name:"id",type:"string"}],async t=>{const{id:e}=t.options;return Or().getItemAmount(e)}),HK=new Ze("enable_interaction",[{name:"tag",type:"string"}],async t=>{const e=t.options.tag;Or().enableInteraction(e)}),WK=new Ze("disable_interaction",[{name:"tag",type:"string"}],async t=>{const e=t.options.tag;Or().disableInteraction(e)}),UK=new Ze("start_quest",[{name:"questId",type:"string"}],async t=>{const e=t.options.questId;Vr().startQuest(e)}),JK=new Ze("start_objective",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;Vr().startObjective(e,n)}),GK=new Ze("complete_objective",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;Vr().completeObjective(e,n)}),KK=new Ze("complete_quest",[{name:"questId",type:"string"},{name:"ending",type:"string",optional:!0}],async t=>{const{questId:e,ending:n}=t.options;Vr().completeQuest(e,n)}),QK=new Ze("quest_completed?",[{name:"questId",type:"string"}],async t=>{const{questId:e}=t.options;return Vr().isQuestCompleted(e)}),YK=new Ze("objective_completed?",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;return Vr().isObjectiveCompleted(e,n)}),XK=new Ze("quest_started?",[{name:"questId",type:"string"}],async t=>{const{questId:e}=t.options;return Vr().isQuestStarted(e)}),ZK=new Ze("objective_started?",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;return Vr().isObjectiveStarted(e,n)}),eQ=Ze.FromOptions({keyword:"wait",argTypes:[{name:"duration",type:"number"}],runner:async t=>{await $d(t.options.duration)}}),tQ=new Ze("notify",[{name:"text",type:"string"}],async t=>{const{text:e}=t.options;Co().addNotification(e)}),nQ=new Ze("disable_notifications",[],async t=>{Co().disableNotifications()}),rQ=new Ze("enable_notifications",[],async t=>{Co().enableNotifications()}),oQ=new Ze("clear_dialog",[],async t=>{co().clearDialog()}),iQ=new Ze("if",[{name:"condition",type:"boolean"}],async t=>{const e=gU(t),n=fn();if(e){const r={branchData:{branch:e},currentIndex:0};return n.addAndRunBlock(r)}},(t,e)=>{let n=t.currentLine;Nl("if",[{name:"condition",type:"string"}])(t,e);const{lines:o,currentLine:i,line:a}=t,s=e.command;let u;const l=yU(o,i+1);return l&&l.code==="else:"&&(u=t.processCommandsFunction(t.parserContext,l.branch,a),n++),s.staticOptions={success:t.processCommandsFunction(t.parserContext,a.branch,a),failure:u},n++,{newLine:n}}),aQ=new Ze("==","any",async t=>{t.args.length<2&&dn(t,"requires at least two arguments");let e=t.args[0],n=!0;for(const r of t.args)if(r!=e){n=!1;break}else e=r;return n}),sQ=new Ze(">",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e>n}),uQ=new Ze("<",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e<n}),lQ=new Ze(">=",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e>=n}),cQ=new Ze("<=",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e<=n}),fQ=new Ze("!=",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e!=n}),dQ=new Ze("!",[{name:"a",type:"any"}],async t=>{const{a:e}=t.options;return!e}),hQ=new Ze("&&","any",async t=>{const e=t.args;return t.args.length<2&&dn(t,"requires at least two arguments"),e.reduce((n,r)=>n&&r,!0)}),pQ=new Ze("||","any",async t=>(t.args.length<2&&dn(t,"requires at least two arguments"),t.args.reduce((e,n)=>e||n,!1))),vQ=new Ze("?",[{name:"a",type:"any"},{name:"b",type:"any"},{name:"c",type:"any"}],async t=>{const{a:e,b:n,c:r}=t.options;return e?n:r}),mQ=new Ze("+","any",async t=>(t.args.length<2&&dn(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="number"?e+n:(dn(t,"requires all arguments to be numbers"),e),0))),gQ=new Ze("-","any",async t=>(t.args.length<2&&dn(t,"requires at least two arguments"),t.args.slice(1).reduce((e,n)=>typeof n=="number"?e-n:(dn(t,"requires all arguments to be numbers"),e),t.args[0]))),yQ=new Ze("neg",[{name:"a",type:"number"}],async t=>(t.args.length!==1&&dn(t,"requires one argument"),-t.options.a)),bQ=new Ze("abs",[{name:"a",type:"number"}],async t=>(t.args.length!==1&&dn(t,"requires one argument"),Math.abs(t.options.a))),kQ=new Ze("*","any",async t=>(t.args.length<2&&dn(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="number"?e*n:(dn(t,"requires all arguments to be numbers"),e),1))),wQ=new Ze("/","any",async t=>{t.args.length<2&&dn(t,"requires at least two arguments");const e=t.args[0]/t.args[1];return t.args.slice(2).reduce((n,r)=>typeof r=="number"?n/r:(dn(t,"requires all arguments to be numbers"),n),e)}),jQ=async t=>{const{prompt:e,choices:n}=t.staticOptions,r=[];for(const[,a]of n.entries()){const s=await Qg(a.prompt);r.push(s)}t.options.choiceResults=r;const o=r.map((a,s)=>{var f,c;let u=!0;return a.skillCheck&&(u=(c=(f=a.skillCheck)==null?void 0:f.allowed)!=null?c:!1),{choice:a.text,originalIndex:s,allowed:u}}).filter(a=>a.choice),i=await j8(e,o);return await CQ(t,i)};function xQ(t,e){e.branch||t.parserContext.error(e.line,`Choice option doesn't have any branch to go to (${e.code} - ${e.line})`);let n,r;const o=e.branch;return e.expression[1]==="roll"?((!o[0].branch||!o[1].branch)&&t.parserContext.error(e.line,`Choice option with a skill roll needs success and failure branches (${e.code} - ${e.line})`),n={success:t.processCommandsFunction(t.parserContext,o[0].branch,e),failure:t.processCommandsFunction(t.parserContext,o[1].branch,e)}):r=t.processCommandsFunction(t.parserContext,o,e),{prompt:t.processCommandsFunction(t.parserContext,[e],e)[0],branch:r,skillBranches:n}}const _Q=(t,e)=>{let n=t.currentLine;Nl("choice",[]);const{line:r}=t,o=e.command;(!r.branch||r.branch.length<2)&&t.parserContext.error(r.line,"Choice menu needs to have at least one option");const i=r.branch[0];i||t.parserContext.error(t.line.line,"Choice prompt is missing ");const s=r.branch.slice(1).map((u,l)=>(u.branch||t.parserContext.error(u.line,`Choice option doesn't have any branch to go to (${u.code})`),u=$Q(t.parserContext,u),xQ(t,u)));return o.staticOptions={prompt:t.processCommandsFunction(t.parserContext,[i],r)[0],choices:s},n++,{newLine:n}},SQ=Ze.FromOptions({keyword:"choice",argTypes:[],runner:jQ,parser:_Q}),CQ=async(t,e)=>{const n=e,r=fn(),{choices:o}=t.staticOptions,i=o[n],a=t.options.choiceResults[n];let s=a.text,u;if(a.skillCheck?(s=null,y8({skill:a.skillCheck.skillId,value:a.skillCheck.difficulty,id:a.skillCheck.skillCheckId,hideAfterRoll:a.skillCheck.hideAfterRoll}).succeeded?u=i.skillBranches.success:u=i.skillBranches.failure):u=i.branch,s){const l={speaker:"player",text:s,interactive:!1};co().addDialog(l)}if(u){const l={currentIndex:0,branchData:{branch:u}};return await r.addAndRunBlock(l)}};function $Q(t,e){return{code:`choicePrompt ${e.code}`,indentation:e.indentation,line:e.line,branch:e.branch,expression:["choicePrompt",...e.expression]}}const OQ=new Ze("choicePrompt","any",async t=>{const e=t.args;if(e[0]==="roll"){const n=e[1],r=e[2],o=e[3],i=e[4],a=e.length>5?e[5]:!1,s=cr().getSkillCheck(n);if(s.hidden)return{text:null};const u=s.happened&&!s.succeeded,{difficultyText:l}=hU({skill:r,skillCheckId:n,value:o});return{text:`${l} ${i}`,skillCheck:{allowed:!u,skillId:r,skillCheckId:n,difficulty:o,hideAfterRoll:a}}}else if(e.length>1&&e[1]==="if"){const n=e[0];let r=!0;return e.length>2&&(r=e[2]),r?{text:n}:{text:null}}else return{text:e[0]}}),O8=Ze.FromOptions({keyword:"text_field",argTypes:[{name:"prompt",type:"string"}],returnAfterPlayerAnswer:!0,runner:async t=>{const e={speaker:"game",text:t.options.prompt,textField:!0,interactive:!0};co().addDialog(e)}});O8.onPlayerAnswered=async(t,e)=>(typeof e!="string"&&dn(t,"The player's answer should be a string"),e);const AQ=Ze.FromOptions({keyword:"text_field_prompt",argTypes:[{name:"prompt",type:"string"}],runner:async t=>{const e={speaker:"game",text:t.options.prompt,textField:!0,interactive:!0};co().addDialog(e)}}),EQ=new Ze("random",[{name:"a",type:"number"},{name:"b",type:"number"}],async t=>{const{a:e,b:n}=t.options;return typeof e!="number"||typeof n!="number"?(dn(t,"random command needs two numbers as parameters"),0):Math.floor(Math.random()*(n-e+1))+e}),PQ=new Ze("random_float",[{name:"a",type:"number"},{name:"b",type:"number"}],async t=>{const{a:e,b:n}=t.options;return typeof e!="number"||typeof n!="number"?(dn(t,"random_float command needs two numbers as parameters"),0):Math.random()*(n-e)+e}),TQ=new Ze("random_from_args",[],async t=>{const e=t.args;return!e||!e.length?(dn(t,"random_from_args command needs at least one argument"),0):e[Math.floor(Math.random()*e.length)]}),MQ=new Ze("concat","any",async t=>(t.args.length<2&&dn(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="string"?`${e}${n}`:(dn(t,"requires all arguments to be strings"),e),""))),IQ=new Ze("join","any",async t=>{const e=t.args[0];return t.args.length<3&&dn(t,"requires at least 3 arguments"),t.args.slice(1).reduce((n,r)=>typeof r=="string"?`${n}${e}${r}`:(dn(t,"requires all arguments to be strings"),n),"")}),NQ=Ze.FromOptions({keyword:"min",argTypes:[{name:"min",type:"number"},{name:"value",type:"number"}],runner:async t=>{const{min:e,value:n}=t.options;return n<e?n:e}}),LQ=Ze.FromOptions({keyword:"max",argTypes:[{name:"max",type:"number"},{name:"value",type:"number"}],runner:async t=>{const{max:e,value:n}=t.options;return n>e?n:e}}),RQ=Ze.FromOptions({keyword:"clamp",argTypes:[{name:"min",type:"number"},{name:"max",type:"number"},{name:"value",type:"number"}],runner:async t=>{const{min:e,max:n,value:r}=t.options;return r<e?e:r>n?n:r}}),DQ=Ze.FromOptions({keyword:"floor",argTypes:[{name:"value",type:"number"}],runner:async t=>{const{value:e}=t.options;return Math.floor(e)}}),BQ=Ze.FromOptions({keyword:"ceil",argTypes:[{name:"value",type:"number"}],runner:async t=>{const{value:e}=t.options;return Math.ceil(e)}}),zQ=Ze.FromOptions({keyword:"round",argTypes:[{name:"value",type:"number"}],runner:async t=>{const{value:e}=t.options;return Math.round(e)}}),VQ=Ze.FromOptions({keyword:"sqrt",argTypes:[{name:"value",type:"number"}],runner:async t=>{const{value:e}=t.options;return Math.sqrt(e)}}),FQ=Ze.FromOptions({keyword:"^",argTypes:[{name:"base",type:"number"},{name:"exponent",type:"number"}],runner:async t=>{const{base:e,exponent:n}=t.options;return Math.pow(e,n)}});function qQ(t){t.addCommand(SQ),t.addCommand(OQ),t.addCommand(iQ),t.addCommand(yK),t.addCommand(bK),t.addCommand(kK),t.addCommand(oQ),t.addCommand(tQ),t.addCommand(nQ),t.addCommand(rQ),t.addCommand(OK),t.addCommand($K),t.addCommand(AK),t.addCommand(NK),t.addCommand(MK),t.addCommand(IK),t.addCommand(eQ),t.addCommand(aQ),t.addCommand(sQ),t.addCommand(uQ),t.addCommand(lQ),t.addCommand(cQ),t.addCommand(fQ),t.addCommand(dQ),t.addCommand(hQ),t.addCommand(pQ),t.addCommand(vQ),t.addCommand(mQ),t.addCommand(gQ),t.addCommand(kQ),t.addCommand(wQ),t.addCommand(yQ),t.addCommand(bQ),t.addCommand(TK),t.addCommand(PK),t.addCommand(BK),t.addCommand(LK),t.addCommand(RK),t.addCommand(wK),t.addCommand(jK),t.addCommand(xK),t.addCommand(_K),t.addCommand(SK),t.addCommand(UK),t.addCommand(JK),t.addCommand(GK),t.addCommand(KK),t.addCommand(XK),t.addCommand(ZK),t.addCommand(QK),t.addCommand(YK),t.addCommand(zK),t.addCommand(VK),t.addCommand(HK),t.addCommand(WK),t.addCommand(FK),t.addCommand(qK),t.addCommand(dK),t.addCommand(hK),t.addCommand(pK),t.addCommand(gK),t.addCommand(vK),t.addCommand(mK),t.addCommand(O8),t.addCommand(AQ),t.addCommand(EQ),t.addCommand(PQ),t.addCommand(TQ),t.addCommand(MQ),t.addCommand(IQ),t.addCommand(NQ),t.addCommand(LQ),t.addCommand(RQ),t.addCommand(DQ),t.addCommand(zQ),t.addCommand(BQ),t.addCommand(VQ),t.addCommand(FQ)}let Ll;ar.callHook("onPageLoaded");async function HQ(t,e){const n=await Hg(t.configPath);eW(JSON.parse(n)),t.baseAssetsPath&&(jt().baseAssetsPath=t.baseAssetsPath),Ll=j.createApp(cK,{config:t,options:e});const r=EW();if(Ll.use(r),kn().setOptions(e),Ll.use(N8,{breakpoints:{s:0,m:800,l:1200}}),qQ(ar),d0.setupDebugger(e.debug),console.log("%c Narrat game engine \u2013 [VI]{version} - {date}[/VI]","background: #222; color: #bada55"),ar.callHook("onNarratSetup"),Ll.mount("#game-holder"),e.debug){const o={app:Ll,vm:ar,jump:i=>{fn().runLabel(i)}};window.narrat=o}}class WQ{onPageLoaded(){}onNarratSetup(){}onAppMounted(){}onAssetsLoaded(){}onGameSetup(){}onGameStart(){}onGameMounted(){}onGameDismounted(){}}function UQ(t){ar.addPlugin(t)}function JQ(t){ar.addCommand(t)}sn.CommandPlugin=Ze,sn.NarratPlugin=WQ,sn.addCommand=JQ,sn.aspectRatioFit=_8,sn.generateParser=Nl,sn.getConfig=jt,sn.registerPlugin=UQ,sn.startApp=HQ,Object.defineProperties(sn,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
185
185
|
//# sourceMappingURL=narrat.umd.js.map
|