mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2026-10-25 00:02:16 +00:00
3 lines
3.0 KiB
JavaScript
3 lines
3.0 KiB
JavaScript
import{b as k,c as S}from"./chunk-3H6WIH6E.js";import{B as h,G as v,I as y,J as c,P as d,l as p,z as w}from"./chunk-VZWSP3EG.js";import{g as M}from"./chunk-N7W4C4V2.js";var C=M(S()),i,t,f,m=c(window.location.search),R=window.location.hash?c(window.location.hash.substr(1)):{};for(u in R)m[u]=R[u];var u;function E(){typeof window.onerror=="object"&&(window.onerror=function(e,r,n,o,a){var s=e+" "+r+" "+n+":"+o+", "+a;$.get("/error?msg="+encodeURIComponent(s),"text")})}function F(){var e=!1;document.addEventListener("visibilitychange",function(r){document.visibilityState=="hidden"&&t.isRunning()?(t.pause(),e=!0):document.visibilityState=="visible"&&e&&(t.resume(),e=!1)}),$(window).on("focus",function(){e&&(t.resume(),e=!1)}),$(window).on("blur",function(){t.isRunning()&&(t.pause(),e=!0)})}async function b(e,r){if(!r){alert("No ROM found.");return}console.log(r.length+" bytes"),await t.loadROM(e,r),t.resume()}function I(){return $("#emulator").find("canvas")}function O(e,r,n){v("gif.js/dist/gif.js").then(()=>{var o=I()[0];if(!o){alert("Could not find canvas element to record video!");return}var a=0;o.style&&o.style.transform&&(o.style.transform.indexOf("rotate(-90deg)")>=0?a=-1:o.style.transform.indexOf("rotate(90deg)")>=0&&(a=1));var s=new GIF({workerScript:"gif.js/dist/gif.worker.js",workers:4,quality:10,rotate:a});s.on("finished",function(x){console.log("finished encoding GIF"),n(x)}),e=e||100+(Math.random()*256&3),r=r||100+(Math.random()*256&15);var l=0;console.log("Recording video",o);var g=()=>{l++>r?(console.log("Rendering video"),s.render()):(s.addFrame(o,{delay:e,copy:!0}),setTimeout(g,e))};g()})}async function j(e){if(!d[i])throw Error("Invalid platform '"+i+"'.");t=new d[i]($("#emuscreen")[0]),await t.start(),e.rec&&I().on("focus",()=>{t.resume()});var r=e.n||"Game",n,o=e.url,a=e.r;if(o)return console.log(o),w(o,l=>{b(r,l)},"arraybuffer"),!0;if(a){var s=y(a);n=new p().decode(s)}return F(),b(r,n),!0}async function P(e){if(e.data&&(e=e.data),i=e.p,!i)throw new Error("No platform variable!");try{var r=await k(h(i));console.log("starting platform",i),await j(e)}catch(n){console.log(n),alert('Platform "'+i+'" not supported.')}}function G(){E(),m.p&&P(m)}window.addEventListener("message",H,!1);function H(e){if(e.data){var r=e.data.cmd;if(r=="start"&&!t)P(e);else if(r=="reset")t.reset(),f.reset();else if(r=="getReplay"){var n={frameCount:f.frameCount,checkpoints:f.checkpoints,framerecs:f.framerecs,checkpointInterval:f.checkpointInterval,maxCheckpoints:f.maxCheckpoints};e.source.postMessage({ack:r,replay:n},e.origin)}else if(r=="watchState"){var o=new Function("platform","state",e.data.fn);f.callbackNewCheckpoint=a=>{e.source.postMessage({ack:r,state:o(t,a)},e.origin)}}else r=="recordVideo"?O(e.data.intervalMsec,e.data.maxFrames,function(a){e.data.filename&&(0,C.saveAs)(a,e.data.filename),e.source.postMessage({ack:r,gif:a},e.origin)}):console.log("Unknown data.cmd: "+r)}}self===top&&(document.body.style.backgroundColor="#555");G();export{t as platform,i as platform_id,G as startEmbed,f as stateRecorder};
|
|
//# sourceMappingURL=embedui.js.map
|