narrat 2.0.6 → 2.0.7
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/LICENSE +21 -21
- package/README.md +38 -38
- package/dist/app.vue.d.ts +106 -106
- package/dist/components/MainMenu.vue.d.ts +12 -12
- package/dist/components/Skills.vue.d.ts +22 -22
- package/dist/components/debug/debug-menu.vue.d.ts +48 -48
- package/dist/components/dialog-picture.vue.d.ts +9 -9
- package/dist/components/game-dialog.vue.d.ts +65 -65
- package/dist/components/hud.vue.d.ts +12 -12
- package/dist/components/inventory-ui.vue.d.ts +30 -30
- package/dist/components/loading-bar.vue.d.ts +10 -10
- package/dist/components/menu-buttons.vue.d.ts +26 -26
- package/dist/components/notification-toast.vue.d.ts +6 -6
- package/dist/components/quests-ui.vue.d.ts +20 -20
- package/dist/components/utils/modal.vue.d.ts +6 -6
- package/dist/components/volume-controls.vue.d.ts +7 -7
- package/dist/config.d.ts +151 -151
- package/dist/constants.d.ts +1 -1
- package/dist/data/characters.json +62 -62
- package/dist/data/config.json +182 -182
- package/dist/data/example.rpy +360 -360
- package/dist/data/refactor.rpy +30 -30
- package/dist/defaultConfig.d.ts +2 -2
- package/dist/demo/demo.d.ts +1 -1
- package/dist/dialog-box.vue.d.ts +37 -37
- package/dist/exports/config.d.ts +1 -1
- package/dist/exports/display.d.ts +2 -2
- package/dist/exports/plugins.d.ts +20 -20
- package/dist/fonts/OpenDyslexic.ttf.svg +2326 -2326
- package/dist/gameloop.d.ts +3 -3
- package/dist/lib/lib.d.ts +15 -15
- package/dist/main.d.ts +5 -5
- package/dist/narrat.es.js +1 -1
- package/dist/narrat.es.js.map +1 -1
- package/dist/narrat.umd.js +1 -1
- package/dist/narrat.umd.js.map +1 -1
- package/dist/plugins/NarratPlugin.d.ts +11 -11
- package/dist/stores/audio-store.d.ts +12 -12
- package/dist/stores/dialog-store.d.ts +31 -31
- package/dist/stores/hud-stats-store.d.ts +22 -22
- package/dist/stores/inventory-store.d.ts +37 -37
- package/dist/stores/main-store.d.ts +276 -276
- package/dist/stores/notification-store.d.ts +12 -12
- package/dist/stores/quest-log.d.ts +39 -39
- package/dist/stores/rendering-store.d.ts +13 -13
- package/dist/stores/screens-store.d.ts +23 -23
- package/dist/stores/skills.d.ts +36 -36
- package/dist/stores/vm-store.d.ts +148 -148
- package/dist/types/app-types.d.ts +4 -4
- package/dist/types/character-types.d.ts +27 -27
- package/dist/types/dialog-box-types.d.ts +10 -10
- package/dist/types/game-save.d.ts +21 -21
- package/dist/types/parser.d.ts +92 -92
- package/dist/types/state.d.ts +3 -3
- package/dist/utils/ajax.d.ts +1 -1
- package/dist/utils/audio-loader.d.ts +13 -13
- package/dist/utils/characters.d.ts +5 -5
- package/dist/utils/data-helpers.d.ts +19 -19
- package/dist/utils/debounce.d.ts +14 -14
- package/dist/utils/error-handling.d.ts +3 -3
- package/dist/utils/helpers.d.ts +6 -6
- package/dist/utils/images-loader.d.ts +6 -6
- package/dist/utils/logger.d.ts +11 -11
- package/dist/utils/object-iterators.d.ts +8 -8
- package/dist/utils/promises.d.ts +1 -1
- package/dist/utils/randomId.d.ts +1 -1
- package/dist/utils/save-helpers.d.ts +3 -3
- package/dist/utils/skillchecks.d.ts +17 -17
- package/dist/utils/string-helpers.d.ts +3 -3
- package/dist/utils/time-helpers.d.ts +2 -2
- package/dist/vm/commands/arithmetic-commands.d.ts +17 -17
- package/dist/vm/commands/audio-commands.d.ts +8 -8
- package/dist/vm/commands/choice.d.ts +37 -37
- package/dist/vm/commands/clear_dialog.d.ts +2 -2
- package/dist/vm/commands/command-helpers.d.ts +2 -2
- package/dist/vm/commands/command-plugin.d.ts +30 -30
- package/dist/vm/commands/flow-commands.d.ts +14 -14
- package/dist/vm/commands/if.d.ts +10 -10
- package/dist/vm/commands/index.d.ts +2 -2
- package/dist/vm/commands/inventory-commands.d.ts +15 -15
- package/dist/vm/commands/logic-command.d.ts +42 -42
- package/dist/vm/commands/notify.d.ts +4 -4
- package/dist/vm/commands/quest-commands.d.ts +30 -30
- package/dist/vm/commands/screen-commands.d.ts +8 -8
- package/dist/vm/commands/set.d.ts +6 -6
- package/dist/vm/commands/skill-commands.d.ts +33 -33
- package/dist/vm/commands/stats-commands.d.ts +12 -12
- package/dist/vm/commands/string-commands.d.ts +9 -9
- package/dist/vm/commands/text-field.d.ts +7 -7
- package/dist/vm/commands/text.d.ts +13 -13
- package/dist/vm/commands/wait.d.ts +4 -4
- package/dist/vm/vm-helpers.d.ts +16 -16
- package/dist/vm/vm-parser.d.ts +19 -19
- package/dist/vm/vm-parser.test.d.ts +1 -1
- package/dist/vm/vm.d.ts +19 -19
- package/package.json +79 -79
- package/CHANGELOG.md +0 -776
- package/dist/.DS_Store +0 -0
- package/dist/img/.DS_Store +0 -0
- package/dist/music/.DS_Store +0 -0
- package/dist/sounds/.DS_Store +0 -0
package/dist/narrat.umd.js
CHANGED
|
@@ -191,5 +191,5 @@ return query;
|
|
|
191
191
|
`)();const mJ=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}}}),gJ={class:"menu-container"},yJ=["onClick","id"];function bJ(t,e,n,r,o,i){return M.openBlock(),M.createElementBlock("div",gJ,[(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,yJ))),128))])}var wJ=zr(mJ,[["render",bJ]]),pK=(()=>`#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 kJ=M.defineComponent({setup(){const t=so(),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:BW,LoadingBar:tU,NotificationToast:oU,Hud:QW,MainMenu:dU,Skills:$U,InventoryUi:VU,GameDialog:iJ,QuestsUi:vJ,MenuButtons:wJ},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 wg("data/characters.json");await iU(JSON.parse(t)),this.loadingPercentage=.2,this.loadingStep="Data",this.loadingPercentage=.3,this.loadingStep="Images",await aU(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:{...yi(xc,["screenWidth","screenHeight","canvasWidth","canvasHeight","topOffset","leftOffset","layoutMode"]),...yi(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(gA)},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=_g(o.choice)}),{title:r!=null?r:"",text:t.text,styleId:t.speaker,choices:t.choices,old:e<this.dialog.length-1,interactive:t.interactive}}}}),xJ=["width","height"],jJ={key:2,id:"game-menu",style:{height:"100%",padding:"20px"}},_J={id:"game-header"},SJ={id:"game-title-container"},CJ={id:"game-title-text"},$J={class:"flex flex-col"},OJ={key:3};function AJ(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,xJ)],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",jJ,[M.createElementVNode("div",_J,[M.createElementVNode("div",SJ,[M.createElementVNode("h1",CJ,M.toDisplayString(t.gameTitle),1)]),M.createElementVNode("div",$J,[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",OJ,[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 EJ=zr(kJ,[["render",AJ]]);let Fo,wi;const ya={x:0,y:0};function MJ(){document.addEventListener("mousemove",t=>{ya.x=t.clientX,ya.y=t.clientY}),document.addEventListener("click",HA(PJ,100,{maxWait:200})),WA()}function WA(){const t=Bi();if(Sn().playing){if(!Fo)Fo=document.querySelector("#background-canvas"),Fo&&!wi&&(wi=Fo.getContext("2d"));else if(Fo&&wi){wi.fillStyle="white",wi.fillRect(0,0,Fo.width,Fo.height);const n=t.currentScreen,r=Rt().screens[n],o=r.background;wi.drawImage($g[o],0,0);let i=!1;const a=BA(ya.x,ya.y,Fo);if(r.buttons){for(const s of r.buttons)if(t.buttons[s].enabled){const l=Rt().buttons[s],c=$g[l.background];wi.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",wi.fillStyle="black",wi.textAlign="left"}}else Fo=void 0,wi=void 0;window.requestAnimationFrame(WA)}function PJ(t){const e=Bi(),n=mt();if(!Fo)return;ya.x=t.clientX,ya.y=t.clientY;const r=BA(ya.x,ya.y,Fo),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
|
-
Error: ${e}`),console.error("============================")}class wt{constructor(e,n,r,o){ki(this,"keyword");ki(this,"runner");ki(this,"argTypes");ki(this,"parser");ki(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 TJ=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()}),IJ=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()}),NJ=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})}),LJ=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()}),RJ=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()}),DJ=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)}),zJ=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()}),BJ=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))}),qJ=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()}),VJ=new wt("return",[{name:"value",type:"any"}],async t=>{const{value:e}=t.options;return mt().setReturnValue(e),mt().nextLine()}),Og=[{name:"mode",type:"string"},{name:"audio",type:"string",optional:!0}],FJ=new wt("play",Og,async t=>{const e=t.options;e.mode==="music"?pd(e.audio):pA(e.audio),mt().nextLine()}),HJ=new wt("pause",Og,async t=>{const e=t.options;if(e.mode==="music"){const n=ao();n.currentMusic&&mA(n.currentMusic)}else e.mode==="sound"&&e.audio?mA(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()}),WJ=new wt("stop",Og,async t=>{const e=t.options;return e.mode==="music"?ao().currentMusic&&ao().stopMusic():e.mode==="sound"&&e.audio?vA(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."),mt().nextLine()}),UJ=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()}),JJ=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()}),GJ=new wt("set_screen",[{name:"screen",type:"string"}],t=>(Bi().setScreen(t.options.screen),mt().nextLine())),KJ=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()}),QJ=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})}),YJ=()=>{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})},YJ());console.log(UA);const XJ=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()}),ZJ=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()}),eG=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)}),tG=new wt("item_amount?",[{name:"id",type:"string"}],async t=>{const{id:e}=t.options;return _r().getItemAmount(e)}),nG=new wt("enable_interaction",[{name:"tag",type:"string"}],async t=>{const e=t.options.tag;return _r().enableInteraction(e),mt().nextLine()}),rG=new wt("disable_interaction",[{name:"tag",type:"string"}],async t=>{const e=t.options.tag;return _r().disableInteraction(e),mt().nextLine()}),oG=new wt("start_quest",[{name:"questId",type:"string"}],async t=>{const e=t.options.questId;return Rr().startQuest(e),mt().nextLine()}),iG=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()}),aG=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()}),sG=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()}),lG=new wt("quest_completed?",[{name:"questId",type:"string"}],async t=>{const{questId:e}=t.options;return Rr().isQuestCompleted(e)}),cG=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)}),uG=new wt("quest_started?",[{name:"questId",type:"string"}],async t=>{const{questId:e}=t.options;return Rr().isQuestStarted(e)}),fG=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)}),dG=new wt("wait",[{name:"duration",type:"number"}],async t=>(await mg(t.options.duration),mt().nextLine())),hG=new wt("notify",[{name:"text",type:"string"}],async t=>{const{text:e}=t.options;return bi().addNotification(e),mt().nextLine()}),pG=new wt("clear_dialog",[],async t=>(so().clearDialog(),mt().nextLine())),vG=new wt("if",[{name:"condition",type:"boolean"}],async t=>{const e=lW(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=cW(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}}),mG=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}),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"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e!=n}),xG=new wt("!",[{name:"a",type:"any"}],async t=>{const{a:e}=t.options;return!e}),jG=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)}),_G=new wt("||","any",async t=>(t.args.length<2&&Qn(t,"requires at least two arguments"),t.args.reduce((e,n)=>e||n,!1))),SG=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}),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=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))),EG=async t=>{mt().lastChoiceCommand=t;const{prompt:e,choices:n}=t.staticOptions,r=[];for(const[i,a]of n.entries()){const s=await Sg(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 MG(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 PG=(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=TG(t.parserContext,l),MG(t,l)));return o.staticOptions={prompt:t.processCommandsFunction(t.parserContext,[i],r)[0],choices:s},n++,{newLine:n}},JA=new wt("choice",[],EG,PG);JA.onPlayerAnswered=async(t,e)=>{const n=e,r=mt(),{choices:o}=t.staticOptions,i=o[n],a=t.options.choiceResults[n];let s=a.text,l;if(a.skillCheck?(s=null,MA({skill:a.skillCheck.skillId,value:a.skillCheck.difficulty,id:a.skillCheck.skillCheckId,hideAfterRoll:a.skillCheck.hideAfterRoll}).succeeded?l=i.skillBranches.success:l=i.skillBranches.failure):l=i.branch,s){const c={speaker:"player",text:s,interactive:!1};so().addDialog(c)}if(l){const c={currentIndex:0,branchData:{branch:l}};return r.addStack(c)}else r.nextLine()};function TG(t,e){return{code:`choicePrompt ${e.code}`,indentation:e.indentation,line:e.line,branch:e.branch,expression:["choicePrompt",...e.expression]}}const IG=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}=oW({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};so().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 NG=new wt("text_field_prompt",[{name:"prompt",type:"string"}],async t=>{const e={speaker:"game",text:t.options.prompt,textField:!0,interactive:!0};so().addDialog(e)});function LG(t){t.addCommand(JA),t.addCommand(IG),t.addCommand(vG),t.addCommand(LJ),t.addCommand(RJ),t.addCommand(DJ),t.addCommand(pG),t.addCommand(hG),t.addCommand(HJ),t.addCommand(FJ),t.addCommand(WJ),t.addCommand(KJ),t.addCommand(GJ),t.addCommand(dG),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(AG),t.addCommand(JJ),t.addCommand(UJ),t.addCommand(UA),t.addCommand(QJ),t.addCommand(zJ),t.addCommand(BJ),t.addCommand(qJ),t.addCommand(VJ),t.addCommand(oG),t.addCommand(iG),t.addCommand(aG),t.addCommand(sG),t.addCommand(uG),t.addCommand(fG),t.addCommand(lG),t.addCommand(cG),t.addCommand(XJ),t.addCommand(ZJ),t.addCommand(nG),t.addCommand(rG),t.addCommand(eG),t.addCommand(tG),t.addCommand(TJ),t.addCommand(IJ),t.addCommand(NJ),t.addCommand(GA),t.addCommand(NG)}let _c;or.callHook("onPageLoaded");async function RG(t,e){const n=await wg("data/config.json");wH(JSON.parse(n)),_c=M.createApp(EJ,{config:t,options:e});const r=xH();if(_c.use(r),Sn().setOptions(e),_c.use(tE,{breakpoints:{s:0,m:800,l:1200}}),LG(or),qg.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}MJ()}class DG{onPageLoaded(){}onNarratSetup(){}onAppMounted(){}onAssetsLoaded(){}onGameSetup(){}onGameStart(){}onGameMounted(){}onGameDismounted(){}}function zG(t){or.addPlugin(t)}function BG(t){or.addCommand(t)}ln.CommandPlugin=wt,ln.NarratPlugin=DG,ln.addCommand=BG,ln.aspectRatioFit=zA,ln.generateParser=jc,ln.getConfig=Rt,ln.registerPlugin=zG,ln.startApp=RG,Object.defineProperties(ln,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
194
|
+
Error: ${e}`),console.error("============================")}class wt{constructor(e,n,r,o){ki(this,"keyword");ki(this,"runner");ki(this,"argTypes");ki(this,"parser");ki(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 TJ=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()}),IJ=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()}),NJ=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}).succeeded}),LJ=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()}),RJ=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()}),DJ=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)}),zJ=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()}),BJ=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))}),qJ=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()}),VJ=new wt("return",[{name:"value",type:"any"}],async t=>{const{value:e}=t.options;return mt().setReturnValue(e),mt().nextLine()}),Og=[{name:"mode",type:"string"},{name:"audio",type:"string",optional:!0}],FJ=new wt("play",Og,async t=>{const e=t.options;e.mode==="music"?pd(e.audio):pA(e.audio),mt().nextLine()}),HJ=new wt("pause",Og,async t=>{const e=t.options;if(e.mode==="music"){const n=ao();n.currentMusic&&mA(n.currentMusic)}else e.mode==="sound"&&e.audio?mA(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()}),WJ=new wt("stop",Og,async t=>{const e=t.options;return e.mode==="music"?ao().currentMusic&&ao().stopMusic():e.mode==="sound"&&e.audio?vA(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."),mt().nextLine()}),UJ=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()}),JJ=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()}),GJ=new wt("set_screen",[{name:"screen",type:"string"}],t=>(Bi().setScreen(t.options.screen),mt().nextLine())),KJ=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()}),QJ=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})}),YJ=()=>{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})},YJ());console.log(UA);const XJ=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()}),ZJ=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()}),eG=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)}),tG=new wt("item_amount?",[{name:"id",type:"string"}],async t=>{const{id:e}=t.options;return _r().getItemAmount(e)}),nG=new wt("enable_interaction",[{name:"tag",type:"string"}],async t=>{const e=t.options.tag;return _r().enableInteraction(e),mt().nextLine()}),rG=new wt("disable_interaction",[{name:"tag",type:"string"}],async t=>{const e=t.options.tag;return _r().disableInteraction(e),mt().nextLine()}),oG=new wt("start_quest",[{name:"questId",type:"string"}],async t=>{const e=t.options.questId;return Rr().startQuest(e),mt().nextLine()}),iG=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()}),aG=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()}),sG=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()}),lG=new wt("quest_completed?",[{name:"questId",type:"string"}],async t=>{const{questId:e}=t.options;return Rr().isQuestCompleted(e)}),cG=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)}),uG=new wt("quest_started?",[{name:"questId",type:"string"}],async t=>{const{questId:e}=t.options;return Rr().isQuestStarted(e)}),fG=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)}),dG=new wt("wait",[{name:"duration",type:"number"}],async t=>(await mg(t.options.duration),mt().nextLine())),hG=new wt("notify",[{name:"text",type:"string"}],async t=>{const{text:e}=t.options;return bi().addNotification(e),mt().nextLine()}),pG=new wt("clear_dialog",[],async t=>(so().clearDialog(),mt().nextLine())),vG=new wt("if",[{name:"condition",type:"boolean"}],async t=>{const e=lW(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=cW(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}}),mG=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}),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"},{name:"b",type:"any"}],async t=>{const{a:e,b:n}=t.options;return e!=n}),xG=new wt("!",[{name:"a",type:"any"}],async t=>{const{a:e}=t.options;return!e}),jG=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)}),_G=new wt("||","any",async t=>(t.args.length<2&&Qn(t,"requires at least two arguments"),t.args.reduce((e,n)=>e||n,!1))),SG=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}),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=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))),EG=async t=>{mt().lastChoiceCommand=t;const{prompt:e,choices:n}=t.staticOptions,r=[];for(const[i,a]of n.entries()){const s=await Sg(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 MG(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 PG=(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=TG(t.parserContext,l),MG(t,l)));return o.staticOptions={prompt:t.processCommandsFunction(t.parserContext,[i],r)[0],choices:s},n++,{newLine:n}},JA=new wt("choice",[],EG,PG);JA.onPlayerAnswered=async(t,e)=>{const n=e,r=mt(),{choices:o}=t.staticOptions,i=o[n],a=t.options.choiceResults[n];let s=a.text,l;if(a.skillCheck?(s=null,MA({skill:a.skillCheck.skillId,value:a.skillCheck.difficulty,id:a.skillCheck.skillCheckId,hideAfterRoll:a.skillCheck.hideAfterRoll}).succeeded?l=i.skillBranches.success:l=i.skillBranches.failure):l=i.branch,s){const c={speaker:"player",text:s,interactive:!1};so().addDialog(c)}if(l){const c={currentIndex:0,branchData:{branch:l}};return r.addStack(c)}else r.nextLine()};function TG(t,e){return{code:`choicePrompt ${e.code}`,indentation:e.indentation,line:e.line,branch:e.branch,expression:["choicePrompt",...e.expression]}}const IG=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}=oW({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};so().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 NG=new wt("text_field_prompt",[{name:"prompt",type:"string"}],async t=>{const e={speaker:"game",text:t.options.prompt,textField:!0,interactive:!0};so().addDialog(e)});function LG(t){t.addCommand(JA),t.addCommand(IG),t.addCommand(vG),t.addCommand(LJ),t.addCommand(RJ),t.addCommand(DJ),t.addCommand(pG),t.addCommand(hG),t.addCommand(HJ),t.addCommand(FJ),t.addCommand(WJ),t.addCommand(KJ),t.addCommand(GJ),t.addCommand(dG),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(AG),t.addCommand(JJ),t.addCommand(UJ),t.addCommand(UA),t.addCommand(QJ),t.addCommand(zJ),t.addCommand(BJ),t.addCommand(qJ),t.addCommand(VJ),t.addCommand(oG),t.addCommand(iG),t.addCommand(aG),t.addCommand(sG),t.addCommand(uG),t.addCommand(fG),t.addCommand(lG),t.addCommand(cG),t.addCommand(XJ),t.addCommand(ZJ),t.addCommand(nG),t.addCommand(rG),t.addCommand(eG),t.addCommand(tG),t.addCommand(TJ),t.addCommand(IJ),t.addCommand(NJ),t.addCommand(GA),t.addCommand(NG)}let _c;or.callHook("onPageLoaded");async function RG(t,e){const n=await wg("data/config.json");wH(JSON.parse(n)),_c=M.createApp(EJ,{config:t,options:e});const r=xH();if(_c.use(r),Sn().setOptions(e),_c.use(tE,{breakpoints:{s:0,m:800,l:1200}}),LG(or),qg.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}MJ()}class DG{onPageLoaded(){}onNarratSetup(){}onAppMounted(){}onAssetsLoaded(){}onGameSetup(){}onGameStart(){}onGameMounted(){}onGameDismounted(){}}function zG(t){or.addPlugin(t)}function BG(t){or.addCommand(t)}ln.CommandPlugin=wt,ln.NarratPlugin=DG,ln.addCommand=BG,ln.aspectRatioFit=zA,ln.generateParser=jc,ln.getConfig=Rt,ln.registerPlugin=zG,ln.startApp=RG,Object.defineProperties(ln,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
195
195
|
//# sourceMappingURL=narrat.umd.js.map
|