narrat 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/narrat.es.js +1 -0
- package/dist/narrat.es.js.map +1 -0
- package/dist/narrat.umd.js +1 -0
- package/dist/narrat.umd.js.map +1 -0
- package/package.json +1 -1
package/dist/narrat.umd.js
CHANGED
|
@@ -192,3 +192,4 @@ return query;
|
|
|
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"}})});
|
|
195
|
+
//# sourceMappingURL=narrat.umd.js.map
|