mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 00:31:34 +11:00
2 lines
175 KiB
JavaScript
2 lines
175 KiB
JavaScript
|
!function(e){var o={};function i(a){if(o[a])return o[a].exports;var r=o[a]={i:a,l:!1,exports:{}};return e[a].call(r.exports,r,r.exports,i),r.l=!0,r.exports}i.m=e,i.c=o,i.d=function(e,o,a){i.o(e,o)||Object.defineProperty(e,o,{configurable:!1,enumerable:!0,get:a})},i.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},i.n=function(e){var o=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(o,"a",o),o},i.o=function(e,o){return Object.prototype.hasOwnProperty.call(e,o)},i.p="",i(i.s=15)}([function(e,o,i){!function(){"use strict";var o=i(8);e.exports=function(e){return o[e]?escapeHtml(o[e][0]):"Unknown Game"}}()},,,,,,function(e,o,i){!function(){"use strict";function o(e){this.el=e,this.currentlyBinding=!1,this.initialHTML=e.innerHTML,this.el.addEventListener("keydown",this.onKeyDown.bind(this)),this.paused=!1}o.prototype=Object.create(Object.prototype),o.prototype.constructor=o,o.prototype.setPausedState=function(e){this.paused=e,this.el.querySelector(".load-rom-section").style.display=e?"none":"",this.el.querySelector(".paused-section").style.display=e?"":"none"},o.prototype.reset=function(){var e;this.el.innerHTML=this.initialHTML,this.currentlyBinding=!1;var o=this.el.querySelector(".saves-list"),a="<table>",r=window.vbaSaves.listSaves();for(e=0;e<r.length;e++)a+="<tr><td>["+r[e].romCode+"] "+i(0)(r[e].romCode)+"</td><td><a class='export-save-button' onclick='vbaUI.exportSave(\""+r[e].romCode+"\")' href='javascript:void 0;' data-rom-code='"+r[e].romCode+"'>Export</a></td><td><a class='delete-save-button' onclick='vbaUI.deleteSave(\""+r[e].romCode+"\")' href='javascript:void 0;' data-rom-code='"+r[e].romCode+"'>Delete</a></td></tr>";r.length||(a+="<tr><td>None</td></tr>"),window.isShittyLocalstorage&&(a+="<tr><td><strong>Saving will not be possible because the 'LocalStorage'<br/>feature of your browser is disabled.</strong></td></tr>"),a+="</table>",o.innerHTML=a;var s=this.el.querySelector(".keyboard-bindings"),n="<table>",t=window.vbaInput.listBindings();function m(e){return e.join(", ").replace(/Key/im,"Key ").replace(/Arrow/im,"Arrow ").replace(/Digit/im,"Digit ").replace(/Numpad/im,"Numpad ").replace(/Left/im," Left").replace(/Right/im," Right")}for(e=0;e<t.length;e++)n+="<tr><td>"+t[e].friendlyName+"</td><td>"+m(t[e].codes)+"</td><td><a class='rebind-key-button' onclick='vbaUI.startRebinding(this, \""+t[e].name+"\")' href='javascript:void 0;'>Rebind</a></td></tr>","PAUSE"===t[e].name&&(this.el.querySelector(".unpause-key-prompt").innerText=m(t[e].codes));n+="</table>",s.innerHTML=n,this.setPausedState(this.paused)},o.prototype.export=function(){vbaSaves.exportSave()},o.prototype.onKeyDown=function(e){if(this.currentlyBinding){var o=vbaInput.bindings[this.currentlyBinding].codes.join();vbaInput.setBinding(this.currentlyBinding,e.code,e.keyCode);var i=vbaInput.bindings[this.currentlyBinding].codes.join();gtag("event","rebind_key_1",{event_label:"Change "+this.currentlyBinding+" from "+o+" to "+i}),this.reset()}},o.prototype.startRebinding=function(e,o){this.currentlyBinding=o,this.el.querySelectorAll(".rebind-key-button").forEach(function(e){e.innerText="Rebind"}),e.innerText="Rebinding..."},o.prototype.resetBindings=function(){gtag("event","reset_bindings_1",{}),vbaInput.resetBindings(),this.reset()},o.prototype.exportSave=function(e){vbaSaves.exportSave(e),this.reset(),gtag("event","export_save_1",{event_label:e+" "+i(0)(e)})},o.prototype.deleteSave=function(e){var o=modal("Are you sure you want to delete your save for ["+e+"] "+i(0)(e)+"?",{title:"Confirm Deletion",leftButtonText:"Delete",leftButtonFn:function(){vbaSaves.deleteSave(e),this.reset(),gtag("event","delete_save_1",{event_label:e+" "+i(0)(e)})}.bind(this),rightButtonText:"Cancel",rightButtonFn:function(){o.hideModal()}})},e.exports=o}()},function(e,o){!function(){"use strict";var o={};function i(){this.downCodes={},this.downKeyCodes={},window.addEventListener("keydown",function(e){var o=this.isKeyDown(this.bindings.PERF_STATS),i=this.isKeyDown(this.bindings.PAUSE);this.downCodes[e.code]=1,this.downKeyCodes[e.keyCode]
|
||
|
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */void 0!==e&&e.exports?e.exports.saveAs=r:null!==i(10)&&null!==i(9)&&(void 0===(a=function(){return r}.apply(o,[]))||(e.exports=a))},function(e,o,i){!function(){"use strict";var o="local",a=i(11).saveAs;function r(e){this.emscriptenModule=e,this.mode=o,this.safeSaveTimeout=null,this.unsafeSaveTimeout=null,this.unsafeSaveBuffer=null,this.localStoragePrefix="VBAsave_",this.lastWarningTime=0}r.prototype=Object.create(Object.prototype),r.prototype.constructor=r,r.prototype.getRomCode=function(){var e=this.emscriptenModule.HEAPU8,o=VBAInterface.VBA_get_rom();return String.fromCharCode(e[o+172],e[o+173],e[o+174],e[o+175]).replace(/[^ -~]/g,function(){return"?"})},r.prototype.getSave=function(e){e=e||this.getRomCode();var o=localStorage[this.localStoragePrefix+e];return o?new Uint8Array(atob(o).split("").map(function(e){return e.charCodeAt(0)})):null},r.prototype.getSaveSize=function(){var e=this.getSave();return e?e.byteLength:0},r.prototype.softCommit=function(e,o){for(var i=this.emscriptenModule.HEAPU8,a=new Uint8Array(o),r=0;r<o;r++)a[r]=i[e+r];this.unsafeSaveBuffer=a},r.prototype.hardCommit=function(e,o){for(var i="",a=o.byteLength,r=0;r<a;r++)i+=String.fromCharCode(o[r]);try{localStorage[this.localStoragePrefix+e]=window.btoa(i)}catch(e){if(window.isShittyLocalstorage)return;this.lastWarningTime<Date.now()-5e3&&(this.lastWarningTime=Date.now(),modal("Unable to save because the storage quota is exceeded. Try opening a new gba.ninja tab and deleting some saves, then save again.",{title:"Error"}))}},r.prototype.restoreSaveMemory=function(e,o){var i=this.getSave();if(i){if(i.byteLength!==o)throw new Error("Incompatible save size");for(var a=this.emscriptenModule.HEAPU8,r=0;r<o;r++)a[e+r]=i[r]}},r.prototype.checkSaves=function(){if(VBAInterface.VBA_get_systemSaveUpdateCounter()&&(this.unsafeSaveTimeout||(this.unsafeSaveTimeout=setTimeout(function(){this.unsafeSaveTimeout=null,VBAInterface.VBA_get_emulating()&&(console.log("[SAVE] changes detected"),VBAInterface.VBA_emuWriteBattery(),VBAInterface.VBA_reset_systemSaveUpdateCounter())}.bind(this),32))),this.unsafeSaveBuffer){var e=this.unsafeSaveBuffer;this.unsafeSaveBuffer=null,clearTimeout(this.safeSaveTimeout),this.safeSaveTimeout=setTimeout(function(){this.safeSaveTimeout=null,VBAInterface.VBA_get_emulating()?(this.hardCommit(this.getRomCode(),e),console.log("[SAVE] changes committed")):console.log("[SAVE] changes discarded, emulator not running")}.bind(this),70)}},r.prototype.exportSave=function(e){var o=this.getSave(e);if(!o)throw new Error("No save found for "+e);var r=new Blob([o],{contentType:"application/octet-stream"});a(r,e+" "+i(0)(e)+".sav",!0)},r.prototype.deleteSave=function(e){delete localStorage[this.localStoragePrefix+e]},r.prototype.onFileImportInputChanged=function(e,o){var i=e.currentTarget.files[0];if(e.currentTarget.form.reset(),i){var a=new FileReader;a.readAsArrayBuffer(i),a.onload=function(){var e=/^[A-Z1-9]{4}/,r=i.name.substr(0,4),s=function(){this.importSave(r,new Uint8Array(a.result)),o()}.bind(this),n=function(){return window.modal("Invalid ROM Code",{title:"Error"})}.bind(this);if(-1===r.search(e))var t=window.modal("What is the ROM code of the game that this save file belongs to? (4 uppercase letters or numbers)",{title:"Enter ROM Code",input:"",leftButtonText:"Submit",leftButtonFn:function(){if(r=t.getInputValue(),t.hideModal(),-1===r.search(e))return n(),!1;s()},rightButtonText:"Cancel",rightButtonFn:function(){t.hideModal()}});else s()}.bind(this)}},r.prototype.listSaves=function(){return Object.keys(localStorage).filter(function(e){return 0===e.indexOf(this.localStoragePrefix)}.bind(this)).map(function(e){return{romCode:e.substr(this.localStoragePrefix.length,4)}}.bind(this))},r.prototype.importSave=function(e,o){this.hardCommit(e,o)},e.exports=r}()},function(e,o){!function(){"use strict";function o(e){this.emscriptenModule=e;var o=window.AudioContext||window.webkitAudioContext;this.audioCtx=new o,this.audioChannels=2,this.audioScriptNode=this.audioCtx.createSc
|