UNPKG

wasm4

Version:

Build retro games using WebAssembly for a fantasy console.

50 lines 74.8 kB
var wasm4=function(t){"use strict"; /** * @license * Copyright 2019 Google LLC * SPDX-License-Identifier: BSD-3-Clause */var e;const s=globalThis,i=s.ShadowRoot&&(void 0===s.ShadyCSS||s.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,n=Symbol(),r=new WeakMap;let o=class{constructor(t,e,s){if(this._$cssResult$=!0,s!==n)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(i&&void 0===t){const s=void 0!==e&&1===e.length;s&&(t=r.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),s&&r.set(e,t))}return t}toString(){return this.cssText}};const a=(t,...e)=>{const s=1===t.length?t[0]:e.reduce(((e,s,i)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(s)+t[i+1]),t[0]);return new o(s,t,n)},l=i?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return(t=>new o("string"==typeof t?t:t+"",void 0,n))(e)})(t):t /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */,{is:h,defineProperty:c,getOwnPropertyDescriptor:d,getOwnPropertyNames:u,getOwnPropertySymbols:p,getPrototypeOf:f}=Object,m=globalThis,y=m.trustedTypes,w=y?y.emptyScript:"",g=m.reactiveElementPolyfillSupport,b=(t,e)=>t,v={toAttribute(t,e){switch(e){case Boolean:t=t?w:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let s=t;switch(e){case Boolean:s=null!==t;break;case Number:s=null===t?null:Number(t);break;case Object:case Array:try{s=JSON.parse(t)}catch(i){s=null}}return s}},A=(t,e)=>!h(t,e),x={attribute:!0,type:String,converter:v,reflect:!1,hasChanged:A};Symbol.metadata??(Symbol.metadata=Symbol("metadata")),m.litPropertyMetadata??(m.litPropertyMetadata=new WeakMap);class k extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??(this.l=[])).push(t)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,e=x){if(e.state&&(e.attribute=!1),this._$Ei(),this.elementProperties.set(t,e),!e.noAccessor){const s=Symbol(),i=this.getPropertyDescriptor(t,s,e);void 0!==i&&c(this.prototype,t,i)}}static getPropertyDescriptor(t,e,s){const{get:i,set:n}=d(this.prototype,t)??{get(){return this[e]},set(t){this[e]=t}};return{get(){return null==i?void 0:i.call(this)},set(e){const r=null==i?void 0:i.call(this);n.call(this,e),this.requestUpdate(t,r,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??x}static _$Ei(){if(this.hasOwnProperty(b("elementProperties")))return;const t=f(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(b("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(b("properties"))){const t=this.properties,e=[...u(t),...p(t)];for(const s of e)this.createProperty(s,t[s])}const t=this[Symbol.metadata];if(null!==t){const e=litPropertyMetadata.get(t);if(void 0!==e)for(const[t,s]of e)this.elementProperties.set(t,s)}this._$Eh=new Map;for(const[e,s]of this.elementProperties){const t=this._$Eu(e,s);void 0!==t&&this._$Eh.set(t,e)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const s=new Set(t.flat(1/0).reverse());for(const t of s)e.unshift(l(t))}else void 0!==t&&e.push(l(t));return e}static _$Eu(t,e){const s=e.attribute;return!1===s?void 0:"string"==typeof s?s:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){var t;this._$ES=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$E_(),this.requestUpdate(),null==(t=this.constructor.l)||t.forEach((t=>t(this)))}addController(t){var e;(this._$EO??(this._$EO=new Set)).add(t),void 0!==this.renderRoot&&this.isConnected&&(null==(e=t.hostConnected)||e.call(t))}removeController(t){var e;null==(e=this._$EO)||e.delete(t)}_$E_(){const t=new Map,e=this.constructor.elementProperties;for(const s of e.keys())this.hasOwnProperty(s)&&(t.set(s,this[s]),delete this[s]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return((t,e)=>{if(i)t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const i of e){const e=document.createElement("style"),n=s.litNonce;void 0!==n&&e.setAttribute("nonce",n),e.textContent=i.cssText,t.appendChild(e)}})(t,this.constructor.elementStyles),t}connectedCallback(){var t;this.renderRoot??(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null==(t=this._$EO)||t.forEach((t=>{var e;return null==(e=t.hostConnected)?void 0:e.call(t)}))}enableUpdating(t){}disconnectedCallback(){var t;null==(t=this._$EO)||t.forEach((t=>{var e;return null==(e=t.hostDisconnected)?void 0:e.call(t)}))}attributeChangedCallback(t,e,s){this._$AK(t,s)}_$EC(t,e){var s;const i=this.constructor.elementProperties.get(t),n=this.constructor._$Eu(t,i);if(void 0!==n&&!0===i.reflect){const r=(void 0!==(null==(s=i.converter)?void 0:s.toAttribute)?i.converter:v).toAttribute(e,i.type);this._$Em=t,null==r?this.removeAttribute(n):this.setAttribute(n,r),this._$Em=null}}_$AK(t,e){var s;const i=this.constructor,n=i._$Eh.get(t);if(void 0!==n&&this._$Em!==n){const t=i.getPropertyOptions(n),r="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null==(s=t.converter)?void 0:s.fromAttribute)?t.converter:v;this._$Em=n,this[n]=r.fromAttribute(e,t.type),this._$Em=null}}requestUpdate(t,e,s){if(void 0!==t){if(s??(s=this.constructor.getPropertyOptions(t)),!(s.hasChanged??A)(this[t],e))return;this.P(t,e,s)}!1===this.isUpdatePending&&(this._$ES=this._$ET())}P(t,e,s){this._$AL.has(t)||this._$AL.set(t,e),!0===s.reflect&&this._$Em!==t&&(this._$Ej??(this._$Ej=new Set)).add(t)}async _$ET(){this.isUpdatePending=!0;try{await this._$ES}catch(e){Promise.reject(e)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??(this.renderRoot=this.createRenderRoot()),this._$Ep){for(const[t,e]of this._$Ep)this[t]=e;this._$Ep=void 0}const t=this.constructor.elementProperties;if(t.size>0)for(const[e,s]of t)!0!==s.wrapped||this._$AL.has(e)||void 0===this[e]||this.P(e,this[e],s)}let e=!1;const s=this._$AL;try{e=this.shouldUpdate(s),e?(this.willUpdate(s),null==(t=this._$EO)||t.forEach((t=>{var e;return null==(e=t.hostUpdate)?void 0:e.call(t)})),this.update(s)):this._$EU()}catch(i){throw e=!1,this._$EU(),i}e&&this._$AE(s)}willUpdate(t){}_$AE(t){var e;null==(e=this._$EO)||e.forEach((t=>{var e;return null==(e=t.hostUpdated)?void 0:e.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EU(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return!0}update(t){this._$Ej&&(this._$Ej=this._$Ej.forEach((t=>this._$EC(t,this[t])))),this._$EU()}updated(t){}firstUpdated(t){}}k.elementStyles=[],k.shadowRootOptions={mode:"open"},k[b("elementProperties")]=new Map,k[b("finalized")]=new Map,null==g||g({ReactiveElement:k}),(m.reactiveElementVersions??(m.reactiveElementVersions=[])).push("2.0.4"); /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const S=globalThis,E=S.trustedTypes,$=E?E.createPolicy("lit-html",{createHTML:t=>t}):void 0,_="$lit$",P=`lit$${(Math.random()+"").slice(9)}$`,C="?"+P,U=`<${C}>`,I=document,T=()=>I.createComment(""),M=t=>null===t||"object"!=typeof t&&"function"!=typeof t,L=Array.isArray,O="[ \t\n\f\r]",R=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,N=/-->/g,B=/>/g,D=RegExp(`>|${O}(?:([^\\s"'>=/]+)(${O}*=${O}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),F=/'/g,H=/"/g,z=/^(?:script|style|textarea|title)$/i,j=(q=1,(t,...e)=>({_$litType$:q,strings:t,values:e})),V=Symbol.for("lit-noChange"),W=Symbol.for("lit-nothing"),G=new WeakMap,K=I.createTreeWalker(I,129);var q;function Y(t,e){if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==$?$.createHTML(e):e}class J{constructor({strings:t,_$litType$:e},s){let i;this.parts=[];let n=0,r=0;const o=t.length-1,a=this.parts,[l,h]=((t,e)=>{const s=t.length-1,i=[];let n,r=2===e?"<svg>":"",o=R;for(let a=0;a<s;a++){const e=t[a];let s,l,h=-1,c=0;for(;c<e.length&&(o.lastIndex=c,l=o.exec(e),null!==l);)c=o.lastIndex,o===R?"!--"===l[1]?o=N:void 0!==l[1]?o=B:void 0!==l[2]?(z.test(l[2])&&(n=RegExp("</"+l[2],"g")),o=D):void 0!==l[3]&&(o=D):o===D?">"===l[0]?(o=n??R,h=-1):void 0===l[1]?h=-2:(h=o.lastIndex-l[2].length,s=l[1],o=void 0===l[3]?D:'"'===l[3]?H:F):o===H||o===F?o=D:o===N||o===B?o=R:(o=D,n=void 0);const d=o===D&&t[a+1].startsWith("/>")?" ":"";r+=o===R?e+U:h>=0?(i.push(s),e.slice(0,h)+_+e.slice(h)+P+d):e+P+(-2===h?a:d)}return[Y(t,r+(t[s]||"<?>")+(2===e?"</svg>":"")),i]})(t,e);if(this.el=J.createElement(l,s),K.currentNode=this.el.content,2===e){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes)}for(;null!==(i=K.nextNode())&&a.length<o;){if(1===i.nodeType){if(i.hasAttributes())for(const t of i.getAttributeNames())if(t.endsWith(_)){const e=h[r++],s=i.getAttribute(t).split(P),o=/([.?@])?(.*)/.exec(e);a.push({type:1,index:n,name:o[2],strings:s,ctor:"."===o[1]?et:"?"===o[1]?st:"@"===o[1]?it:tt}),i.removeAttribute(t)}else t.startsWith(P)&&(a.push({type:6,index:n}),i.removeAttribute(t));if(z.test(i.tagName)){const t=i.textContent.split(P),e=t.length-1;if(e>0){i.textContent=E?E.emptyScript:"";for(let s=0;s<e;s++)i.append(t[s],T()),K.nextNode(),a.push({type:2,index:++n});i.append(t[e],T())}}}else if(8===i.nodeType)if(i.data===C)a.push({type:2,index:n});else{let t=-1;for(;-1!==(t=i.data.indexOf(P,t+1));)a.push({type:7,index:n}),t+=P.length-1}n++}}static createElement(t,e){const s=I.createElement("template");return s.innerHTML=t,s}}function X(t,e,s=t,i){var n,r;if(e===V)return e;let o=void 0!==i?null==(n=s._$Co)?void 0:n[i]:s._$Cl;const a=M(e)?void 0:e._$litDirective$;return(null==o?void 0:o.constructor)!==a&&(null==(r=null==o?void 0:o._$AO)||r.call(o,!1),void 0===a?o=void 0:(o=new a(t),o._$AT(t,s,i)),void 0!==i?(s._$Co??(s._$Co=[]))[i]=o:s._$Cl=o),void 0!==o&&(e=X(t,o._$AS(t,e.values),o,i)),e}class Z{constructor(t,e){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:e},parts:s}=this._$AD,i=((null==t?void 0:t.creationScope)??I).importNode(e,!0);K.currentNode=i;let n=K.nextNode(),r=0,o=0,a=s[0];for(;void 0!==a;){if(r===a.index){let e;2===a.type?e=new Q(n,n.nextSibling,this,t):1===a.type?e=new a.ctor(n,a.name,a.strings,this,t):6===a.type&&(e=new nt(n,this,t)),this._$AV.push(e),a=s[++o]}r!==(null==a?void 0:a.index)&&(n=K.nextNode(),r++)}return K.currentNode=I,i}p(t){let e=0;for(const s of this._$AV)void 0!==s&&(void 0!==s.strings?(s._$AI(t,s,e),e+=s.strings.length-2):s._$AI(t[e])),e++}}class Q{get _$AU(){var t;return(null==(t=this._$AM)?void 0:t._$AU)??this._$Cv}constructor(t,e,s,i){this.type=2,this._$AH=W,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=s,this.options=i,this._$Cv=(null==i?void 0:i.isConnected)??!0}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return void 0!==e&&11===(null==t?void 0:t.nodeType)&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=X(this,t,e),M(t)?t===W||null==t||""===t?(this._$AH!==W&&this._$AR(),this._$AH=W):t!==this._$AH&&t!==V&&this._(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):(t=>L(t)||"function"==typeof(null==t?void 0:t[Symbol.iterator]))(t)?this.k(t):this._(t)}S(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.S(t))}_(t){this._$AH!==W&&M(this._$AH)?this._$AA.nextSibling.data=t:this.T(I.createTextNode(t)),this._$AH=t}$(t){var e;const{values:s,_$litType$:i}=t,n="number"==typeof i?this._$AC(t):(void 0===i.el&&(i.el=J.createElement(Y(i.h,i.h[0]),this.options)),i);if((null==(e=this._$AH)?void 0:e._$AD)===n)this._$AH.p(s);else{const t=new Z(n,this),e=t.u(this.options);t.p(s),this.T(e),this._$AH=t}}_$AC(t){let e=G.get(t.strings);return void 0===e&&G.set(t.strings,e=new J(t)),e}k(t){L(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let s,i=0;for(const n of t)i===e.length?e.push(s=new Q(this.S(T()),this.S(T()),this,this.options)):s=e[i],s._$AI(n),i++;i<e.length&&(this._$AR(s&&s._$AB.nextSibling,i),e.length=i)}_$AR(t=this._$AA.nextSibling,e){var s;for(null==(s=this._$AP)||s.call(this,!1,!0,e);t&&t!==this._$AB;){const e=t.nextSibling;t.remove(),t=e}}setConnected(t){var e;void 0===this._$AM&&(this._$Cv=t,null==(e=this._$AP)||e.call(this,t))}}class tt{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,e,s,i,n){this.type=1,this._$AH=W,this._$AN=void 0,this.element=t,this.name=e,this._$AM=i,this.options=n,s.length>2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=W}_$AI(t,e=this,s,i){const n=this.strings;let r=!1;if(void 0===n)t=X(this,t,e,0),r=!M(t)||t!==this._$AH&&t!==V,r&&(this._$AH=t);else{const i=t;let o,a;for(t=n[0],o=0;o<n.length-1;o++)a=X(this,i[s+o],e,o),a===V&&(a=this._$AH[o]),r||(r=!M(a)||a!==this._$AH[o]),a===W?t=W:t!==W&&(t+=(a??"")+n[o+1]),this._$AH[o]=a}r&&!i&&this.j(t)}j(t){t===W?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}}class et extends tt{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===W?void 0:t}}class st extends tt{constructor(){super(...arguments),this.type=4}j(t){this.element.toggleAttribute(this.name,!!t&&t!==W)}}class it extends tt{constructor(t,e,s,i,n){super(t,e,s,i,n),this.type=5}_$AI(t,e=this){if((t=X(this,t,e,0)??W)===V)return;const s=this._$AH,i=t===W&&s!==W||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,n=t!==W&&(s===W||i);i&&this.element.removeEventListener(this.name,this,s),n&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var e;"function"==typeof this._$AH?this._$AH.call((null==(e=this.options)?void 0:e.host)??this.element,t):this._$AH.handleEvent(t)}}class nt{constructor(t,e,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=s}get _$AU(){return this._$AM._$AU}_$AI(t){X(this,t)}}const rt=S.litHtmlPolyfillSupport;null==rt||rt(J,Q),(S.litHtmlVersions??(S.litHtmlVersions=[])).push("3.1.2"); /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ class ot extends k{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){var t;const e=super.createRenderRoot();return(t=this.renderOptions).renderBefore??(t.renderBefore=e.firstChild),e}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=((t,e,s)=>{const i=(null==s?void 0:s.renderBefore)??e;let n=i._$litPart$;if(void 0===n){const t=(null==s?void 0:s.renderBefore)??null;i._$litPart$=n=new Q(e.insertBefore(T(),t),t,void 0,s??{})}return n._$AI(t),n})(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),null==(t=this._$Do)||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),null==(t=this._$Do)||t.setConnected(!1)}render(){return V}}ot._$litElement$=!0,ot.finalized=!0,null==(e=globalThis.litElementHydrateSupport)||e.call(globalThis,{LitElement:ot});const at=globalThis.litElementPolyfillSupport;null==at||at({LitElement:ot}),(globalThis.litElementVersions??(globalThis.litElementVersions=[])).push("4.0.4"); /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const lt=t=>(e,s)=>{void 0!==s?s.addInitializer((()=>{customElements.define(t,e)})):customElements.define(t,e)} /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */,ht={attribute:!0,type:String,converter:v,reflect:!1,hasChanged:A},ct=(t=ht,e,s)=>{const{kind:i,metadata:n}=s;let r=globalThis.litPropertyMetadata.get(n);if(void 0===r&&globalThis.litPropertyMetadata.set(n,r=new Map),r.set(s.name,t),"accessor"===i){const{name:i}=s;return{set(s){const n=e.get.call(this);e.set.call(this,s),this.requestUpdate(i,n,t)},init(e){return void 0!==e&&this.P(i,void 0,t),e}}}if("setter"===i){const{name:i}=s;return function(s){const n=this[i];e.call(this,s),this.requestUpdate(i,n,t)}}throw Error("Unsupported decorator location: "+i)}; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ function dt(t){return function(t){return(e,s)=>"object"==typeof s?ct(t,e,s):((t,e,s)=>{const i=e.hasOwnProperty(s);return e.constructor.createProperty(s,i?{...t,wrapped:!0}:t),i?Object.getOwnPropertyDescriptor(e,s):void 0})(t,e,s)}({...t,state:!0,attribute:!1})} /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */const ut=(t,e,s)=>(s.configurable=!0,s.enumerable=!0,Reflect.decorate&&"object"!=typeof e&&Object.defineProperty(t,e,s),s) /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */;function pt(t,e){return(s,i,n)=>{const r=e=>{var s;return(null==(s=e.renderRoot)?void 0:s.querySelector(t))??null};if(e){const{get:t,set:e}="object"==typeof i?s:n??(()=>{const t=Symbol();return{get(){return this[t]},set(e){this[t]=e}}})();return ut(s,i,{get(){let s=t.call(this);return void 0===s&&(s=r(this),(null!==s||this.hasUpdated)&&e.call(this,s)),s}})}return ut(s,i,{get(){return r(this)}})}}const ft=160,mt=160,yt=1024,wt=[14743759,8831084,3172432,464929],gt=16,bt=32,vt=64,At=128,xt=Uint8Array.of(255,255,255,255,255,255,255,255,199,199,199,207,207,255,207,255,147,147,147,255,255,255,255,255,147,1,147,147,147,1,147,255,239,131,47,131,233,3,239,255,157,91,55,239,217,181,115,255,143,39,39,143,37,51,129,255,207,207,207,255,255,255,255,255,243,231,207,207,207,231,243,255,159,207,231,231,231,207,159,255,255,147,199,1,199,147,255,255,255,231,231,129,231,231,255,255,255,255,255,255,255,207,207,159,255,255,255,129,255,255,255,255,255,255,255,255,255,207,207,255,253,251,247,239,223,191,127,255,199,179,57,57,57,155,199,255,231,199,231,231,231,231,129,255,131,57,241,195,135,31,1,255,129,243,231,195,249,57,131,255,227,195,147,51,1,243,243,255,3,63,3,249,249,57,131,255,195,159,63,3,57,57,131,255,1,57,243,231,207,207,207,255,135,59,27,135,97,121,131,255,131,57,57,129,249,243,135,255,255,207,207,255,207,207,255,255,255,207,207,255,207,207,159,255,243,231,207,159,207,231,243,255,255,255,1,255,1,255,255,255,159,207,231,243,231,207,159,255,131,1,57,243,199,255,199,255,131,125,69,85,65,127,131,255,199,147,57,57,1,57,57,255,3,57,57,3,57,57,3,255,195,153,63,63,63,153,195,255,7,51,57,57,57,51,7,255,1,63,63,3,63,63,1,255,1,63,63,3,63,63,63,255,193,159,63,49,57,153,193,255,57,57,57,1,57,57,57,255,129,231,231,231,231,231,129,255,249,249,249,249,249,57,131,255,57,51,39,15,7,35,49,255,159,159,159,159,159,159,129,255,57,17,1,1,41,57,57,255,57,25,9,1,33,49,57,255,131,57,57,57,57,57,131,255,3,57,57,57,3,63,63,255,131,57,57,57,33,51,133,255,3,57,57,49,7,35,49,255,135,51,63,131,249,57,131,255,129,231,231,231,231,231,231,255,57,57,57,57,57,57,131,255,57,57,57,17,131,199,239,255,57,57,41,1,1,17,57,255,57,17,131,199,131,17,57,255,153,153,153,195,231,231,231,255,1,241,227,199,143,31,1,255,195,207,207,207,207,207,195,255,127,191,223,239,247,251,253,255,135,231,231,231,231,231,135,255,199,147,255,255,255,255,255,255,255,255,255,255,255,255,255,1,239,247,255,255,255,255,255,255,255,255,131,249,129,57,129,255,63,63,3,57,57,57,131,255,255,255,129,63,63,63,129,255,249,249,129,57,57,57,129,255,255,255,131,57,1,63,131,255,241,231,129,231,231,231,231,255,255,255,129,57,57,129,249,131,63,63,3,57,57,57,57,255,231,255,199,231,231,231,129,255,243,255,227,243,243,243,243,135,63,63,49,3,7,35,49,255,199,231,231,231,231,231,129,255,255,255,3,73,73,73,73,255,255,255,3,57,57,57,57,255,255,255,131,57,57,57,131,255,255,255,3,57,57,3,63,63,255,255,129,57,57,129,249,249,255,255,145,143,159,159,159,255,255,255,131,63,131,249,3,255,231,231,129,231,231,231,231,255,255,255,57,57,57,57,129,255,255,255,153,153,153,195,231,255,255,255,73,73,73,73,129,255,255,255,57,1,199,1,57,255,255,255,57,57,57,129,249,131,255,255,1,227,199,143,1,255,243,231,231,207,231,231,243,255,231,231,231,231,231,231,231,255,159,207,207,231,207,207,159,255,255,255,143,69,227,255,255,255,255,255,255,255,255,147,147,255,131,41,41,17,41,41,131,255,131,57,9,17,33,57,131,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,131,17,33,125,33,17,131,255,131,17,9,125,9,17,131,255,131,17,57,85,17,17,131,255,131,17,17,85,57,17,131,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,231,255,231,231,199,199,199,255,239,131,41,47,41,131,239,255,195,153,159,3,159,159,1,255,255,165,219,219,219,165,255,255,153,153,195,129,231,129,231,255,231,231,231,255,231,231,231,255,195,153,135,219,225,153,195,255,147,255,255,255,255,255,255,255,195,189,102,94,94,102,189,195,135,195,147,195,255,255,255,255,255,201,147,39,147,201,255,255,255,255,129,249,249,255,255,255,255,255,255,255,255,255,255,255,195,189,70,90,70,90,189,195,131,255,255,255,255,255,255,255,239,215,239,255,255,255,255,255,231,231,129,231,231,255,129,255,199,243,231,195,255,255,255,255,195,231,243,199,255,255,255,255,247,239,255,255,255,255,255,255,255,255,51,51,51,51,9,63,193,149,181,149,193,245,245,255,255,255,255,207,207,255,255,255,255,255,255,255,255,255,247,207,231,199,231,195,255,255,255,255,199,147,147,199,255,255,255,255,255,39,147,201,147,39,255,255,189,59,183,173,217,177,125,255,189,59,183,169,221,187,113,255,29,187,215,45,217,177,125,255,199,255,199,159,57,1,131,255,223,239,199,147,57,1,57,255,247,239,199,147,57,1,57,255,199,147,199,147,57,1,57,255,203,167,199,147,57,1,57,255,147,255,199,147,57,1,57,255,239,215,199,147,57,1,57,255,193,135,39,33,7,39,33,255,195,153,63,63,153,195,247,207,223,239,1,63,3,63,1,255,247,239,1,63,3,63,1,255,199,147,1,63,3,63,1,255,147,255,1,63,3,63,1,255,239,247,129,231,231,231,129,255,247,239,129,231,231,231,129,255,231,195,129,231,231,231,129,255,153,255,129,231,231,231,129,255,135,147,153,9,153,147,135,255,203,167,25,9,1,33,49,255,223,239,131,57,57,57,131,255,247,239,131,57,57,57,131,255,199,147,131,57,57,57,131,255,203,167,131,57,57,57,131,255,147,255,131,57,57,57,131,255,255,187,215,239,215,187,255,255,131,57,49,41,25,57,131,255,223,239,57,57,57,57,131,255,247,239,57,57,57,57,131,255,199,147,255,57,57,57,131,255,147,255,57,57,57,57,131,255,247,239,153,153,195,231,231,255,63,3,57,57,57,3,63,255,195,153,153,147,153,137,147,255,223,239,131,249,129,57,129,255,247,239,131,249,129,57,129,255,199,147,131,249,129,57,129,255,203,167,131,249,129,57,129,255,147,255,131,249,129,57,129,255,239,215,131,249,129,57,129,255,255,255,131,233,129,47,131,255,255,255,129,63,63,129,247,207,223,239,131,57,1,63,131,255,247,239,131,57,1,63,131,255,199,147,131,57,1,63,131,255,147,255,131,57,1,63,131,255,223,239,255,199,231,231,129,255,247,239,255,199,231,231,129,255,199,147,255,199,231,231,129,255,147,255,199,231,231,231,129,255,155,135,103,131,57,57,131,255,203,167,3,57,57,57,57,255,223,239,131,57,57,57,131,255,247,239,131,57,57,57,131,255,199,147,131,57,57,57,131,255,203,167,131,57,57,57,131,255,147,255,131,57,57,57,131,255,255,231,255,129,255,231,255,255,255,255,131,49,41,25,131,255,223,239,57,57,57,57,129,255,247,239,57,57,57,57,129,255,199,147,255,57,57,57,129,255,147,255,57,57,57,57,129,255,247,239,57,57,57,129,249,131,63,63,3,57,57,3,63,63,147,255,57,57,57,129,249,131);function kt(t){const e=new URL(location.href),s=e.searchParams.get(t);if(null!=s)return s;return new URL(e.hash.substring(1),"https://x").searchParams.get(t)}function St(){if(null==document.fullscreenElement){let t=function(){const t=window.frameElement;t&&(t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.zIndex="99999",t.style.width="100%",t.style.height="100%")};const e=document.body.requestFullscreen&&document.body.requestFullscreen({navigationUI:"hide"});e?e.catch(t):t()}}const Et="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#".split(""),$t=[0,68,0,84,83,82,72,0,75,76,70,65,0,63,62,69,0,1,2,3,4,5,6,7,8,9,64,0,73,66,74,71,81,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,77,0,78,67,0,0,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,79,0,80,0,0];function _t(t){const e=t.length,s=e%4,i=s?e+4-s:e;let n="",r=0,o=0;for(;r<i;){const s=r<e?t[r]:0;if(++r,o=256*o+s,r%4==0){let t=52200625;for(;t>=1;){const e=Math.floor(o/t)%85;n+=Et[e],t/=85}o=0}}return n}function Pt(t,e){let s=0,i=0,n=0;const r=t.length,o=e.length;if(t.length%5==0)for(;i<r;){const r=t.charCodeAt(i++)-32;if(r<0||r>=$t.length)return s;if(n=85*n+$t[r],i%5==0){let t=16777216;for(;t>=1;){if(s>=o)return s;e[s++]=n/t%256,t/=256}n=0}}return s}class Ct{constructor(){this.memory=new ArrayBuffer(65536),this.globals={},this.diskBuffer=new ArrayBuffer(yt),this.diskSize=0}read(t){new Uint8Array(this.memory).set(new Uint8Array(t.memory.buffer)),this.globals={};for(const e in t.wasm.exports){const s=t.wasm.exports[e];s instanceof WebAssembly.Global&&(this.globals[e]=s.value.toString())}this.diskSize=t.diskSize,new Uint8Array(this.diskBuffer).set(new Uint8Array(t.diskBuffer,0,t.diskSize))}write(t){new Uint8Array(t.memory.buffer).set(new Uint8Array(this.memory));for(const e in t.wasm.exports){const s=t.wasm.exports[e];if(s instanceof WebAssembly.Global&&e in this.globals)try{s.value=this.globals[e]}catch{}}t.diskSize=this.diskSize,new Uint8Array(t.diskBuffer).set(new Uint8Array(this.diskBuffer,0,this.diskSize))}toBytes(){const t=(new TextEncoder).encode(JSON.stringify(this.globals)),e=new Uint8Array(65544+t.byteLength+this.diskSize),s=new DataView(e.buffer,e.byteOffset,e.byteLength);e.set(new Uint8Array(this.memory),0);let i=65536;return s.setUint32(i,t.byteLength),e.set(t,i+4),i+=4+t.byteLength,s.setUint32(i,this.diskSize),e.set(new Uint8Array(this.diskBuffer,0,this.diskSize),i+4),e}fromBytes(t){const e=new DataView(t.buffer,t.byteOffset,t.byteLength);new Uint8Array(this.memory).set(t.subarray(0,65536));let s=65536;const i=e.getUint32(s),n=t.slice(s+4,s+4+i);this.globals=JSON.parse((new TextDecoder).decode(n)),s+=4+i,this.diskSize=e.getUint32(s),new Uint8Array(this.diskBuffer).set(t.subarray(s+4,s+4+this.diskSize))}}const Ut=20;class It{constructor(){this.frame=-1,this.state=new Ct,this.inputs=new Array(4),this.predicted=new Array(4);for(let t=0;t<4;++t)this.inputs[t]=0,this.predicted[t]=!0}}class Tt{constructor(){this.futureInputs=new Map}}class Mt{constructor(t,e){this.currentFrame=t,this.runtime=e,this.rollbackIdx=Ut,this.history=new Array(Ut);for(let s=0;s<Ut;++s)this.history[s]=new It;this.players=new Array(4);for(let s=0;s<4;++s)this.players[s]=new Tt}addInputs(t,e,s){const i=this.players[t];for(const n of s){if(e>=this.currentFrame)i.futureInputs.has(e)||i.futureInputs.set(e,n);else for(let s=0,i=Ut;s<i;++s){const i=this.history[s];if(i.frame==e){i.predicted[t]&&(i.predicted[t]=!1,i.inputs[t]!=n&&(i.inputs[t]=n,this.rollbackIdx=Math.min(s,this.rollbackIdx)));break}}++e}}update(){if(this.rollbackIdx<Ut){for(let e=this.rollbackIdx+1;e<Ut;++e){const t=this.history[e];for(let s=0;s<4;++s)if(t.predicted[s]){const i=this.history[e-1];t.inputs[s]=i.inputs[s]}}let t=!0;for(;this.rollbackIdx<Ut;){const e=this.history[this.rollbackIdx++];t?(t=!1,e.state.write(this.runtime)):e.state.read(this.runtime);for(let t=0;t<4;++t)this.runtime.setGamepad(t,e.inputs[t]);this.runtime.update()}}const t=this.history[19],e=this.history.shift();this.history.push(e),e.frame=this.currentFrame,e.state.read(this.runtime);for(let s=0;s<4;++s){const i=this.players[s];let n=i.futureInputs.get(this.currentFrame);null!=n?(e.predicted[s]=!1,i.futureInputs.delete(this.currentFrame)):(e.predicted[s]=!0,n=t.inputs[s]),e.inputs[s]=n,this.runtime.setGamepad(s,n)}this.runtime.update(),++this.currentFrame}}class Lt{constructor(t){this.onMessage=t,this.bufferedOutput=[],this.connect(),this.keepaliveInterval=window.setInterval((()=>{this.send("",{type:"KEEPALIVE"},!1)}),15e3)}async connect(){const t=["wss://webrtc-signal-server.wasm4.org","wss://ywc2h85cv1.execute-api.us-east-1.amazonaws.com/production","wss://webrtc-signal-server.wasm4.jwq.moe","wss://iyuavuru2h.execute-api.eu-central-1.amazonaws.com/production"];for(const s of t)try{this.socket=await new Promise(((t,e)=>{const i=new WebSocket(s);i.addEventListener("open",(()=>{t(i)})),i.addEventListener("error",(()=>{e()}))}));break}catch(e){console.error(e)}if(!this.socket)throw new Error("Unable to connect to signal server");this.socket.addEventListener("message",(t=>{const{source:e,message:s}=JSON.parse(t.data);this.onMessage(e,s)}));for(const s of this.bufferedOutput)this.socket.send(s);this.bufferedOutput.length=0}send(t,e,s=!0){var i;const n=JSON.stringify({target:t,message:e});1==(null==(i=this.socket)?void 0:i.readyState)?this.socket.send(n):s&&this.bufferedOutput.push(n)}close(){var t;null==(t=this.socket)||t.close(),window.clearInterval(this.keepaliveInterval)}}class Ot{constructor(t){let e;this.connections=new Map,this.localPeerId=new Promise((t=>{e=t})),this.signalClient=new Lt((async(s,i)=>{switch(i.type){case"WHOAMI_REPLY":this.iceServers=i.iceServers,e(i.yourPeerId);break;case"OFFER":if(this.connections.has(s))throw new Error("Received offer for a connection we already initiated");{const e=this.createConnection(s);await e.setRemoteDescription(i.description),await e.setLocalDescription(await e.createAnswer()),t(e,s),this.signalClient.send(s,{type:"ANSWER",description:e.localDescription.toJSON()})}break;case"ANSWER":{const t=this.connections.get(s);t&&await t.setRemoteDescription(i.description)}break;case"CANDIDATE":{const t=this.connections.get(s);t&&await t.addIceCandidate(new RTCIceCandidate(i.candidate))}break;case"ABORT":{const t=this.connections.get(s);t&&t.close()}}})),this.signalClient.send("",{type:"WHOAMI_REQUEST"})}createConnection(t){const e=new RTCPeerConnection({iceServers:this.iceServers});return this.connections.set(t,e),e.addEventListener("negotiationneeded",(async()=>{await e.setLocalDescription(await e.createOffer()),this.signalClient.send(t,{type:"OFFER",description:e.localDescription.toJSON()})})),e.addEventListener("icecandidate",(({candidate:e})=>{e&&this.signalClient.send(t,{type:"CANDIDATE",candidate:e.toJSON()})})),e.addEventListener("connectionstatechange",(()=>{const s=e.connectionState;"connected"!=s&&"failed"!=s||this.connections.delete(t)})),e}connect(t){return this.connections.get(t)||this.createConnection(t)}close(){this.signalClient.close();for(const[t,e]of this.connections)e.close()}}const Rt=16384;class Nt{constructor(t){this.chunks=[],this.size=0,t.addEventListener("message",(t=>{if(t.data instanceof ArrayBuffer){const e=new Uint8Array(t.data);this.size+=e.byteLength,this.chunks.push(e)}}))}read(){const t=new Uint8Array(this.size);let e=0;for(const s of this.chunks)t.set(s,e),e+=s.byteLength;return this.chunks.length=0,this.size=0,t}}class Bt{constructor(t){this.channel=t,this.size=0}write(t){this.buffer||(this.buffer=new Uint8Array(Rt));let e=this.size,s=0;for(;s<t.length;){const i=t.subarray(s,s+Rt-e);this.buffer.set(i,e),s+=i.length,e+=i.length,e>=Rt&&(e-=Rt,this.channel.send(this.buffer))}this.size=e}flush(){this.buffer&&this.size>0&&this.channel.send(this.buffer.subarray(0,this.size)),this.buffer=void 0}}class Dt{constructor(t,e=0){this.buffer=t,this.position=e}readBit(){const t=!!(this.buffer[this.position/8>>>0]&1<<(7&this.position));return++this.position,t}readBits(t){let e=0;for(let s=0;s<t;++s)e|=+this.readBit()<<s;return e}}class Ft{constructor(t,e=0){this.buffer=t,this.position=e}write1(){this.buffer[this.position/8>>>0]|=1<<(7&this.position),++this.position}write0(){this.buffer[this.position/8>>>0]&=~(1<<(7&this.position)),++this.position}writeBits(t,e){for(let s=0;s<e;++s)t&1<<s?this.write1():this.write0()}}class Ht{constructor(t=.125){this.discount=t,this.average=0,this.firstUpdate=!0}update(t){if(this.firstUpdate)this.firstUpdate=!1,this.average=t;else{const e=this.discount;this.average=(1-e)*this.average+e*t}}}const zt=8+Math.ceil(82.5),jt=new ArrayBuffer(zt);class Vt{constructor(t,e,s,i){this.peerId=t,this.connection=e,this.reliableChannel=s,this.unreliableChannel=i,this.playerIdx=-1,this.frame=0,this.nextNeededFrame=0,this.outboundFrame=0,this.outboundInputs=[],this.ping=new Ht,this.drift=new Ht,this.chunkReader=new Nt(s),this.chunkWriter=new Bt(s)}addOutboundInput(t,e){if(0==this.outboundFrame&&(this.outboundFrame=t),t<this.outboundFrame){for(let s=this.outboundFrame-t;s>0;--s)this.outboundInputs.unshift(e);this.outboundFrame=t}else{const s=t-this.outboundFrame;if(s>=this.outboundInputs.length){for(let t=this.outboundInputs.length;t<s;++t)this.outboundInputs[t]=t>0?this.outboundInputs[t-1]:0;this.outboundInputs[s]=e}}}sendMessage(t){this.reliableChannel.send(JSON.stringify(t))}sendUnreliableBuffer(t){this.unreliableChannel.send(t)}sendPingRequest(){const t=new DataView(jt);t.setUint8(0,2),t.setUint32(1,performance.now()>>>0),this.sendUnreliableBuffer(new Uint8Array(jt,0,5))}sendPingReply(t){const e=new DataView(jt);e.setUint8(0,3),e.setUint32(1,t),this.sendUnreliableBuffer(new Uint8Array(jt,0,5))}sendTick(t){const e=new DataView(jt);e.setUint8(0,1),e.setUint32(1,t),e.setInt8(5,0==this.nextNeededFrame?-127:this.nextNeededFrame-t),e.setInt8(6,this.outboundFrame-t),e.setUint8(7,this.outboundInputs.length);const s=new Ft(new Uint8Array(jt,8));let i=0;for(const r of this.outboundInputs){const t=i^r;i=r;for(let e=0;e<8;++e)t&1<<e&&(s.write1(),s.writeBits(e,3));s.write0()}const n=8+Math.ceil(s.position/8);this.sendUnreliableBuffer(new Uint8Array(jt,0,n))}close(){this.reliableChannel.close(),this.unreliableChannel.close(),this.connection.close()}}class Wt{constructor(t){this.runtime=t,this.remotePlayers=new Map,this.localPlayerIdx=-1,this.updateCount=0,this.peerMgr=new Ot((async(t,e)=>{const s=Array.from(this.remotePlayers.keys()),i=await this.createRemotePlayer(t,e);i.sendMessage({type:"WELCOME",otherPeers:s}),this.localPlayerIdx>=0&&i.sendMessage({type:"PLAYER_INFO",playerIdx:this.localPlayerIdx})}))}host(){this.runtime.setNetplay(0),this.rollbackMgr=new Mt(1,this.runtime),this.localPlayerIdx=0}join(t){const e=this.peerMgr.connect(t);this.createRemotePlayer(e,t).then((t=>{t.sendMessage({type:"JOIN_REQUEST"})}),(t=>{this.runtime.blueScreen("Failed to connect\nto peer. They may\nbe offline?")}))}async getInviteLink(){const t=await this.peerMgr.localPeerId,e=window.location;if("file:"==e.protocol||"localhost"==e.hostname||"127.0.0.1"==e.hostname||"wasm4.org"==e.hostname)return`https://wasm4.org/netplay/#${t}`;const s=new URL(e.href);return s.searchParams.set("netplay",t),s.href}close(){for(const t of this.remotePlayers.values())t.close();this.peerMgr.close()}async createRemotePlayer(t,e){function s(e){return new Promise(((s,i)=>{const n=t.createDataChannel("WASM-4",e);n.binaryType="arraybuffer",n.onopen=()=>{s(n)},n.onerror=i}))}const[i,n]=await Promise.all([s({negotiated:!0,id:0}),s({negotiated:!0,id:1,ordered:!1,maxRetransmits:0})]),r=new Vt(e,t,i,n);this.remotePlayers.set(e,r);const o=()=>{this.remotePlayers.has(e)&&(this.remotePlayers.delete(e),this.onleave&&r.playerIdx>=0&&this.onleave(r.playerIdx))};return t.addEventListener("connectionstatechange",(()=>{"disconnected"==t.connectionState&&o()})),i.addEventListener("close",o),n.addEventListener("close",o),i.addEventListener("message",(async t=>{if("string"!=typeof t.data)return;const e=JSON.parse(t.data);switch(e.type){case"WELCOME":for(const t of e.otherPeers)if(!this.remotePlayers.has(t)){const e=this.peerMgr.connect(t),s=await this.createRemotePlayer(e,t);this.localPlayerIdx>=0&&s.sendMessage({type:"PLAYER_INFO",playerIdx:this.localPlayerIdx})}break;case"JOIN_REQUEST":{const t=this.nextPlayerIdx();if(t>=4)r.sendMessage({type:"JOIN_REJECT"}),r.close();else{r.playerIdx=t,r.chunkWriter.write(this.runtime.wasmBuffer);const e=new Ct;e.read(this.runtime),r.chunkWriter.write(e.toBytes()),r.chunkWriter.flush(),r.sendMessage({type:"JOIN_REPLY",yourPlayerIdx:r.playerIdx,frame:this.rollbackMgr.currentFrame,stateOffset:this.runtime.wasmBuffer.byteLength}),this.onjoin&&this.onjoin(r.playerIdx)}}break;case"JOIN_REPLY":{this.localPlayerIdx=e.yourPlayerIdx;for(const e of this.remotePlayers.values())e!=r&&e.sendMessage({type:"PLAYER_INFO",playerIdx:this.localPlayerIdx});const t=r.chunkReader.read(),s=t.subarray(0,e.stateOffset),i=t.subarray(e.stateOffset);await this.runtime.load(s,!1);const n=new Ct;n.fromBytes(i),n.write(this.runtime),this.runtime.setNetplay(this.localPlayerIdx),this.rollbackMgr=new Mt(e.frame,this.runtime),this.onstart&&this.onstart(this.localPlayerIdx)}break;case"JOIN_REJECT":this.runtime.blueScreen("Connected, but the\ngame is already\nfull!"),this.close();break;case"PLAYER_INFO":-1==r.playerIdx&&(r.playerIdx=e.playerIdx,this.onjoin&&this.onjoin(r.playerIdx))}})),n.addEventListener("message",(async t=>{const e=t.data,s=new DataView(e);switch(s.getUint8(0)){case 1:if(this.rollbackMgr&&r.playerIdx>=0){const t=s.getUint32(1);if(t>r.frame){const i=s.getInt8(5)+t,n=s.getInt8(6)+t,o=s.getUint8(7),a=new Dt(new Uint8Array(e,8)),l=new Array(o);let h=0;for(let t=0;t<o;++t){for(;a.readBit();){h^=1<<a.readBits(3)}l[t]=h}if(r.frame=t,r.nextNeededFrame=n+l.length,0==r.outboundFrame)r.outboundFrame=i;else if(i>r.outboundFrame){const t=i-r.outboundFrame;r.outboundFrame=i,r.outboundInputs.splice(0,t)}const c=t+.5*r.ping.average*60/1e3,d=this.rollbackMgr.currentFrame-c;r.drift.update(d),this.rollbackMgr.addInputs(r.playerIdx,n,l)}}break;case 2:{const t=s.getUint32(1);r.sendPingReply(t)}break;case 3:{const t=s.getUint32(1),e=(performance.now()>>>0)-t;r.ping.update(e)}}})),r}nextPlayerIdx(){t:for(let t=0;t<4;++t)if(this.localPlayerIdx!=t){for(const e of this.remotePlayers.values())if(e.playerIdx==t)continue t;return t}return-1}update(t){if(!this.rollbackMgr)return!1;const e=0==(7&this.updateCount),s=0==(31&this.updateCount);++this.updateCount;const i=this.rollbackMgr.currentFrame,n=i+2;this.rollbackMgr.addInputs(this.localPlayerIdx,n,[t]);let r=!1;for(const o of this.remotePlayers.values())o.addOutboundInput(n,t),o.sendTick(i),(o.nextNeededFrame<i-Ut||o.outboundInputs.length>=20)&&(r=!0),s&&o.sendPingRequest();if(e){let t=0;for(const e of this.remotePlayers.values())t=Math.max(e.drift.average,t);t>=1&&(r=!0)}return r||this.rollbackMgr.update(),!r}getSummary(){const t=[{playerIdx:this.localPlayerIdx,ping:-1}];for(const e of this.remotePlayers.values())t.push({playerIdx:e.playerIdx,ping:e.ping.average});return t.sort(((t,e)=>t.playerIdx-e.playerIdx)),t}}const Gt='"use strict";(()=>{var M=Math.floor(44.1),b=class{constructor(){this.freq1=0;this.freq2=0;this.startTime=0;this.attackTime=0;this.decayTime=0;this.sustainTime=0;this.releaseTime=0;this.endTick=0;this.sustainVolume=0;this.peakVolume=0;this.phase=0;this.pan=0;this.pulseDutyCycle=0;this.noiseSeed=1;this.noiseLastRandom=0}};function L(m,e,s){return m+s*(e-m)}function V(m,e){if(m<e){let s=m/e;return s+s-s*s}else if(m>1-e){let s=(m-(1-e))/e;return 1-(s+s-s*s)}else return 1}function x(m,e){return Math.pow(2,(m-69+e/256)/12)*440}var y=class extends AudioWorkletProcessor{constructor(){super(),this.time=0,this.ticks=0,this.channels=new Array(4);for(let e=0;e<4;++e)this.channels[e]=new b;this.port!=null&&(this.port.onmessage=e=>{e.data==="tick"?this.tick():this.tone(...e.data)})}ramp(e,s,f,u){if(this.time>=u)return s;let a=(this.time-f)/(u-f);return L(e,s,a)}getCurrentFrequency(e){return e.freq2>0?this.ramp(e.freq1,e.freq2,e.startTime,e.releaseTime):e.freq1}getCurrentVolume(e){let s=this.time;return s>=e.sustainTime&&e.releaseTime-e.sustainTime>M?this.ramp(e.sustainVolume,0,e.sustainTime,e.releaseTime):s>=e.decayTime?e.sustainVolume:s>=e.attackTime?this.ramp(e.peakVolume,e.sustainVolume,e.attackTime,e.decayTime):this.ramp(0,e.peakVolume,e.startTime,e.attackTime)}tick(){this.ticks++}tone(e,s,f,u){let a=e&65535,p=e>>16&65535,A=s&255,h=s>>8&255,o=s>>16&255,i=s>>24&255,E=Math.min(f&255,100),l=Math.min(f>>8&255,100),n=u&3,r=u>>2&3,c=u>>4&3,d=u&64,t=this.channels[n];this.time>t.releaseTime&&this.ticks!=t.endTick&&(t.phase=n==2?.25:0),d?(t.freq1=x(a&255,a>>8),t.freq2=p==0?0:x(p&255,p>>8)):(t.freq1=a,t.freq2=p),t.startTime=this.time,t.attackTime=t.startTime+(44100*i/60>>>0),t.decayTime=t.attackTime+(44100*o/60>>>0),t.sustainTime=t.decayTime+(44100*A/60>>>0),t.releaseTime=t.sustainTime+(44100*h/60>>>0),t.endTick=this.ticks+i+o+A+h,t.pan=c;let T=n==2?.25:.15;if(t.sustainVolume=T*E/100,t.peakVolume=l?T*l/100:T,n==0||n==1)switch(r){case 0:t.pulseDutyCycle=.125;break;case 1:case 3:default:t.pulseDutyCycle=.25;break;case 2:t.pulseDutyCycle=.5;break}else n==2&&h==0&&(t.releaseTime+=M)}process(e,[[s,f]],u){for(let a=0,p=s.length;a<p;++a,++this.time){let A=0,h=0;for(let o=0;o<4;++o){let i=this.channels[o];if(this.time<i.releaseTime||this.ticks==i.endTick){let E=this.getCurrentFrequency(i),l=this.getCurrentVolume(i),n;if(o==3){for(i.phase+=E*E/(1e6/44100*44100);i.phase>0;){i.phase--;let r=i.noiseSeed;r^=r>>7,r^=r<<9,r^=r>>13,i.noiseSeed=r,i.noiseLastRandom=((r&1)<<1)-1}n=l*i.noiseLastRandom}else{let r=E/44100,c=i.phase+r;if(c>=1&&c--,i.phase=c,o==2)n=l*(2*Math.abs(2*i.phase-1)-1);else{let d,t,T,k=i.pulseDutyCycle;c<k?(d=c/k,t=r/k,T=l):(d=(c-k)/(1-k),t=r/(1-k),T=-l),n=T*V(d,t)}}i.pan!=1&&(h+=n),i.pan!=2&&(A+=n)}}s[a]=A,f[a]=h}return!0}};registerProcessor("wasm4-apu",y);})();\n';class Kt{constructor(){this.audioCtx=new(window.AudioContext||window.webkitAudioContext)({sampleRate:44100})}async init(){const t=this.audioCtx,e=new Blob([Gt],{type:"application/javascript"}),s=URL.createObjectURL(e);try{await t.audioWorklet.addModule(s);const e=new AudioWorkletNode(t,"wasm4-apu",{outputChannelCount:[2]});this.processorPort=e.port,e.connect(t.destination)}catch(i){let e;console.warn("AudioWorklet loading failed, falling back to slow audio",i);const s=(t,s)=>{e=new s};new Function("registerProcessor","AudioWorkletProcessor",Gt)(s,class{}),this.processor=e;const n=t.createScriptProcessor(1024,0,2);n.onaudioprocess=t=>{const s=t.outputBuffer.getChannelData(0),i=t.outputBuffer.getChannelData(1);e.process(null,[[s,i]],null)},n.connect(t.destination)}}tick(){null!=this.processorPort?this.processorPort.postMessage("tick"):this.processor.tick()}tone(t,e,s,i){null!=this.processorPort?this.processorPort.postMessage([t,e,s,i]):this.processor.tone(t,e,s,i)}unlockAudio(){const t=this.audioCtx;"suspended"==t.state&&t.resume()}pauseAudio(){const t=this.audioCtx;"running"==t.state&&t.suspend()}}class qt{constructor(t){this.bytes=new Uint8Array(t,160,6400),this.drawColors=new Uint16Array(t,20,1)}clear(){this.bytes.fill(0)}drawPoint(t,e,s){const i=ft*s+e>>>2,n=(3&e)<<1,r=3<<n;this.bytes[i]=t<<n|this.bytes[i]&~r}drawPointUnclipped(t,e,s){e>=0&&e<ft&&s>=0&&s<mt&&this.drawPoint(t,e,s)}drawHLineFast(t,e,s,i){const n=i-(3&i),r=Math.min(e+3&-4,n);if(n-r>3){for(let n=e;n<r;n++)this.drawPoint(t,n,s);const i=ft*s+r>>>2,o=ft*s+n>>>2,a=85*t;this.bytes.fill(a,i,o),e=n}for(let o=e;o<i;o++)this.drawPoint(t,o,s)}drawHLineUnclipped(t,e,s,i){s>=0&&s<mt&&(e<0&&(e=0),i>ft&&(i=ft),e<i&&this.drawHLineFast(t,e,s,i))}drawHLine(t,e,s){const i=15&this.drawColors[0];if(0==i)return;const n=i-1&3;this.drawHLineUnclipped(n,t,e,t+s)}drawVLine(t,e,s){if(e+s<=0||t<0||t>=ft)return;const i=15&this.drawColors[0];if(0==i)return;const n=Math.max(0,e),r=Math.min(mt,e+s),o=i-1&3;for(let a=n;a<r;a++)this.drawPoint(o,t,a)}drawRect(t,e,s,i){const n=Math.max(0,t),r=Math.max(0,e),o=t+s,a=e+i,l=Math.max(0,Math.min(o,ft)),h=Math.max(0,Math.min(a,mt)),c=this.drawColors[0],d=15&c,u=c>>>4&15;if(0!==d){const t=d-1&3;for(let e=r;e<h;++e)this.drawHLineFast(t,n,e,l)}if(0!==u){const s=u-1&3;if(t>=0&&t<ft)for(let e=r;e<h;++e)this.drawPoint(s,t,e);if(o>0&&o<=ft)for(let t=r;t<h;++t)this.drawPoint(s,o-1,t);e>=0&&e<mt&&this.drawHLineFast(s,n,e,l),a>0&&a<=mt&&this.drawHLineFast(s,n,a-1,l)}}drawOval(t,e,s,i){const n=this.drawColors[0],r=15&n,o=n>>>4&15;if(15===o)return;const a=o-1&3,l=r-1&3;let h=s-1;const c=i-1;let d=c%2,u=e+Math.floor(i/2),p=t,f=t+s-1,m=u-d;const y=h*h,w=c*c;let g=4*(1-h)*w,b=4*(d+1)*y,v=g+b+d*y;h=8*y,d=8*w;do{this.drawPointUnclipped(a,f,u),this.drawPointUnclipped(a,p,u),this.drawPointUnclipped(a,p,m),this.drawPointUnclipped(a,f,m);const t=p+1;0!==r&&f-t>0&&(this.drawHLineUnclipped(l,t,u,f),this.drawHLineUnclipped(l,t,m,f));const e=2*v;e<=b&&(u+=1,m-=1,b+=h,v+=b),(e>=g||e>b)&&(p+=1,f-=1,g+=d,v+=g)}while(p<=f);for(;u-m<i;)this.drawPointUnclipped(a,p-1,u),this.drawPointUnclipped(a,f+1,u),u+=1,this.drawPointUnclipped(a,p-1,m),this.drawPointUnclipped(a,f+1,m),m-=1}drawLine(t,e,s,i){const n=15&this.drawColors[0];if(0===n)return;const r=n-1&3;if(e>i){let n=t;t=s,s=n,n=e,e=i,i=n}const o=Math.abs(s-t),a=t<s?1:-1,l=i-e;let h,c=(o>l?o:-l)/2;for(;this.drawPointUnclipped(r,t,e),t!==s||e!==i;)h=c,h>-o&&(c-=l,t+=a),h<l&&(c+=o,e++)}drawText(t,e,s){let i=e;for(let n=0,r=t.length;n<r;++n){const r=t[n];if(0===r)return;10===r?(s+=8,i=e):r>=32&&r<=255?(this.blit(xt,i,s,8,8,0,r-32<<3,8),i+=8):i+=8}}blit(t,e,s,i,n,r,o,a,l=!1,h=!1,c=!1,d=!1){const u=this.drawColors[0];let p,f,m,y;d?(h=!h,p=Math.max(0,s)-s,f=Math.max(0,e)-e,m=Math.min(i,mt-s),y=Math.min(n,ft-e)):(p=Math.max(0,e)-e,f=Math.max(0,s)-s,m=Math.min(i,ft-e),y=Math.min(n,mt-s));for(let w=f;w<y;w++)for(let f=p;f<m;f++){const p=e+(d?w:f),m=s+(d?f:w);let y;const g=(o+(c?n-w-1:w))*a+(r+(h?i-f-1:f));if(l){y=t[g>>>2]>>>6-((3&g)<<1)&3}else{y=t[g>>>3]>>>7-(7&g)&1}const b=u>>>(y<<2)&15;0!==b&&this.drawPoint(b-1&3,p,m)}}}const Yt=6409,Jt=3553;class Xt{constructor(t){this.gl=t,this.colorBuffer=new Uint32Array(6400),this.paletteBuffer=new Float32Array(12),this.lastPalette=Array(4),this.paletteLocation=null;const e=new Uint32Array(256);for(let i=0;i<256;++i){const t=i>>6&3,s=i>>4&3,n=i>>2&3,r=3&i;e[i]=t<<30|s<<22|n<<14|r<<6}this.table=e;const s=t.canvas;s.addEventListener("webglcontextlost",(t=>{t.preventDefault()})),s.addEventListener("webglcontextrestored",(()=>{this.initGL()})),this.initGL()}initGL(){const t=this.gl;function e(e,s){const i=t.createShader(e);if(t.shaderSource(i,s),t.compileShader(i),!t.getShaderParameter(i,35713))throw new Error(t.getShaderInfoLog(i)+"");return i}this.lastPalette=Array(4);const s=e(35633,"\n attribute vec2 pos;\n varying vec2 framebufferCoord;\n\n void main () {\n framebufferCoord = pos*vec2(0.5, -0.5) + 0.5;\n gl_Position = vec4(pos, 0, 1);\n }\n "),i=e(35632,`\n precision mediump float;\n uniform vec3 palette[4];\n uniform sampler2D framebuffer;\n varying vec2 framebufferCoord;\n\n vec3 lookup(float index) {\n vec3 p = palette[0];\n ${Array.from({length:3},((t,e)=>`p = mix(p, palette[${e+1}], step(${((e+1)/4).toFixed(2)}, index));`)).join("\n")}\n return p;\n }\n\n void main () {\n gl_FragColor = vec4(lookup(texture2D(framebuffer, framebufferCoord).r), 1.);\n }\n `),n=t.createProgram();if(t.attachShader(n,s),t.attachShader(n,i),t.linkProgram(n),!t.getProgramParameter(n,35714))throw new Error(t.getProgramInfoLog(n)+"");t.useProgram(n),this.paletteLocation=t.getUniformLocation(n,"palette"),t.uniform1i(t.getUniformLocation(n,"framebuffer"),0),t.detachShader(n,s),t.deleteShader(s),t.detachShader(n,i),t.deleteShader(i),function(e){const s=t.createTexture();t.activeTexture(e),t.bindTexture(Jt,s),t.texParameteri(Jt,10242,33071),t.texParameteri(Jt,10243,33071),t.texParameteri(Jt,10240,9728),t.texParameteri(Jt,10241,9728)}(33984),t.texImage2D(Jt,0,Yt,ft,mt,0,Yt,5121,null);const r=t.getAttribLocation(n,"pos"),o=t.createBuffer(),a=new Float32Array([-1,-1,-1,1,1,1,1,1,1,-1,-1,-1]);t.bindBuffer(34962,o),t.bufferData(34962,a,35044),t.enableVertexAttribArray(r),t.vertexAttribPointer(r,2,5126,!1,0,0)}composite(t,e){const s=this.gl,i=e.bytes,n=this.colorBuffer,r=this.table,o=this.lastPalette,a=this.paletteBuffer;let l=!1;for(let h=0,c=0;h<4;++h){const e=t[h];l=l||o[h]!==e,a[c++]=(e>>16&255)/255,a[c++]=(e>>8&255)/255,a[c++]=(255&e)/255,o[h]=e}l&&s.uniform3fv(this.paletteLocation,this.paletteBuffer);for(let h=0;h<6400;++h)n[h]=r[i[h]];s.texImage2D(Jt,0,Yt,ft,mt,0,Yt,5121,new Uint8Array(n.buffer)),s.drawArrays(4,0,6)}}function Zt(t,e){const s=e.reduce(((t,e)=>t+(0===e[0]?e[2]-e[1]:e[1].length)),0),i=new Uint8Array(s);let n=0;for(const r of e)0===r[0]?(i.set(t.slice(r[1],r[2]),n),n+=r[2]-r[1]):(i.set(r[1],n),n+=r[1].length);return i}function Qt(t){const e=[];do{const s=127&t;t>>=7,e.push(t?128|s:s)}while(t);return new Uint8Array(e)}function te(t,e=0){let s=0,i=0,n=0;do{s=t[e++],i|=(127&s)<<n,n+=7}while(128&s);return[i,e]}class ee{constructor(t){this.wasmBuffer=null