shinygen 4.6.2-rc.3 → 4.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.pck CHANGED
Binary file
package/index.wasm.br CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shinygen",
3
- "version": "4.6.2-rc.3",
3
+ "version": "4.6.2",
4
4
  "description": "Shiny Gen Engine \u2014 a WebGPU game engine for the browser, with a WebGL2 fallback engine. One script tag; ShinyGen.start() boots the engine on your canvas and runs inline gds scripts.",
5
5
  "main": "shinygen.js",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
package/shinygen.js CHANGED
@@ -1 +1 @@
1
- !function(){"use strict";var e=document.currentScript,t=e?e.src.replace(/[^/]*$/,""):"./";function n(e,t,n){console.error("[ShinyGen] "+e+(t?": "+t:""));var o=document.createElement("div");o.id="shinygen-error",o.style.cssText=["position:fixed","inset:0","z-index:99999","display:flex","align-items:center","justify-content:center","background:rgba(0,0,0,0.92)","color:#e8e8e8",'font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif',"padding:2em","text-align:center"].join(";");var i=document.createElement("div");i.style.cssText="max-width:540px;line-height:1.6;";var r=document.createElement("div");if(r.style.cssText="font-size:1.4em;font-weight:600;color:#ff6b6b;margin-bottom:0.8em;",r.textContent=e,i.appendChild(r),t){var a=document.createElement("div");a.style.cssText="font-size:0.95em;color:#ccc;margin-bottom:1em;white-space:pre-wrap;font-family:monospace;text-align:left;background:rgba(255,255,255,0.06);padding:1em;border-radius:6px;max-height:300px;overflow-y:auto;",a.textContent=t,i.appendChild(a)}if(n){var d=document.createElement("div");d.style.cssText="font-size:0.9em;color:#999;margin-top:0.5em;",d.innerHTML=n,i.appendChild(d)}o.appendChild(i);var l=document.getElementById("shinygen-error");l&&l.remove(),document.body.appendChild(o)}var o=null,i=0;function r(e,t,n){var r=o!==e;o=e;var a=document.getElementById("shinygen-loading-bar"),d=document.getElementById("shinygen-loading-label"),l=document.getElementById("shinygen-loading-detail");if(r&&console.log("[ShinyGen] loading stage: "+e),a)if("connect"===e)d.textContent="Preparing...",a.style.width="2%",a.style.opacity="1",l.textContent="";else if("download"===e){d.textContent="Downloading engine...";var s=Date.now();if(!r&&s-i<80&&t!==n)return;i=s,n>0&&t<=n?(a.style.width=(t/n*100).toFixed(1)+"%",a.style.opacity="1",l.textContent=(t/1048576).toFixed(1)+" / "+(n/1048576).toFixed(1)+" MB"):(a.style.width="60%",a.style.opacity="0.5",l.textContent=(t/1048576).toFixed(1)+" MB")}else"decompress"===e?(d.textContent="Decompressing...",a.style.width="100%",a.style.opacity="0.8"):"start"===e&&(d.textContent="Starting engine...",a.style.width="100%",a.style.opacity="0.7",l.textContent="")}function a(e,t){if(!o){var n=document.getElementById("shinygen-loading-bar"),i=document.getElementById("shinygen-loading-label"),r=document.getElementById("shinygen-loading-detail");if(n)if(t>0){var a=Math.min(100,e/t*100);n.style.width=a.toFixed(1)+"%",i.textContent="Loading engine...";var d=(e/1048576).toFixed(1),l=(t/1048576).toFixed(1);r.textContent=d+" / "+l+" MB",console.log("[ShinyGen] Loading: "+d+"/"+l+" MB ("+a.toFixed(0)+"%)")}else{n.style.width="60%",n.style.opacity="0.5",i.textContent="Loading engine...";var s=(e/1048576).toFixed(1);r.textContent=s+" MB downloaded"}}}function d(){var e=document.getElementById("shinygen-loading");e&&(e.style.transition="opacity 0.3s ease",e.style.opacity="0",setTimeout(function(){e.remove()},300));var t=document.getElementById("canvas");t&&(t.style.visibility="visible")}function l(e,t){if(void 0===t.autoFit||t.autoFit){var n=(e.width||1280)/(e.height||720),o=document.createElement("style");o.id="shinygen-autofit-style",o.textContent="#canvas{max-width:100vw!important;max-height:100vh!important;object-fit:contain!important;}",document.head.appendChild(o),a(),window.addEventListener("resize",a),window.visualViewport&&window.visualViewport.addEventListener("resize",a),window.addEventListener("orientationchange",function(){setTimeout(a,100),setTimeout(a,300)});var i=null;"undefined"!=typeof MutationObserver&&(i=new MutationObserver(function(){a()})).observe(e,{attributes:!0,attributeFilter:["width","height"]});var r=Date.now();requestAnimationFrame(function e(){a(),Date.now()-r<2e3&&requestAnimationFrame(e)}),s._fitCanvas=a}function a(){var i=function(){var e=t.container?"string"==typeof t.container?document.querySelector(t.container):t.container:null;if(e)return{w:e.clientWidth,h:e.clientHeight};var n=window.visualViewport,o=Math.min(window.innerWidth,document.documentElement.clientWidth||1/0),i=Math.min(window.innerHeight,document.documentElement.clientHeight||1/0);return n&&(o=Math.min(o,n.width),i=Math.min(i,n.height)),{w:o,h:i}}(),r=i.w,a=r/n;a>i.h&&(r=(a=i.h)*n),r=Math.floor(r),a=Math.floor(a);var d=Math.max(0,Math.floor((i.h-a)/2));Math.max(0,Math.floor((i.w-r)/2));e.style.cssText="display:block!important;width:"+r+"px!important;height:"+a+"px!important;margin:"+d+"px auto 0!important;padding:0!important;touch-action:none!important;max-width:100vw!important;max-height:100vh!important;",o.textContent="#canvas{width:"+r+"px!important;height:"+a+"px!important;max-width:100vw!important;max-height:100vh!important;margin:"+d+"px auto 0!important;display:block!important;touch-action:none!important;}"}}var s={};s._reportError=function(e,t){n(e,t,'Check your <code>&lt;script type="text/gdscript"&gt;</code> for errors.')},s._pendingReload=null,s._onReloadResult=null,s.reload=function(e,t){return t=t||0,new Promise(function(n,o){s._onReloadResult=function(e,t){s._onReloadResult=null,e?n(t):o(new Error(t))},s._pendingReload={index:t,source:e}})},s._eventHandlers={},s._gdCallback=null,s._setGDCallback=function(e){s._gdCallback=e},s._dispatch=function(e,t){var n=s._eventHandlers[e];if(n)for(var o=0;o<n.length;o++)try{n[o](t)}catch(t){console.error("[ShinyGen] Event handler error ("+e+"):",t)}},s.on=function(e,t){s._eventHandlers[e]||(s._eventHandlers[e]=[]),s._eventHandlers[e].push(t)},s.send=function(e,t){s._gdCallback?s._gdCallback(e,t||""):console.warn('[ShinyGen] Engine not ready — cannot send "'+e+'"')},s.sendJSON=function(e,t){s.send(e,JSON.stringify(t))},s.onJSON=function(e,t){s.on(e,function(n){try{t(JSON.parse(n))}catch(t){console.error("[ShinyGen] JSON parse error ("+e+"):",t)}})};var c=!1,u=null;function h(e,t){if(!c){c=!0;var n=function(e){var t=e+"vendor/brotli/brotli_dec_wasm.js",n=e+"vendor/brotli/brotli_dec_wasm_bg.wasm";return import(t).then(function(e){return Promise.resolve(e.default(n)).then(function(){return e})})}(e),i=window.fetch.bind(window);if(t&&/index$/.test(t)){var a=t+".wasm.br",d=i(a);d.then(function(e){var t=parseInt(e.headers.get("content-length")||"0",10);e.ok&&"connect"===o&&r("download",0,t)},function(){}),u={url:a,promise:d}}var l=function(e){return new Response(e,{status:200,headers:{"Content-Type":"application/wasm"}})},s=function(e){return e.arrayBuffer().then(function(e){var t=new Uint8Array(e);return 0===t[0]&&97===t[1]&&115===t[2]&&109===t[3]?(console.log("[ShinyGen] engine wasm: served pre-decoded ("+(e.byteLength/1048576).toFixed(1)+" MB)"),r("start"),l(e)):n.then(function(n){var o=n.decompress(t);return console.log("[ShinyGen] engine wasm: brotli "+(e.byteLength/1048576).toFixed(1)+" MB → "+(o.byteLength/1048576).toFixed(1)+" MB"),r("start"),l(o)})})};window.fetch=function(e,t){var a="string"==typeof e?e:e&&e.url||"";if(!/index\.wasm($|\?)/.test(a))return i(e,t);var d,c=a.replace(/index\.wasm/,"index.wasm.br"),h=function(n){return console.log("[ShinyGen] engine wasm: "+n+", falling back to raw index.wasm"),o=null,i(e,t)};return u&&u.url===c?(d=u.promise,u=null):d=i(c,t),d.then(function(e){return e.ok?e.body&&"undefined"!=typeof ReadableStream?function(e){var t=parseInt(e.headers.get("content-length")||"0",10)||0,o=0,i=e.body.getReader(),a=function(e){return i.read().then(function(n){if(n.done)return e;r("download",o+=n.value.length,t);var i=n.value;return e&&((i=new Uint8Array(e.length+n.value.length)).set(e,0),i.set(n.value,e.length)),i.length>=4?i:a(i)})};return a(null).then(function(e){if(!e||e.length<4)throw new Error("engine wasm response is empty");return 0===e[0]&&97===e[1]&&115===e[2]&&109===e[3]?l(new ReadableStream({start:function(t){t.enqueue(e),r("download",o,0)},pull:function(e){return i.read().then(function(t){if(t.done)return console.log("[ShinyGen] engine wasm: served pre-decoded ("+(o/1048576).toFixed(1)+" MB, streamed)"),r("start"),void e.close();r("download",o+=t.value.length,0),e.enqueue(t.value)})},cancel:function(e){return i.cancel(e)}})):n.then(function(n){if(!n||"function"!=typeof n.DecompressStream){var a=[e],d=e.length,s=function(){return i.read().then(function(e){if(e.done){var i=new Uint8Array(d),c=0;a.forEach(function(e){i.set(e,c),c+=e.length});var u=n.decompress(i);return console.log("[ShinyGen] engine wasm: brotli "+(d/1048576).toFixed(1)+" MB → "+(u.byteLength/1048576).toFixed(1)+" MB"),r("start"),l(u)}return r("download",o+=e.value.length,t),a.push(e.value),d+=e.value.length,s()})};return s()}var c=new n.DecompressStream,u=new Uint8Array(0),h=e,g=!1,p=!1,m=!1,f=function(){try{c.free()}catch(e){}},y=function(e,t){m=!0,f(),i.cancel().catch(function(){}),e.error(t)},v=function(e){if(!m){if(g||h&&h.length){var n,a,d,l=h&&h.length?h:u;try{var s=c.decompress(l,4194304);n=s.code,a=s.input_offset,d=s.buf,s.free()}catch(t){return void y(e,new Error("brotli decode failed: "+t))}if(l.length&&(h=a<l.length?l.subarray(a):null),g=3===n,d&&d.length&&e.enqueue(d),1===n){m=!0;var b=0;try{b=c.total_out()}catch(e){}return f(),i.cancel().catch(function(){}),console.log("[ShinyGen] engine wasm: brotli "+(o/1048576).toFixed(1)+" MB → "+(b/1048576).toFixed(1)+" MB (streamed)"),r("start"),void e.close()}if(d&&d.length)return;return v(e)}if(!p)return i.read().then(function(n){return n.done?(p=!0,r("decompress"),v(e)):(r("download",o+=n.value.length,t),h=n.value,v(e))},function(t){y(e,t)});y(e,new Error("brotli stream truncated after "+o+" bytes"))}};return l(new ReadableStream({pull:function(e){return v(e)},cancel:function(e){return m=!0,f(),i.cancel(e)}}))})})}(e).catch(function(e){return console.warn("[ShinyGen] engine wasm: streaming decode failed ("+e+"), retrying one-shot"),i(c,t).then(function(e){return e.ok?s(e):h("no .br (HTTP "+e.status+")")},function(e){return h(".br refetch failed ("+e+")")}).catch(function(e){return h("brotli decode unavailable ("+e+")")})}):s(e):h("no .br (HTTP "+e.status+")")},function(e){return h(".br fetch failed ("+e+")")})}}}var g="4.6.2-rc.3";s.start=async function(e){if(e=e||{},console.log("[ShinyGen] shinygen package "+(0===g.indexOf("__")?"dev (unstamped loader)":"v"+g)+" — the engine banner below reports the ENGINE build, not the package version"),void 0===e.extras||void 0===e.i18n||void 0===e.renderer){var o=document.querySelector('script[type="application/shinygen-project"]');if(o)try{var i=JSON.parse(o.textContent);void 0===e.extras&&(e.extras=!!i.extras),void 0===e.i18n&&(e.i18n=!!i.i18n),void 0===e.renderer&&i.renderer&&(e.renderer=String(i.renderer))}catch(e){}}var c=e.renderer;if("webgl"!==c&&"auto"!==c&&(c="webgpu"),"auto"===c){var u=null;if(navigator.gpu)try{await navigator.gpu.requestAdapter()||(u="no WebGPU adapter")}catch(e){u="adapter request failed: "+(e.message||e)}else u="navigator.gpu is undefined";c=u?"webgl":"webgpu",u&&console.warn("[ShinyGen] WebGPU is not available ("+u+") — running under the WebGL2 engine.")}s.renderer=c;var p="webgl"===c?"webgl/":"",m=e.executable||t+p+"index";if(console.log("[ShinyGen] engine: single build, renderer: "+c+(e.i18n?" + i18n (ICU data)":"")),"webgpu"===c){if(!navigator.gpu){var f=navigator.userAgent;throw n("WebGPU is not available",null,"This app requires WebGPU, which your browser does not currently support.<br><br>"+(-1!==f.indexOf("Firefox")?"Firefox: Open <code>about:config</code> and set <code>dom.webgpu.enabled</code> to <code>true</code>, then restart.":-1!==f.indexOf("Safari")&&-1===f.indexOf("Chrome")?"Safari: Open Settings &rarr; Feature Flags and enable <b>WebGPU</b>.":"Try <b>Chrome 113+</b>, <b>Edge 113+</b>, or <b>Opera 99+</b> on desktop.")),new Error("ShinyGen: WebGPU is not available (navigator.gpu is undefined).")}}else{var y=null;try{y=document.createElement("canvas").getContext("webgl2")}catch(e){}if(!y)throw n("WebGL2 is not available",null,"This engine requires WebGL2, which your browser does not currently support.<br><br>WebGL2 ships in all modern browsers — try updating your browser or enabling hardware acceleration."),new Error("ShinyGen: WebGL2 is not available.")}if(function(){var e=document.createElement("div");e.id="shinygen-loading",e.style.cssText=["position:fixed","inset:0","z-index:99998","display:flex","flex-direction:column","align-items:center","justify-content:center","background:#111","color:#e8e8e8",'font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif',"will-change:transform"].join(";");var t=document.createElement("div");t.id="shinygen-loading-label",t.style.cssText="font-size:1.1em;margin-bottom:1.2em;color:#ccc;",t.textContent="Initializing engine...",e.appendChild(t);var n=document.createElement("div");n.style.cssText="width:280px;height:4px;background:rgba(255,255,255,0.1);border-radius:2px;overflow:hidden;";var o=document.createElement("div");o.id="shinygen-loading-bar",o.style.cssText="width:0%;height:100%;background:#4a9eff;border-radius:2px;transition:width 0.2s ease;",n.appendChild(o),e.appendChild(n);var i=document.createElement("div");i.id="shinygen-loading-detail",i.style.cssText="font-size:0.8em;color:#666;margin-top:0.8em;",i.textContent="",e.appendChild(i);var r=document.createElement("div");r.id="shinygen-loading-brand",r.style.cssText="position:absolute;bottom:1.6em;font-size:0.72em;color:#555;letter-spacing:0.04em;",r.textContent="Made with Shiny Gen Engine",e.appendChild(r),(document.body||document.documentElement).appendChild(e)}(),!1!==e.brotliWasm&&(r("connect"),h(t,m)),"webgpu"===c)try{if(!await navigator.gpu.requestAdapter())throw d(),n("No WebGPU adapter found",null,"Your browser supports WebGPU but no compatible GPU was found.<br><br>This can happen with unsupported GPUs, outdated drivers, or headless/virtual environments.<br><br>Try updating your GPU drivers, or use a different device."),new Error("ShinyGen: WebGPU adapter not available.")}catch(e){if(-1!==e.message.indexOf("ShinyGen"))throw e;throw d(),n("WebGPU adapter request failed",e.message,"Your browser supports WebGPU but failed to initialize it."),new Error("ShinyGen: WebGPU adapter request failed: "+e.message)}var v=null;e.canvas&&(v="string"==typeof e.canvas?document.querySelector(e.canvas):e.canvas),v&&"canvas"!==v.id&&(v.id="canvas"),v||(v=document.getElementById("canvas")),v||((v=document.createElement("canvas")).id="canvas",v.style.cssText="display:block;margin:0 auto;padding:0;max-width:100vw;max-height:100vh;",document.body.appendChild(v)),v.style.visibility="hidden";var b,w=e.engineJs||t+p+"index.js";try{await(b=w,new Promise(function(e,t){var n=document.createElement("script");n.src=b,n.onload=e,n.onerror=function(){t(new Error("Failed to load: "+b))},document.head.appendChild(n)}))}catch(e){throw d(),n("Failed to load engine",e.message,"Check that the engine files ("+p+"index.js, "+p+"index.wasm) are served relative to shinygen.js."),e}if("undefined"==typeof Engine)throw d(),n("Engine failed to initialize","The Engine class was not found after loading "+w,"The engine JS file may be corrupt or incompatible."),new Error("ShinyGen: Engine class not found after loading "+w);console.log("[ShinyGen] Engine JS loaded");var x=void 0===e.autoFit||e.autoFit?0:2,E=new Engine({args:"webgl"===c?["--rendering-driver","opengl3","--rendering-method","gl_compatibility"]:[],canvasResizePolicy:void 0!==e.canvasResizePolicy?e.canvasResizePolicy:x,executable:m,mainPack:e.mainPack||("webgl"===c?t+"index.pck":null),focusCanvas:!0,renderingDriver:"webgl"===c?"":"webgpu",onProgress:a});e.i18n&&"function"==typeof E.preloadFile&&(E.preloadFile(t+"icudt_godot.dat","icudt_godot.dat"),console.log("[ShinyGen] i18n: ICU data queued → res://icudt_godot.dat")),console.log("[ShinyGen] Starting engine...");try{await E.startGame()}catch(e){d();var C=e.message||String(e),k="The engine failed to start.";throw-1!==C.indexOf("wasm")||-1!==C.indexOf("fetch")||-1!==C.indexOf("Fetch")?k="Check that <code>"+p+"index.wasm</code> is served relative to shinygen.js.":"webgpu"!==c||-1===C.indexOf("WebGPU")&&-1===C.indexOf("gpu")?"webgl"===c&&-1!==C.toLowerCase().indexOf("gl")&&(k="WebGL2 initialization failed. Try updating your browser or enabling hardware acceleration."):k="WebGPU initialization failed. Your GPU or driver may not be supported.",n("Engine failed to start",C,k),e}return d(),function(e){var t=document.querySelector('meta[name="viewport"]');t&&t.setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"),e.style.touchAction="none",document.body.style.touchAction="none",document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.width="100%",document.body.style.height="100%",document.documentElement.style.overflow="hidden",document.documentElement.style.position="fixed",document.documentElement.style.width="100%",document.documentElement.style.height="100%",document.addEventListener("touchmove",function(t){t.target===e||t.target.closest("#shinygen-touchcontrols")||t.preventDefault()},{passive:!1})}(v),l(v,e),function(e,t){var n=void 0!==t.touchControls?t.touchControls:"auto";if(!1!==n&&"none"!==n&&("auto"!==n||"ontouchstart"in window)){var o=document.createElement("div");o.id="shinygen-touchcontrols",o.style.cssText=["position:fixed","inset:0","z-index:9999","pointer-events:none","user-select:none","-webkit-user-select:none","touch-action:none"].join(";");var i=document.createElement("div");i.style.cssText=["position:absolute","left:16px","bottom:16px","width:140px","height:140px","pointer-events:auto"].join(";"),[{key:"w",label:"▲",x:45,y:0,w:50,h:45},{key:"s",label:"▼",x:45,y:95,w:50,h:45},{key:"a",label:"◀",x:0,y:45,w:45,h:50},{key:"d",label:"▶",x:95,y:45,w:45,h:50}].forEach(function(e){var t=document.createElement("div");t.style.cssText="position:absolute;display:flex;align-items:center;justify-content:center;background:rgba(255,255,255,0.13);border:1.5px solid rgba(255,255,255,0.25);border-radius:8px;color:rgba(255,255,255,0.7);font-size:18px;transition:background 0.08s;-webkit-tap-highlight-color:transparent;left:"+e.x+"px;top:"+e.y+"px;width:"+e.w+"px;height:"+e.h+"px;",t.textContent=e.label,t.dataset.key=e.key,i.appendChild(t)});var r=document.createElement("div");r.style.cssText="position:absolute;left:45px;top:45px;width:50px;height:50px;background:rgba(255,255,255,0.06);border-radius:50%;",i.appendChild(r),o.appendChild(i),[{key:"Enter",label:"A",bottom:60,right:16},{key:"Escape",label:"B",bottom:16,right:72}].forEach(function(e){var t=document.createElement("div");t.style.cssText=["position:absolute","pointer-events:auto","bottom:"+e.bottom+"px","right:"+e.right+"px","width:52px","height:52px","border-radius:50%","display:flex","align-items:center","justify-content:center","background:rgba(255,255,255,0.13)","border:1.5px solid rgba(255,255,255,0.25)","color:rgba(255,255,255,0.7)","font-size:16px","font-weight:bold","font-family:-apple-system,BlinkMacSystemFont,sans-serif","-webkit-tap-highlight-color:transparent"].join(";"),t.textContent=e.label,t.dataset.key=e.key,o.appendChild(t)}),document.body.appendChild(o);var a={};o.addEventListener("touchstart",l,{passive:!1}),o.addEventListener("touchend",l,{passive:!1}),o.addEventListener("touchcancel",l,{passive:!1}),o.addEventListener("touchmove",function(e){e.preventDefault();for(var t={},n=0;n<e.touches.length;n++){var i=e.touches[n],r=document.elementFromPoint(i.clientX,i.clientY);r&&r.dataset&&r.dataset.key&&(t[r.dataset.key]=r)}Object.keys(a).forEach(function(e){t[e]||(delete a[e],o.querySelectorAll('[data-key="'+e+'"]').forEach(function(e){e.style.background="rgba(255,255,255,0.13)"}),d(e,"keyup"))}),Object.keys(t).forEach(function(e){a[e]||(a[e]=!0,t[e].style.background="rgba(255,255,255,0.35)",d(e,"keydown"))})},{passive:!1})}function d(t,n){e.focus();var o=new KeyboardEvent(n,{key:t,code:"Enter"===t?"Enter":"Escape"===t?"Escape":"ArrowUp"===t?"ArrowUp":"ArrowDown"===t?"ArrowDown":"ArrowLeft"===t?"ArrowLeft":"ArrowRight"===t?"ArrowRight":"Key"+t.toUpperCase(),keyCode:"Enter"===t?13:"Escape"===t?27:t.toUpperCase().charCodeAt(0),bubbles:!0,cancelable:!0});e.dispatchEvent(o)}function l(e){e.preventDefault();var t=e.target.closest("[data-key]");if(t){var n=t.dataset.key;"touchstart"===e.type?a[n]||(a[n]=!0,t.style.background="rgba(255,255,255,0.35)",d(n,"keydown")):"touchend"!==e.type&&"touchcancel"!==e.type||a[n]&&(delete a[n],t.style.background="rgba(255,255,255,0.13)",d(n,"keyup"))}}}(v,e),console.log("[ShinyGen] Engine started"),E},window.ShinyGen=s}();
1
+ !function(){"use strict";var e=document.currentScript,t=e?e.src.replace(/[^/]*$/,""):"./";function n(e,t,n){console.error("[ShinyGen] "+e+(t?": "+t:""));var o=document.createElement("div");o.id="shinygen-error",o.style.cssText=["position:fixed","inset:0","z-index:99999","display:flex","align-items:center","justify-content:center","background:rgba(0,0,0,0.92)","color:#e8e8e8",'font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif',"padding:2em","text-align:center"].join(";");var i=document.createElement("div");i.style.cssText="max-width:540px;line-height:1.6;";var r=document.createElement("div");if(r.style.cssText="font-size:1.4em;font-weight:600;color:#ff6b6b;margin-bottom:0.8em;",r.textContent=e,i.appendChild(r),t){var a=document.createElement("div");a.style.cssText="font-size:0.95em;color:#ccc;margin-bottom:1em;white-space:pre-wrap;font-family:monospace;text-align:left;background:rgba(255,255,255,0.06);padding:1em;border-radius:6px;max-height:300px;overflow-y:auto;",a.textContent=t,i.appendChild(a)}if(n){var d=document.createElement("div");d.style.cssText="font-size:0.9em;color:#999;margin-top:0.5em;",d.innerHTML=n,i.appendChild(d)}o.appendChild(i);var l=document.getElementById("shinygen-error");l&&l.remove(),document.body.appendChild(o)}var o=null,i=0;function r(e,t,n){var r=o!==e;o=e;var a=document.getElementById("shinygen-loading-bar"),d=document.getElementById("shinygen-loading-label"),l=document.getElementById("shinygen-loading-detail");if(r&&console.log("[ShinyGen] loading stage: "+e),a)if("connect"===e)d.textContent="Preparing...",a.style.width="2%",a.style.opacity="1",l.textContent="";else if("download"===e){d.textContent="Downloading engine...";var s=Date.now();if(!r&&s-i<80&&t!==n)return;i=s,n>0&&t<=n?(a.style.width=(t/n*100).toFixed(1)+"%",a.style.opacity="1",l.textContent=(t/1048576).toFixed(1)+" / "+(n/1048576).toFixed(1)+" MB"):(a.style.width="60%",a.style.opacity="0.5",l.textContent=(t/1048576).toFixed(1)+" MB")}else"decompress"===e?(d.textContent="Decompressing...",a.style.width="100%",a.style.opacity="0.8"):"start"===e&&(d.textContent="Starting engine...",a.style.width="100%",a.style.opacity="0.7",l.textContent="")}function a(e,t){if(!o){var n=document.getElementById("shinygen-loading-bar"),i=document.getElementById("shinygen-loading-label"),r=document.getElementById("shinygen-loading-detail");if(n)if(t>0){var a=Math.min(100,e/t*100);n.style.width=a.toFixed(1)+"%",i.textContent="Loading engine...";var d=(e/1048576).toFixed(1),l=(t/1048576).toFixed(1);r.textContent=d+" / "+l+" MB",console.log("[ShinyGen] Loading: "+d+"/"+l+" MB ("+a.toFixed(0)+"%)")}else{n.style.width="60%",n.style.opacity="0.5",i.textContent="Loading engine...";var s=(e/1048576).toFixed(1);r.textContent=s+" MB downloaded"}}}function d(){var e=document.getElementById("shinygen-loading");e&&(e.style.transition="opacity 0.3s ease",e.style.opacity="0",setTimeout(function(){e.remove()},300));var t=document.getElementById("canvas");t&&(t.style.visibility="visible")}function l(e,t){if(void 0===t.autoFit||t.autoFit){var n=(e.width||1280)/(e.height||720),o=document.createElement("style");o.id="shinygen-autofit-style",o.textContent="#canvas{max-width:100vw!important;max-height:100vh!important;object-fit:contain!important;}",document.head.appendChild(o),a(),window.addEventListener("resize",a),window.visualViewport&&window.visualViewport.addEventListener("resize",a),window.addEventListener("orientationchange",function(){setTimeout(a,100),setTimeout(a,300)});var i=null;"undefined"!=typeof MutationObserver&&(i=new MutationObserver(function(){a()})).observe(e,{attributes:!0,attributeFilter:["width","height"]});var r=Date.now();requestAnimationFrame(function e(){a(),Date.now()-r<2e3&&requestAnimationFrame(e)}),s._fitCanvas=a}function a(){var i=function(){var e=t.container?"string"==typeof t.container?document.querySelector(t.container):t.container:null;if(e)return{w:e.clientWidth,h:e.clientHeight};var n=window.visualViewport,o=Math.min(window.innerWidth,document.documentElement.clientWidth||1/0),i=Math.min(window.innerHeight,document.documentElement.clientHeight||1/0);return n&&(o=Math.min(o,n.width),i=Math.min(i,n.height)),{w:o,h:i}}(),r=i.w,a=r/n;a>i.h&&(r=(a=i.h)*n),r=Math.floor(r),a=Math.floor(a);var d=Math.max(0,Math.floor((i.h-a)/2));Math.max(0,Math.floor((i.w-r)/2));e.style.cssText="display:block!important;width:"+r+"px!important;height:"+a+"px!important;margin:"+d+"px auto 0!important;padding:0!important;touch-action:none!important;max-width:100vw!important;max-height:100vh!important;",o.textContent="#canvas{width:"+r+"px!important;height:"+a+"px!important;max-width:100vw!important;max-height:100vh!important;margin:"+d+"px auto 0!important;display:block!important;touch-action:none!important;}"}}var s={};s._reportError=function(e,t){n(e,t,'Check your <code>&lt;script type="text/gdscript"&gt;</code> for errors.')},s._pendingReload=null,s._onReloadResult=null,s.reload=function(e,t){return t=t||0,new Promise(function(n,o){s._onReloadResult=function(e,t){s._onReloadResult=null,e?n(t):o(new Error(t))},s._pendingReload={index:t,source:e}})},s._eventHandlers={},s._gdCallback=null,s._setGDCallback=function(e){s._gdCallback=e},s._dispatch=function(e,t){var n=s._eventHandlers[e];if(n)for(var o=0;o<n.length;o++)try{n[o](t)}catch(t){console.error("[ShinyGen] Event handler error ("+e+"):",t)}},s.on=function(e,t){s._eventHandlers[e]||(s._eventHandlers[e]=[]),s._eventHandlers[e].push(t)},s.send=function(e,t){s._gdCallback?s._gdCallback(e,t||""):console.warn('[ShinyGen] Engine not ready — cannot send "'+e+'"')},s.sendJSON=function(e,t){s.send(e,JSON.stringify(t))},s.onJSON=function(e,t){s.on(e,function(n){try{t(JSON.parse(n))}catch(t){console.error("[ShinyGen] JSON parse error ("+e+"):",t)}})};var c=!1,u=null;function h(e,t){if(!c){c=!0;var n=function(e){var t=e+"vendor/brotli/brotli_dec_wasm.js",n=e+"vendor/brotli/brotli_dec_wasm_bg.wasm";return import(t).then(function(e){return Promise.resolve(e.default(n)).then(function(){return e})})}(e),i=window.fetch.bind(window);if(t&&/index$/.test(t)){var a=t+".wasm.br",d=i(a);d.then(function(e){var t=parseInt(e.headers.get("content-length")||"0",10);e.ok&&"connect"===o&&r("download",0,t)},function(){}),u={url:a,promise:d}}var l=function(e){return new Response(e,{status:200,headers:{"Content-Type":"application/wasm"}})},s=function(e){return e.arrayBuffer().then(function(e){var t=new Uint8Array(e);return 0===t[0]&&97===t[1]&&115===t[2]&&109===t[3]?(console.log("[ShinyGen] engine wasm: served pre-decoded ("+(e.byteLength/1048576).toFixed(1)+" MB)"),r("start"),l(e)):n.then(function(n){var o=n.decompress(t);return console.log("[ShinyGen] engine wasm: brotli "+(e.byteLength/1048576).toFixed(1)+" MB → "+(o.byteLength/1048576).toFixed(1)+" MB"),r("start"),l(o)})})};window.fetch=function(e,t){var a="string"==typeof e?e:e&&e.url||"";if(!/index\.wasm($|\?)/.test(a))return i(e,t);var d,c=a.replace(/index\.wasm/,"index.wasm.br"),h=function(n){return console.log("[ShinyGen] engine wasm: "+n+", falling back to raw index.wasm"),o=null,i(e,t)};return u&&u.url===c?(d=u.promise,u=null):d=i(c,t),d.then(function(e){return e.ok?e.body&&"undefined"!=typeof ReadableStream?function(e){var t=parseInt(e.headers.get("content-length")||"0",10)||0,o=0,i=e.body.getReader(),a=function(e){return i.read().then(function(n){if(n.done)return e;r("download",o+=n.value.length,t);var i=n.value;return e&&((i=new Uint8Array(e.length+n.value.length)).set(e,0),i.set(n.value,e.length)),i.length>=4?i:a(i)})};return a(null).then(function(e){if(!e||e.length<4)throw new Error("engine wasm response is empty");return 0===e[0]&&97===e[1]&&115===e[2]&&109===e[3]?l(new ReadableStream({start:function(t){t.enqueue(e),r("download",o,0)},pull:function(e){return i.read().then(function(t){if(t.done)return console.log("[ShinyGen] engine wasm: served pre-decoded ("+(o/1048576).toFixed(1)+" MB, streamed)"),r("start"),void e.close();r("download",o+=t.value.length,0),e.enqueue(t.value)})},cancel:function(e){return i.cancel(e)}})):n.then(function(n){if(!n||"function"!=typeof n.DecompressStream){var a=[e],d=e.length,s=function(){return i.read().then(function(e){if(e.done){var i=new Uint8Array(d),c=0;a.forEach(function(e){i.set(e,c),c+=e.length});var u=n.decompress(i);return console.log("[ShinyGen] engine wasm: brotli "+(d/1048576).toFixed(1)+" MB → "+(u.byteLength/1048576).toFixed(1)+" MB"),r("start"),l(u)}return r("download",o+=e.value.length,t),a.push(e.value),d+=e.value.length,s()})};return s()}var c=new n.DecompressStream,u=new Uint8Array(0),h=e,g=!1,p=!1,m=!1,f=function(){try{c.free()}catch(e){}},y=function(e,t){m=!0,f(),i.cancel().catch(function(){}),e.error(t)},v=function(e){if(!m){if(g||h&&h.length){var n,a,d,l=h&&h.length?h:u;try{var s=c.decompress(l,4194304);n=s.code,a=s.input_offset,d=s.buf,s.free()}catch(t){return void y(e,new Error("brotli decode failed: "+t))}if(l.length&&(h=a<l.length?l.subarray(a):null),g=3===n,d&&d.length&&e.enqueue(d),1===n){m=!0;var b=0;try{b=c.total_out()}catch(e){}return f(),i.cancel().catch(function(){}),console.log("[ShinyGen] engine wasm: brotli "+(o/1048576).toFixed(1)+" MB → "+(b/1048576).toFixed(1)+" MB (streamed)"),r("start"),void e.close()}if(d&&d.length)return;return v(e)}if(!p)return i.read().then(function(n){return n.done?(p=!0,r("decompress"),v(e)):(r("download",o+=n.value.length,t),h=n.value,v(e))},function(t){y(e,t)});y(e,new Error("brotli stream truncated after "+o+" bytes"))}};return l(new ReadableStream({pull:function(e){return v(e)},cancel:function(e){return m=!0,f(),i.cancel(e)}}))})})}(e).catch(function(e){return console.warn("[ShinyGen] engine wasm: streaming decode failed ("+e+"), retrying one-shot"),i(c,t).then(function(e){return e.ok?s(e):h("no .br (HTTP "+e.status+")")},function(e){return h(".br refetch failed ("+e+")")}).catch(function(e){return h("brotli decode unavailable ("+e+")")})}):s(e):h("no .br (HTTP "+e.status+")")},function(e){return h(".br fetch failed ("+e+")")})}}}var g="4.6.2";s.start=async function(e){if(e=e||{},console.log("[ShinyGen] shinygen package "+(0===g.indexOf("__")?"dev (unstamped loader)":"v"+g)+" — the engine banner below reports the ENGINE build, not the package version"),void 0===e.extras||void 0===e.i18n||void 0===e.renderer){var o=document.querySelector('script[type="application/shinygen-project"]');if(o)try{var i=JSON.parse(o.textContent);void 0===e.extras&&(e.extras=!!i.extras),void 0===e.i18n&&(e.i18n=!!i.i18n),void 0===e.renderer&&i.renderer&&(e.renderer=String(i.renderer))}catch(e){}}var c=e.renderer;if("webgl"!==c&&"auto"!==c&&(c="webgpu"),"auto"===c){var u=null;if(navigator.gpu)try{await navigator.gpu.requestAdapter()||(u="no WebGPU adapter")}catch(e){u="adapter request failed: "+(e.message||e)}else u="navigator.gpu is undefined";c=u?"webgl":"webgpu",u&&console.warn("[ShinyGen] WebGPU is not available ("+u+") — running under the WebGL2 engine.")}s.renderer=c;var p="webgl"===c?"webgl/":"",m=e.executable||t+p+"index";if(console.log("[ShinyGen] engine: single build, renderer: "+c+(e.i18n?" + i18n (ICU data)":"")),"webgpu"===c){if(!navigator.gpu){var f=navigator.userAgent;throw n("WebGPU is not available",null,"This app requires WebGPU, which your browser does not currently support.<br><br>"+(-1!==f.indexOf("Firefox")?"Firefox: Open <code>about:config</code> and set <code>dom.webgpu.enabled</code> to <code>true</code>, then restart.":-1!==f.indexOf("Safari")&&-1===f.indexOf("Chrome")?"Safari: Open Settings &rarr; Feature Flags and enable <b>WebGPU</b>.":"Try <b>Chrome 113+</b>, <b>Edge 113+</b>, or <b>Opera 99+</b> on desktop.")),new Error("ShinyGen: WebGPU is not available (navigator.gpu is undefined).")}}else{var y=null;try{y=document.createElement("canvas").getContext("webgl2")}catch(e){}if(!y)throw n("WebGL2 is not available",null,"This engine requires WebGL2, which your browser does not currently support.<br><br>WebGL2 ships in all modern browsers — try updating your browser or enabling hardware acceleration."),new Error("ShinyGen: WebGL2 is not available.")}if(function(){var e=document.createElement("div");e.id="shinygen-loading",e.style.cssText=["position:fixed","inset:0","z-index:99998","display:flex","flex-direction:column","align-items:center","justify-content:center","background:#111","color:#e8e8e8",'font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif',"will-change:transform"].join(";");var t=document.createElement("div");t.id="shinygen-loading-label",t.style.cssText="font-size:1.1em;margin-bottom:1.2em;color:#ccc;",t.textContent="Initializing engine...",e.appendChild(t);var n=document.createElement("div");n.style.cssText="width:280px;height:4px;background:rgba(255,255,255,0.1);border-radius:2px;overflow:hidden;";var o=document.createElement("div");o.id="shinygen-loading-bar",o.style.cssText="width:0%;height:100%;background:#4a9eff;border-radius:2px;transition:width 0.2s ease;",n.appendChild(o),e.appendChild(n);var i=document.createElement("div");i.id="shinygen-loading-detail",i.style.cssText="font-size:0.8em;color:#666;margin-top:0.8em;",i.textContent="",e.appendChild(i);var r=document.createElement("div");r.id="shinygen-loading-brand",r.style.cssText="position:absolute;bottom:1.6em;font-size:0.72em;color:#555;letter-spacing:0.04em;",r.textContent="Made with Shiny Gen Engine",e.appendChild(r),(document.body||document.documentElement).appendChild(e)}(),!1!==e.brotliWasm&&(r("connect"),h(t,m)),"webgpu"===c)try{if(!await navigator.gpu.requestAdapter())throw d(),n("No WebGPU adapter found",null,"Your browser supports WebGPU but no compatible GPU was found.<br><br>This can happen with unsupported GPUs, outdated drivers, or headless/virtual environments.<br><br>Try updating your GPU drivers, or use a different device."),new Error("ShinyGen: WebGPU adapter not available.")}catch(e){if(-1!==e.message.indexOf("ShinyGen"))throw e;throw d(),n("WebGPU adapter request failed",e.message,"Your browser supports WebGPU but failed to initialize it."),new Error("ShinyGen: WebGPU adapter request failed: "+e.message)}var v=null;e.canvas&&(v="string"==typeof e.canvas?document.querySelector(e.canvas):e.canvas),v&&"canvas"!==v.id&&(v.id="canvas"),v||(v=document.getElementById("canvas")),v||((v=document.createElement("canvas")).id="canvas",v.style.cssText="display:block;margin:0 auto;padding:0;max-width:100vw;max-height:100vh;",document.body.appendChild(v)),v.style.visibility="hidden";var b,w=e.engineJs||t+p+"index.js";try{await(b=w,new Promise(function(e,t){var n=document.createElement("script");n.src=b,n.onload=e,n.onerror=function(){t(new Error("Failed to load: "+b))},document.head.appendChild(n)}))}catch(e){throw d(),n("Failed to load engine",e.message,"Check that the engine files ("+p+"index.js, "+p+"index.wasm) are served relative to shinygen.js."),e}if("undefined"==typeof Engine)throw d(),n("Engine failed to initialize","The Engine class was not found after loading "+w,"The engine JS file may be corrupt or incompatible."),new Error("ShinyGen: Engine class not found after loading "+w);console.log("[ShinyGen] Engine JS loaded");var x=void 0===e.autoFit||e.autoFit?0:2,E=new Engine({args:"webgl"===c?["--rendering-driver","opengl3","--rendering-method","gl_compatibility"]:[],canvasResizePolicy:void 0!==e.canvasResizePolicy?e.canvasResizePolicy:x,executable:m,mainPack:e.mainPack||("webgl"===c?t+"index.pck":null),focusCanvas:!0,renderingDriver:"webgl"===c?"":"webgpu",onProgress:a});e.i18n&&"function"==typeof E.preloadFile&&(E.preloadFile(t+"icudt_godot.dat","icudt_godot.dat"),console.log("[ShinyGen] i18n: ICU data queued → res://icudt_godot.dat")),console.log("[ShinyGen] Starting engine...");try{await E.startGame()}catch(e){d();var C=e.message||String(e),k="The engine failed to start.";throw-1!==C.indexOf("wasm")||-1!==C.indexOf("fetch")||-1!==C.indexOf("Fetch")?k="Check that <code>"+p+"index.wasm</code> is served relative to shinygen.js.":"webgpu"!==c||-1===C.indexOf("WebGPU")&&-1===C.indexOf("gpu")?"webgl"===c&&-1!==C.toLowerCase().indexOf("gl")&&(k="WebGL2 initialization failed. Try updating your browser or enabling hardware acceleration."):k="WebGPU initialization failed. Your GPU or driver may not be supported.",n("Engine failed to start",C,k),e}return d(),function(e){var t=document.querySelector('meta[name="viewport"]');t&&t.setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"),e.style.touchAction="none",document.body.style.touchAction="none",document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.width="100%",document.body.style.height="100%",document.documentElement.style.overflow="hidden",document.documentElement.style.position="fixed",document.documentElement.style.width="100%",document.documentElement.style.height="100%",document.addEventListener("touchmove",function(t){t.target===e||t.target.closest("#shinygen-touchcontrols")||t.preventDefault()},{passive:!1})}(v),l(v,e),function(e,t){var n=void 0!==t.touchControls?t.touchControls:"auto";if(!1!==n&&"none"!==n&&("auto"!==n||"ontouchstart"in window)){var o=document.createElement("div");o.id="shinygen-touchcontrols",o.style.cssText=["position:fixed","inset:0","z-index:9999","pointer-events:none","user-select:none","-webkit-user-select:none","touch-action:none"].join(";");var i=document.createElement("div");i.style.cssText=["position:absolute","left:16px","bottom:16px","width:140px","height:140px","pointer-events:auto"].join(";"),[{key:"w",label:"▲",x:45,y:0,w:50,h:45},{key:"s",label:"▼",x:45,y:95,w:50,h:45},{key:"a",label:"◀",x:0,y:45,w:45,h:50},{key:"d",label:"▶",x:95,y:45,w:45,h:50}].forEach(function(e){var t=document.createElement("div");t.style.cssText="position:absolute;display:flex;align-items:center;justify-content:center;background:rgba(255,255,255,0.13);border:1.5px solid rgba(255,255,255,0.25);border-radius:8px;color:rgba(255,255,255,0.7);font-size:18px;transition:background 0.08s;-webkit-tap-highlight-color:transparent;left:"+e.x+"px;top:"+e.y+"px;width:"+e.w+"px;height:"+e.h+"px;",t.textContent=e.label,t.dataset.key=e.key,i.appendChild(t)});var r=document.createElement("div");r.style.cssText="position:absolute;left:45px;top:45px;width:50px;height:50px;background:rgba(255,255,255,0.06);border-radius:50%;",i.appendChild(r),o.appendChild(i),[{key:"Enter",label:"A",bottom:60,right:16},{key:"Escape",label:"B",bottom:16,right:72}].forEach(function(e){var t=document.createElement("div");t.style.cssText=["position:absolute","pointer-events:auto","bottom:"+e.bottom+"px","right:"+e.right+"px","width:52px","height:52px","border-radius:50%","display:flex","align-items:center","justify-content:center","background:rgba(255,255,255,0.13)","border:1.5px solid rgba(255,255,255,0.25)","color:rgba(255,255,255,0.7)","font-size:16px","font-weight:bold","font-family:-apple-system,BlinkMacSystemFont,sans-serif","-webkit-tap-highlight-color:transparent"].join(";"),t.textContent=e.label,t.dataset.key=e.key,o.appendChild(t)}),document.body.appendChild(o);var a={};o.addEventListener("touchstart",l,{passive:!1}),o.addEventListener("touchend",l,{passive:!1}),o.addEventListener("touchcancel",l,{passive:!1}),o.addEventListener("touchmove",function(e){e.preventDefault();for(var t={},n=0;n<e.touches.length;n++){var i=e.touches[n],r=document.elementFromPoint(i.clientX,i.clientY);r&&r.dataset&&r.dataset.key&&(t[r.dataset.key]=r)}Object.keys(a).forEach(function(e){t[e]||(delete a[e],o.querySelectorAll('[data-key="'+e+'"]').forEach(function(e){e.style.background="rgba(255,255,255,0.13)"}),d(e,"keyup"))}),Object.keys(t).forEach(function(e){a[e]||(a[e]=!0,t[e].style.background="rgba(255,255,255,0.35)",d(e,"keydown"))})},{passive:!1})}function d(t,n){e.focus();var o=new KeyboardEvent(n,{key:t,code:"Enter"===t?"Enter":"Escape"===t?"Escape":"ArrowUp"===t?"ArrowUp":"ArrowDown"===t?"ArrowDown":"ArrowLeft"===t?"ArrowLeft":"ArrowRight"===t?"ArrowRight":"Key"+t.toUpperCase(),keyCode:"Enter"===t?13:"Escape"===t?27:t.toUpperCase().charCodeAt(0),bubbles:!0,cancelable:!0});e.dispatchEvent(o)}function l(e){e.preventDefault();var t=e.target.closest("[data-key]");if(t){var n=t.dataset.key;"touchstart"===e.type?a[n]||(a[n]=!0,t.style.background="rgba(255,255,255,0.35)",d(n,"keydown")):"touchend"!==e.type&&"touchcancel"!==e.type||a[n]&&(delete a[n],t.style.background="rgba(255,255,255,0.13)",d(n,"keyup"))}}}(v,e),console.log("[ShinyGen] Engine started"),E},window.ShinyGen=s}();