1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-18 03:05:35 +00:00
8bitworkshop/gen/embedui.js.map

8 lines
9.8 KiB
Plaintext

{
"version": 3,
"sources": ["../src/ide/embedui.ts"],
"sourcesContent": ["\nimport { lzgmini } from \"../common/util\";\nimport { PLATFORMS } from \"../common/emu\";\nimport { Platform } from \"../common/baseplatform\";\nimport { stringToByteArray, getWithBinary, loadScript, getRootBasePlatform } from \"../common/util\";\nimport { StateRecorderImpl } from \"../common/recorder\";\nimport { importPlatform } from \"../platform/_index\";\nimport { saveAs } from \"file-saver\";\n\nexport var platform_id : string;\t// platform ID string\nexport var platform : Platform;\t// platform object\nexport var stateRecorder : StateRecorderImpl;\n\n// external libs (TODO)\ndeclare var ga, GIF;\n\nvar _qs = (function (a) {\n if (!a || a.length == 0)\n return {};\n var b = {};\n for (var i = 0; i < a.length; ++i) {\n var p = a[i].split('=', 2);\n if (p.length == 1)\n b[p[0]] = \"\";\n else\n b[p[0]] = decodeURIComponent(p[1].replace(/\\+/g, \" \"));\n }\n return b;\n})(window.location.search.substr(1).split('&'));\n\n// catch errors\nfunction installErrorHandler() {\n if (typeof window.onerror == \"object\") {\n window.onerror = function (msgevent, url, line, col, error) {\n var msg = msgevent + \" \" + url + \" \" + \" \" + line + \":\" + col + \", \" + error;\n $.get(\"/error?msg=\" + encodeURIComponent(msg), \"text\");\n };\n }\n}\n\nfunction uninstallErrorHandler() {\n window.onerror = null;\n}\n\nfunction addPageFocusHandlers() {\n var hidden = false;\n document.addEventListener(\"visibilitychange\", function(e) {\n if (document.visibilityState == 'hidden' && platform.isRunning()) {\n platform.pause();\n hidden = true;\n } else if (document.visibilityState == 'visible' && hidden) {\n platform.resume();\n hidden = false;\n }\n });\n $(window).on(\"focus\", function() {\n if (hidden) {\n platform.resume();\n hidden = false;\n }\n });\n $(window).on(\"blur\", function() {\n if (platform.isRunning()) {\n platform.pause();\n hidden = true;\n }\n });\n}\n\nasync function startROM(title, rom) {\n if (!rom ) {\n alert(\"No ROM found.\");\n return;\n }\n console.log(rom.length + ' bytes');\n await platform.loadROM(title, rom);\n platform.resume();\n}\n\nfunction enableRecording() {\n stateRecorder = new StateRecorderImpl(platform);\n stateRecorder.reset();\n stateRecorder.checkpointInterval = 60*5; // every 5 sec\n stateRecorder.maxCheckpoints = 360; // 30 minutes\n platform.setRecorder(stateRecorder);\n console.log('start recording');\n}\n\nfunction findPrimaryCanvas() {\n return $(\"#emulator\").find('canvas');\n}\n\nfunction recordVideo(intervalMsec, maxFrames, callback) {\n loadScript(\"gif.js/dist/gif.js\").then( () => {\n var canvas = findPrimaryCanvas()[0] as HTMLCanvasElement;\n if (!canvas) {\n alert(\"Could not find canvas element to record video!\");\n return;\n }\n var rotate = 0;\n if (canvas.style && canvas.style.transform) {\n if (canvas.style.transform.indexOf(\"rotate(-90deg)\") >= 0)\n rotate = -1;\n else if (canvas.style.transform.indexOf(\"rotate(90deg)\") >= 0)\n rotate = 1;\n }\n var gif = new GIF({\n workerScript: 'gif.js/dist/gif.worker.js',\n workers: 4,\n quality: 10,\n rotate: rotate\n });\n gif.on('finished', function(blob) {\n console.log('finished encoding GIF');\n callback(blob);\n });\n intervalMsec = intervalMsec || (100 + ((Math.random()*256)&3));\n maxFrames = maxFrames || (100 + ((Math.random()*256)&15));\n var nframes = 0;\n console.log(\"Recording video\", canvas);\n var f = () => {\n if (nframes++ > maxFrames) {\n console.log(\"Rendering video\");\n gif.render();\n } else {\n gif.addFrame(canvas, {delay: intervalMsec, copy: true});\n setTimeout(f, intervalMsec);\n }\n };\n f();\n });\n}\n\nasync function startPlatform(qs) {\n if (!PLATFORMS[platform_id]) throw Error(\"Invalid platform '\" + platform_id + \"'.\");\n platform = new PLATFORMS[platform_id]($(\"#emuscreen\")[0]);\n await platform.start();\n // start recorder when click on canvas (TODO?)\n if (qs['rec']) {\n findPrimaryCanvas().on('focus', () => {\n //if (!stateRecorder) { enableRecording(); }\n // toggle sound for browser autoplay\n platform.resume();\n });\n }\n var title = qs['n'] || 'Game';\n var rom : Uint8Array;\n var romurl = qs['url'];\n var lzgvar = qs['r'];\n if (romurl) {\n // load rom url remotely\n console.log(romurl);\n getWithBinary(romurl, (data) => {\n startROM(title, data);\n }, 'arraybuffer');\n return true;\n } else if (lzgvar) {\n // decompress from lzg\n var lzgrom = stringToByteArray(atob(lzgvar));\n rom = new lzgmini().decode(lzgrom);\n }\n addPageFocusHandlers();\n startROM(title, rom);\n return true;\n}\n\n// TODO: merge with ui\nasync function loadPlatform(qs) {\n if (qs.data) qs = qs.data;\n platform_id = qs['p'];\n if (!platform_id) throw new Error('No platform variable!');\n try {\n var module = await importPlatform(getRootBasePlatform(platform_id));\n console.log(\"starting platform\", platform_id); // loaded required <platform_id>.js file\n await startPlatform(qs);\n } catch (e) {\n console.log(e);\n alert('Platform \"' + platform_id + '\" not supported.');\n }\n}\n\n// start\nexport function startEmbed() {\n installErrorHandler();\n if (_qs['p']) {\n loadPlatform(_qs);\n }\n}\n\n// iframe API\n\nwindow.addEventListener(\"message\", receiveMessage, false);\n\nfunction receiveMessage(event) {\n if (event.data) {\n var cmd = event.data.cmd;\n if (cmd == 'start' && !platform) {\n loadPlatform(event);\n }\n else if (cmd == 'reset') {\n platform.reset();\n stateRecorder.reset();\n }\n else if (cmd == 'getReplay') {\n var replay = {\n frameCount: stateRecorder.frameCount,\n checkpoints: stateRecorder.checkpoints,\n framerecs: stateRecorder.framerecs,\n checkpointInterval: stateRecorder.checkpointInterval,\n maxCheckpoints: stateRecorder.maxCheckpoints,\n }\n event.source.postMessage({ack:cmd, replay:replay}, event.origin);\n }\n else if (cmd == 'watchState') {\n var watchfn = new Function('platform', 'state', event.data.fn);\n stateRecorder.callbackNewCheckpoint = (state) => {\n event.source.postMessage({ack:cmd, state:watchfn(platform, state)}, event.origin);\n }\n }\n else if (cmd == 'recordVideo') {\n recordVideo(event.data.intervalMsec, event.data.maxFrames, function(blob) {\n if (event.data.filename) {\n saveAs(blob, event.data.filename);\n }\n event.source.postMessage({ack:cmd, gif:blob}, event.origin);\n });\n }\n else {\n console.log(\"Unknown data.cmd: \" + cmd);\n }\n }\n}\n\n/////\n\n// are we not in an iframe?\nif(self === top) {\n document.body.style.backgroundColor = '#555';\n}\nstartEmbed();\n"],
"mappings": "kKAOA,MAAuB,OAEZ,EACA,EACA,EAKP,EAAO,SAAU,EAAG,CACpB,GAAI,CAAC,GAAK,EAAE,QAAU,EAClB,MAAO,GAEX,OADI,GAAI,GACC,EAAI,EAAG,EAAI,EAAE,OAAQ,EAAE,EAAG,CAC/B,GAAI,GAAI,EAAE,GAAG,MAAM,IAAK,GACxB,AAAI,EAAE,QAAU,EACZ,EAAE,EAAE,IAAM,GAEV,EAAE,EAAE,IAAM,mBAAmB,EAAE,GAAG,QAAQ,MAAO,MAEzD,MAAO,IACR,OAAO,SAAS,OAAO,OAAO,GAAG,MAAM,MAG1C,YAA+B,CAC7B,AAAI,MAAO,QAAO,SAAW,UACzB,QAAO,QAAU,SAAU,EAAU,EAAK,EAAM,EAAK,EAAO,CAC1D,GAAI,GAAM,EAAW,IAAM,EAAM,KAAY,EAAO,IAAM,EAAM,KAAO,EACvE,EAAE,IAAI,cAAgB,mBAAmB,GAAM,UASvD,YAAgC,CAC9B,GAAI,GAAS,GACb,SAAS,iBAAiB,mBAAoB,SAAS,EAAG,CACxD,AAAI,SAAS,iBAAmB,UAAY,EAAS,YACnD,GAAS,QACT,EAAS,IACA,SAAS,iBAAmB,WAAa,GAClD,GAAS,SACT,EAAS,MAGb,EAAE,QAAQ,GAAG,QAAS,UAAW,CAC/B,AAAI,GACF,GAAS,SACT,EAAS,MAGb,EAAE,QAAQ,GAAG,OAAQ,UAAW,CAC9B,AAAI,EAAS,aACX,GAAS,QACT,EAAS,MAKf,iBAAwB,EAAO,EAAK,CAClC,GAAI,CAAC,EAAM,CACT,MAAM,iBACN,OAEF,QAAQ,IAAI,EAAI,OAAS,UACzB,KAAM,GAAS,QAAQ,EAAO,GAC9B,EAAS,SAYX,YAA6B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