narrat 2.1.5 → 2.1.6
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 +3 -3
- 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=Ec,s._s.has(r)||(i?Vg(r,e,o,s):G7(r,o,s),proce
|
|
|
181
181
|
Label: ${((r=n.currentFrame)==null?void 0:r.label)||"none"}`)}}async function gU(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(g8(s))u=await Gg(s,e);else if(typeof s=="string")if(s.search(p8)===0)u=s.substring(3);else if(y8(s)){const c=cu(),f=sU(c,s.substring(1));if(f){const[l,d]=f;u=l[d]}else u=s}else u=s;else u=s;if(o.args.push(u),Array.isArray(i)&&i.length>a){const c=i[a];u!==null&&(o.options[c.name]=u)}}return o}else throw new Error(`${n.commandType} is not a valid command`)}async function Gg(t,e){const n=await gU(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 yU(t){Pc("onPlayerAnswered");const e=dn(),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),tr(`Error after player answer at ${r.fileName}:${r.line+1} (${r.code}<br /> - Error: ${o}`)}}const lu=Go("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<It().layout.verticalLayoutThreshold?this.layoutMode="vertical":this.layoutMode="horizontal"}}}),kn=Go("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){e.audioOptions.defaultMusic&&Pd(e.audioOptions.defaultMusic),await dn().loadScripts(t),$i().setButtons(e),lr().setupSkills(e.skills),Wi().setupHudStats(e.hudStats),$r().setupItems(e.items),zr().setupQuests(e.quests)},startMachine(){co().stopMusic(),dn().start(),this.ready=!0,this.startPlaying(),ar.callHook("onGameStart"),this.setFlowState("playing")},setSaveSlot(t){this.saveSlot=t,TW(t)},async startGame(t){this.setSaveSlot(t),this.startMachine(),await this.saveGame(),dn().runGame()},async loadGame(t,e){this.setSaveSlot(e),this.startMachine(),t&&(this.setLoadedData(t),t.audio.currentMusic&&Pd(t.audio.currentMusic),dn().runLabel(t.vm.lastLabel))},playerAnswered(t){yU(t)},menuReturn(){this.reset(),co().stopMusic(),this.setFlowState("menu"),It().audioOptions.defaultMusic&&Pd(It().audioOptions.defaultMusic)},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,dn().reset(),co().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=lr(),n=lo(),r=dn(),o=kn(),i=Wi(),a=co(),s=$r(),u={version:"1.1.0",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:zr().generateSaveData(),metadata:{saveDate:new Date().toISOString()}};PW(u,this.saveSlot)},setLoadedData(t){const e=$i(),n=lr(),r=lo(),o=dn(),i=kn(),a=Wi(),s=co(),u=$r();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),zr().loadSaveData(t.quests)},getAllStates(){return{main:this,screens:$i(),skills:lr(),dialog:lo(),vm:dn(),hud:Wi(),audio:co(),rendering:lu(),notifications:Ci(),inventory:$r(),quests:zr()}},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 bU(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>`;tr(r)}function tr(t){const e=kn();console.error(t),t=t.replace(/[\r\n]/g,`
|
|
182
182
|
<br />`),e.createError(`\u274C ${t}`)}const lr=Go("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||tr(`Skill ${t} doesn't exist`),n.xp+=e,n.xp>=It().skillOptions.xpPerLevel&&(n.xp=0,n.level++,this.levelledUp(t))},setSkillLevel(t,e){const n=this.getSkill(t);n||tr(`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=It().skills[t].name,n=this.skills[t].level;Ci().addNotification(`Your skill in ${e} is now level ${n}`)}}});let j8;const kU=j.defineComponent({components:{Modal:ds},setup(){const t=lr(),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];dn().runLabel(e),this.finishJumping()}})},methods:{finishJumping(){this.jumping=!1,this.matches=[],this.searchString=""},labelSelected(t){const e=t.target.value;dn().runLabel(e),this.close()},close(){this.showDebug=!1},closeErrors(){kn().clearErrors()},open(){this.showDebug=!0;const t=dn(),e=kn(),n=zr(),r=$r(),o=lr();this.$nextTick(()=>{new j7({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 j7({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(){j8=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=j8.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)=>(Ao.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:{...Si(dn,["script","data"]),...Si(kn,["playTime","errors","playing","flowState"]),labels(){const t=this.script;return Object.keys(t).sort()},variables(){return this.data}}}),UQ="",wU={class:"debug-menu"},jU={key:0,class:"debug-info"},xU=[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),SU={key:0,class:"search-results"},CU={key:1},$U=[j.createElementVNode("h3",null,"No matches found",-1)],OU=j.createElementVNode("h3",{class:"title"},"Error(s)",-1),EU=j.createTextVNode(" There are errors in your dialogue scripts. Open the developer console for more details. "),AU=["innerHTML"],PU=j.createElementVNode("h3",{class:"title"},"Debug Menu!",-1),TU={class:"container"},MU=j.createTextVNode(" Hello this is the debug menu. "),IU=j.createElementVNode("option",{class:"option",selected:"",disabled:""},"Jump to a label",-1),NU=["value"],LU={class:"grid grid-cols-3 gap-4"},DU=j.createElementVNode("h2",null,"Variables Editor",-1),RU={ref:"variablesViewer"},BU=j.createElementVNode("h2",null,"Skill Checks",-1),zU={class:"table-auto"},VU=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),FU=j.createElementVNode("h2",null,"App State editor (entire app and engine",-1),qU=j.createElementVNode("h3",{style:{color:"pink"}}," Use for debugging, editing some of those things can cause issues ",-1),HU={ref:"stateViewer"};function WU(t,e,n,r,o,i){const a=j.resolveComponent("modal");return j.openBlock(),j.createElementBlock("div",wU,[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",jU,xU)):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",SU,[(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",CU,$U))]),_: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(()=>[OU]),body:j.withCtx(()=>[EU,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,AU))),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(()=>[PU]),body:j.withCtx(()=>[j.createElementVNode("div",TU,[MU,j.createElementVNode("select",{class:"select",name:"label-selector",onChange:e[3]||(e[3]=s=>t.labelSelected(s))},[IU,(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,NU))),128))],32),j.createElementVNode("div",LU,[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),DU,j.createElementVNode("div",RU,null,512),BU,j.createElementVNode("table",zU,[VU,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))])]),FU,qU,j.createElementVNode("div",HU,null,512)])]),_:1},8,["onClose"])):j.createCommentVNode("",!0)])}const UU=Fr(kU,[["render",WU]]),JU=j.defineComponent({data(){return{}},methods:{getStatImage(t){return Oc(this.statsConfig[t].icon)}},computed:{...Si(Wi,["hudStats"]),...Si(lu,["layoutMode"]),statsConfig(){return It().hudStats},stats(){return this.hudStats},hudStyle(){let t="0";return this.layoutMode==="horizontal"&&(t=`${It().layout.minTextWidth}px`),{right:t}}}}),QQ="",GU=["src"],KU={class:"bold hud-text"},QU=j.createTextVNode(": ");function YU(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,GU),j.createElementVNode("span",KU,j.toDisplayString(t.statsConfig[s].name),1),QU,j.createElementVNode("span",null,j.toDisplayString(Math.floor(a.value*100)/100),1)]))),128))],4)}const XU=Fr(JU,[["render",YU]]),ZU=j.defineComponent({props:{percentage:Number,step:String},methods:{loadingStyle(){return{width:`${this.percentage*40}vw`}}},computed:{}}),YQ="",eJ={id:"loading-bar"},tJ={id:"loading-text"};function nJ(t,e,n,r,o,i){return j.openBlock(),j.createElementBlock("div",eJ,[j.createElementVNode("div",{id:"inner-loading-bar",style:j.normalizeStyle(t.loadingStyle())},null,4),j.createElementVNode("div",tJ,[j.createElementVNode("h3",null,"Loading "+j.toDisplayString(Math.floor(t.percentage*100))+"% - "+j.toDisplayString(t.step),1)])])}const rJ=Fr(ZU,[["render",nJ]]),oJ=j.defineComponent({data(){},methods:{},computed:{...Si(Ci,["notifications"])}}),XQ="";function iJ(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",null,j.toDisplayString(a.text),1)]))),128))]),_:1})}const aJ=Fr(oJ,[["render",iJ]]);let Kg;function sJ(t){Kg=t}function Qg(t){return Kg.characters[t]}function uJ(t,e){const n=Qg(t);if(e||(e="default"),n.sprites)return`${Kg.config.imagesPath}${n.sprites[e]}`}function Id(t){return t?Qg(t).style||{}:{}}function x8(t,e,n,r){const o=t/n,i=e/r;return Math.min(o,i)}let _8=0,S8=0;function cJ(t){return Ao.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];lJ(r,o,e,n)}})}function lJ(t,e,n,r){_8++,Ao.log(`Loading image ${t} at ${e}`);const o=new Image;o.onload=()=>{S8+=1,Ao.log(`Loaded image ${t} successfully`),S8>=_8&&(Ao.log("All images loaded"),n())},o.onerror=i=>{console.error(`Error loading image ${t}`),r(i)},o.src=e}function C8(t,e=50,n={}){var l,d;let r;const o=(l=n.isImmediate)!=null?l:!1,i=(d=n.callback)!=null?d:!1,a=n.maxWait;let s=Date.now(),u=[];function c(){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=c();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 fJ=j.defineComponent({data(){return{muted:!1}},mounted(){const t=ja.Howler.volume();this.$refs.slider.value=t},methods:{changeVolume(t){const e=t.target;ja.Howler.volume(e.value)},toggleMute(){this.muted?(ja.Howler.mute(!1),this.muted=!1):(ja.Howler.mute(!0),this.muted=!0)}}}),ZQ="",dJ={class:"volume-controls"},hJ=j.createElementVNode("label",{for:"volume",class:"volume-label"},"Volume",-1);function pJ(t,e,n,r,o,i){return j.openBlock(),j.createElementBlock("div",dJ,[hJ,j.createElementVNode("input",{ref:"slider",class:"volume-slider",type:"range",id:"volume",name:"volume",min:"0",max:"1",step:"0.1",value:"0.5",onChange:e[0]||(e[0]=(...a)=>t.changeVolume&&t.changeVolume(...a))},null,544)])}const vJ=Fr(fJ,[["render",pJ]]),mJ=j.defineComponent({components:{Modal:ds,VolumeControls:vJ},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:{...Si(kn,["playTime"])}}),eY="",gJ=j.createElementVNode("h3",{class:"title"},"Menu",-1),yJ={class:"menu-content"};function bJ(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:"menu-modal"},{header:j.withCtx(()=>[gJ]),body:j.withCtx(()=>[j.createElementVNode("div",yJ,[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 kJ=Fr(mJ,[["render",bJ]]),wJ=j.defineComponent({setup(){const t=lr();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 It().skills},xpPerLevel(){return It().skillOptions.xpPerLevel}}}),tY="",jJ=j.createElementVNode("h3",{class:"title"},"Skills",-1),xJ={key:0,class:"skills-container"},_J=["onClick"],SJ={class:"skill-title"},CJ={class:"skill-xp-container"},$J={class:"skill-xp-text"},OJ={class:"skill-level"},EJ={key:1},AJ={class:"flex flex-row skill-description-container"},PJ={class:"flex skill-left"},TJ={class:"flex skill-right"},MJ=j.createElementVNode("hr",{class:"hr-solid"},null,-1);function IJ(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(()=>[jJ]),body:j.withCtx(()=>[t.chosenSkill?typeof t.chosenSkill=="string"?(j.openBlock(),j.createElementBlock("div",EJ,[j.createElementVNode("div",AJ,[j.createElementVNode("div",PJ,[j.createElementVNode("div",{class:"skill-display",style:j.normalizeStyle(t.getSkillStyle(t.chosenSkill))},null,4)]),j.createElementVNode("div",TJ,[j.createElementVNode("h2",null,j.toDisplayString(t.getSkillName(t.chosenSkill)),1),MJ,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",xJ,[(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",SJ,j.toDisplayString(t.getSkillName(s.id)),1),j.createElementVNode("div",CJ,[j.createElementVNode("div",{class:"skill-xp-bar",style:j.normalizeStyle(t.xpBarWidth(s.xp))},null,4),j.createElementVNode("h3",$J,j.toDisplayString(s.xp)+" / "+j.toDisplayString(t.xpPerLevel)+" XP",1)]),j.createElementVNode("h3",OJ,j.toDisplayString(s.level),1)],12,_J))),128))]))]),_:1})}const NJ=Fr(wJ,[["render",IJ]]),LJ=j.defineComponent({setup(){const t=$r(),e=lo(),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"?dn().runLabel(t.label):t.action==="run"?dn().runLabelFunction(t.label,!0):tr(`Unknown action ${t.action}`)}},canUseItem(t){const e=this.itemConf[t.id];return!!(e&&e.onUse&&!$r().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 It().items}}}),nY="",DJ=j.createElementVNode("h3",{class:"title"},"Inventory",-1),RJ={key:0,class:"inventory-container"},BJ=["onClick"],zJ={class:"item-title"},VJ={class:"item-amount"},FJ={key:1},qJ={class:"flex flex-row item-description-container"},HJ={class:"flex item-left"},WJ={class:"flex item-right"},UJ=j.createElementVNode("hr",{class:"hr-solid"},null,-1),JJ={key:2},GJ=[j.createElementVNode("h2",null,"The inventory is empty!",-1)];function KJ(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(()=>[DJ]),body:j.withCtx(()=>[!t.chosenItem&&Object.keys(t.itemsToDisplay).length>0?(j.openBlock(),j.createElementBlock("div",RJ,[(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",zJ,j.toDisplayString(t.getItemName(s.id)),1),j.createElementVNode("h3",VJ,j.toDisplayString(s.amount),1)],12,BJ))),128))])):typeof t.chosenId=="string"?(j.openBlock(),j.createElementBlock("div",FJ,[j.createElementVNode("div",qJ,[j.createElementVNode("div",HJ,[j.createElementVNode("div",{class:"item-display",style:j.normalizeStyle(t.getItemStyle(t.chosenId))},null,4)]),j.createElementVNode("div",WJ,[j.createElementVNode("h2",null,j.toDisplayString(t.getItemName(t.chosenId)),1),UJ,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",JJ,GJ))]),_:1},8,["onClose"])}const QJ=Fr(LJ,[["render",KJ]]),YJ=j.defineComponent({props:{pictureUrl:String},computed:{...Si(lu,["layoutMode"]),boxStyle(){const t=It().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`}}}}),oY="",XJ=["src"];function ZJ(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,XJ)],4)}const eG=Fr(YJ,[["render",ZJ]]);class tG{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 nG extends tG{setup(e=!1){const r=e?"keydown":"keyup",o=C8(i=>{Ic.emit("debouncedKeydown",i)},10,{isImmediate:!0,maxWait:10});document.addEventListener("keydown",i=>{Ic.emit("keydown",i)}),document.addEventListener(r,i=>{o(i)})}}const Ic=new nG,rG=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=Ic.on("debouncedKeydown",t),this.timeout=setTimeout(()=>{this.options.textField&&this.$refs.playerInput.focus()},10)}},unmounted(){this.clearListeners()},computed:{...Si(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&&(Ic.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)}}}),iY="",oG={class:"dialog-content"},iG=["innerHTML"],aG=["innerHTML"],sG=["innerHTML"],uG={key:1,class:"dialog-choices"},cG=["onClick","innerHTML"],lG={key:2},fG={key:3,class:"buttons-container"};function dG(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",oG,[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,iG)):j.createCommentVNode("",!0),j.createElementVNode("span",{class:"dialog-text dialog-separator override",style:j.normalizeStyle(t.textStyle),innerHTML:t.preText},null,12,aG),j.createElementVNode("span",{class:"dialog-text override",style:j.normalizeStyle(t.textStyle),innerHTML:t.options.text},null,12,sG),t.canInteract&&t.choices?(j.openBlock(),j.createElementBlock("div",uG,[(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,cG))),128))])):t.canInteract&&t.options.textField?(j.openBlock(),j.createElementBlock("div",lG,[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",fG,[j.createElementVNode("div",{onClick:e[2]||(e[2]=a=>t.chooseOption(0)),class:"interact-button button override"}," Continue ")])):j.createCommentVNode("",!0)])],4)}const hG=Fr(rG,[["render",dG]]),pG=j.createElementVNode("div",{class:"anchor"},null,-1),vG=j.defineComponent({__name:"game-dialog",props:{layoutMode:String,inGame:Boolean},setup(t){const e=t,n=dn(),r=j.computed(()=>n.stack),o=lo(),i=j.computed(()=>o.dialog),a=j.ref(null),s=j.computed(()=>e.layoutMode==="vertical"?{}:{paddingBottom:`${It().layout.dialogBottomPadding}px`}),u=j.computed(()=>{if(i.value.length>0)return i.value[i.value.length-1]}),c=j.computed(()=>{if(u.value)return uJ(u.value.speaker,u.value.pose)}),f=j.computed(()=>It().layout.minTextWidth),l=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=Qg(p.speaker).name;return v>=1&&i.value[v-1].speaker===p.speaker&&(m=void 0),p.choices&&p.choices.forEach(y=>{y.choice=h8(y.choice)}),{title:m!=null?m:"",text:p.text,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(c)?(j.openBlock(),j.createBlock(eG,{key:0,pictureUrl:j.unref(c)},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(l))},[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(hG,{key:g.id,options:d(g,m),active:h(m)},null,8,["options","active"]))),128))]),_:1},8,["style"]),pG],4)):j.createCommentVNode("",!0)],64))}}),aY="",$8=(t,e)=>{const n={};for(const r in t)e(t[r])&&(n[r]=t[r]);return n},mG=j.defineComponent({setup(){const t=zr();return{quests:j.computed(()=>t.quests)}},computed:{questsToDisplay(){return $8(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 $8(t.objectives,e=>e.state!=="hidden")}},components:{Modal:ds}}),sY="",gG=j.createElementVNode("h3",{class:"title"},"Quests",-1),yG={key:0,class:"quests-container"},bG={class:"quest-title"},kG={class:"quest-description"},wG={key:0,class:"quest-objectives-container list-disc"},jG={key:1,class:"menu-container"},xG=[j.createElementVNode("h2",{class:"title"},"There are no quests!",-1)];function _G(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(()=>[gG]),body:j.withCtx(()=>[Object.keys(t.questsToDisplay).length>0?(j.openBlock(),j.createElementBlock("div",yG,[(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",bG,j.toDisplayString(t.getQuestData(s.id).title)+" "+j.toDisplayString(t.getDisplayTextForQuestState(s)),1)],2),j.createElementVNode("p",kG,j.toDisplayString(t.getQuestDescription(s)),1),s.state!=="completed"?(j.openBlock(),j.createElementBlock("ul",wG,[(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",jG,xG))]),_:1},8,["onClose"])}const SG=Fr(mG,[["render",_G]]),CG=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=It().menuButtons[t.id]||{};return{...t,...e}}).filter(t=>t.condition?t.condition():!0)},showSkills(){return Object.entries(It().skills).length>0},showInventory(){return Object.entries(It().items).length>0},showQuests(){return Object.entries(It().quests).length>0}}}),cY="",$G={class:"menu-container"},OG=["onClick","id"];function EG(t,e,n,r,o,i){return j.openBlock(),j.createElementBlock("div",$G,[(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,OG))),128))])}const AG=Fr(CG,[["render",EG]]),PG=["id"],TG=["id","onClick"],MG=j.defineComponent({__name:"screen-layer",props:{layer:String},setup(t){const e=t,n=dn(),r=kn(),o=$i(),i=j.computed(()=>e.layer),a=j.computed(()=>o.buttons),s=j.computed(()=>{const p=It().screens[i.value];if(!p)throw new Error(`Screen ${i.value} doesn't have a config`);return p}),u=j.computed(()=>s.value.buttons||[]),c=j.computed(()=>r.isInGame);function f(p){const g=_d(p).background;if(!!g)return E7(g)}function l(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(${E7(s.value.background)})`}));return(p,v)=>j.unref(c)?(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(l(g))},j.toDisplayString(j.unref(_d)(g).text),13,TG))),128))],12,PG)):j.createCommentVNode("",!0)}}),lY="",IG=j.defineComponent({__name:"screens",setup(t){const e=lu(),n=kn(),r=$i(),o=j.computed(()=>r.layers.filter(f=>f)),i=j.computed(()=>e.layoutMode),a=j.computed(()=>It().layout.backgrounds.width),s=j.computed(()=>It().layout.backgrounds.height),u=j.computed(()=>n.isInGame),c=j.computed(()=>{const f=`${a.value}px`;let l=`${s.value}px`;return i.value==="vertical"&&(l=`${100-It().layout.mobileDialogHeightPercentage}%`),{height:l,width:f}});return(f,l)=>j.unref(u)?(j.openBlock(),j.createElementBlock("div",{key:0,class:"viewport",id:"narrat-viewport",style:j.normalizeStyle(j.unref(c))},[(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(j.unref(o),(d,h)=>(j.openBlock(),j.createBlock(MG,{key:h,layer:d},null,8,["layer"]))),128))],4)):j.createCommentVNode("",!0)}}),fY="",NG=j.createElementVNode("h3",{class:"title"},"Choose a save file",-1),LG={class:"saves-container flex flex-col"},DG={key:0,class:"empty-save-slot flex flex-row justify-around items-center grow"},RG=["onClick"],BG=[j.createElementVNode("h3",null,"Create a new save slot",-1)],zG={key:1,class:"used-save-slot flex flex-row justify-between items-center grow"},VG={class:"flex flex-col"},FG={class:"flex flex-col"},qG={class:"flex flex-row"},HG=["onClick"],WG=[j.createElementVNode("h3",null,"Load",-1)],UG=["onClick"],JG=[j.createElementVNode("h3",null,"Delete",-1)],GG=j.defineComponent({__name:"save-slots",emits:["chosen","close"],setup(t,{emit:e}){const n=j.reactive([]);j.onMounted(()=>{t8().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){NW(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(()=>[NG]),body:j.withCtx(()=>[j.createElementVNode("div",LG,[(j.openBlock(!0),j.createElementBlock(j.Fragment,null,j.renderList(n,(u,c)=>(j.openBlock(),j.createElementBlock("div",{class:"save-slot flex flex-row",key:c},[u==null?(j.openBlock(),j.createElementBlock("div",DG,[j.createElementVNode("button",{class:"button",onClick:f=>r(c)},BG,8,RG)])):(j.openBlock(),j.createElementBlock("div",zG,[j.createElementVNode("div",VG,[j.createElementVNode("h3",null,"Slot "+j.toDisplayString(c+1),1),j.createElementVNode("div",FG,[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",qG,[j.createElementVNode("button",{class:"button",onClick:f=>r(c)},WG,8,HG),j.createElementVNode("button",{class:"button",onClick:f=>o(c)},JG,8,UG)])]))]))),128))])]),_:1}))}}),vY="",KG={id:"game-menu",style:{height:"100%",padding:"20px"}},QG={id:"game-header",class:"flex flex-col justify-between items-center"},YG={id:"game-title-container"},XG={id:"game-title-text"},ZG={class:"flex flex-col start-menu-buttons-container"},eK=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(){Pc("onPressStart");const l=kn();r.value===-1&&(r.value=MW()),await l.startGame(r.value)}async function a(){Pc("onPressStart");const l=IW(r.value);if(!l){tr("No save file found");return}kn().loadGame(l,r.value)}function s(){typeof n.value=="number"&&(r.value=n.value,a())}function u(){o.value=!0}function c({saveData:l,slot:d}){r.value=d,l?a():i()}j.onMounted(()=>{const l=t8();l.slots.length>0&&(e.value=!0),l.lastSaveSlot&&l.slots.length>l.lastSaveSlot&&l.slots[l.lastSaveSlot]&&(n.value=l.lastSaveSlot)});const f=j.computed(()=>It().gameTitle);return(l,d)=>(j.openBlock(),j.createElementBlock("div",KG,[o.value?(j.openBlock(),j.createBlock(GG,{key:0,onChosen:c,onClose:d[0]||(d[0]=h=>o.value=!1)})):j.createCommentVNode("",!0),j.createElementVNode("div",QG,[j.createElementVNode("div",YG,[j.createElementVNode("h1",XG,j.toDisplayString(j.unref(f)),1)]),j.createElementVNode("div",ZG,[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)])])]))}}),mY="",tK=j.defineComponent({setup(){const t=lo(),e=dn(),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:UU,LoadingBar:rJ,NotificationToast:aJ,Hud:XU,MainMenu:kJ,Skills:NJ,InventoryUi:QJ,GameDialog:vG,QuestsUi:SG,MenuButtons:AG,Screens:IG,StartMenu:eK},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 sJ(JSON.parse(t)),this.loadingPercentage=.2,this.loadingStep="Data",this.loadingPercentage=.3,this.loadingStep="Images",await cJ(It()),this.loadingPercentage=.7,this.loadingStep="Audio",await $W(It()),ar.callHook("onAssetsLoaded"),this.loadingPercentage=.95,this.loadingStep="Starting...",await this.setupMachine(),ar.callHook("onGameSetup"),this.loadingPercentage=.1,this.gameLoaded=!0,window.addEventListener("resize",C8(()=>{this.updateScreenSize()},100,{maxWait:200})),Ic.setup(this.options.debug),setTimeout(()=>{this.updateScreenSize()},50)},computed:{...Si(lu,["screenWidth","screenHeight","canvasWidth","canvasHeight","topOffset","leftOffset","layoutMode"]),...Si(dn,["currentLine"]),backgroundStyle(){let t;return this.layoutMode==="vertical"&&(t=`${100-It().layout.mobileDialogHeightPercentage}%`),{backgroundColor:"red",height:t}},layoutWidth(){return It().layout.backgrounds.width},inGame(){return this.flowState==="playing"},layoutHeight(){return It().layout.backgrounds.height},backgroundSize(){return{width:this.canvasWidth,height:this.canvasHeight,top:this.topOffset,left:this.leftOffset}},gameWidth(){const t=It();return this.layoutMode==="vertical"?window.innerWidth:t.layout.backgrounds.width+t.layout.minTextWidth},gameHeight(){const t=It();return this.layoutMode==="vertical"?window.innerHeight:t.layout.backgrounds.height},appStyle(){const t=It();if(this.screenWidth&&this.screenHeight&&t&&this.layoutMode==="horizontal"){const e=x8(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=It(),e=t.layout.minTextWidth+t.layout.backgrounds.width;return this.screenWidth/e}},methods:{async setupMachine(){const t=It().scripts;return kn().setup(t,It())},updateScreenSize(){lu().updateScreenSize(window.innerWidth,window.innerHeight,this.layoutMode==="horizontal"?It().layout.minTextWidth*this.screenRatio:0)},closeModal(){kn().closeModal()}}}),gY="",nK={key:3};function rK(t,e,n,r,o,i){const a=j.resolveComponent("Hud"),s=j.resolveComponent("MenuButtons"),u=j.resolveComponent("Skills"),c=j.resolveComponent("InventoryUi"),f=j.resolveComponent("QuestsUi"),l=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(c,{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(l,{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",nK,[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 oK=Fr(tK,[["render",rK]]);function cn(t,e){console.error("Runtime error ========================="),console.error(`Command: ${t.commandType}`),console.error("Args: ",t.args),console.error("Options: ",t.options),tr(`Runtime error at ${t.fileName}:${t.line} (${t.commandType}) ${t.code}. -
|
|
183
183
|
<br />
|
|
184
|
-
Error: ${e}`),console.error("============================")}function iK(t,...e){console.log(`[${t.fileName}:${t.line}] log: `,...e)}class rt{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=Nc(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)=>{dn().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 rt(e.keyword,e.argTypes,e.runner,e.parser);return n.onPlayerAnswered=e.onPlayerAnswered,n.returnAfterPlayerAnswer=(r=e.returnAfterPlayerAnswer)!=null?r:!1,n}}function Nc(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 c=e[u];!g8(s)&&!y8(s)&&(c.type==="any"||typeof s===c.type||r.parserContext.error(r.line.line,`Command ${t}: Argument #${u+1} (${c.name}) should be a ${c.type}, but got type ${typeof s}: ${JSON.stringify(s)}`))}),{newLine:r.currentLine+1})}}const aK=new rt("add_level",[{name:"skillKey",type:"string"},{name:"amount",type:"number"}],async t=>{let{skillKey:e,amount:n}=t.options;if((!e||!n)&&cn(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}`)}lr().incrementSkill(e,n)}),sK=rt.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)&&cn(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}`)}lr().setSkillLevel(e,n)}}),uK=new rt("add_xp",[{name:"xpKey",type:"string"},{name:"xpToAdd",type:"number"}],async t=>{const{xpKey:e,xpToAdd:n}=t.options;(!e||!n)&&cn(t,"add_xp command needs a skill id and a value as parameters"),lr().addXp(e,n)}),cK=new rt("get_level",[{name:"skillKey",type:"string"}],async t=>{const{skillKey:e}=t.options;e||cn(t,"get_level command needs a skill id as parameter");const n=lr().getSkill(e);return n||cn(t,`Skill ${e} not found`),n.level}),lK=new rt("get_xp",[{name:"xpKey",type:"string"}],async t=>{const{xpKey:e}=t.options;e||cn(t,"get_xp command needs a skill id as parameter");const n=lr().getSkillXp(e);return n||cn(t,`XP ${e} not found`),n}),fK=new rt("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 m8({id:e,skill:n,value:r,hideAfterRoll:o}).succeeded}),dK=new rt("add_stat",[{name:"statKey",type:"string"},{name:"amountToAdd",type:"number"}],async t=>{const{statKey:e,amountToAdd:n}=t.options;(!e||typeof n!="number")&&cn(t,"add_stat command needs a stat id and a value as parameters"),Wi().addStat(e,n)}),hK=new rt("set_stat",[{name:"statKey",type:"string"},{name:"value",type:"number"}],async t=>{const{statKey:e,value:n}=t.options;(!e||typeof n!="number")&&cn(t,"set_stat command needs a stat id and a value as parameters"),Wi().setStat(e,n)}),pK=new rt("get_stat_value",[{name:"statKey",type:"string"}],async t=>{const{statKey:e}=t.options;return e||cn(t,"get_stat_value command needs a stat id as parameter"),Wi().getStatValue(e)}),vK=rt.FromOptions({keyword:"jump",argTypes:"any",runner:async t=>{(t.args.length<1||typeof t.args[0]!="string")&&cn(t,"requires a label argument");const e=t.args[0],n=dn(),r={branchData:n.script[e],label:e,args:t.args.splice(1),currentIndex:0};return n.jumpTarget=r,await kn().saveGame(),Td}}),mK=rt.FromOptions({keyword:"run",argTypes:"any",runner:async t=>{(t.args.length<1||typeof t.args[0]!="string")&&cn(t,"run command needs a label to argument run");const e=t.args[0];return await dn().runLabelFunction(e,...t.args.slice(1))}}),gK=rt.FromOptions({keyword:"var",argTypes:[{name:"name",type:"string"},{name:"value",type:"any"}],runner:async t=>{const{name:e,value:n}=t.options;dn().addScopedVariable(e,n)}}),yK=rt.FromOptions({keyword:"return",argTypes:[{name:"value",type:"any"}],runner:async t=>{const{value:e}=t.options;return dn().setReturnValue(e),qg}}),bK=rt.FromOptions({keyword:"log",argTypes:"any",runner:async t=>{iK(t,...t.args)}}),Yg=[{name:"mode",type:"string"},{name:"audio",type:"string",optional:!0}],kK=new rt("play",Yg,async t=>{const e=t.options;e.mode==="music"?Pd(e.audio):Q7(e.audio)}),wK=new rt("pause",Yg,async t=>{const e=t.options;if(e.mode==="music"){const n=co();n.currentMusic&&X7(n.currentMusic)}else e.mode==="sound"&&e.audio?X7(e.audio):cn(t,"pause first option needs to either be in music mode, or if stopping a sound needs to have the sound name supplied as second argument.")}),jK=new rt("stop",Yg,async t=>{const e=t.options;e.mode==="music"?co().currentMusic&&co().stopMusic():e.mode==="sound"&&e.audio?Y7(e.audio):cn(t,"stop option needs to either be in music mode, or if stopping a sound needs to have the sound name supplied as second argument.")}),xK=new rt("set",[{name:"key",type:"string"},{name:"value",type:"any"}],async t=>{const e=cu();f8(e,t.options.key,t.options.value)}),_K=new rt("add",[{name:"key",type:"string"},{name:"value",type:"any"}],async t=>{const e=cu();d8(e,t.options.key,t.options.value)}),SK=new rt("set_screen",[{name:"screen",type:"string"},{name:"layer",type:"number",optional:!0}],async t=>{$i().setScreen(t.options.screen,t.options.layer)}),CK=new rt("empty_layer",[{name:"layer",type:"number"}],async t=>{$i().emptyLayer(t.options.layer)}),$K=new rt("set_button",[{name:"buttonId",type:"string"},{name:"state",type:"any"}],async t=>{const{buttonId:e,state:n}=t.options;$i().changeButton(e,n)}),OK=rt.FromOptions({keyword:"talk",argTypes:[{name:"speaker",type:"string"},{name:"pose",type:"string"},{name:"text",type:"string"}],runner:async(t,e)=>{await k8({speaker:t.options.speaker,pose:t.options.pose,text:`"${t.options.text}"`,choices:e,interactive:!0})},returnAfterPlayerAnswer:!0}),EK=()=>{const t=Nc("text",[]);return(e,n)=>{const r=t(e,n);return n.command.staticOptions={text:n.code.substring(1,n.code.length-1)},r}},AK=rt.FromOptions({keyword:"text",argTypes:[],runner:async(t,e)=>{await k8({speaker:"game",text:t.staticOptions.text,choices:e,interactive:!0})},parser:EK(),returnAfterPlayerAnswer:!0}),PK=new rt("add_item",[{name:"id",type:"string"},{name:"amount",type:"number"}],async t=>{const{id:e,amount:n}=t.options;$r().add({id:e,amount:n})}),TK=new rt("remove_item",[{name:"id",type:"string"},{name:"amount",type:"number"}],async t=>{const{id:e,amount:n}=t.options;$r().remove({id:e,amount:n})}),MK=new rt("has_item?",[{name:"id",type:"string"},{name:"amount",type:"number",optional:!0}],async t=>{const{id:e,amount:n}=t.options;return $r().hasItem(e,n)}),IK=new rt("item_amount?",[{name:"id",type:"string"}],async t=>{const{id:e}=t.options;return $r().getItemAmount(e)}),NK=new rt("enable_interaction",[{name:"tag",type:"string"}],async t=>{const e=t.options.tag;$r().enableInteraction(e)}),LK=new rt("disable_interaction",[{name:"tag",type:"string"}],async t=>{const e=t.options.tag;$r().disableInteraction(e)}),DK=new rt("start_quest",[{name:"questId",type:"string"}],async t=>{const e=t.options.questId;zr().startQuest(e)}),RK=new rt("start_objective",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;zr().startObjective(e,n)}),BK=new rt("complete_objective",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;zr().completeObjective(e,n)}),zK=new rt("complete_quest",[{name:"questId",type:"string"},{name:"ending",type:"string",optional:!0}],async t=>{const{questId:e,ending:n}=t.options;zr().completeQuest(e,n)}),VK=new rt("quest_completed?",[{name:"questId",type:"string"}],async t=>{const{questId:e}=t.options;return zr().isQuestCompleted(e)}),FK=new rt("objective_completed?",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;return zr().isObjectiveCompleted(e,n)}),qK=new rt("quest_started?",[{name:"questId",type:"string"}],async t=>{const{questId:e}=t.options;return zr().isQuestStarted(e)}),HK=new rt("objective_started?",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;return zr().isObjectiveStarted(e,n)}),WK=rt.FromOptions({keyword:"wait",argTypes:[{name:"duration",type:"number"}],runner:async t=>{await Ig(t.options.duration)}}),UK=new rt("notify",[{name:"text",type:"string"}],async t=>{const{text:e}=t.options;Ci().addNotification(e)}),JK=new rt("clear_dialog",[],async t=>{lo().clearDialog()}),GK=new rt("if",[{name:"condition",type:"boolean"}],async t=>{const e=pU(t),n=dn();if(e){const r={branchData:{branch:e},currentIndex:0};return n.addAndRunBlock(r)}},(t,e)=>{let n=t.currentLine;Nc("if",[{name:"condition",type:"string"}])(t,e);const{lines:o,currentLine:i,line:a}=t,s=e.command;let u;const c=vU(o,i+1);return c&&c.code==="else:"&&(u=t.processCommandsFunction(t.parserContext,c.branch,a),n++),s.staticOptions={success:t.processCommandsFunction(t.parserContext,a.branch,a),failure:u},n++,{newLine:n}}),KK=new rt("==","any",async t=>{t.args.length<2&&cn(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}),QK=new rt(">",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e>n}),YK=new rt("<",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e<n}),XK=new rt(">=",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e>=n}),ZK=new rt("<=",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e<=n}),eQ=new rt("!=",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e!=n}),tQ=new rt("!",[{name:"a",type:"any"}],async t=>{const{a:e}=t.options;return!e}),nQ=new rt("&&","any",async t=>{const e=t.args;return t.args.length<2&&cn(t,"requires at least two arguments"),e.reduce((n,r)=>n&&r,!0)}),rQ=new rt("||","any",async t=>(t.args.length<2&&cn(t,"requires at least two arguments"),t.args.reduce((e,n)=>e||n,!1))),oQ=new rt("?",[{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}),iQ=new rt("+","any",async t=>(t.args.length<2&&cn(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="number"?e+n:(cn(t,"requires all arguments to be numbers"),e),0))),aQ=new rt("-","any",async t=>(t.args.length<2&&cn(t,"requires at least two arguments"),t.args.slice(1).reduce((e,n)=>typeof n=="number"?e-n:(cn(t,"requires all arguments to be numbers"),e),t.args[0]))),sQ=new rt("neg",[{name:"a",type:"number"}],async t=>(t.args.length!==1&&cn(t,"requires one argument"),-t.options.a)),uQ=new rt("abs",[{name:"a",type:"number"}],async t=>(t.args.length!==1&&cn(t,"requires one argument"),Math.abs(t.options.a))),cQ=new rt("*","any",async t=>(t.args.length<2&&cn(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="number"?e*n:(cn(t,"requires all arguments to be numbers"),e),1))),lQ=new rt("/","any",async t=>{t.args.length<2&&cn(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:(cn(t,"requires all arguments to be numbers"),n),e)}),fQ=async t=>{const{prompt:e,choices:n}=t.staticOptions,r=[];for(const[,a]of n.entries()){const s=await Gg(a.prompt);r.push(s)}t.options.choiceResults=r;const o=r.map((a,s)=>{var f,l;let u=!0;return a.skillCheck&&(u=(l=(f=a.skillCheck)==null?void 0:f.allowed)!=null?l:!1),{choice:a.text,originalIndex:s,allowed:u}}).filter(a=>a.choice),i=await w8(e,o);return await vQ(t,i)};function dQ(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 hQ=(t,e)=>{let n=t.currentLine;Nc("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,c)=>(u.branch||t.parserContext.error(u.line,`Choice option doesn't have any branch to go to (${u.code})`),u=mQ(t.parserContext,u),dQ(t,u)));return o.staticOptions={prompt:t.processCommandsFunction(t.parserContext,[i],r)[0],choices:s},n++,{newLine:n}},pQ=rt.FromOptions({keyword:"choice",argTypes:[],runner:fQ,parser:hQ}),vQ=async(t,e)=>{const n=e,r=dn(),{choices:o}=t.staticOptions,i=o[n],a=t.options.choiceResults[n];let s=a.text,u;if(a.skillCheck?(s=null,m8({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 c={speaker:"player",text:s,interactive:!1};lo().addDialog(c)}if(u){const c={currentIndex:0,branchData:{branch:u}};return await r.addAndRunBlock(c)}};function mQ(t,e){return{code:`choicePrompt ${e.code}`,indentation:e.indentation,line:e.line,branch:e.branch,expression:["choicePrompt",...e.expression]}}const gQ=new rt("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=lr().getSkillCheck(n);if(s.hidden)return{text:null};const u=s.happened&&!s.succeeded,{difficultyText:c}=lU({skill:r,skillCheckId:n,value:o});return{text:`${c} ${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=rt.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};lo().addDialog(e)}});O8.onPlayerAnswered=async(t,e)=>(typeof e!="string"&&cn(t,"The player's answer should be a string"),e);const yQ=rt.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};lo().addDialog(e)}}),bQ=new rt("random",[{name:"a",type:"number"},{name:"b",type:"number"}],async t=>{const{a:e,b:n}=t.options;return(!e||!n)&&cn(t,"random command needs two numbers as parameters"),Math.floor(Math.random()*(n-e+1))+e}),kQ=new rt("random_float",[{name:"a",type:"number"},{name:"b",type:"number"}],async t=>{const{a:e,b:n}=t.options;return(!e||!n)&&cn(t,"random_float command needs two numbers as parameters"),Math.random()*(n-e)+e}),wQ=new rt("random_from_args",[],async t=>{const e=t.args;return(!e||!e.length)&&cn(t,"random_from_args command needs at least one argument"),e[Math.floor(Math.random()*e.length)]}),jQ=new rt("concat","any",async t=>(t.args.length<2&&cn(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="string"?`${e}${n}`:(cn(t,"requires all arguments to be strings"),e),""))),xQ=new rt("join","any",async t=>{const e=t.args[0];return t.args.length<3&&cn(t,"requires at least 3 arguments"),t.args.slice(1).reduce((n,r)=>typeof r=="string"?`${n}${e}${r}`:(cn(t,"requires all arguments to be strings"),n),"")}),_Q=rt.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}}),SQ=rt.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}}),CQ=rt.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}}),$Q=rt.FromOptions({keyword:"floor",argTypes:[{name:"value",type:"number"}],runner:async t=>{const{value:e}=t.options;return Math.floor(e)}}),OQ=rt.FromOptions({keyword:"ceil",argTypes:[{name:"value",type:"number"}],runner:async t=>{const{value:e}=t.options;return Math.ceil(e)}}),EQ=rt.FromOptions({keyword:"round",argTypes:[{name:"value",type:"number"}],runner:async t=>{const{value:e}=t.options;return Math.round(e)}}),AQ=rt.FromOptions({keyword:"sqrt",argTypes:[{name:"value",type:"number"}],runner:async t=>{const{value:e}=t.options;return Math.sqrt(e)}}),PQ=rt.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 TQ(t){t.addCommand(pQ),t.addCommand(gQ),t.addCommand(GK),t.addCommand(dK),t.addCommand(hK),t.addCommand(pK),t.addCommand(JK),t.addCommand(UK),t.addCommand(wK),t.addCommand(kK),t.addCommand(jK),t.addCommand($K),t.addCommand(SK),t.addCommand(CK),t.addCommand(WK),t.addCommand(KK),t.addCommand(QK),t.addCommand(YK),t.addCommand(XK),t.addCommand(ZK),t.addCommand(eQ),t.addCommand(tQ),t.addCommand(nQ),t.addCommand(rQ),t.addCommand(oQ),t.addCommand(iQ),t.addCommand(aQ),t.addCommand(cQ),t.addCommand(lQ),t.addCommand(sQ),t.addCommand(uQ),t.addCommand(_K),t.addCommand(xK),t.addCommand(AK),t.addCommand(OK),t.addCommand(vK),t.addCommand(mK),t.addCommand(gK),t.addCommand(yK),t.addCommand(bK),t.addCommand(DK),t.addCommand(RK),t.addCommand(BK),t.addCommand(zK),t.addCommand(qK),t.addCommand(HK),t.addCommand(VK),t.addCommand(FK),t.addCommand(PK),t.addCommand(TK),t.addCommand(NK),t.addCommand(LK),t.addCommand(MK),t.addCommand(IK),t.addCommand(aK),t.addCommand(sK),t.addCommand(uK),t.addCommand(fK),t.addCommand(cK),t.addCommand(lK),t.addCommand(O8),t.addCommand(yQ),t.addCommand(bQ),t.addCommand(kQ),t.addCommand(wQ),t.addCommand(jQ),t.addCommand(xQ),t.addCommand(_Q),t.addCommand(SQ),t.addCommand(CQ),t.addCommand($Q),t.addCommand(EQ),t.addCommand(OQ),t.addCommand(AQ),t.addCommand(PQ)}let Lc;ar.callHook("onPageLoaded");async function MQ(t,e){const n=await Hg(t.configPath);eW(JSON.parse(n)),t.baseAssetsPath&&(It().baseAssetsPath=t.baseAssetsPath),Lc=j.createApp(oK,{config:t,options:e});const r=_W();if(Lc.use(r),kn().setOptions(e),Lc.use(N8,{breakpoints:{s:0,m:800,l:1200}}),TQ(ar),l0.setupDebugger(e.debug),console.log("%c Narrat game engine \u2013 [VI]{version} - {date}[/VI]","background: #222; color: #bada55"),ar.callHook("onNarratSetup"),Lc.mount("#game-holder"),e.debug){const o={app:Lc,vm:ar,jump:i=>{dn().runLabel(i)}};window.narrat=o}}class IQ{onPageLoaded(){}onNarratSetup(){}onAppMounted(){}onAssetsLoaded(){}onGameSetup(){}onGameStart(){}onGameMounted(){}onGameDismounted(){}}function NQ(t){ar.addPlugin(t)}function LQ(t){ar.addCommand(t)}sn.CommandPlugin=rt,sn.NarratPlugin=IQ,sn.addCommand=LQ,sn.aspectRatioFit=x8,sn.generateParser=Nc,sn.getConfig=It,sn.registerPlugin=NQ,sn.startApp=MQ,Object.defineProperties(sn,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
184
|
+
Error: ${e}`),console.error("============================")}function iK(t,...e){console.log(`[${t.fileName}:${t.line}] log: `,...e)}class rt{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=Nc(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)=>{dn().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 rt(e.keyword,e.argTypes,e.runner,e.parser);return n.onPlayerAnswered=e.onPlayerAnswered,n.returnAfterPlayerAnswer=(r=e.returnAfterPlayerAnswer)!=null?r:!1,n}}function Nc(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 c=e[u];!g8(s)&&!y8(s)&&(c.type==="any"||typeof s===c.type||r.parserContext.error(r.line.line,`Command ${t}: Argument #${u+1} (${c.name}) should be a ${c.type}, but got type ${typeof s}: ${JSON.stringify(s)}`))}),{newLine:r.currentLine+1})}}const aK=new rt("add_level",[{name:"skillKey",type:"string"},{name:"amount",type:"number"}],async t=>{let{skillKey:e,amount:n}=t.options;if((!e||!n)&&cn(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}`)}lr().incrementSkill(e,n)}),sK=rt.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)&&cn(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}`)}lr().setSkillLevel(e,n)}}),uK=new rt("add_xp",[{name:"xpKey",type:"string"},{name:"xpToAdd",type:"number"}],async t=>{const{xpKey:e,xpToAdd:n}=t.options;(!e||!n)&&cn(t,"add_xp command needs a skill id and a value as parameters"),lr().addXp(e,n)}),cK=new rt("get_level",[{name:"skillKey",type:"string"}],async t=>{const{skillKey:e}=t.options;e||cn(t,"get_level command needs a skill id as parameter");const n=lr().getSkill(e);return n||cn(t,`Skill ${e} not found`),n.level}),lK=new rt("get_xp",[{name:"xpKey",type:"string"}],async t=>{const{xpKey:e}=t.options;e||cn(t,"get_xp command needs a skill id as parameter");const n=lr().getSkillXp(e);return n||cn(t,`XP ${e} not found`),n}),fK=new rt("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 m8({id:e,skill:n,value:r,hideAfterRoll:o}).succeeded}),dK=new rt("add_stat",[{name:"statKey",type:"string"},{name:"amountToAdd",type:"number"}],async t=>{const{statKey:e,amountToAdd:n}=t.options;(!e||typeof n!="number")&&cn(t,"add_stat command needs a stat id and a value as parameters"),Wi().addStat(e,n)}),hK=new rt("set_stat",[{name:"statKey",type:"string"},{name:"value",type:"number"}],async t=>{const{statKey:e,value:n}=t.options;(!e||typeof n!="number")&&cn(t,"set_stat command needs a stat id and a value as parameters"),Wi().setStat(e,n)}),pK=new rt("get_stat_value",[{name:"statKey",type:"string"}],async t=>{const{statKey:e}=t.options;return e||cn(t,"get_stat_value command needs a stat id as parameter"),Wi().getStatValue(e)}),vK=rt.FromOptions({keyword:"jump",argTypes:"any",runner:async t=>{(t.args.length<1||typeof t.args[0]!="string")&&cn(t,"requires a label argument");const e=t.args[0],n=dn(),r={branchData:n.script[e],label:e,args:t.args.splice(1),currentIndex:0};return n.jumpTarget=r,await kn().saveGame(),Td}}),mK=rt.FromOptions({keyword:"run",argTypes:"any",runner:async t=>{(t.args.length<1||typeof t.args[0]!="string")&&cn(t,"run command needs a label to argument run");const e=t.args[0];return await dn().runLabelFunction(e,...t.args.slice(1))}}),gK=rt.FromOptions({keyword:"var",argTypes:[{name:"name",type:"string"},{name:"value",type:"any"}],runner:async t=>{const{name:e,value:n}=t.options;dn().addScopedVariable(e,n)}}),yK=rt.FromOptions({keyword:"return",argTypes:[{name:"value",type:"any"}],runner:async t=>{const{value:e}=t.options;return dn().setReturnValue(e),qg}}),bK=rt.FromOptions({keyword:"log",argTypes:"any",runner:async t=>{iK(t,...t.args)}}),Yg=[{name:"mode",type:"string"},{name:"audio",type:"string",optional:!0}],kK=new rt("play",Yg,async t=>{const e=t.options;e.mode==="music"?Pd(e.audio):Q7(e.audio)}),wK=new rt("pause",Yg,async t=>{const e=t.options;if(e.mode==="music"){const n=co();n.currentMusic&&X7(n.currentMusic)}else e.mode==="sound"&&e.audio?X7(e.audio):cn(t,"pause first option needs to either be in music mode, or if stopping a sound needs to have the sound name supplied as second argument.")}),jK=new rt("stop",Yg,async t=>{const e=t.options;e.mode==="music"?co().currentMusic&&co().stopMusic():e.mode==="sound"&&e.audio?Y7(e.audio):cn(t,"stop option needs to either be in music mode, or if stopping a sound needs to have the sound name supplied as second argument.")}),xK=new rt("set",[{name:"key",type:"string"},{name:"value",type:"any"}],async t=>{const e=cu();f8(e,t.options.key,t.options.value)}),_K=new rt("add",[{name:"key",type:"string"},{name:"value",type:"any"}],async t=>{const e=cu();d8(e,t.options.key,t.options.value)}),SK=new rt("set_screen",[{name:"screen",type:"string"},{name:"layer",type:"number",optional:!0}],async t=>{$i().setScreen(t.options.screen,t.options.layer)}),CK=new rt("empty_layer",[{name:"layer",type:"number"}],async t=>{$i().emptyLayer(t.options.layer)}),$K=new rt("set_button",[{name:"buttonId",type:"string"},{name:"state",type:"any"}],async t=>{const{buttonId:e,state:n}=t.options;$i().changeButton(e,n)}),OK=rt.FromOptions({keyword:"talk",argTypes:[{name:"speaker",type:"string"},{name:"pose",type:"string"},{name:"text",type:"string"}],runner:async(t,e)=>{await k8({speaker:t.options.speaker,pose:t.options.pose,text:`"${t.options.text}"`,choices:e,interactive:!0})},returnAfterPlayerAnswer:!0}),EK=()=>{const t=Nc("text",[]);return(e,n)=>{const r=t(e,n);return n.command.staticOptions={text:n.code.substring(1,n.code.length-1)},r}},AK=rt.FromOptions({keyword:"text",argTypes:[],runner:async(t,e)=>{await k8({speaker:"game",text:t.staticOptions.text,choices:e,interactive:!0})},parser:EK(),returnAfterPlayerAnswer:!0}),PK=new rt("add_item",[{name:"id",type:"string"},{name:"amount",type:"number"}],async t=>{const{id:e,amount:n}=t.options;$r().add({id:e,amount:n})}),TK=new rt("remove_item",[{name:"id",type:"string"},{name:"amount",type:"number"}],async t=>{const{id:e,amount:n}=t.options;$r().remove({id:e,amount:n})}),MK=new rt("has_item?",[{name:"id",type:"string"},{name:"amount",type:"number",optional:!0}],async t=>{const{id:e,amount:n}=t.options;return $r().hasItem(e,n)}),IK=new rt("item_amount?",[{name:"id",type:"string"}],async t=>{const{id:e}=t.options;return $r().getItemAmount(e)}),NK=new rt("enable_interaction",[{name:"tag",type:"string"}],async t=>{const e=t.options.tag;$r().enableInteraction(e)}),LK=new rt("disable_interaction",[{name:"tag",type:"string"}],async t=>{const e=t.options.tag;$r().disableInteraction(e)}),DK=new rt("start_quest",[{name:"questId",type:"string"}],async t=>{const e=t.options.questId;zr().startQuest(e)}),RK=new rt("start_objective",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;zr().startObjective(e,n)}),BK=new rt("complete_objective",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;zr().completeObjective(e,n)}),zK=new rt("complete_quest",[{name:"questId",type:"string"},{name:"ending",type:"string",optional:!0}],async t=>{const{questId:e,ending:n}=t.options;zr().completeQuest(e,n)}),VK=new rt("quest_completed?",[{name:"questId",type:"string"}],async t=>{const{questId:e}=t.options;return zr().isQuestCompleted(e)}),FK=new rt("objective_completed?",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;return zr().isObjectiveCompleted(e,n)}),qK=new rt("quest_started?",[{name:"questId",type:"string"}],async t=>{const{questId:e}=t.options;return zr().isQuestStarted(e)}),HK=new rt("objective_started?",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;return zr().isObjectiveStarted(e,n)}),WK=rt.FromOptions({keyword:"wait",argTypes:[{name:"duration",type:"number"}],runner:async t=>{await Ig(t.options.duration)}}),UK=new rt("notify",[{name:"text",type:"string"}],async t=>{const{text:e}=t.options;Ci().addNotification(e)}),JK=new rt("clear_dialog",[],async t=>{lo().clearDialog()}),GK=new rt("if",[{name:"condition",type:"boolean"}],async t=>{const e=pU(t),n=dn();if(e){const r={branchData:{branch:e},currentIndex:0};return n.addAndRunBlock(r)}},(t,e)=>{let n=t.currentLine;Nc("if",[{name:"condition",type:"string"}])(t,e);const{lines:o,currentLine:i,line:a}=t,s=e.command;let u;const c=vU(o,i+1);return c&&c.code==="else:"&&(u=t.processCommandsFunction(t.parserContext,c.branch,a),n++),s.staticOptions={success:t.processCommandsFunction(t.parserContext,a.branch,a),failure:u},n++,{newLine:n}}),KK=new rt("==","any",async t=>{t.args.length<2&&cn(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}),QK=new rt(">",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e>n}),YK=new rt("<",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e<n}),XK=new rt(">=",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e>=n}),ZK=new rt("<=",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e<=n}),eQ=new rt("!=",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e!=n}),tQ=new rt("!",[{name:"a",type:"any"}],async t=>{const{a:e}=t.options;return!e}),nQ=new rt("&&","any",async t=>{const e=t.args;return t.args.length<2&&cn(t,"requires at least two arguments"),e.reduce((n,r)=>n&&r,!0)}),rQ=new rt("||","any",async t=>(t.args.length<2&&cn(t,"requires at least two arguments"),t.args.reduce((e,n)=>e||n,!1))),oQ=new rt("?",[{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}),iQ=new rt("+","any",async t=>(t.args.length<2&&cn(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="number"?e+n:(cn(t,"requires all arguments to be numbers"),e),0))),aQ=new rt("-","any",async t=>(t.args.length<2&&cn(t,"requires at least two arguments"),t.args.slice(1).reduce((e,n)=>typeof n=="number"?e-n:(cn(t,"requires all arguments to be numbers"),e),t.args[0]))),sQ=new rt("neg",[{name:"a",type:"number"}],async t=>(t.args.length!==1&&cn(t,"requires one argument"),-t.options.a)),uQ=new rt("abs",[{name:"a",type:"number"}],async t=>(t.args.length!==1&&cn(t,"requires one argument"),Math.abs(t.options.a))),cQ=new rt("*","any",async t=>(t.args.length<2&&cn(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="number"?e*n:(cn(t,"requires all arguments to be numbers"),e),1))),lQ=new rt("/","any",async t=>{t.args.length<2&&cn(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:(cn(t,"requires all arguments to be numbers"),n),e)}),fQ=async t=>{const{prompt:e,choices:n}=t.staticOptions,r=[];for(const[,a]of n.entries()){const s=await Gg(a.prompt);r.push(s)}t.options.choiceResults=r;const o=r.map((a,s)=>{var f,l;let u=!0;return a.skillCheck&&(u=(l=(f=a.skillCheck)==null?void 0:f.allowed)!=null?l:!1),{choice:a.text,originalIndex:s,allowed:u}}).filter(a=>a.choice),i=await w8(e,o);return await vQ(t,i)};function dQ(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 hQ=(t,e)=>{let n=t.currentLine;Nc("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,c)=>(u.branch||t.parserContext.error(u.line,`Choice option doesn't have any branch to go to (${u.code})`),u=mQ(t.parserContext,u),dQ(t,u)));return o.staticOptions={prompt:t.processCommandsFunction(t.parserContext,[i],r)[0],choices:s},n++,{newLine:n}},pQ=rt.FromOptions({keyword:"choice",argTypes:[],runner:fQ,parser:hQ}),vQ=async(t,e)=>{const n=e,r=dn(),{choices:o}=t.staticOptions,i=o[n],a=t.options.choiceResults[n];let s=a.text,u;if(a.skillCheck?(s=null,m8({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 c={speaker:"player",text:s,interactive:!1};lo().addDialog(c)}if(u){const c={currentIndex:0,branchData:{branch:u}};return await r.addAndRunBlock(c)}};function mQ(t,e){return{code:`choicePrompt ${e.code}`,indentation:e.indentation,line:e.line,branch:e.branch,expression:["choicePrompt",...e.expression]}}const gQ=new rt("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=lr().getSkillCheck(n);if(s.hidden)return{text:null};const u=s.happened&&!s.succeeded,{difficultyText:c}=lU({skill:r,skillCheckId:n,value:o});return{text:`${c} ${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=rt.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};lo().addDialog(e)}});O8.onPlayerAnswered=async(t,e)=>(typeof e!="string"&&cn(t,"The player's answer should be a string"),e);const yQ=rt.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};lo().addDialog(e)}}),bQ=new rt("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"?(cn(t,"random command needs two numbers as parameters"),0):Math.floor(Math.random()*(n-e+1))+e}),kQ=new rt("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"?(cn(t,"random_float command needs two numbers as parameters"),0):Math.random()*(n-e)+e}),wQ=new rt("random_from_args",[],async t=>{const e=t.args;return!e||!e.length?(cn(t,"random_from_args command needs at least one argument"),0):e[Math.floor(Math.random()*e.length)]}),jQ=new rt("concat","any",async t=>(t.args.length<2&&cn(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="string"?`${e}${n}`:(cn(t,"requires all arguments to be strings"),e),""))),xQ=new rt("join","any",async t=>{const e=t.args[0];return t.args.length<3&&cn(t,"requires at least 3 arguments"),t.args.slice(1).reduce((n,r)=>typeof r=="string"?`${n}${e}${r}`:(cn(t,"requires all arguments to be strings"),n),"")}),_Q=rt.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}}),SQ=rt.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}}),CQ=rt.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}}),$Q=rt.FromOptions({keyword:"floor",argTypes:[{name:"value",type:"number"}],runner:async t=>{const{value:e}=t.options;return Math.floor(e)}}),OQ=rt.FromOptions({keyword:"ceil",argTypes:[{name:"value",type:"number"}],runner:async t=>{const{value:e}=t.options;return Math.ceil(e)}}),EQ=rt.FromOptions({keyword:"round",argTypes:[{name:"value",type:"number"}],runner:async t=>{const{value:e}=t.options;return Math.round(e)}}),AQ=rt.FromOptions({keyword:"sqrt",argTypes:[{name:"value",type:"number"}],runner:async t=>{const{value:e}=t.options;return Math.sqrt(e)}}),PQ=rt.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 TQ(t){t.addCommand(pQ),t.addCommand(gQ),t.addCommand(GK),t.addCommand(dK),t.addCommand(hK),t.addCommand(pK),t.addCommand(JK),t.addCommand(UK),t.addCommand(wK),t.addCommand(kK),t.addCommand(jK),t.addCommand($K),t.addCommand(SK),t.addCommand(CK),t.addCommand(WK),t.addCommand(KK),t.addCommand(QK),t.addCommand(YK),t.addCommand(XK),t.addCommand(ZK),t.addCommand(eQ),t.addCommand(tQ),t.addCommand(nQ),t.addCommand(rQ),t.addCommand(oQ),t.addCommand(iQ),t.addCommand(aQ),t.addCommand(cQ),t.addCommand(lQ),t.addCommand(sQ),t.addCommand(uQ),t.addCommand(_K),t.addCommand(xK),t.addCommand(AK),t.addCommand(OK),t.addCommand(vK),t.addCommand(mK),t.addCommand(gK),t.addCommand(yK),t.addCommand(bK),t.addCommand(DK),t.addCommand(RK),t.addCommand(BK),t.addCommand(zK),t.addCommand(qK),t.addCommand(HK),t.addCommand(VK),t.addCommand(FK),t.addCommand(PK),t.addCommand(TK),t.addCommand(NK),t.addCommand(LK),t.addCommand(MK),t.addCommand(IK),t.addCommand(aK),t.addCommand(sK),t.addCommand(uK),t.addCommand(fK),t.addCommand(cK),t.addCommand(lK),t.addCommand(O8),t.addCommand(yQ),t.addCommand(bQ),t.addCommand(kQ),t.addCommand(wQ),t.addCommand(jQ),t.addCommand(xQ),t.addCommand(_Q),t.addCommand(SQ),t.addCommand(CQ),t.addCommand($Q),t.addCommand(EQ),t.addCommand(OQ),t.addCommand(AQ),t.addCommand(PQ)}let Lc;ar.callHook("onPageLoaded");async function MQ(t,e){const n=await Hg(t.configPath);eW(JSON.parse(n)),t.baseAssetsPath&&(It().baseAssetsPath=t.baseAssetsPath),Lc=j.createApp(oK,{config:t,options:e});const r=_W();if(Lc.use(r),kn().setOptions(e),Lc.use(N8,{breakpoints:{s:0,m:800,l:1200}}),TQ(ar),l0.setupDebugger(e.debug),console.log("%c Narrat game engine \u2013 [VI]{version} - {date}[/VI]","background: #222; color: #bada55"),ar.callHook("onNarratSetup"),Lc.mount("#game-holder"),e.debug){const o={app:Lc,vm:ar,jump:i=>{dn().runLabel(i)}};window.narrat=o}}class IQ{onPageLoaded(){}onNarratSetup(){}onAppMounted(){}onAssetsLoaded(){}onGameSetup(){}onGameStart(){}onGameMounted(){}onGameDismounted(){}}function NQ(t){ar.addPlugin(t)}function LQ(t){ar.addCommand(t)}sn.CommandPlugin=rt,sn.NarratPlugin=IQ,sn.addCommand=LQ,sn.aspectRatioFit=x8,sn.generateParser=Nc,sn.getConfig=It,sn.registerPlugin=NQ,sn.startApp=MQ,Object.defineProperties(sn,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
185
185
|
//# sourceMappingURL=narrat.umd.js.map
|