t2-mapper/docs/assets/mission-yeigCtfF.js

29 lines
107 KiB
JavaScript
Raw Permalink Normal View History

import{r as e,t}from"./chunk-DECur_0Z.js";import{t as n}from"./logger-B058WGzf.js";function r(e){let t=e.indexOf(`::`);return t===-1?null:{namespace:e.slice(0,t),method:e.slice(t+2)}}var i={"+":`$.add`,"-":`$.sub`,"*":`$.mul`,"/":`$.div`,"<":`$.lt`,"<=":`$.le`,">":`$.gt`,">=":`$.ge`,"==":`$.eq`,"!=":`$.ne`,"%":`$.mod`,"&":`$.bitand`,"|":`$.bitor`,"^":`$.bitxor`,"<<":`$.shl`,">>":`$.shr`},a=class{indent;runtime;functions;globals;locals;indentLevel=0;currentClass=null;currentFunction=null;constructor(e={}){this.indent=e.indent??` `,this.runtime=e.runtime??`$`,this.functions=e.functions??`$f`,this.globals=e.globals??`$g`,this.locals=e.locals??`$l`}getAccessInfo(e){if(e.type===`Variable`){let t=JSON.stringify(e.name),n=e.scope===`global`?this.globals:this.locals;return{getter:`${n}.get(${t})`,setter:e=>`${n}.set(${t}, ${e})`,postIncHelper:`${n}.postInc(${t})`,postDecHelper:`${n}.postDec(${t})`}}if(e.type===`MemberExpression`){let t=this.expression(e.object),n=e.property.type===`Identifier`?JSON.stringify(e.property.name):this.expression(e.property);return{getter:`${this.runtime}.prop(${t}, ${n})`,setter:e=>`${this.runtime}.setProp(${t}, ${n}, ${e})`,postIncHelper:`${this.runtime}.propPostInc(${t}, ${n})`,postDecHelper:`${this.runtime}.propPostDec(${t}, ${n})`}}if(e.type===`IndexExpression`){let t=Array.isArray(e.index)?e.index.map(e=>this.expression(e)):[this.expression(e.index)];if(e.object.type===`Variable`){let n=JSON.stringify(e.object.name),r=e.object.scope===`global`?this.globals:this.locals,i=t.join(`, `);return{getter:`${r}.get(${n}, ${i})`,setter:e=>`${r}.set(${n}, ${i}, ${e})`,postIncHelper:`${r}.postInc(${n}, ${i})`,postDecHelper:`${r}.postDec(${n}, ${i})`}}if(e.object.type===`MemberExpression`){let n=e.object,r=this.expression(n.object),i=n.property.type===`Identifier`?JSON.stringify(n.property.name):this.expression(n.property),a=`${this.runtime}.key(${i}, ${t.join(`, `)})`;return{getter:`${this.runtime}.prop(${r}, ${a})`,setter:e=>`${this.runtime}.setProp(${r}, ${a}, ${e})`,postIncHelper:`${this.runtime}.propPostInc(${r}, ${a})`,postDecHelper:`${this.runtime}.propPostDec(${r}, ${a})`}}let n=this.expression(e.object),r=t.length===1?t[0]:`${this.runtime}.key(${t.join(`, `)})`;return{getter:`${this.runtime}.getIndex(${n}, ${r})`,setter:e=>`${this.runtime}.setIndex(${n}, ${r}, ${e})`,postIncHelper:`${this.runtime}.indexPostInc(${n}, ${r})`,postDecHelper:`${this.runtime}.indexPostDec(${n}, ${r})`}}return null}generate(e){let t=[];for(let n of e.body){let e=this.statement(n);e&&t.push(e)}return t.join(`
2026-04-01 14:35:47 -07:00
`)}statement(e){switch(e.type){case`Comment`:return``;case`ExpressionStatement`:return this.line(`${this.expression(e.expression)};`);case`FunctionDeclaration`:return this.functionDeclaration(e);case`PackageDeclaration`:return this.packageDeclaration(e);case`DatablockDeclaration`:return this.datablockDeclaration(e);case`ObjectDeclaration`:return this.line(`${this.objectDeclaration(e)};`);case`IfStatement`:return this.ifStatement(e);case`ForStatement`:return this.forStatement(e);case`WhileStatement`:return this.whileStatement(e);case`DoWhileStatement`:return this.doWhileStatement(e);case`SwitchStatement`:return this.switchStatement(e);case`ReturnStatement`:return this.returnStatement(e);case`BreakStatement`:return this.line(`break;`);case`ContinueStatement`:return this.line(`continue;`);case`BlockStatement`:return this.blockStatement(e);default:throw Error(`Unknown statement type: ${e.type}`)}}functionDeclaration(e){let t=r(e.name.name);if(t){let n=t.namespace,r=t.method;this.currentClass=n.toLowerCase(),this.currentFunction=r.toLowerCase();let i=this.functionBody(e.body,e.params);return this.currentClass=null,this.currentFunction=null,`${this.line(`${this.runtime}.registerMethod(${JSON.stringify(n)}, ${JSON.stringify(r)}, function() {`)}\n${i}\n${this.line(`});`)}`}else{let t=e.name.name;this.currentFunction=t.toLowerCase();let n=this.functionBody(e.body,e.params);return this.currentFunction=null,`${this.line(`${this.runtime}.registerFunction(${JSON.stringify(t)}, function() {`)}\n${n}\n${this.line(`});`)}`}}functionBody(e,t){this.indentLevel++;let n=[];n.push(this.line(`const ${this.locals} = ${this.runtime}.locals();`));for(let e=0;e<t.length;e++)n.push(this.line(`${this.locals}.set(${JSON.stringify(t[e].name)}, arguments[${e}]);`));for(let t of e.body)n.push(this.statement(t));return this.indentLevel--,n.join(`
`)}packageDeclaration(e){let t=JSON.stringify(e.name.name);this.indentLevel++;let n=e.body.map(e=>this.statement(e)).join(`
`);return this.indentLevel--,`${this.line(`${this.runtime}.package(${t}, function() {`)}\n${n}\n${this.line(`});`)}`}datablockDeclaration(e){let t=JSON.stringify(e.className.name),n=e.instanceName?JSON.stringify(e.instanceName.name):`null`,r=e.parent?JSON.stringify(e.parent.name):`null`,i=this.objectBody(e.body);return this.line(`${this.runtime}.datablock(${t}, ${n}, ${r}, ${i});`)}objectDeclaration(e){let t=e.className.type===`Identifier`?JSON.stringify(e.className.name):this.expression(e.className),n=e.instanceName===null?`null`:e.instanceName.type===`Identifier`?JSON.stringify(e.instanceName.name):this.expression(e.instanceName),r=[],i=[];for(let t of e.body)t.type===`Assignment`?r.push(t):i.push(t);let a=this.objectBody(r);if(i.length>0){let e=i.map(e=>this.objectDeclaration(e)).join(`,
`);return`${this.runtime}.create(${t}, ${n}, ${a}, [\n${e}\n])`}return`${this.runtime}.create(${t}, ${n}, ${a})`}objectBody(e){if(e.length===0)return`{}`;let t=[];for(let n of e)if(n.type===`Assignment`){let e=this.expression(n.value);if(n.target.type===`Identifier`){let r=n.target.name;/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)?t.push(`${r}: ${e}`):t.push(`[${JSON.stringify(r)}]: ${e}`)}else if(n.target.type===`IndexExpression`){let r=this.objectPropertyKey(n.target);t.push(`[${r}]: ${e}`)}else{let r=this.expression(n.target);t.push(`[${r}]: ${e}`)}}if(t.length<=1)return`{ ${t.join(`, `)} }`;let n=this.indent.repeat(this.indentLevel+1),r=this.indent.repeat(this.indentLevel);return`{\n${n}${t.join(`,
`+n)}\n${r}}`}objectPropertyKey(e){let t=e.object.type===`Identifier`?JSON.stringify(e.object.name):this.expression(e.object),n=Array.isArray(e.index)?e.index.map(e=>this.expression(e)).join(`, `):this.expression(e.index);return`${this.runtime}.key(${t}, ${n})`}ifStatement(e){let t=this.expression(e.test),n=this.statementAsBlock(e.consequent);if(e.alternate)if(e.alternate.type===`IfStatement`){let r=this.ifStatement(e.alternate).replace(/^\s*/,``);return this.line(`if (${t}) ${n} else ${r}`)}else{let r=this.statementAsBlock(e.alternate);return this.line(`if (${t}) ${n} else ${r}`)}return this.line(`if (${t}) ${n}`)}forStatement(e){let t=e.init?this.expression(e.init):``,n=e.test?this.expression(e.test):``,r=e.update?this.expression(e.update):``,i=this.statementAsBlock(e.body);return this.line(`for (${t}; ${n}; ${r}) ${i}`)}whileStatement(e){let t=this.expression(e.test),n=this.statementAsBlock(e.body);return this.line(`while (${t}) ${n}`)}doWhileStatement(e){let t=this.statementAsBlock(e.body),n=this.expression(e.test);return this.line(`do ${t} while (${n});`)}switchStatement(e){if(e.stringMode)return this.switchStringStatement(e);let t=this.expression(e.discriminant);this.indentLevel++;let n=[];for(let t of e.cases)n.push(this.switchCase(t));return this.indentLevel--,`${this.line(`switch (${t}) {`)}\n${n.join(`
`)}\n${this.line(`}`)}`}switchCase(e){let t=[];if(e.test===null)t.push(this.line(`default:`));else if(Array.isArray(e.test))for(let n of e.test)t.push(this.line(`case ${this.expression(n)}:`));else t.push(this.line(`case ${this.expression(e.test)}:`));this.indentLevel++;for(let n of e.consequent)t.push(this.statement(n));return t.push(this.line(`break;`)),this.indentLevel--,t.join(`
`)}switchStringStatement(e){let t=this.expression(e.discriminant),n=[];for(let t of e.cases)if(t.test===null)n.push(`default: () => { ${this.blockContent(t.consequent)} }`);else if(Array.isArray(t.test))for(let e of t.test)n.push(`${this.expression(e)}: () => { ${this.blockContent(t.consequent)} }`);else n.push(`${this.expression(t.test)}: () => { ${this.blockContent(t.consequent)} }`);return this.line(`${this.runtime}.switchStr(${t}, { ${n.join(`, `)} });`)}returnStatement(e){return e.value?this.line(`return ${this.expression(e.value)};`):this.line(`return;`)}blockStatement(e){this.indentLevel++;let t=e.body.map(e=>this.statement(e)).join(`
`);return this.indentLevel--,`{\n${t}\n${this.line(`}`)}`}statementAsBlock(e){if(e.type===`BlockStatement`)return this.blockStatement(e);this.indentLevel++;let t=this.statement(e);return this.indentLevel--,`{\n${t}\n${this.line(`}`)}`}blockContent(e){return e.map(e=>this.statement(e).trim()).join(` `)}expression(e){switch(e.type){case`Identifier`:return this.identifier(e);case`Variable`:return this.variable(e);case`NumberLiteral`:return String(e.value);case`StringLiteral`:return JSON.stringify(e.value);case`BooleanLiteral`:return String(e.value);case`BinaryExpression`:return this.binaryExpression(e);case`UnaryExpression`:return this.unaryExpression(e);case`PostfixExpression`:return this.postfixExpression(e);case`AssignmentExpression`:return this.assignmentExpression(e);case`ConditionalExpression`:return`(${this.expression(e.test)} ? ${this.expression(e.consequent)} : ${this.expression(e.alternate)})`;case`CallExpression`:return this.callExpression(e);case`MemberExpression`:return this.memberExpression(e);case`IndexExpression`:return this.indexExpression(e);case`TagDereferenceExpression`:return`${this.runtime}.deref(${this.expression(e.argument)})`;case`ObjectDeclaration`:return this.objectDeclaration(e);case`DatablockDeclaration`:return`${this.runtime}.datablock(${JSON.stringify(e.className.name)}, ${e.instanceName?JSON.stringify(e.instanceName.name):`null`}, ${e.parent?JSON.stringify(e.parent.name):`null`}, ${this.objectBody(e.body)})`;default:throw Error(`Unknown expression type: ${e.type}`)}}identifier(e){let t=r(e.name);return t&&t.namespace.toLowerCase()===`parent`?e.name:t?`${this.runtime}.nsRef(${JSON.stringify(t.namespace)}, ${JSON.stringify(t.method)})`:JSON.stringify(e.name)}variable(e){return e.scope===`global`?`${this.globals}.get(${JSON.stringify(e.name)})`:`${this.locals}.get(${JSON.stringify(e.name)})`}binaryExpression(e){let t=this.expression(e.left),n=this.expression(e.right),r=e.operator,a=this.concatExpression(t,r,n);if(a)return a;if(r===`$=`)return`${this.runtime}.streq(${t}, ${n})`;if(r===`!$=`)return`!${this.runtime}.streq(${t}, ${n})`;if(r===`&&`||r===`||`)return`(${t} ${r} ${n})`;let o=i[r];return o?`${o}(${t}, ${n})`:`(${t} ${r} ${n})`}unaryExpression(e){if(e.operator===`++`||e.operator===`--`){let t=this.getAccessInfo(e.argument);if(t){let n=e.operator===`++`?1:-1;return t.setter(`${this.runtime}.add(${t.getter}, ${n})`)}}let t=this.expression(e.argument);return e.operator===`~`?`${this.runtime}.bitnot(${t})`:e.operator===`-`?`${this.runtime}.neg(${t})`:`${e.operator}${t}`}postfixExpression(e){let t=this.getAccessInfo(e.argument);if(t){let n=e.operator===`++`?t.postIncHelper:t.postDecHelper;if(n)return n}return`${this.expression(e.argument)}${e.operator}`}assignmentExpression(e){let t=this.expression(e.value),n=e.operator,r=this.getAccessInfo(e.target);if(!r)throw Error(`Unhandled assignment target type: ${e.target.type}`);if(n===`=`)return r.setter(t);{let e=n.slice(0,-1),i=this.compoundAssignmentValue(r.getter,e,t);return r.setter(i)}}callExpression(e){let t=e.arguments.map(e=>this.expression(e)).join(`, `);if(e.callee.type===`Identifier`){let n=e.callee.name,i=r(n);if(i&&i.namespace.toLowerCase()===`parent`){if(this.currentClass)return`${this.runtime}.parent(${JSON.stringify(this.currentClass)}, ${JSON.stringify(i.method)}, arguments[0]${t?`, `+t:``})`;if(this.currentFunction)return`${this.runtime}.parentFunc(${JSON.stringify(this.currentFunction)}${t?`, `+t:``})`;throw Error(`Parent:: call outside of function context`)}return i?`${this.runtime}.nsCall(${JSON.stringify(i.namespace)}, ${JSON.stringify(i.method)}${t?`, `+t:``})`:`${this.functions}.call(${JSON.stringify(n)}${t?`, `+t:``})`}if(e.callee.type===`MemberExpression`){let n=this.expression(e.callee.object),r=e.callee.property.type===`Identifier`?JSON.stringify(e.callee.property.name):this.expression(e.callee.property);return`${this.runtime}.call(${n}, ${r}${t?`, `+t:``})`}return`${this.expression(e.callee)}(${t})`}memberExpression(e){let t=this.expression(e.object);return e.computed||e.property.type!==`Identifier`?`${this.runtime}.pro
--> `+o+`
`+r+` |
`+a.line+` | `+s+`
`+r+` | `+``.padEnd(i.column-1,` `)+``.padEnd(c,`^`)}else t+=`
at `+o}return t}static buildMessage(e,t){function n(e){return e.codePointAt(0).toString(16).toUpperCase()}let r=Object.prototype.hasOwnProperty.call(RegExp.prototype,`unicode`)?RegExp(`[\\p{C}\\p{Mn}\\p{Mc}]`,`gu`):null;function i(e){return r?e.replace(r,e=>`\\u{`+n(e)+`}`):e}function a(e){return i(e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\0/g,`\\0`).replace(/\t/g,`\\t`).replace(/\n/g,`\\n`).replace(/\r/g,`\\r`).replace(/[\x00-\x0F]/g,e=>`\\x0`+n(e)).replace(/[\x10-\x1F\x7F-\x9F]/g,e=>`\\x`+n(e)))}function o(e){return i(e.replace(/\\/g,`\\\\`).replace(/\]/g,`\\]`).replace(/\^/g,`\\^`).replace(/-/g,`\\-`).replace(/\0/g,`\\0`).replace(/\t/g,`\\t`).replace(/\n/g,`\\n`).replace(/\r/g,`\\r`).replace(/[\x00-\x0F]/g,e=>`\\x0`+n(e)).replace(/[\x10-\x1F\x7F-\x9F]/g,e=>`\\x`+n(e)))}let s={literal(e){return`"`+a(e.text)+`"`},class(e){let t=e.parts.map(e=>Array.isArray(e)?o(e[0])+`-`+o(e[1]):o(e));return`[`+(e.inverted?`^`:``)+t.join(``)+`]`+(e.unicode?`u`:``)},any(){return`any character`},end(){return`end of input`},other(e){return e.description}};function c(e){return s[e.type](e)}function l(e){let t=e.map(c);if(t.sort(),t.length>0){let e=1;for(let n=1;n<t.length;n++)t[n-1]!==t[n]&&(t[e]=t[n],e++);t.length=e}switch(t.length){case 1:return t[0];case 2:return t[0]+` or `+t[1];default:return t.slice(0,-1).join(`, `)+`, or `+t[t.length-1]}}function u(e){return e?`"`+a(e)+`"`:`end of input`}return`Expected `+l(e)+` but `+u(t)+` found.`}};function m(e,t){t=t===void 0?{}:t;let n={},r=t.grammarSource,i={Program:Cr},a=Cr,o=`package`,m=`function`,h=`datablock`,g=`else`,_=`while`,v=`switch$`,ee=`switch`,te=`case`,ne=`default`,y=`return`,re=`break`,b=`continue`,x=`parent`,S=`true`,C=`false`,w=/^[<>]/,T=/^[+\-]/,ie=/^[%*\/]/,ae=/^[!\-~]/,E=/^[a-zA-Z_]/,D=/^[a-zA-Z0-9_]/,oe=/^[ \t]/,se=/^[^"\\\n\r]/,O=/^[^'\\\n\r]/,k=/^[0-9a-fA-F]/,A=/^[0-9]/,j=/^[xX]/,M=/^[^\n\r]/,N=/^[\n\r]/,P=/^[ \t\n\r]/,F=Y(`;`,!1),I=Y(`package`,!1),L=Y(`{`,!1),R=Y(`}`,!1),z=Y(`function`,!1),B=Y(`(`,!1),V=Y(`)`,!1),H=Y(`::`,!1),ce=Y(`,`,!1),U=Y(`datablock`,!1),le=Y(`:`,!1),ue=Y(`new`,!1),de=Y(`[`,!1),fe=Y(`]`,!1),W=Y(`=`,!1),pe=Y(`.`,!1),me=Y(`if`,!1),he=Y(`else`,!1),ge=Y(`for`,!1),_e=Y(`while`,!1),ve=Y(`do`,!1),ye=Y(`switch$`,!1),be=Y(`switch`,!1),xe=Y(`case`,!1),Se=Y(`default`,!1),Ce=Y(`or`,!1),we=Y(`return`,!1),Te=Y(`break`,!1),Ee=Y(`continue`,!1),De=Y(`+=`,!1),Oe=Y(`-=`,!1),ke=Y(`*=`,!1),Ae=Y(`/=`,!1),je=Y(`%=`,!1),Me=Y(`<<=`,!1),Ne=Y(`>>=`,!1),Pe=Y(`&=`,!1),Fe=Y(`|=`,!1),Ie=Y(`^=`,!1),Le=Y(`?`,!1),Re=Y(`||`,!1),ze=Y(`&&`,!1),Be=Y(`|`,!1),Ve=Y(`^`,!1),He=Y(`&`,!1),Ue=Y(`==`,!1),We=Y(`!=`,!1),Ge=Y(`<=`,!1),Ke=Y(`>=`,!1),qe=_r([`<`,`>`],!1,!1,!1),Je=Y(`$=`,!1),Ye=Y(`!$=`,!1),Xe=Y(`@`,!1),Ze=Y(`NL`,!1),G=Y(`TAB`,!1),Qe=Y(`SPC`,!1),$e=Y(`<<`,!1),et=Y(`>>`,!1),tt=_r([`+`,`-`],!1,!1,!1),nt=_r([`%`,`*`,`/`],!1,!1,!1),rt=_r([`!`,`-`,`~`],!1,!1,!1),it=Y(`++`,!1),at=Y(`--`,!1),ot=Y(`*`,!1),st=Y(`%`,!1),ct=_r([[`a`,`z`],[`A`,`Z`],`_`],!1,!1,!1),K=_r([[`a`,`z`],[`A`,`Z`],[`0`,`9`],`_`],!1,!1,!1),lt=Y(`$`,!1),ut=Y(`parent`,!1),dt=_r([` `,` `],!1,!1,!1),ft=Y(`"`,!1),pt=Y(`'`,!1),mt=Y(`\\`,!1),ht=_r([`"`,`\\`,`
`,`\r`],!0,!1,!1),gt=_r([`'`,`\\`,`
`,`\r`],!0,!1,!1),_t=Y(`n`,!1),vt=Y(`r`,!1),yt=Y(`t`,!1),bt=Y(`x`,!1),xt=_r([[`0`,`9`],[`a`,`f`],[`A`,`F`]],!1,!1,!1),St=Y(`cr`,!1),Ct=Y(`cp`,!1),wt=Y(`co`,!1),Tt=Y(`c`,!1),Et=_r([[`0`,`9`]],!1,!1,!1),Dt=vr(),Ot=Y(`0`,!1),kt=_r([`x`,`X`],!1,!1,!1),At=Y(`-`,!1),jt=Y(`true`,!1),Mt=Y(`false`,!1),Nt=Y(`//`,!1),Pt=_r([`
`,`\r`],!0,!1,!1),Ft=_r([`
`,`\r`],!1,!1,!1),It=Y(`/*`,!1),Lt=Y(`*/`,!1),Rt=_r([` `,` `,`
`,`\r`],!1,!1,!1);function zt(e){return{type:`Program`,body:e.map(([e])=>e).filter(Boolean),execScriptPaths:f(),hasDynamicExec:c}}function Bt(){return null}function Vt(e){return e}function Ht(e){return e}function Ut(e,t){return{type:`PackageDeclaration`,name:e,body:t.map(([e])=>e).filter(Boolean)}}function Wt(e,t,n){return{type:`FunctionDeclaration`,name:e,params:t||[],body:n}}function Gt(e,t){return{type:`MethodName`,namespace:e,method:t}}function Kt(e,t){return[e,...t.map(([,,,e])=>e)]}function qt(e,t,n,r){return{type:`DatablockDeclaration`,className:e,instanceName:t,parent:n?n[2]:null,body:r?r[2].filter(Boolean):[]}}function Jt(e,t,n){return{type:`ObjectDeclaration`,className:e,instanceName:t,body:n?n[2].filter(Boolean):[]}}function Yt(e){return e}function Xt(e,t){return t.reduce((e,[,,,t])=>({type:`IndexExpression`,object:e,index:t}),e)}function Zt(e){return e}function Qt(e){return e}function $t(e,t){return{type:`Assignment`,target:e,value:t}}function en(e,t){return t.reduce((e,t)=>t.type===`property`?{type:`MemberExpression`,object:e,property:t.value}:{type:`IndexExpression`,object:e,index:t.value},e)}function tn(e){return{type:`property`,value:e}}function nn(e){return{type:`index`,value:e}}function rn(e,t){return t.length>0?[e,...t.map(([,,,e])=>e)]:e}function an(e,t,n){return{type:`IfStatement`,test:e,consequent:t,alternate:n?n[3]:null}}function on(e,t,n,r){return{type:`ForStatement`,init:e,test:t,update:n,body:r}}function sn(e,t){return{type:`WhileStatement`,test:e,body:t}}function cn(e,t){return{type:`DoWhileStatement`,test:t,body:e}}function ln(e,t){return{type:`SwitchStatement`,stringMode:!0,discriminant:e,cases:t.map(([e])=>e).filter(e=>e&&e.type===`SwitchCase`)}}function un(e,t){return{type:`SwitchStatement`,stringMode:!1,discriminant:e,cases:t.map(([e])=>e).filter(e=>e&&e.type===`SwitchCase`)}}function dn(e,t){return{type:`SwitchCase`,test:e,consequent:t.map(([e])=>e).filter(Boolean)}}function fn(e){return{type:`SwitchCase`,test:null,consequent:e.map(([e])=>e).filter(Boolean)}}function pn(e,t){return t.length>0?[e,...t.map(([,,,e])=>e)]:e}function mn(e){return{type:`ReturnStatement`,value:e?e[1]:null}}function hn(){return{type:`BreakStatement`}}function gn(){return{type:`ContinueStatement`}}function _n(e){return{type:`ExpressionStatement`,expression:e}}function vn(e){return{type:`BlockStatement`,body:e.map(([e])=>e).filter(Boolean)}}function yn(e,t,n){return{type:`AssignmentExpression`,operator:t,target:e,value:n}}function bn(e,t,n){return{type:`ConditionalExpression`,test:e,consequent:t,alternate:n}}function xn(e,t){return l(e,t.map(([,e,,t])=>[e,t]))}function Sn(e,t){return l(e,t.map(([,e,,t])=>[e,t]))}function Cn(e,t){return l(e,t.map(([,e,,,t])=>[e,t]))}function wn(e,t){return l(e,t.map(([,e,,t])=>[e,t]))}function Tn(e,t){return l(e,t.map(([,e,,,t])=>[e,t]))}function En(e,t){return l(e,t.map(([,e,,t])=>[e,t]))}function Dn(e,t){return l(e,t.map(([,e,,t])=>[e,t]))}function On(e,t){return l(e,t.map(([,e,,t])=>[e,t]))}function kn(e,t,n){return{type:`AssignmentExpression`,operator:t,target:e,value:n}}function An(e,t){return l(e,t.map(([,e,,t])=>[e,t]))}function jn(e,t){return l(e,t.map(([,e,,t])=>[e,t]))}function Mn(e,t){return l(e,t.map(([,e,,t])=>[e,t]))}function Nn(e,t){return u(e,t)}function Pn(e,t){return u(e,t)}function Fn(e){return{type:`TagDereferenceExpression`,argument:e}}function In(e,t,n){return{type:`AssignmentExpression`,operator:t,target:e,value:n}}function Ln(e,t){return{type:`PostfixExpression`,operator:t,argument:e}}function Rn(e,t){return t.reduce((e,t)=>{if(t[1]===`(`){let[,,,n]=t;return d(e,n||[])}let n=t[1];return n.type===`property`?{type:`MemberExpression`,object:e,property:n.value}:{type:`IndexExpression`,object:e,index:n.value}},e)}function zn(e,t){return t.reduce((e,[,t])=>t.type===`property`?{type:`MemberExpression`,object:e,property:t.value}:{type:`IndexExpression`,object:e,index:t.value},e)}function Bn(e,t){return[e,...t.map(([,,,e])=>e)]}function Vn(e){return e}function Hn(e){return{type:`Variable`,scope:`local`,name:e}}function Un(e){return{type:`Variable`,scope:`global`,name
`}function Qn(){return`\r`}function $n(){return` `}function er(e){return String.fromCharCode(parseInt(e,16))}function tr(){return``}function nr(){return``}function rr(){return``}function ir(e){return String.fromCharCode([2,3,4,5,6,7,8,11,12,14][parseInt(e,10)])}function ar(e){return e}function or(e){return{type:`NumberLiteral`,value:parseInt(e,16)}}function sr(e){return{type:`NumberLiteral`,value:parseFloat(e)}}function cr(e){return{type:`BooleanLiteral`,value:e===`true`}}function lr(e){return{type:`Comment`,value:e}}function ur(e){return{type:`Comment`,value:e}}function dr(){return null}let q=t.peg$currPos|0,fr=[{line:1,column:1}],pr=q,mr=t.peg$maxFailExpected||[],J=t.peg$silentFails|0,hr;if(t.startRule){if(!(t.startRule in i))throw Error(`Can't start parsing from rule "`+t.startRule+`".`);a=i[t.startRule]}function gr(t=q){let n=e.codePointAt(t);return n===void 0?``:String.fromCodePoint(n)}function Y(e,t){return{type:`literal`,text:e,ignoreCase:t}}function _r(e,t,n,r){return{type:`class`,parts:e,inverted:t,ignoreCase:n,unicode:r}}function vr(){return{type:`any`}}function yr(){return{type:`end`}}function br(t){let n=fr[t],r;if(n)return n;if(t>=fr.length)r=fr.length-1;else for(r=t;!fr[--r];);for(n=fr[r],n={line:n.line,column:n.column};r<t;)e.charCodeAt(r)===10?(n.line++,n.column=1):n.column++,r++;return fr[t]=n,n}function xr(e,t,n){let i=br(e),a=br(t),o={source:r,start:{offset:e,line:i.line,column:i.column},end:{offset:t,line:a.line,column:a.column}};return n&&r&&typeof r.offset==`function`&&(o.start=r.offset(o.start),o.end=r.offset(o.end)),o}function X(e){q<pr||(q>pr&&(pr=q,mr=[]),mr.push(e))}function Sr(e,t,n){return new p(p.buildMessage(e,t),e,t,n)}function Cr(){let e,t,r,i,a;for(e=q,$(),t=[],r=q,i=Fi(),i===n&&(i=wr()),i===n?(q=r,r=n):(a=$(),i=[i,a],r=i);r!==n;)t.push(r),r=q,i=Fi(),i===n&&(i=wr()),i===n?(q=r,r=n):(a=$(),i=[i,a],r=i);return e=zt(t),e}function wr(){let t,r;return t=Dr(),t===n&&(t=Or(),t===n&&(t=Tr(),t===n&&(t=Er(),t===n&&(t=Br(),t===n&&(t=Vr(),t===n&&(t=Ur(),t===n&&(t=Hr(),t===n&&(t=Wr(),t===n&&(t=qr(),t===n&&(t=Jr(),t===n&&(t=Yr(),t===n&&(t=Xr(),t===n&&(t=Zr(),t===n&&(t=Fi(),t===n&&(t=q,Q(),e.charCodeAt(q)===59?(r=`;`,q++):(r=n,J===0&&X(F)),r===n?(q=t,t=n):(Q(),t=Bt())))))))))))))))),t}function Tr(){let t,r,i;return t=q,r=jr(),r===n?(q=t,t=n):(Q(),e.charCodeAt(q)===59?(i=`;`,q++):(i=n,J===0&&X(F)),i===n&&(i=null),Q(),t=Vt(r)),t}function Er(){let t,r,i;return t=q,r=Mr(),r===n?(q=t,t=n):(Q(),e.charCodeAt(q)===59?(i=`;`,q++):(i=n,J===0&&X(F)),i===n&&(i=null),Q(),t=Ht(r)),t}function Dr(){let t,r,i,a,s,c,l,u,d;if(t=q,e.substr(q,7)===o?(r=o,q+=7):(r=n,J===0&&X(I)),r!==n)if(i=zi(),i!==n)if(a=Oi(),a!==n)if(Q(),e.charCodeAt(q)===123?(s=`{`,q++):(s=n,J===0&&X(L)),s!==n){for($(),c=[],l=q,u=Fi(),u===n&&(u=wr()),u===n?(q=l,l=n):(d=$(),u=[u,d],l=u);l!==n;)c.push(l),l=q,u=Fi(),u===n&&(u=wr()),u===n?(q=l,l=n):(d=$(),u=[u,d],l=u);e.charCodeAt(q)===125?(l=`}`,q++):(l=n,J===0&&X(R)),l===n?(q=t,t=n):(u=Q(),e.charCodeAt(q)===59?(d=`;`,q++):(d=n,J===0&&X(F)),d===n&&(d=null),t=Ut(a,c))}else q=t,t=n;else q=t,t=n;else q=t,t=n;else q=t,t=n;return t}function Or(){let t,r,i,a,o,s,c,l;return t=q,e.substr(q,8)===m?(r=m,q+=8):(r=n,J===0&&X(z)),r===n?(q=t,t=n):(i=zi(),i===n?(q=t,t=n):(a=kr(),a===n?(q=t,t=n):(Q(),e.charCodeAt(q)===40?(o=`(`,q++):(o=n,J===0&&X(B)),o===n?(q=t,t=n):(Q(),s=Ar(),s===n&&(s=null),Q(),e.charCodeAt(q)===41?(c=`)`,q++):(c=n,J===0&&X(V)),c===n?(q=t,t=n):(Q(),l=Zr(),l===n?(q=t,t=n):t=Wt(a,s,l)))))),t}function kr(){let t,r,i,a;return t=q,r=Oi(),r===n?(q=t,t=n):(e.substr(q,2)===`::`?(i=`::`,q+=2):(i=n,J===0&&X(H)),i===n?(q=t,t=n):(a=Oi(),a===n?(q=t,t=n):t=Gt(r,a))),t===n&&(t=Oi()),t}function Ar(){let t,r,i,a,o,s,c,l;if(t=q,r=Oi(),r!==n){for(i=[],a=q,o=Q(),e.charCodeAt(q)===44?(s=`,`,q++):(s=n,J===0&&X(ce)),s===n?(q=a,a=n):(c=Q(),l=Oi(),l===n?(q=a,a=n):(o=[o,s,c,l],a=o));a!==n;)i.push(a),a=q,o=Q(),e.charCodeAt(q)===44?(s=`,`,q++):(s=n,J===0&&X(ce)),s===n?(q=a,a=n):(c=Q(),l=Oi(),l===n?(q=a,a=n):(o=[o,s,c,l],a=o));t=Kt(r,i)}else q=t,t=n;return t}function jr(){let t,r,i,a,o,s,c,l,u,d,f,p,m,g,_,v;if(t=q,e.substr(q,9)
`,ie=`
`,ae=`
`,E=` `;function D(e,t,n){let r=0;for(;t+r<e.length&&!n.includes(e[t+r]);)r++;return r}function oe(e,t,n){let r=0;for(;t>0;){if(r>=e.length)return``;let i=D(e,r,n);if(r+i>=e.length)return``;r+=i+1,t--}let i=D(e,r,n);return i===0?``:e.substring(r,r+i)}function se(e,t,n,r){let i=0,a=t;for(;a>0;){if(i>=e.length)return``;let t=D(e,i,r);if(i+t>=e.length)return``;i+=t+1,a--}let o=i,s=n-t+1;for(;s>0;){let t=D(e,i,r);if(i+=t,i>=e.length)break;i++,s--}let c=i;return c>o&&r.includes(e[c-1])&&c--,e.substring(o,c)}function O(e,t){if(e===``)return 0;let n=0;for(let r=0;r<e.length;r++)t.includes(e[r])&&n++;return n+1}function k(e,t,n,r,i){let a=[],o=0,s=0;for(;o<e.length||s<=t;){if(o<e.length){let i=D(e,o,r);s===t?a.push(n):a.push(e.substring(o,o+i)),o+=i,o<e.length&&o++}else s===t?a.push(n):a.push(``);if(s++,s>t&&o>=e.length)break}return a.join(i)}function A(e,t,n,r){let i=[],a=0,o=0;for(;a<e.length;){let r=D(e,a,n);o!==t&&i.push(e.substring(a,a+r)),a+=r,a<e.length&&a++,o++}return i.join(r)}function j(e){let{runtime:t,fileSystem:n}=e,r=[],i=0,a=``;return{echo(...e){console.log(...e.map(S))},warn(...e){console.warn(...e.map(S))},error(...e){console.error(...e.map(S))},call(e,...n){return t().$f.call(S(e),...n)},eval(e){throw Error(`eval() not implemented: requires runtime parsing and execution`)},collapseescape(e){return S(e).replace(/\\([ntr\\])/g,(e,t)=>t===`n`?`
`:t===`t`?` `:t===`r`?`\r`:`\\`)},expandescape(e){return S(e).replace(/\\/g,`\\\\`).replace(/\n/g,`\\n`).replace(/\t/g,`\\t`).replace(/\r/g,`\\r`)},export(e,t,n){console.warn(`export(${e}): not implemented`)},quit(){console.warn(`quit(): not implemented in browser`)},trace(e){},isobject(e){return t().$.isObject(e)},nametoid(e){return t().$.nameToId(e)},strlen(e){return S(e).length},strchr(e,t){let n=S(e),r=S(t)[0]??``,i=n.indexOf(r);return i>=0?n.substring(i):``},strpos(e,t,n){return S(e).indexOf(S(t),C(n))},strcmp(e,t){let n=S(e),r=S(t);return n<r?-1:n>r?1:0},stricmp(e,t){let n=S(e).toLowerCase(),r=S(t).toLowerCase();return n<r?-1:n>r?1:0},strstr(e,t){return S(e).indexOf(S(t))},getsubstr(e,t,n){let r=S(e),i=C(t);return n===void 0?r.substring(i):r.substring(i,i+C(n))},getword(e,t){return oe(S(e),C(t),T)},getwordcount(e){return O(S(e),T)},getfield(e,t){return oe(S(e),C(t),ie)},getfieldcount(e){return O(S(e),ie)},setword(e,t,n){return k(S(e),C(t),S(n),T,` `)},setfield(e,t,n){return k(S(e),C(t),S(n),ie,E)},firstword(e){return oe(S(e),0,T)},restwords(e){return se(S(e),1,1e6,T)},trim(e){return S(e).trim()},ltrim(e){return S(e).replace(/^\s+/,``)},rtrim(e){return S(e).replace(/\s+$/,``)},strupr(e){return S(e).toUpperCase()},strlwr(e){return S(e).toLowerCase()},strreplace(e,t,n){return S(e).split(S(t)).join(S(n))},filterstring(e,t){return S(e)},stripchars(e,t){let n=S(e),r=new Set(S(t).split(``));return n.split(``).filter(e=>!r.has(e)).join(``)},getfields(e,t,n){let r=n===void 0?1e6:Number(n);return se(S(e),C(t),r,ie)},getwords(e,t,n){let r=n===void 0?1e6:Number(n);return se(S(e),C(t),r,T)},removeword(e,t){return A(S(e),C(t),T,` `)},removefield(e,t){return A(S(e),C(t),ie,E)},getrecord(e,t){return oe(S(e),C(t),ae)},getrecordcount(e){return O(S(e),ae)},setrecord(e,t,n){return k(S(e),C(t),S(n),ae,`
`)},removerecord(e,t){return A(S(e),C(t),ae,`
`)},nexttoken(e,t,n){throw Error(`nextToken() is not implemented: it requires variable mutation`)},strtoplayername(e){return S(e).replace(/[^\w\s-]/g,``).trim()},mabs(e){return Math.abs(C(e))},mfloor(e){return Math.floor(C(e))},mceil(e){return Math.ceil(C(e))},msqrt(e){return Math.sqrt(C(e))},mpow(e,t){return C(e)**+C(t)},msin(e){return Math.sin(C(e))},mcos(e){return Math.cos(C(e))},mtan(e){return Math.tan(C(e))},masin(e){return Math.asin(C(e))},macos(e){return Math.acos(C(e))},matan(e,t){return Math.atan2(C(e),C(t))},mlog(e){return Math.log(C(e))},getrandom(e,t){if(e===void 0)return Math.random();if(t===void 0)return Math.floor(Math.random()*(C(e)+1));let n=C(e),r=C(t);return Math.floor(Math.random()*(r-n+1))+n},mdegtorad(e){return C(e)*(Math.PI/180)},mradtodeg(e){return C(e)*(180/Math.PI)},mfloatlength(e,t){return C(e).toFixed(C(t))},getboxcenter(e){let t=S(e).split(` `).map(Number),n=t[0]||0,r=t[1]||0,i=t[2]||0,a=t[3]||0,o=t[4]||0,s=t[5]||0;return`${(n+a)/2} ${(r+o)/2} ${(i+s)/2}`},vectoradd(e,t){let[n,r,i]=w(e),[a,o,s]=w(t);return`${n+a} ${r+o} ${i+s}`},vectorsub(e,t){let[n,r,i]=w(e),[a,o,s]=w(t);return`${n-a} ${r-o} ${i-s}`},vectorscale(e,t){let[n,r,i]=w(e),a=C(t);return`${n*a} ${r*a} ${i*a}`},vectordot(e,t){let[n,r,i]=w(e),[a,o,s]=w(t);return n*a+r*o+i*s},vectorcross(e,t){let[n,r,i]=w(e),[a,o,s]=w(t);return`${r*s-i*o} ${i*a-n*s} ${n*o-r*a}`},vectorlen(e){let[t,n,r]=w(e);return Math.sqrt(t*t+n*n+r*r)},vectornormalize(e){let[t,n,r]=w(e),i=Math.sqrt(t*t+n*n+r*r);return i===0?`0 0 0`:`${t/i} ${n/i} ${r/i}`},vectordist(e,t){let[n,r,i]=w(e),[a,o,s]=w(t),c=n-a,l=r-o,u=i-s;return Math.sqrt(c*c+l*l+u*u)},matrixcreate(e,t){throw Error(`MatrixCreate() not implemented: requires axis-angle rotation math`)},matrixcreatefromeuler(e){throw Error(`MatrixCreateFromEuler() not implemented: requires EulerQuaternionAxisAngle conversion`)},matrixmultiply(e,t){throw Error(`MatrixMultiply() not implemented: requires full 4x4 matrix multiplication`)},matrixmulpoint(e,t){throw Error(`MatrixMulPoint() not implemented: requires full transform application`)},matrixmulvector(e,t){throw Error(`MatrixMulVector() not implemented: requires rotation matrix application`)},getsimtime(){return Date.now()-t().state.startTime},getrealtime(){return Date.now()},schedule(e,n,r,...i){let a=Number(e)||0,o=t(),s=setTimeout(()=>{o.state.pendingTimeouts.delete(s);try{o.$f.call(String(r),...i)}catch(e){throw console.error(`schedule: error calling ${r}:`,e),e}},a);return o.state.pendingTimeouts.add(s),s},cancel(e){clearTimeout(e),t().state.pendingTimeouts.delete(e)},iseventpending(e){return t().state.pendingTimeouts.has(e)},exec(e){let n=String(e??``);if(console.debug(`exec(${JSON.stringify(n)}): preparing to execute`),!n.includes(`.`))return console.error(`exec: invalid script file name ${JSON.stringify(n)}.`),!1;let r=x(n),i=t(),{executedScripts:a,scripts:o}=i.state;if(a.has(r))return console.debug(`exec(${JSON.stringify(n)}): skipping (already executed)`),!0;let s=o.get(r);return s==null?(console.warn(`exec(${JSON.stringify(n)}): script not found`),!1):(a.add(r),console.debug(`exec(${JSON.stringify(n)}): executing!`),i.executeAST(s),!0)},compile(e){throw Error(`compile() not implemented: requires DSO bytecode compiler`)},isdemo(){return!1},isfile(e){return n?n.isFile(S(e)):(console.warn(`isFile(): no fileSystem handler configured`),!1)},fileext(e){let t=S(e),n=t.lastIndexOf(`.`);return n>=0?t.substring(n):``},filebase(e){let t=S(e),n=Math.max(t.lastIndexOf(`/`),t.lastIndexOf(`\\`)),r=t.lastIndexOf(`.`),i=n>=0?n+1:0,a=r>i?r:t.length;return t.substring(i,a)},filepath(e){let t=S(e),n=Math.max(t.lastIndexOf(`/`),t.lastIndexOf(`\\`));return n>=0?t.substring(0,n):``},expandfilename(e){throw Error(`expandFilename() not implemented: requires filesystem path expansion`)},findfirstfile(e){return n?(a=S(e),r=n.findFiles(a),i=0,r[i++]??``):(console.warn(`findFirstFile(): no fileSystem handler configured`),``)},findnextfile(e){let t=S(e);if(t!==a){if(!n)return``;a=t,r=n.findFiles(t)}return r[i++]??``},getfilecrc(e){return S(e)},iswriteablefilename(e){return!1},act
`)??null}return{displayName:n.displayname??null,missionTypes:n.missiontypes?.split(/\s+/).filter(Boolean).map(e=>De[e.toLowerCase()]??e)??[],missionBriefing:i(`MISSION BRIEFING`),briefingWav:n.briefingwav??null,bitmap:n.bitmap??null,planetName:n.planetname??null,missionBlurb:i(`MISSION BLURB`),missionQuote:i(`MISSION QUOTE`),missionString:i(`MISSION STRING`),execScriptPaths:t.execScriptPaths,hasDynamicExec:t.hasDynamicExec,ast:t}}function je(e,t){if(e)return e[t.toLowerCase()]}function Me(e){let[t,n,r]=(e.position??`0 0 0`).split(` `).map(e=>parseFloat(e));return[n||0,r||0,t||0]}function Ne(e){let[t,n,r]=(e.scale??`1 1 1`).split(` `).map(e=>parseFloat(e));return[n||0,r||0,t||0]}export{Ae as a,fe as c,De as i,ne as l,je as n,Ce as o,Ne as r,ye as s,Me as t};