narrat 2.0.0-test-1 → 2.0.0-test-2

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 CHANGED
@@ -4,7 +4,7 @@ var __publicField = (obj, key, value) => {
4
4
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
  return value;
6
6
  };
7
- import { ref, reactive, readonly, defineComponent, openBlock, createBlock, Transition, withCtx, createElementVNode, normalizeClass, renderSlot, createTextVNode, getCurrentInstance, inject, effectScope, markRaw, watch, isRef, isReactive, toRaw, onUnmounted, nextTick, toRefs, computed, resolveComponent, createElementBlock, createCommentVNode, withDirectives, vModelText, Fragment, renderList, normalizeStyle, toDisplayString, TransitionGroup, createVNode, unref, createApp } from "vue";
7
+ import { ref, reactive, readonly, defineComponent, openBlock, createBlock, Transition, withCtx, createElementVNode, normalizeClass, renderSlot, createTextVNode, getCurrentInstance, inject, effectScope, markRaw, watch, isRef, isReactive, toRaw, onUnmounted, nextTick, toRefs, computed, resolveComponent, createElementBlock, createCommentVNode, withDirectives, vModelText, Fragment, renderList, normalizeStyle, toDisplayString, TransitionGroup, createVNode, unref, withDefaults, defineProps, createApp } from "vue";
8
8
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
9
9
  function commonjsRequire(path) {
10
10
  throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
@@ -187,7 +187,7 @@ return query;
187
187
  `)();const zG=I.defineComponent({data(){return{passed:!1}},props:{options:{type:Object,required:!0},active:Boolean},mounted(){document.addEventListener("keydown",t=>{if(this.canInteract){let e=-1;if(t.key===" ")this.choices?e=0:this.chooseOption(0);else switch(t.key){case" ":e=0;break;case"1":e=0;break;case"2":e=1;break;case"3":e=2;break;case"4":e=3;break;case"5":e=4;break;case"6":e=5;break;case"7":e=6;break;case"8":e=7;break}e!==-1&&this.choices&&e<this.choices.length&&this.chooseOption(this.choices[e])}})},computed:{...So(Pn,["paused"]),preText(){return this.options.title?" &nbsp;\u2013&nbsp; ":""},style(){return rh(this.options.styleId)},dialogBoxStyle(){const t=rh(this.options.styleId),e={opacity:this.options.old?"0.7":"1"};return this.options.title||(e.marginTop="-20px"),{...t.boxCss,...e}},titleStyle(){const t=rh(this.options.styleId);return{color:t.color,...t.nameCss}},textStyle(){return rh(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:{chooseOption(t){this.passed=!0;let e;typeof t=="object"?e=t.originalIndex:e=t,Pn().playerAnswered(e)},dialogStyle(t){const e={};return t.allowed||(e.pointerEvents="none",e.textDecoration="line-through"),e},dialogClass(t){if(!t.allowed)return"strike-anim"}}}),VG={class:"dialog-content"},qG=["innerHTML"],FG=["innerHTML"],HG=["innerHTML"],WG={key:1,class:"dialog-choices"},UG=["onClick","innerHTML"],JG={key:2,class:"buttons-container"};function GG(t,e,n,r,i,o){return I.openBlock(),I.createElementBlock("div",{class:"dialog-box w-full override",style:I.normalizeStyle(t.dialogBoxStyle)},[I.createElementVNode("div",VG,[t.options.title?(I.openBlock(),I.createElementBlock("span",{key:0,class:"dialog-title override",style:I.normalizeStyle(t.titleStyle),innerHTML:t.options.title},null,12,qG)):I.createCommentVNode("",!0),I.createElementVNode("span",{class:"dialog-text dialog-separator override",style:I.normalizeStyle(t.textStyle),innerHTML:t.preText},null,12,FG),I.createElementVNode("span",{class:"dialog-text override",style:I.normalizeStyle(t.textStyle),innerHTML:t.options.text},null,12,HG),t.canInteract&&t.choices?(I.openBlock(),I.createElementBlock("div",WG,[(I.openBlock(!0),I.createElementBlock(I.Fragment,null,I.renderList(t.choices,(a,s)=>(I.openBlock(),I.createElementBlock("p",{key:s,style:I.normalizeStyle(t.dialogStyle(a)),class:I.normalizeClass([t.dialogClass(a),"dialog-choice override"]),onClick:u=>t.chooseOption(a),innerHTML:`${s+1}. \u2013\xA0 ${a.choice}`},null,14,UG))),128))])):t.canInteract?(I.openBlock(),I.createElementBlock("div",JG,[I.createElementVNode("div",{onClick:e[0]||(e[0]=a=>t.chooseOption(0)),class:"interact-button button override"}," Continue ")])):I.createCommentVNode("",!0)])],4)}var KG=Ur(zG,[["render",GG]]),uY=(()=>`.dialog-container{flex-shrink:2;min-height:100%;width:100%;background-color:(var(--bg-color));box-sizing:border-box;display:flex;flex-direction:column;justify-content:flex-end;align-items:center;overflow-x:hidden}.dialog{overflow-y:auto;overflow-x:hidden;position:relative;-ms-overflow-style:none;scrollbar-width:none}.dialog::-webkit-scrollbar{display:none}.dialog *{overflow-anchor:none}.anchor{overflow-anchor:auto;height:1px}
188
188
  `)();const QG=I.createElementVNode("div",{class:"anchor"},null,-1),YG=I.defineComponent({__name:"game-dialog",props:{layoutMode:String,inGame:Boolean},setup(t){const e=t,n=kt(),r=I.computed(()=>n.stack),i=$o(),o=I.computed(()=>i.dialog),a=I.computed(()=>e.layoutMode==="vertical"?{}:{paddingBottom:`${Ft().layout.dialogBottomPadding}px`}),s=I.computed(()=>{if(o.value.length>0)return o.value[o.value.length-1]}),u=I.computed(()=>{if(s.value)return tM(s.value.speaker,s.value.pose)}),l=I.computed(()=>Ft().layout.minTextWidth),f=I.computed(()=>{let h;const p="100%";return e.layoutMode,{width:e.layoutMode==="horizontal"?`${l.value}px`:"100%",height:p,transform:h,transformOrigin:"right"}});function c(h,p){let m=nh(h.speaker).name;return p>=1&&o.value[p-1].speaker===h.speaker&&(m=void 0),h.choices&&h.choices.forEach(g=>{g.choice=w0(g.choice)}),{title:m!=null?m:"",text:h.text,styleId:h.speaker,choices:h.choices,old:p<o.value.length-1,interactive:h.interactive}}function d(h){return h===i.dialog.length-1&&r.value.length>0}return(h,p)=>(I.openBlock(),I.createElementBlock(I.Fragment,null,[I.createVNode(I.Transition,{name:"fade"},{default:I.withCtx(()=>[I.unref(u)?(I.openBlock(),I.createBlock(BG,{key:0,pictureUrl:I.unref(u)},null,8,["pictureUrl"])):I.createCommentVNode("",!0)]),_:1}),t.inGame?(I.openBlock(),I.createElementBlock("div",{key:0,class:"dialog override",ref_key:"dialog",ref:o,style:I.normalizeStyle(I.unref(f))},[I.createVNode(I.TransitionGroup,{name:"list",tag:"div",class:"dialog-container w-full override",style:I.normalizeStyle(I.unref(a))},{default:I.withCtx(()=>[(I.openBlock(!0),I.createElementBlock(I.Fragment,null,I.renderList(I.unref(o),(v,m)=>(I.openBlock(),I.createBlock(KG,{key:v.id,options:c(v,m),active:d(m)},null,8,["options","active"]))),128))]),_:1},8,["style"]),QG],4)):I.createCommentVNode("",!0)],64))}});var lY=(()=>`.quests-modal{width:100%;min-height:50%}.quest-header{display:flex;flex-direction:row;align-items:center}.quest-title{font-size:1.5rem;font-weight:700;margin-bottom:.5rem}.quest-completed{color:var(--completed-quest-title-color)}.quest-in-progress{color:var(--quest-title-color)}.quest-state{font-size:1.25rem;font-weight:700;margin-bottom:.5rem}.quest-description{font-size:1.1rem;text-align:justify;font-style:italic;margin-bottom:.5rem}.quest-objectives-container{margin-left:10px}.quest-objective-completed{color:var(--objective-completed-color);text-decoration:line-through}.quest-objective-in-progress{color:var(--objective-in-progress-color)}.quest-objective-description{font-size:1rem;margin-bottom:.5rem}
189
189
  `)();const XG=I.defineComponent({setup(){const t=Hr();return{quests:I.computed(()=>t.quests)}},computed:{questsToDisplay(){return DE(this.quests,t=>t.state!=="hidden")}},props:{close:Function},methods:{getQuestData(t){return Xd(t)},getObjectiveData(t,e){return f0(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 DE(t.objectives,e=>e.state!=="hidden")}},components:{Modal:mu}}),ZG=I.createElementVNode("h3",{class:"title"},"Quests",-1),eK={key:0,class:"quests-container"},tK={class:"quest-title"},nK={class:"quest-description"},rK={key:0,class:"quest-objectives-container list-disc"},iK={key:1,class:"menu-container"},oK=[I.createElementVNode("h2",{class:"title"},"There are no quests!",-1)];function aK(t,e,n,r,i,o){const a=I.resolveComponent("modal");return I.openBlock(),I.createBlock(a,{class:"quests",close:t.close,containerCssClass:"quests-modal"},{header:I.withCtx(()=>[ZG]),body:I.withCtx(()=>[Object.keys(t.questsToDisplay).length>0?(I.openBlock(),I.createElementBlock("div",eK,[(I.openBlock(!0),I.createElementBlock(I.Fragment,null,I.renderList(t.questsToDisplay,s=>(I.openBlock(),I.createElementBlock("div",{class:"quest-display",key:s.id},[I.createElementVNode("div",{class:I.normalizeClass(["quest-header",s.state==="completed"?"quest-completed":"quest-in-progress"])},[I.createElementVNode("h3",tK,I.toDisplayString(t.getQuestData(s.id).title)+" "+I.toDisplayString(t.getDisplayTextForQuestState(s)),1)],2),I.createElementVNode("p",nK,I.toDisplayString(t.getQuestDescription(s)),1),s.state!=="completed"?(I.openBlock(),I.createElementBlock("ul",rK,[(I.openBlock(!0),I.createElementBlock(I.Fragment,null,I.renderList(t.getAvailableObjectives(s),u=>(I.openBlock(),I.createElementBlock("li",{class:"quest-objective-display",key:u.id},[I.createElementVNode("p",{class:I.normalizeClass(["quest-objective-description",u.state==="completed"?"quest-objective-completed":"quest-objctive-in-progress"])},I.toDisplayString(t.getObjectiveData(s.id,u.id).description),3)]))),128))])):I.createCommentVNode("",!0)]))),128))])):(I.openBlock(),I.createElementBlock("div",iK,oK))]),_:1},8,["close"])}var sK=Ur(XG,[["render",aK]]),fY=(()=>`.menu-content{text-align:center}.menu-toggle-button{margin:0;padding:2px;border-radius:5px}.menu-toggle-button:not(:last-child){margin-right:10px}.menu-modal{width:500px}
190
- `)();const uK=I.defineComponent({inheritAttrs:!0,components:{},setup(){return withDefaults({},defineProps({}))},data(){return{activeMenu:!1}},mounted(){document.addEventListener("keydown",t=>{t.key==="Escape"&&this.toggleMenu()}),sr.callHook("onGameMounted")},unmounted(){sr.callHook("onGameUnmounted")},methods:{openMenu(){Pn().openModal("menu")},openSkills(){Pn().openModal("skills")},openInventory(){Pn().openModal("inventory")},openQuests(){Pn().openModal("quests")},closeMenu(){Pn().closeModal()},toggleMenu(){Pn().toggleMenu()}},computed:{showSkills(){return Object.entries(Ft().skills).length>0},showInventory(){return Object.entries(Ft().items).length>0},showQuests(){return Object.entries(Ft().quests).length>0}}}),lK={class:"menu-container"};function cK(t,e,n,r,i,o){return I.openBlock(),I.createElementBlock("div",lK,[I.createElementVNode("button",{class:"button menu-toggle-button",id:"menu-button",onClick:e[0]||(e[0]=(...a)=>t.openMenu&&t.openMenu(...a))}," Menu "),t.showSkills?(I.openBlock(),I.createElementBlock("button",{key:0,class:"button menu-toggle-button",id:"skills-menu-button",onClick:e[1]||(e[1]=(...a)=>t.openSkills&&t.openSkills(...a))}," Skills ")):I.createCommentVNode("",!0),t.showInventory?(I.openBlock(),I.createElementBlock("button",{key:1,class:"button menu-toggle-button",id:"inventory-menu-button",onClick:e[2]||(e[2]=(...a)=>t.openInventory&&t.openInventory(...a))}," Items ")):I.createCommentVNode("",!0),t.showQuests?(I.openBlock(),I.createElementBlock("button",{key:2,class:"button menu-toggle-button",id:"quests-menu-button",onClick:e[3]||(e[3]=(...a)=>t.openQuests&&t.openQuests(...a))}," Quests ")):I.createCommentVNode("",!0)])}var fK=Ur(uK,[["render",cK]]),dY=(()=>`#app{background-color:var(--bg-color);width:100%;height:100%;position:absolute;display:flex;flex-direction:row;align-items:center;justify-content:center;color:var(--text-color);box-sizing:border-box;overflow:hidden;transform-origin:center center}.game{background-color:var(--bg-color);position:relative;display:flex;flex-direction:row;align-items:center;justify-content:space-between;width:100%;height:100%;box-sizing:border-box;overflow:hidden}.interact-button{height:50px;border:1px solid black;font-weight:700;font-size:20px;text-align:center;flex-grow:2;display:flex;align-items:center;justify-content:center;box-sizing:border-box}.interact-button:not(:last-child){margin-right:10px}.background{margin:0}#background-canvas{height:100%}.menu-toggle{position:fixed;bottom:0px;right:15%;z-index:2}#game-title-container{margin-bottom:50px}#game-title-text{text-align:center;font-size:50px}.menu-button{font-size:25px}#game-header{position:relative;top:100px}
190
+ `)();const uK=I.defineComponent({inheritAttrs:!0,components:{},setup(){return I.withDefaults({},I.defineProps({}))},data(){return{activeMenu:!1}},mounted(){document.addEventListener("keydown",t=>{t.key==="Escape"&&this.toggleMenu()}),sr.callHook("onGameMounted")},unmounted(){sr.callHook("onGameUnmounted")},methods:{openMenu(){Pn().openModal("menu")},openSkills(){Pn().openModal("skills")},openInventory(){Pn().openModal("inventory")},openQuests(){Pn().openModal("quests")},closeMenu(){Pn().closeModal()},toggleMenu(){Pn().toggleMenu()}},computed:{showSkills(){return Object.entries(Ft().skills).length>0},showInventory(){return Object.entries(Ft().items).length>0},showQuests(){return Object.entries(Ft().quests).length>0}}}),lK={class:"menu-container"};function cK(t,e,n,r,i,o){return I.openBlock(),I.createElementBlock("div",lK,[I.createElementVNode("button",{class:"button menu-toggle-button",id:"menu-button",onClick:e[0]||(e[0]=(...a)=>t.openMenu&&t.openMenu(...a))}," Menu "),t.showSkills?(I.openBlock(),I.createElementBlock("button",{key:0,class:"button menu-toggle-button",id:"skills-menu-button",onClick:e[1]||(e[1]=(...a)=>t.openSkills&&t.openSkills(...a))}," Skills ")):I.createCommentVNode("",!0),t.showInventory?(I.openBlock(),I.createElementBlock("button",{key:1,class:"button menu-toggle-button",id:"inventory-menu-button",onClick:e[2]||(e[2]=(...a)=>t.openInventory&&t.openInventory(...a))}," Items ")):I.createCommentVNode("",!0),t.showQuests?(I.openBlock(),I.createElementBlock("button",{key:2,class:"button menu-toggle-button",id:"quests-menu-button",onClick:e[3]||(e[3]=(...a)=>t.openQuests&&t.openQuests(...a))}," Quests ")):I.createCommentVNode("",!0)])}var fK=Ur(uK,[["render",cK]]),dY=(()=>`#app{background-color:var(--bg-color);width:100%;height:100%;position:absolute;display:flex;flex-direction:row;align-items:center;justify-content:center;color:var(--text-color);box-sizing:border-box;overflow:hidden;transform-origin:center center}.game{background-color:var(--bg-color);position:relative;display:flex;flex-direction:row;align-items:center;justify-content:space-between;width:100%;height:100%;box-sizing:border-box;overflow:hidden}.interact-button{height:50px;border:1px solid black;font-weight:700;font-size:20px;text-align:center;flex-grow:2;display:flex;align-items:center;justify-content:center;box-sizing:border-box}.interact-button:not(:last-child){margin-right:10px}.background{margin:0}#background-canvas{height:100%}.menu-toggle{position:fixed;bottom:0px;right:15%;z-index:2}#game-title-container{margin-bottom:50px}#game-title-text{text-align:center;font-size:50px}.menu-button{font-size:25px}#game-header{position:relative;top:100px}
191
191
  `)();const dK=I.defineComponent({setup(){const t=$o(),e=kt(),n=Pn();return{dialog:I.computed(()=>t.dialog),stack:I.computed(()=>e.stack),modal:I.computed(()=>n.modal),flowState:I.computed(()=>n.flowState)}},$refs:{dialogContainer:HTMLInputElement},inject:["mq"],components:{DebugMenu:TJ,LoadingBar:GJ,NotificationToast:YJ,Hud:FJ,MainMenu:oG,Skills:kG,InventoryUi:NG,GameDialog:YG,QuestsUi:sK,MenuButtons:fK},data(){return{lineTitle:"title",lineText:"hello",gameLoaded:!1,loadingStep:"Loading",loadingPercentage:.1,hasSave:!1}},props:{config:Object,options:Object},async mounted(){sr.callHook("onAppMounted"),this.loadingStep="Characters";const t=await g0("data/characters.json");await XJ(JSON.parse(t)),this.loadingPercentage=.2,this.loadingStep="Data",this.loadingPercentage=.3,this.loadingStep="Images",await ZJ(Ft()),this.loadingPercentage=.7,this.loadingStep="Audio",await wU(Ft()),sr.callHook("onAssetsLoaded"),this.loadingPercentage=.95,this.loadingStep="Starting...",await this.setupMachine(),sr.callHook("onGameSetup"),this.loadingPercentage=.1,this.gameLoaded=!0,this.getSaveFile()&&(this.hasSave=!0),window.addEventListener("resize",sM(()=>{this.updateScreenSize()},100,{maxWait:200})),setTimeout(()=>{this.updateScreenSize()},50)},watch:{dialogLength(t,e){if(this.$refs.dialog){const n=this.$refs.dialog;n.scrollTop=n.scrollHeight+1e8}}},computed:{...So(Ul,["screenWidth","screenHeight","canvasWidth","canvasHeight","topOffset","leftOffset","layoutMode"]),...So(kt,["currentLine"]),dialogLength(){return this.dialog.length},lastDialog(){if(this.dialog.length>0)return this.dialog[this.dialog.length-1]},picture(){if(this.lastDialog)return tM(this.lastDialog.speaker,this.lastDialog.pose)},backgroundStyle(){let t;return this.layoutMode==="vertical"&&(t=`${100-Ft().layout.mobileDialogHeightPercentage}%`),{backgroundColor:"red",height:t}},layoutWidth(){return Ft().layout.backgrounds.width},gameTitle(){return Ft().gameTitle},inGame(){return this.flowState==="playing"},layoutHeight(){return Ft().layout.backgrounds.height},backgroundSize(){return{width:this.canvasWidth,height:this.canvasHeight,top:this.topOffset,left:this.leftOffset}},dialogWidth(){const t=Ft().layout.minTextWidth;return this.mq,t},dialogStyle(){let t;const e="100%";return this.layoutMode,{width:this.layoutMode==="horizontal"?`${this.dialogWidth}px`:"100%",height:e,transform:t,transformOrigin:"right"}},gameWidth(){const t=Ft();return this.layoutMode==="vertical"?window.innerWidth:t.layout.backgrounds.width+t.layout.minTextWidth},gameHeight(){const t=Ft();return this.layoutMode==="vertical"?window.innerHeight:t.layout.backgrounds.height},appStyle(){const t=Ft();if(this.screenWidth&&this.screenHeight&&t&&this.layoutMode==="horizontal"){const e=nM(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=Ft(),e=t.layout.minTextWidth+t.layout.backgrounds.width;return this.screenWidth/e},dialogContainerStyle(){return this.layoutMode==="vertical"?{}:{paddingBottom:`${Ft().layout.dialogBottomPadding}px`}}},methods:{async setupMachine(){const t=Ft().scripts;return Pn().setup(t,Ft())},getSaveFile(){return localStorage.getItem(_E)},async startGame(){Fl("onPressStart"),await Pn().startGame()},async loadGame(){Fl("onPressStart"),Pn().loadGame(this.getSaveFile())},isDialogActive(t){return t===this.dialog.length-1&&this.stack.length>0},nextLine(){kt().nextLine()},updateScreenSize(){Ul().updateScreenSize(window.innerWidth,window.innerHeight,this.layoutMode==="horizontal"?Ft().layout.minTextWidth*this.screenRatio:0)},closeModal(){Pn().closeModal()},getDialogBoxOptions(t,e){let r=nh(t.speaker).name;return e>=1&&this.dialog[e-1].speaker===t.speaker&&(r=void 0),t.choices&&t.choices.forEach(i=>{i.choice=w0(i.choice)}),{title:r!=null?r:"",text:t.text,styleId:t.speaker,choices:t.choices,old:e<this.dialog.length-1,interactive:t.interactive}}}}),hK=["width","height"],pK={key:2,id:"game-menu",style:{height:"100%",padding:"20px"}},vK={id:"game-header"},mK={id:"game-title-container"},gK={id:"game-title-text"},yK={class:"flex flex-col"},bK={key:3};function kK(t,e,n,r,i,o){const a=I.resolveComponent("Hud"),s=I.resolveComponent("MenuButtons"),u=I.resolveComponent("Skills"),l=I.resolveComponent("InventoryUi"),f=I.resolveComponent("QuestsUi"),c=I.resolveComponent("MainMenu"),d=I.resolveComponent("GameDialog"),h=I.resolveComponent("LoadingBar"),p=I.resolveComponent("DebugMenu"),v=I.resolveComponent("NotificationToast");return I.openBlock(),I.createElementBlock("div",{id:"app",style:I.normalizeStyle(t.appStyle)},[t.inGame?(I.openBlock(),I.createBlock(a,{key:0})):I.createCommentVNode("",!0),t.inGame?(I.openBlock(),I.createElementBlock("div",{key:1,class:"game",style:I.normalizeStyle(t.gameStyle)},[I.createVNode(s,{class:"menu-toggle"}),t.modal==="skills"?(I.openBlock(),I.createBlock(u,{key:0,close:t.closeModal},null,8,["close"])):I.createCommentVNode("",!0),t.modal==="inventory"?(I.openBlock(),I.createBlock(l,{key:1,close:t.closeModal},null,8,["close"])):I.createCommentVNode("",!0),t.modal==="quests"?(I.openBlock(),I.createBlock(f,{key:2,close:t.closeModal},null,8,["close"])):I.createCommentVNode("",!0),t.modal==="menu"?(I.openBlock(),I.createBlock(c,{key:3,close:t.closeModal},null,8,["close"])):I.createCommentVNode("",!0),t.inGame?(I.openBlock(),I.createElementBlock("div",{key:4,class:"background",style:I.normalizeStyle(t.backgroundStyle)},[I.createElementVNode("canvas",{width:t.layoutWidth,height:t.layoutHeight,id:"background-canvas",class:"narrat-canvas"},null,8,hK)],4)):I.createCommentVNode("",!0),I.createVNode(d,{inGame:t.inGame,layoutMode:t.layoutMode},null,8,["inGame","layoutMode"])],4)):t.gameLoaded?(I.openBlock(),I.createElementBlock("div",pK,[I.createElementVNode("div",vK,[I.createElementVNode("div",mK,[I.createElementVNode("h1",gK,I.toDisplayString(t.gameTitle),1)]),I.createElementVNode("div",yK,[I.createElementVNode("button",{class:"button menu-button main-menu-button larg start-button override",onClick:e[0]||(e[0]=(...m)=>t.startGame&&t.startGame(...m))}," Start Game "),t.hasSave?(I.openBlock(),I.createElementBlock("button",{key:0,class:"button menu-button main-menu-button large continue-button override",onClick:e[1]||(e[1]=(...m)=>t.loadGame&&t.loadGame(...m))}," Continue Game ")):I.createCommentVNode("",!0)])])])):(I.openBlock(),I.createElementBlock("div",bK,[I.createVNode(h,{percentage:t.loadingPercentage,step:t.loadingStep},null,8,["percentage","step"])])),t.options.debug?(I.openBlock(),I.createBlock(p,{key:4})):I.createCommentVNode("",!0),I.createVNode(v)],4)}var wK=Ur(dK,[["render",kK]]);let Gi,Oo;const $a={x:0,y:0};function xK(){document.addEventListener("mousemove",t=>{$a.x=t.clientX,$a.y=t.clientY}),document.addEventListener("click",sM(jK,100,{maxWait:200})),uM()}function uM(){const t=Ko();if(Pn().playing){if(!Gi)Gi=document.querySelector("#background-canvas"),Gi&&!Oo&&(Oo=Gi.getContext("2d"));else if(Gi&&Oo){Oo.fillStyle="white",Oo.fillRect(0,0,Gi.width,Gi.height);const n=t.currentScreen,r=Ft().screens[n],i=r.background;Oo.drawImage(_0[i],0,0);let o=!1;const a=rM($a.x,$a.y,Gi);if(r.buttons){for(const s of r.buttons)if(t.buttons[s].enabled){const u=Ft().buttons[s],l=_0[u.background];Oo.drawImage(l,u.position.left,u.position.top),iM(a.x,a.y,1,1,u.position.left,u.position.top,u.position.width,u.position.height)&&(o=!0)}}o?document.body.style.cursor="pointer":document.body.style.cursor="default",Oo.fillStyle="black",Oo.textAlign="left"}}else Gi=void 0,Oo=void 0;window.requestAnimationFrame(uM)}function jK(t){const e=Ko(),n=kt();if(!Gi)return;$a.x=t.clientX,$a.y=t.clientY;const r=rM($a.x,$a.y,Gi),i=e.currentScreen,o=Ft().screens[i];if(o.buttons){for(const a of o.buttons)if(e.buttons[a].enabled){const s=Ft().buttons[a];if(iM(r.x,r.y,1,1,s.position.left,s.position.top,s.position.width,s.position.height)){const u=s.action,l={branchData:n.script[u],currentIndex:0,label:u};n.setStack(l),n.runLine()}}}}function rr(t,e){console.error("Runtime error ========================="),console.error("Args: ",t.args),console.error("Options: ",t.options),Ar(`Runtime error at ${t.fileName}:${t.line} (${t.commandType}) ${t.code}. -
192
192
  <br />
193
193
  Error: ${e}`),console.error("============================")}class $t{constructor(e,n,r,i){Ao(this,"keyword");Ao(this,"runner");Ao(this,"argTypes");Ao(this,"parser");Ao(this,"onPlayerAnswered");this.keyword=e,this.runner=r,this.argTypes=n,i?this.parser=i:this.parser=Jl(this.keyword,this.argTypes)}}function Jl(t,e){let n=[];if(e!=="any"){n=[e.length];const r=e.reduce((i,o)=>o.optional?i+1:i,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,i)=>{const o={newLine:r.currentLine+1},a=i.command.args;return e!=="any"&&!n.includes(a.length)?(console.log("Error details"),console.log(i.command),console.log(a),r.parserContext.error(r.line.line,`Command ${t}: Expected ${n.join(" or ")} arguments but got ${a.length}`),o):(i.command.commandType=t,e!=="any"&&i.command.args.forEach((s,u)=>{const l=e[u];KE(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 _K=new $t("add_level",[{name:"skillKey",type:"string"},{name:"amount",type:"number"}],async t=>{const{skillKey:e,amount:n}=t.options;return(!e||!n)&&rr(t,"add_level command needs a skill id and a value as parameters"),Er().incrementSkill(e,n),kt().nextLine()}),SK=new $t("add_xp",[{name:"xpKey",type:"string"},{name:"xpToAdd",type:"number"}],async t=>{const{xpKey:e,xpToAdd:n}=t.options;return(!e||!n)&&rr(t,"add_xp command needs a skill id and a value as parameters"),Er().addXp(e,n),kt().nextLine()}),CK=new $t("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:i}=t.options;return GE({id:e,skill:n,value:r,hideAfterRoll:i})}),$K=new $t("add_stat",[{name:"statKey",type:"string"},{name:"amountToAdd",type:"number"}],async t=>{const{statKey:e,amountToAdd:n}=t.options;return(!e||!n)&&rr(t,"add_stat command needs a stat id and a value as parameters"),Go().addStat(e,n),kt().nextLine()}),OK=new $t("set_stat",[{name:"statKey",type:"string"},{name:"value",type:"number"}],async t=>{const{statKey:e,value:n}=t.options;return(!e||!n)&&rr(t,"set_stat command needs a stat id and a value as parameters"),Go().setStat(e,n),kt().nextLine()}),AK=new $t("get_stat_value",[{name:"statKey",type:"string"}],async t=>{const{statKey:e}=t.options;return e||rr(t,"get_stat_value command needs a stat id as parameter"),Go().getStatValue(e)}),EK=new $t("jump","any",async t=>{(t.args.length<1||typeof t.args[0]!="string")&&rr(t,"requires a label argument");const e=t.args[0],n=kt(),r={branchData:n.script[e],label:e,args:t.args.splice(1),currentIndex:0};n.setStack(r),await Pn().saveGame(),await n.runLine()}),MK=new $t("run_label","any",async t=>{(t.args.length<1||typeof t.args[0]!="string")&&rr(t,"run_label command needs a label to argument run");const e=t.args[0];return await kt().runLabelFunction(e,...t.args.slice(1))}),PK=new $t("var",[{name:"name",type:"string"},{name:"value",type:"any"}],async t=>{const{name:e,value:n}=t.options;return kt().addScopedVariable(e,n),kt().nextLine()}),TK=new $t("return",[{name:"value",type:"any"}],async t=>{const{value:e}=t.options;return kt().setReturnValue(e),kt().nextLine()}),S0=[{name:"mode",type:"string"},{name:"audio",type:"string",optional:!0}],IK=new $t("play",S0,async t=>{const e=t.options;e.mode==="music"?eh(e.audio):TE(e.audio),kt().nextLine()}),NK=new $t("pause",S0,async t=>{const e=t.options;if(e.mode==="music"){const n=Jo();n.currentMusic&&IE(n.currentMusic)}else e.mode==="sound"&&e.audio?IE(e.audio):rr(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.");return kt().nextLine()}),LK=new $t("stop",S0,async t=>{const e=t.options;if(e.mode==="music"){const n=Jo();n.currentMusic&&m0(n.currentMusic)}else e.mode==="sound"&&e.audio?m0(e.audio):rr(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.");return kt().nextLine()}),DK=new $t("set",[{name:"key",type:"string"},{name:"value",type:"any"}],async t=>{const e=hu();return RE(e,t.options.key,t.options.value),kt().nextLine()}),RK=new $t("add",[{name:"key",type:"string"},{name:"value",type:"any"}],async t=>{const e=hu();return BE(e,t.options.key,t.options.value),kt().nextLine()}),BK=new $t("set_screen",[{name:"screen",type:"string"}],t=>(Ko().setScreen(t.options.screen),kt().nextLine())),zK=new $t("set_button",[{name:"buttonId",type:"string"},{name:"enabled",type:"boolean"}],async t=>{const{buttonId:e,enabled:n}=t.options;return Ko().changeButton(e,n),kt().nextLine()}),VK=new $t("talk",[{name:"speaker",type:"string"},{name:"pose",type:"string"},{name:"text",type:"string"}],async(t,e)=>{await YE({speaker:t.options.speaker,pose:t.options.pose,text:`"${t.options.text}"`,choices:e,interactive:!0})}),qK=()=>{const t=Jl("text",[]);return(e,n)=>{const r=t(e,n);return n.command.staticOptions={text:n.code},r}},lM=new $t("text",[],async(t,e)=>{await YE({speaker:"game",text:t.staticOptions.text,choices:e,interactive:!0})},qK());console.log(lM);const FK=new $t("add_item",[{name:"id",type:"string"},{name:"amount",type:"number"}],async t=>{const{id:e,amount:n}=t.options;return Or().add({id:e,amount:n}),kt().nextLine()}),HK=new $t("remove_item",[{name:"id",type:"string"},{name:"amount",type:"number"}],async t=>{const{id:e,amount:n}=t.options;return Or().remove({id:e,amount:n}),kt().nextLine()}),WK=new $t("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)}),UK=new $t("item_amount?",[{name:"id",type:"string"}],async t=>{const{id:e}=t.options;return Or().getItemAmount(e)}),JK=new $t("enable_interaction",[{name:"tag",type:"string"}],async t=>{const e=t.options.tag;return Or().enableInteraction(e),kt().nextLine()}),GK=new $t("disable_interaction",[{name:"tag",type:"string"}],async t=>{const e=t.options.tag;return Or().disableInteraction(e),kt().nextLine()}),KK=new $t("start_quest",[{name:"questId",type:"string"}],async t=>{const e=t.options.questId;return Hr().startQuest(e),kt().nextLine()}),QK=new $t("start_objective",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;return Hr().startObjective(e,n),kt().nextLine()}),YK=new $t("complete_objective",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;return Hr().completeObjective(e,n),kt().nextLine()}),XK=new $t("complete_quest",[{name:"questId",type:"string"},{name:"ending",type:"string",optional:!0}],async t=>{const{questId:e,ending:n}=t.options;return Hr().completeQuest(e,n),kt().nextLine()}),ZK=new $t("quest_completed?",[{name:"questId",type:"string"}],async t=>{const{questId:e}=t.options;return Hr().isQuestCompleted(e)}),eQ=new $t("objective_completed?",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;return Hr().isObjectiveCompleted(e,n)}),tQ=new $t("quest_started?",[{name:"questId",type:"string"}],async t=>{const{questId:e}=t.options;return Hr().isQuestStarted(e)}),nQ=new $t("objective_started?",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;return Hr().isObjectiveStarted(e,n)}),rQ=new $t("wait",[{name:"duration",type:"number"}],async t=>(await d0(t.options.duration),kt().nextLine())),iQ=new $t("notify",[{name:"text",type:"string"}],async t=>{const{text:e}=t.options;return Co().addNotification(e),kt().nextLine()}),oQ=new $t("clear_dialog",[],async t=>($o().clearDialog(),kt().nextLine())),aQ=new $t("if",[{name:"condition",type:"boolean"}],async t=>{const e=tJ(t),n=kt();if(e){const r={branchData:{branch:e},currentIndex:0};return n.addStack(r)}return n.nextLine()},(t,e)=>{let n=t.currentLine;Jl("if",[{name:"condition",type:"string"}])(t,e);const{lines:i,currentLine:o,line:a}=t,s=e.command;let u;const l=nJ(i,o+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}}),sQ=new $t("==","any",async t=>{t.args.length<2&&rr(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}),uQ=new $t(">",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e>n}),lQ=new $t("<",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e<n}),cQ=new $t(">=",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e>=n}),fQ=new $t("<=",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e<=n}),dQ=new $t("!=",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e!=n}),hQ=new $t("!",[{name:"a",type:"any"}],async t=>{const{a:e}=t.options;return!e}),pQ=new $t("&&","any",async t=>{const e=t.args;return t.args.length<2&&rr(t,"requires at least two arguments"),e.reduce((n,r)=>n&&r,!0)}),vQ=new $t("||","any",async t=>(t.args.length<2&&rr(t,"requires at least two arguments"),t.args.reduce((e,n)=>e||n,!1))),mQ=new $t("?",[{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}),gQ=new $t("+","any",async t=>(t.args.length<2&&rr(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="number"?e+n:(rr(t,"requires all arguments to be numbers"),e),0))),yQ=new $t("-","any",async t=>(t.args.length<2&&rr(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="number"?e-n:(rr(t,"requires all arguments to be numbers"),e),0))),bQ=new $t("*","any",async t=>(t.args.length<2&&rr(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="number"?e*n:(rr(t,"requires all arguments to be numbers"),e),0))),kQ=new $t("/","any",async t=>(t.args.length<2&&rr(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="number"?e/n:(rr(t,"requires all arguments to be numbers"),e),0))),wQ=async t=>{kt().lastChoiceCommand=t;const{prompt:e,choices:n}=t.staticOptions,r=[];for(const[o,a]of n.entries()){const s=await x0(a.prompt);r.push(s)}t.options.choiceResults=r;const i=r.map((o,a)=>{var l,f;let s=!0;return o.skillCheck&&(s=(f=(l=o.skillCheck)==null?void 0:l.allowed)!=null?f:!1),{choice:o.text,originalIndex:a,allowed:s}}).filter(o=>o.choice);XE(e,i)};function xQ(t,e,n){e.expression,e.branch||t.parserContext.error(e.line,`Choice option doesn't have any branch to go to (${e.code} - ${e.line})`);let r,i;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})`),r={success:t.processCommandsFunction(t.parserContext,o[0].branch,e),failure:t.processCommandsFunction(t.parserContext,o[1].branch,e)}):i=t.processCommandsFunction(t.parserContext,o,e),{prompt:t.processCommandsFunction(t.parserContext,[e],e)[0],branch:i,skillBranches:r}}const jQ=(t,e)=>{let n=t.currentLine;Jl("choice",[]);const{line:r}=t,i=e.command;(!r.branch||r.branch.length<2)&&t.parserContext.error(r.line,"Choice menu needs to have at least one option");const o=r.branch[0];o||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 i.staticOptions={prompt:t.processCommandsFunction(t.parserContext,[o],r)[0],choices:s},n++,{newLine:n}},cM=new $t("choice",[],wQ,jQ);cM.onPlayerAnswered=async(t,e)=>{const n=kt(),{choices:r}=t.staticOptions,i=r[e],o=t.options.choiceResults[e];let a;if(o.skillCheck?GE({skill:o.skillCheck.skillId,value:o.skillCheck.difficulty,id:o.skillCheck.skillCheckId,hideAfterRoll:o.skillCheck.hideAfterRoll}).succeeded?a=i.skillBranches.success:a=i.skillBranches.failure:a=i.branch,a){const s={currentIndex:0,branchData:{branch:a}};return n.addStack(s)}else n.nextLine()};function _Q(t,e){return{code:`choicePrompt ${e.code}`,indentation:e.indentation,line:e.line,branch:e.branch,expression:["choicePrompt",...e.expression]}}const SQ=new $t("choicePrompt","any",async t=>{const e=t.args;if(e[0]==="roll"){const n=e[1],r=e[2],i=e[3],o=e[4],a=e.length>5?e[5]:!1,s=Er().getSkillCheck(n);if(s.hidden)return{text:null};const u=s.happened&&!s.succeeded,{difficultyText:l,allowed:f}=YU({skill:r,skillCheckId:n,value:i});return{text:`${l} ${o}`,skillCheck:{allowed:!u,skillId:r,skillCheckId:n,difficulty:i,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]}});function CQ(t){t.addCommand(cM),t.addCommand(SQ),t.addCommand(aQ),t.addCommand($K),t.addCommand(OK),t.addCommand(AK),t.addCommand(oQ),t.addCommand(iQ),t.addCommand(NK),t.addCommand(IK),t.addCommand(LK),t.addCommand(zK),t.addCommand(BK),t.addCommand(rQ),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(yQ),t.addCommand(bQ),t.addCommand(kQ),t.addCommand(RK),t.addCommand(DK),t.addCommand(lM),t.addCommand(VK),t.addCommand(EK),t.addCommand(MK),t.addCommand(PK),t.addCommand(TK),t.addCommand(KK),t.addCommand(QK),t.addCommand(YK),t.addCommand(XK),t.addCommand(tQ),t.addCommand(nQ),t.addCommand(ZK),t.addCommand(eQ),t.addCommand(FK),t.addCommand(HK),t.addCommand(JK),t.addCommand(GK),t.addCommand(WK),t.addCommand(UK),t.addCommand(_K),t.addCommand(SK),t.addCommand(CK)}let Gl;sr.callHook("onPageLoaded");async function $Q(t,e){const n=await g0("data/config.json");pU(JSON.parse(n)),Gl=I.createApp(wK,{config:t,options:e});const r=mU();if(Gl.use(r),Pn().setOptions(e),Gl.use(EM,{breakpoints:{s:0,m:800,l:1200}}),CQ(sr),z0.setupDebugger(e.debug),console.log("%c Narrat game engine \u2013 [VI]{version} - {date}[/VI]","background: #222; color: #bada55"),sr.callHook("onNarratSetup"),Gl.mount("#game-holder"),e.debug){const i={app:Gl,vm:sr,jump:o=>{kt().runLabel(o)}};window.narrat=i}xK()}class OQ{onPageLoaded(){}onNarratSetup(){}onAppMounted(){}onAssetsLoaded(){}onGameSetup(){}onGameStart(){}onGameMounted(){}onGameDismounted(){}}function AQ(t){sr.addPlugin(t)}function EQ(t){sr.addCommand(t)}ln.CommandPlugin=$t,ln.NarratPlugin=OQ,ln.addCommand=EQ,ln.aspectRatioFit=nM,ln.generateParser=Jl,ln.getConfig=Ft,ln.registerPlugin=AQ,ln.startApp=$Q,Object.defineProperties(ln,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "narrat",
3
3
  "description": "narrat narrative engine",
4
- "version": "2.0.0-test-1",
4
+ "version": "2.0.0-test-2",
5
5
  "main": "dist/narrat.umd.js",
6
6
  "module": "dist/narrat.es.js",
7
7
  "files": [