narrat 2.0.1 → 2.0.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 +13 -10
- package/dist/narrat.umd.js +1 -1
- package/package.json +1 -1
package/dist/narrat.es.js
CHANGED
|
@@ -40022,17 +40022,20 @@ const _sfc_main$1 = defineComponent({
|
|
|
40022
40022
|
{
|
|
40023
40023
|
id: "skills",
|
|
40024
40024
|
cssId: "skills-menu-button",
|
|
40025
|
-
text: "Skills"
|
|
40025
|
+
text: "Skills",
|
|
40026
|
+
condition: () => this.showSkills
|
|
40026
40027
|
},
|
|
40027
40028
|
{
|
|
40028
40029
|
id: "inventory",
|
|
40029
40030
|
cssId: "inventory-menu-button",
|
|
40030
|
-
text: "Items"
|
|
40031
|
+
text: "Items",
|
|
40032
|
+
condition: () => this.showInventory
|
|
40031
40033
|
},
|
|
40032
40034
|
{
|
|
40033
40035
|
id: "quests",
|
|
40034
40036
|
cssId: "quests-menu-button",
|
|
40035
|
-
text: "Quests"
|
|
40037
|
+
text: "Quests",
|
|
40038
|
+
condition: () => this.showQuests
|
|
40036
40039
|
}
|
|
40037
40040
|
],
|
|
40038
40041
|
activeMenu: false
|
|
@@ -40079,18 +40082,18 @@ const _sfc_main$1 = defineComponent({
|
|
|
40079
40082
|
},
|
|
40080
40083
|
computed: {
|
|
40081
40084
|
buttonsToShow() {
|
|
40082
|
-
return this.buttons.
|
|
40083
|
-
if (button.condition) {
|
|
40084
|
-
return button.condition();
|
|
40085
|
-
} else {
|
|
40086
|
-
return true;
|
|
40087
|
-
}
|
|
40088
|
-
}).map((button) => {
|
|
40085
|
+
return this.buttons.map((button) => {
|
|
40089
40086
|
const buttonData = getConfig().menuButtons[button.id] || {};
|
|
40090
40087
|
return {
|
|
40091
40088
|
...button,
|
|
40092
40089
|
...buttonData
|
|
40093
40090
|
};
|
|
40091
|
+
}).filter((button) => {
|
|
40092
|
+
if (button.condition) {
|
|
40093
|
+
return button.condition();
|
|
40094
|
+
} else {
|
|
40095
|
+
return true;
|
|
40096
|
+
}
|
|
40094
40097
|
});
|
|
40095
40098
|
},
|
|
40096
40099
|
showSkills() {
|
package/dist/narrat.umd.js
CHANGED
|
@@ -188,7 +188,7 @@ return query;
|
|
|
188
188
|
`)();const UU=M.defineComponent({data(){return{playerText:"",passed:!1}},props:{options:{type:Object,required:!0},active:Boolean},mounted(){document.addEventListener("keydown",t=>{if(this.canInteract&&this.options.textField&&t.key==="Enter"&&this.submitText(),this.canInteract&&!this.options.textField){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])}}),setTimeout(()=>{this.options.textField&&this.$refs.playerInput.focus()},10)},computed:{...gi(Sn,["paused"]),preText(){return this.options.title?" \u2013 ":""},style(){return gd(this.options.styleId)},dialogBoxStyle(){const t=gd(this.options.styleId),e={opacity:this.options.old?"0.7":"1"};return this.options.title||(e.marginTop="-20px"),{...t.boxCss,...e}},titleStyle(){const t=gd(this.options.styleId);return{color:t.color,...t.nameCss}},textStyle(){return gd(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,Sn().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"},submitText(){const t=this.playerText;Sn().playerAnswered(t)}}}),JU={class:"dialog-content"},GU=["innerHTML"],KU=["innerHTML"],QU=["innerHTML"],YU={key:1,class:"dialog-choices"},XU=["onClick","innerHTML"],ZU={key:2},eJ={key:3,class:"buttons-container"};function tJ(t,e,n,r,o,i){return M.openBlock(),M.createElementBlock("div",{class:"dialog-box w-full override",style:M.normalizeStyle(t.dialogBoxStyle)},[M.createElementVNode("div",JU,[t.options.title?(M.openBlock(),M.createElementBlock("span",{key:0,class:"dialog-title override",style:M.normalizeStyle(t.titleStyle),innerHTML:t.options.title},null,12,GU)):M.createCommentVNode("",!0),M.createElementVNode("span",{class:"dialog-text dialog-separator override",style:M.normalizeStyle(t.textStyle),innerHTML:t.preText},null,12,KU),M.createElementVNode("span",{class:"dialog-text override",style:M.normalizeStyle(t.textStyle),innerHTML:t.options.text},null,12,QU),t.canInteract&&t.choices?(M.openBlock(),M.createElementBlock("div",YU,[(M.openBlock(!0),M.createElementBlock(M.Fragment,null,M.renderList(t.choices,(a,s)=>(M.openBlock(),M.createElementBlock("p",{key:s,style:M.normalizeStyle(t.dialogStyle(a)),class:M.normalizeClass([t.dialogClass(a),"dialog-choice override"]),onClick:l=>t.chooseOption(a),innerHTML:`${s+1}. \u2013\xA0 ${a.choice}`},null,14,XU))),128))])):t.canInteract&&t.options.textField?(M.openBlock(),M.createElementBlock("div",ZU,[M.withDirectives(M.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),[[M.vModelText,t.playerText]]),M.createElementVNode("button",{onClick:e[1]||(e[1]=(...a)=>t.submitText&&t.submitText(...a)),class:"button",id:"player-input-submit"}," Submit ")])):t.canInteract?(M.openBlock(),M.createElementBlock("div",eJ,[M.createElementVNode("div",{onClick:e[2]||(e[2]=a=>t.chooseOption(0)),class:"interact-button button override"}," Continue ")])):M.createCommentVNode("",!0)])],4)}var nJ=zr(UU,[["render",tJ]]),cK=(()=>`.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}
|
|
189
189
|
`)();const rJ=M.createElementVNode("div",{class:"anchor"},null,-1),oJ=M.defineComponent({__name:"game-dialog",props:{layoutMode:String,inGame:Boolean},setup(t){const e=t,n=mt(),r=M.computed(()=>n.stack),o=xo(),i=M.computed(()=>o.dialog),a=M.computed(()=>e.layoutMode==="vertical"?{}:{paddingBottom:`${Rt().layout.dialogBottomPadding}px`}),s=M.computed(()=>{if(i.value.length>0)return i.value[i.value.length-1]}),l=M.computed(()=>{if(s.value)return DA(s.value.speaker,s.value.pose)}),c=M.computed(()=>Rt().layout.minTextWidth),f=M.computed(()=>{let h;const p="100%";return e.layoutMode,{width:e.layoutMode==="horizontal"?`${c.value}px`:"100%",height:p,transform:h,transformOrigin:"right"}});function u(h,p){let g=md(h.speaker).name;return p>=1&&i.value[p-1].speaker===h.speaker&&(g=void 0),h.choices&&h.choices.forEach(m=>{m.choice=Sg(m.choice)}),{title:g!=null?g:"",text:h.text,styleId:h.speaker,choices:h.choices,old:p<i.value.length-1,interactive:h.interactive,textField:h.textField}}function d(h){return h===o.dialog.length-1&&r.value.length>0}return(h,p)=>(M.openBlock(),M.createElementBlock(M.Fragment,null,[M.createVNode(M.Transition,{name:"fade"},{default:M.withCtx(()=>[M.unref(l)?(M.openBlock(),M.createBlock(WU,{key:0,pictureUrl:M.unref(l)},null,8,["pictureUrl"])):M.createCommentVNode("",!0)]),_:1}),t.inGame?(M.openBlock(),M.createElementBlock("div",{key:0,class:"dialog override",ref_key:"dialog",ref:i,style:M.normalizeStyle(M.unref(f))},[M.createVNode(M.TransitionGroup,{name:"list",tag:"div",class:"dialog-container w-full override",style:M.normalizeStyle(M.unref(a))},{default:M.withCtx(()=>[(M.openBlock(!0),M.createElementBlock(M.Fragment,null,M.renderList(M.unref(i),(v,g)=>(M.openBlock(),M.createBlock(nJ,{key:v.id,options:u(v,g),active:d(g)},null,8,["options","active"]))),128))]),_:1},8,["style"]),rJ],4)):M.createCommentVNode("",!0)],64))}});var uK=(()=>`.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}
|
|
190
190
|
`)();const iJ=M.defineComponent({setup(){const t=Rr();return{quests:M.computed(()=>t.quests)}},computed:{questsToDisplay(){return wA(this.quests,t=>t.state!=="hidden")}},methods:{close(){this.$emit("close")},getQuestData(t){return dd(t)},getObjectiveData(t,e){return vg(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 wA(t.objectives,e=>e.state!=="hidden")}},components:{Modal:tl}}),aJ=M.createElementVNode("h3",{class:"title"},"Quests",-1),sJ={key:0,class:"quests-container"},lJ={class:"quest-title"},cJ={class:"quest-description"},uJ={key:0,class:"quest-objectives-container list-disc"},fJ={key:1,class:"menu-container"},dJ=[M.createElementVNode("h2",{class:"title"},"There are no quests!",-1)];function hJ(t,e,n,r,o,i){const a=M.resolveComponent("modal");return M.openBlock(),M.createBlock(a,{class:"quests",onClose:t.close,containerCssClass:"quests-modal"},{header:M.withCtx(()=>[aJ]),body:M.withCtx(()=>[Object.keys(t.questsToDisplay).length>0?(M.openBlock(),M.createElementBlock("div",sJ,[(M.openBlock(!0),M.createElementBlock(M.Fragment,null,M.renderList(t.questsToDisplay,s=>(M.openBlock(),M.createElementBlock("div",{class:"quest-display",key:s.id},[M.createElementVNode("div",{class:M.normalizeClass(["quest-header",s.state==="completed"?"quest-completed":"quest-in-progress"])},[M.createElementVNode("h3",lJ,M.toDisplayString(t.getQuestData(s.id).title)+" "+M.toDisplayString(t.getDisplayTextForQuestState(s)),1)],2),M.createElementVNode("p",cJ,M.toDisplayString(t.getQuestDescription(s)),1),s.state!=="completed"?(M.openBlock(),M.createElementBlock("ul",uJ,[(M.openBlock(!0),M.createElementBlock(M.Fragment,null,M.renderList(t.getAvailableObjectives(s),l=>(M.openBlock(),M.createElementBlock("li",{class:"quest-objective-display",key:l.id},[M.createElementVNode("p",{class:M.normalizeClass(["quest-objective-description",l.state==="completed"?"quest-objective-completed":"quest-objctive-in-progress"])},M.toDisplayString(t.getObjectiveData(s.id,l.id).description),3)]))),128))])):M.createCommentVNode("",!0)]))),128))])):(M.openBlock(),M.createElementBlock("div",fJ,dJ))]),_:1},8,["onClose"])}var pJ=zr(iJ,[["render",hJ]]),dK=(()=>`.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}
|
|
191
|
-
`)();const vJ=M.defineComponent({data(){return{buttons:[{id:"menu",cssId:"menu-button",text:"Menu"},{id:"skills",cssId:"skills-menu-button",text:"Skills"},{id:"inventory",cssId:"inventory-menu-button",text:"Items"},{id:"quests",cssId:"quests-menu-button",text:"Quests"}],activeMenu:!1}},mounted(){document.addEventListener("keydown",t=>{t.key==="Escape"&&this.toggleMenu()}),or.callHook("onGameMounted")},unmounted(){or.callHook("onGameUnmounted")},methods:{buttonClick(t){t.onClick?t.onClick():Sn().openModal(t.id)},openMenu(){Sn().openModal("menu")},openSkills(){Sn().openModal("skills")},openInventory(){Sn().openModal("inventory")},openQuests(){Sn().openModal("quests")},closeMenu(){Sn().closeModal()},toggleMenu(){Sn().toggleMenu()}},computed:{buttonsToShow(){return this.buttons.
|
|
191
|
+
`)();const vJ=M.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()}),or.callHook("onGameMounted")},unmounted(){or.callHook("onGameUnmounted")},methods:{buttonClick(t){t.onClick?t.onClick():Sn().openModal(t.id)},openMenu(){Sn().openModal("menu")},openSkills(){Sn().openModal("skills")},openInventory(){Sn().openModal("inventory")},openQuests(){Sn().openModal("quests")},closeMenu(){Sn().closeModal()},toggleMenu(){Sn().toggleMenu()}},computed:{buttonsToShow(){return this.buttons.map(t=>{const e=Rt().menuButtons[t.id]||{};return{...t,...e}}).filter(t=>t.condition?t.condition():!0)},showSkills(){return Object.entries(Rt().skills).length>0},showInventory(){return Object.entries(Rt().items).length>0},showQuests(){return Object.entries(Rt().quests).length>0}}}),mJ={class:"menu-container"},gJ=["onClick","id"];function yJ(t,e,n,r,o,i){return M.openBlock(),M.createElementBlock("div",mJ,[(M.openBlock(!0),M.createElementBlock(M.Fragment,null,M.renderList(t.buttonsToShow,a=>(M.openBlock(),M.createElementBlock("button",{key:a.id,onClick:s=>t.buttonClick(a),id:a.cssId,class:"button menu-toggle-button"},M.toDisplayString(a.text),9,gJ))),128))])}var bJ=zr(vJ,[["render",yJ]]),hK=(()=>`#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}
|
|
192
192
|
`)();const wJ=M.defineComponent({setup(){const t=xo(),e=mt(),n=Sn();return{dialog:M.computed(()=>t.dialog),stack:M.computed(()=>e.stack),modal:M.computed(()=>n.modal),flowState:M.computed(()=>n.flowState)}},$refs:{dialogContainer:HTMLInputElement},inject:["mq"],components:{DebugMenu:zW,LoadingBar:eU,NotificationToast:rU,Hud:KW,MainMenu:fU,Skills:CU,InventoryUi:qU,GameDialog:oJ,QuestsUi:pJ,MenuButtons:bJ},data(){return{lineTitle:"title",lineText:"hello",gameLoaded:!1,loadingStep:"Loading",loadingPercentage:.1,hasSave:!1}},props:{config:Object,options:Object},async mounted(){or.callHook("onAppMounted"),this.loadingStep="Characters";const t=await kg("data/characters.json");await oU(JSON.parse(t)),this.loadingPercentage=.2,this.loadingStep="Data",this.loadingPercentage=.3,this.loadingStep="Images",await iU(Rt()),this.loadingPercentage=.7,this.loadingStep="Audio",await $H(Rt()),or.callHook("onAssetsLoaded"),this.loadingPercentage=.95,this.loadingStep="Starting...",await this.setupMachine(),or.callHook("onGameSetup"),this.loadingPercentage=.1,this.gameLoaded=!0,this.getSaveFile()&&(this.hasSave=!0),window.addEventListener("resize",HA(()=>{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:{...gi(xc,["screenWidth","screenHeight","canvasWidth","canvasHeight","topOffset","leftOffset","layoutMode"]),...gi(mt,["currentLine"]),dialogLength(){return this.dialog.length},lastDialog(){if(this.dialog.length>0)return this.dialog[this.dialog.length-1]},picture(){if(this.lastDialog)return DA(this.lastDialog.speaker,this.lastDialog.pose)},backgroundStyle(){let t;return this.layoutMode==="vertical"&&(t=`${100-Rt().layout.mobileDialogHeightPercentage}%`),{backgroundColor:"red",height:t}},layoutWidth(){return Rt().layout.backgrounds.width},gameTitle(){return Rt().gameTitle},inGame(){return this.flowState==="playing"},layoutHeight(){return Rt().layout.backgrounds.height},backgroundSize(){return{width:this.canvasWidth,height:this.canvasHeight,top:this.topOffset,left:this.leftOffset}},dialogWidth(){const t=Rt().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=Rt();return this.layoutMode==="vertical"?window.innerWidth:t.layout.backgrounds.width+t.layout.minTextWidth},gameHeight(){const t=Rt();return this.layoutMode==="vertical"?window.innerHeight:t.layout.backgrounds.height},appStyle(){const t=Rt();if(this.screenWidth&&this.screenHeight&&t&&this.layoutMode==="horizontal"){const e=zA(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=Rt(),e=t.layout.minTextWidth+t.layout.backgrounds.width;return this.screenWidth/e},dialogContainerStyle(){return this.layoutMode==="vertical"?{}:{paddingBottom:`${Rt().layout.dialogBottomPadding}px`}}},methods:{async setupMachine(){const t=Rt().scripts;return Sn().setup(t,Rt())},getSaveFile(){return localStorage.getItem(sA)},async startGame(){bc("onPressStart"),await Sn().startGame()},async loadGame(){bc("onPressStart"),Sn().loadGame(this.getSaveFile())},isDialogActive(t){return t===this.dialog.length-1&&this.stack.length>0},nextLine(){mt().nextLine()},updateScreenSize(){xc().updateScreenSize(window.innerWidth,window.innerHeight,this.layoutMode==="horizontal"?Rt().layout.minTextWidth*this.screenRatio:0)},closeModal(){Sn().closeModal()},getDialogBoxOptions(t,e){let r=md(t.speaker).name;return e>=1&&this.dialog[e-1].speaker===t.speaker&&(r=void 0),t.choices&&t.choices.forEach(o=>{o.choice=Sg(o.choice)}),{title:r!=null?r:"",text:t.text,styleId:t.speaker,choices:t.choices,old:e<this.dialog.length-1,interactive:t.interactive}}}}),kJ=["width","height"],xJ={key:2,id:"game-menu",style:{height:"100%",padding:"20px"}},jJ={id:"game-header"},_J={id:"game-title-container"},SJ={id:"game-title-text"},CJ={class:"flex flex-col"},$J={key:3};function OJ(t,e,n,r,o,i){const a=M.resolveComponent("Hud"),s=M.resolveComponent("MenuButtons"),l=M.resolveComponent("Skills"),c=M.resolveComponent("InventoryUi"),f=M.resolveComponent("QuestsUi"),u=M.resolveComponent("MainMenu"),d=M.resolveComponent("GameDialog"),h=M.resolveComponent("LoadingBar"),p=M.resolveComponent("DebugMenu"),v=M.resolveComponent("NotificationToast");return M.openBlock(),M.createElementBlock("div",{id:"app",style:M.normalizeStyle(t.appStyle)},[t.inGame?(M.openBlock(),M.createBlock(a,{key:0})):M.createCommentVNode("",!0),t.inGame?(M.openBlock(),M.createElementBlock("div",{key:1,class:"game",style:M.normalizeStyle(t.gameStyle)},[M.createVNode(s,{class:"menu-toggle"}),t.modal==="skills"?(M.openBlock(),M.createBlock(l,{key:0,onClose:t.closeModal},null,8,["onClose"])):M.createCommentVNode("",!0),t.modal==="inventory"?(M.openBlock(),M.createBlock(c,{key:1,onClose:t.closeModal},null,8,["onClose"])):M.createCommentVNode("",!0),t.modal==="quests"?(M.openBlock(),M.createBlock(f,{key:2,onClose:t.closeModal},null,8,["onClose"])):M.createCommentVNode("",!0),t.modal==="menu"?(M.openBlock(),M.createBlock(u,{key:3,onClose:t.closeModal},null,8,["onClose"])):M.createCommentVNode("",!0),t.inGame?(M.openBlock(),M.createElementBlock("div",{key:4,class:"background",style:M.normalizeStyle(t.backgroundStyle)},[M.createElementVNode("canvas",{width:t.layoutWidth,height:t.layoutHeight,id:"background-canvas",class:"narrat-canvas"},null,8,kJ)],4)):M.createCommentVNode("",!0),M.createVNode(d,{inGame:t.inGame,layoutMode:t.layoutMode},null,8,["inGame","layoutMode"])],4)):t.gameLoaded?(M.openBlock(),M.createElementBlock("div",xJ,[M.createElementVNode("div",jJ,[M.createElementVNode("div",_J,[M.createElementVNode("h1",SJ,M.toDisplayString(t.gameTitle),1)]),M.createElementVNode("div",CJ,[M.createElementVNode("button",{class:"button menu-button main-menu-button larg start-button override",onClick:e[0]||(e[0]=(...g)=>t.startGame&&t.startGame(...g))}," Start Game "),t.hasSave?(M.openBlock(),M.createElementBlock("button",{key:0,class:"button menu-button main-menu-button large continue-button override",onClick:e[1]||(e[1]=(...g)=>t.loadGame&&t.loadGame(...g))}," Continue Game ")):M.createCommentVNode("",!0)])])])):(M.openBlock(),M.createElementBlock("div",$J,[M.createVNode(h,{percentage:t.loadingPercentage,step:t.loadingStep},null,8,["percentage","step"])])),t.options.debug?(M.openBlock(),M.createBlock(p,{key:4})):M.createCommentVNode("",!0),M.createVNode(v)],4)}var AJ=zr(wJ,[["render",OJ]]);let Vo,bi;const ya={x:0,y:0};function EJ(){document.addEventListener("mousemove",t=>{ya.x=t.clientX,ya.y=t.clientY}),document.addEventListener("click",HA(MJ,100,{maxWait:200})),WA()}function WA(){const t=Bi();if(Sn().playing){if(!Vo)Vo=document.querySelector("#background-canvas"),Vo&&!bi&&(bi=Vo.getContext("2d"));else if(Vo&&bi){bi.fillStyle="white",bi.fillRect(0,0,Vo.width,Vo.height);const n=t.currentScreen,r=Rt().screens[n],o=r.background;bi.drawImage(Og[o],0,0);let i=!1;const a=BA(ya.x,ya.y,Vo);if(r.buttons){for(const s of r.buttons)if(t.buttons[s].enabled){const l=Rt().buttons[s],c=Og[l.background];bi.drawImage(c,l.position.left,l.position.top),qA(a.x,a.y,1,1,l.position.left,l.position.top,l.position.width,l.position.height)&&(i=!0)}}i?document.body.style.cursor="pointer":document.body.style.cursor="default",bi.fillStyle="black",bi.textAlign="left"}}else Vo=void 0,bi=void 0;window.requestAnimationFrame(WA)}function MJ(t){const e=Bi(),n=mt();if(!Vo)return;ya.x=t.clientX,ya.y=t.clientY;const r=BA(ya.x,ya.y,Vo),o=e.currentScreen,i=Rt().screens[o];if(i.buttons){for(const a of i.buttons)if(e.buttons[a].enabled){const s=Rt().buttons[a];if(qA(r.x,r.y,1,1,s.position.left,s.position.top,s.position.width,s.position.height)){const l=s.action,c={branchData:n.script[l],currentIndex:0,label:l};n.setStack(c),n.runLine()}}}}function Qn(t,e){console.error("Runtime error ========================="),console.error("Args: ",t.args),console.error("Options: ",t.options),hr(`Runtime error at ${t.fileName}:${t.line} (${t.commandType}) ${t.code}. -
|
|
193
193
|
<br />
|
|
194
194
|
Error: ${e}`),console.error("============================")}class wt{constructor(e,n,r,o){wi(this,"keyword");wi(this,"runner");wi(this,"argTypes");wi(this,"parser");wi(this,"onPlayerAnswered");this.keyword=e,this.runner=r,this.argTypes=n,o?this.parser=o:this.parser=jc(this.keyword,this.argTypes)}}function jc(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,l)=>{const c=e[l];PA(s)||c.type==="any"||typeof s===c.type||r.parserContext.error(r.line.line,`Command ${t}: Argument #${l+1} (${c.name}) should be a ${c.type}, but got type ${typeof s}: ${JSON.stringify(s)}`)}),{newLine:r.currentLine+1})}}const PJ=new wt("add_level",[{name:"skillKey",type:"string"},{name:"amount",type:"number"}],async t=>{const{skillKey:e,amount:n}=t.options;return(!e||!n)&&Qn(t,"add_level command needs a skill id and a value as parameters"),Sr().incrementSkill(e,n),mt().nextLine()}),TJ=new wt("add_xp",[{name:"xpKey",type:"string"},{name:"xpToAdd",type:"number"}],async t=>{const{xpKey:e,xpToAdd:n}=t.options;return(!e||!n)&&Qn(t,"add_xp command needs a skill id and a value as parameters"),Sr().addXp(e,n),mt().nextLine()}),IJ=new wt("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 MA({id:e,skill:n,value:r,hideAfterRoll:o})}),NJ=new wt("add_stat",[{name:"statKey",type:"string"},{name:"amountToAdd",type:"number"}],async t=>{const{statKey:e,amountToAdd:n}=t.options;return(!e||!n)&&Qn(t,"add_stat command needs a stat id and a value as parameters"),zi().addStat(e,n),mt().nextLine()}),LJ=new wt("set_stat",[{name:"statKey",type:"string"},{name:"value",type:"number"}],async t=>{const{statKey:e,value:n}=t.options;return(!e||!n)&&Qn(t,"set_stat command needs a stat id and a value as parameters"),zi().setStat(e,n),mt().nextLine()}),RJ=new wt("get_stat_value",[{name:"statKey",type:"string"}],async t=>{const{statKey:e}=t.options;return e||Qn(t,"get_stat_value command needs a stat id as parameter"),zi().getStatValue(e)}),DJ=new wt("jump","any",async t=>{(t.args.length<1||typeof t.args[0]!="string")&&Qn(t,"requires a label argument");const e=t.args[0],n=mt(),r={branchData:n.script[e],label:e,args:t.args.splice(1),currentIndex:0};n.setStack(r),await Sn().saveGame(),await n.runLine()}),zJ=new wt("run","any",async t=>{(t.args.length<1||typeof t.args[0]!="string")&&Qn(t,"run command needs a label to argument run");const e=t.args[0];return await mt().runLabelFunction(e,...t.args.slice(1))}),BJ=new wt("var",[{name:"name",type:"string"},{name:"value",type:"any"}],async t=>{const{name:e,value:n}=t.options;return mt().addScopedVariable(e,n),mt().nextLine()}),qJ=new wt("return",[{name:"value",type:"any"}],async t=>{const{value:e}=t.options;return mt().setReturnValue(e),mt().nextLine()}),Ag=[{name:"mode",type:"string"},{name:"audio",type:"string",optional:!0}],VJ=new wt("play",Ag,async t=>{const e=t.options;e.mode==="music"?pd(e.audio):mA(e.audio),mt().nextLine()}),FJ=new wt("pause",Ag,async t=>{const e=t.options;if(e.mode==="music"){const n=Di();n.currentMusic&&gA(n.currentMusic)}else e.mode==="sound"&&e.audio?gA(e.audio):Qn(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 mt().nextLine()}),HJ=new wt("stop",Ag,async t=>{const e=t.options;if(e.mode==="music"){const n=Di();n.currentMusic&&wg(n.currentMusic)}else e.mode==="sound"&&e.audio?wg(e.audio):Qn(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 mt().nextLine()}),WJ=new wt("set",[{name:"key",type:"string"},{name:"value",type:"any"}],async t=>{const e=Xs();return kA(e,t.options.key,t.options.value),mt().nextLine()}),UJ=new wt("add",[{name:"key",type:"string"},{name:"value",type:"any"}],async t=>{const e=Xs();return xA(e,t.options.key,t.options.value),mt().nextLine()}),JJ=new wt("set_screen",[{name:"screen",type:"string"}],t=>(Bi().setScreen(t.options.screen),mt().nextLine())),GJ=new wt("set_button",[{name:"buttonId",type:"string"},{name:"enabled",type:"boolean"}],async t=>{const{buttonId:e,enabled:n}=t.options;return Bi().changeButton(e,n),mt().nextLine()}),KJ=new wt("talk",[{name:"speaker",type:"string"},{name:"pose",type:"string"},{name:"text",type:"string"}],async(t,e)=>{await IA({speaker:t.options.speaker,pose:t.options.pose,text:`"${t.options.text}"`,choices:e,interactive:!0})}),QJ=()=>{const t=jc("text",[]);return(e,n)=>{const r=t(e,n);return n.command.staticOptions={text:n.code},r}},UA=new wt("text",[],async(t,e)=>{await IA({speaker:"game",text:t.staticOptions.text,choices:e,interactive:!0})},QJ());console.log(UA);const YJ=new wt("add_item",[{name:"id",type:"string"},{name:"amount",type:"number"}],async t=>{const{id:e,amount:n}=t.options;return _r().add({id:e,amount:n}),mt().nextLine()}),XJ=new wt("remove_item",[{name:"id",type:"string"},{name:"amount",type:"number"}],async t=>{const{id:e,amount:n}=t.options;return _r().remove({id:e,amount:n}),mt().nextLine()}),ZJ=new wt("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)}),eG=new wt("item_amount?",[{name:"id",type:"string"}],async t=>{const{id:e}=t.options;return _r().getItemAmount(e)}),tG=new wt("enable_interaction",[{name:"tag",type:"string"}],async t=>{const e=t.options.tag;return _r().enableInteraction(e),mt().nextLine()}),nG=new wt("disable_interaction",[{name:"tag",type:"string"}],async t=>{const e=t.options.tag;return _r().disableInteraction(e),mt().nextLine()}),rG=new wt("start_quest",[{name:"questId",type:"string"}],async t=>{const e=t.options.questId;return Rr().startQuest(e),mt().nextLine()}),oG=new wt("start_objective",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;return Rr().startObjective(e,n),mt().nextLine()}),iG=new wt("complete_objective",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;return Rr().completeObjective(e,n),mt().nextLine()}),aG=new wt("complete_quest",[{name:"questId",type:"string"},{name:"ending",type:"string",optional:!0}],async t=>{const{questId:e,ending:n}=t.options;return Rr().completeQuest(e,n),mt().nextLine()}),sG=new wt("quest_completed?",[{name:"questId",type:"string"}],async t=>{const{questId:e}=t.options;return Rr().isQuestCompleted(e)}),lG=new wt("objective_completed?",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;return Rr().isObjectiveCompleted(e,n)}),cG=new wt("quest_started?",[{name:"questId",type:"string"}],async t=>{const{questId:e}=t.options;return Rr().isQuestStarted(e)}),uG=new wt("objective_started?",[{name:"questId",type:"string"},{name:"objectiveId",type:"string"}],async t=>{const{questId:e,objectiveId:n}=t.options;return Rr().isObjectiveStarted(e,n)}),fG=new wt("wait",[{name:"duration",type:"number"}],async t=>(await mg(t.options.duration),mt().nextLine())),dG=new wt("notify",[{name:"text",type:"string"}],async t=>{const{text:e}=t.options;return yi().addNotification(e),mt().nextLine()}),hG=new wt("clear_dialog",[],async t=>(xo().clearDialog(),mt().nextLine())),pG=new wt("if",[{name:"condition",type:"boolean"}],async t=>{const e=sW(t),n=mt();if(e){const r={branchData:{branch:e},currentIndex:0};return n.addStack(r)}return n.nextLine()},(t,e)=>{let n=t.currentLine;jc("if",[{name:"condition",type:"string"}])(t,e);const{lines:o,currentLine:i,line:a}=t,s=e.command;let l;const c=lW(o,i+1);return c&&c.code==="else:"&&(l=t.processCommandsFunction(t.parserContext,c.branch,a),n++),s.staticOptions={success:t.processCommandsFunction(t.parserContext,a.branch,a),failure:l},n++,{newLine:n}}),vG=new wt("==","any",async t=>{t.args.length<2&&Qn(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}),mG=new wt(">",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e>n}),gG=new wt("<",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e<n}),yG=new wt(">=",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e>=n}),bG=new wt("<=",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e<=n}),wG=new wt("!=",[{name:"a",type:"any"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e!=n}),kG=new wt("!",[{name:"a",type:"any"}],async t=>{const{a:e}=t.options;return!e}),xG=new wt("&&","any",async t=>{const e=t.args;return t.args.length<2&&Qn(t,"requires at least two arguments"),e.reduce((n,r)=>n&&r,!0)}),jG=new wt("||","any",async t=>(t.args.length<2&&Qn(t,"requires at least two arguments"),t.args.reduce((e,n)=>e||n,!1))),_G=new wt("?",[{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}),SG=new wt("+","any",async t=>(t.args.length<2&&Qn(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="number"?e+n:(Qn(t,"requires all arguments to be numbers"),e),0))),CG=new wt("-","any",async t=>(t.args.length<2&&Qn(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="number"?e-n:(Qn(t,"requires all arguments to be numbers"),e),0))),$G=new wt("*","any",async t=>(t.args.length<2&&Qn(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="number"?e*n:(Qn(t,"requires all arguments to be numbers"),e),0))),OG=new wt("/","any",async t=>(t.args.length<2&&Qn(t,"requires at least two arguments"),t.args.reduce((e,n)=>typeof n=="number"?e/n:(Qn(t,"requires all arguments to be numbers"),e),0))),AG=async t=>{mt().lastChoiceCommand=t;const{prompt:e,choices:n}=t.staticOptions,r=[];for(const[i,a]of n.entries()){const s=await Cg(a.prompt);r.push(s)}t.options.choiceResults=r;const o=r.map((i,a)=>{var c,f;let s=!0;return i.skillCheck&&(s=(f=(c=i.skillCheck)==null?void 0:c.allowed)!=null?f:!1),{choice:i.text,originalIndex:a,allowed:s}}).filter(i=>i.choice);NA(e,o)};function EG(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,o;const i=e.branch;return e.expression[1]==="roll"?((!i[0].branch||!i[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,i[0].branch,e),failure:t.processCommandsFunction(t.parserContext,i[1].branch,e)}):o=t.processCommandsFunction(t.parserContext,i,e),{prompt:t.processCommandsFunction(t.parserContext,[e],e)[0],branch:o,skillBranches:r}}const MG=(t,e)=>{let n=t.currentLine;jc("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((l,c)=>(l.branch||t.parserContext.error(l.line,`Choice option doesn't have any branch to go to (${l.code})`),l=PG(t.parserContext,l),EG(t,l)));return o.staticOptions={prompt:t.processCommandsFunction(t.parserContext,[i],r)[0],choices:s},n++,{newLine:n}},JA=new wt("choice",[],AG,MG);JA.onPlayerAnswered=async(t,e)=>{const n=e,r=mt(),{choices:o}=t.staticOptions,i=o[n],a=t.options.choiceResults[n];let s;if(a.skillCheck?MA({skill:a.skillCheck.skillId,value:a.skillCheck.difficulty,id:a.skillCheck.skillCheckId,hideAfterRoll:a.skillCheck.hideAfterRoll}).succeeded?s=i.skillBranches.success:s=i.skillBranches.failure:s=i.branch,s){const l={currentIndex:0,branchData:{branch:s}};return r.addStack(l)}else r.nextLine()};function PG(t,e){return{code:`choicePrompt ${e.code}`,indentation:e.indentation,line:e.line,branch:e.branch,expression:["choicePrompt",...e.expression]}}const TG=new wt("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=Sr().getSkillCheck(n);if(s.hidden)return{text:null};const l=s.happened&&!s.succeeded,{difficultyText:c,allowed:f}=rW({skill:r,skillCheckId:n,value:o});return{text:`${c} ${i}`,skillCheck:{allowed:!l,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]}}),GA=new wt("text_field",[{name:"prompt",type:"string"}],async t=>new Promise(e=>{mt().lastChoiceCommand=t,t.options.resolve=e;const n={speaker:"game",text:t.options.prompt,textField:!0,interactive:!0};xo().addDialog(n)}));GA.onPlayerAnswered=async(t,e)=>{typeof e!="string"&&Qn(t,"The player's answer should be a string"),t.options.resolve(e)};const IG=new wt("text_field_prompt",[{name:"prompt",type:"string"}],async t=>{const e={speaker:"game",text:t.options.prompt,textField:!0,interactive:!0};xo().addDialog(e)});function NG(t){t.addCommand(JA),t.addCommand(TG),t.addCommand(pG),t.addCommand(NJ),t.addCommand(LJ),t.addCommand(RJ),t.addCommand(hG),t.addCommand(dG),t.addCommand(FJ),t.addCommand(VJ),t.addCommand(HJ),t.addCommand(GJ),t.addCommand(JJ),t.addCommand(fG),t.addCommand(vG),t.addCommand(mG),t.addCommand(gG),t.addCommand(yG),t.addCommand(bG),t.addCommand(wG),t.addCommand(kG),t.addCommand(xG),t.addCommand(jG),t.addCommand(_G),t.addCommand(SG),t.addCommand(CG),t.addCommand($G),t.addCommand(OG),t.addCommand(UJ),t.addCommand(WJ),t.addCommand(UA),t.addCommand(KJ),t.addCommand(DJ),t.addCommand(zJ),t.addCommand(BJ),t.addCommand(qJ),t.addCommand(rG),t.addCommand(oG),t.addCommand(iG),t.addCommand(aG),t.addCommand(cG),t.addCommand(uG),t.addCommand(sG),t.addCommand(lG),t.addCommand(YJ),t.addCommand(XJ),t.addCommand(tG),t.addCommand(nG),t.addCommand(ZJ),t.addCommand(eG),t.addCommand(PJ),t.addCommand(TJ),t.addCommand(IJ),t.addCommand(GA),t.addCommand(IG)}let _c;or.callHook("onPageLoaded");async function LG(t,e){const n=await kg("data/config.json");wH(JSON.parse(n)),_c=M.createApp(AJ,{config:t,options:e});const r=xH();if(_c.use(r),Sn().setOptions(e),_c.use(tE,{breakpoints:{s:0,m:800,l:1200}}),NG(or),Vg.setupDebugger(e.debug),console.log("%c Narrat game engine \u2013 [VI]{version} - {date}[/VI]","background: #222; color: #bada55"),or.callHook("onNarratSetup"),_c.mount("#game-holder"),e.debug){const o={app:_c,vm:or,jump:i=>{mt().runLabel(i)}};window.narrat=o}EJ()}class RG{onPageLoaded(){}onNarratSetup(){}onAppMounted(){}onAssetsLoaded(){}onGameSetup(){}onGameStart(){}onGameMounted(){}onGameDismounted(){}}function DG(t){or.addPlugin(t)}function zG(t){or.addCommand(t)}ln.CommandPlugin=wt,ln.NarratPlugin=RG,ln.addCommand=zG,ln.aspectRatioFit=zA,ln.generateParser=jc,ln.getConfig=Rt,ln.registerPlugin=DG,ln.startApp=LG,Object.defineProperties(ln,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|