Browse Source

Can now export CHR filesgit add .!

dev
Bryan Miller 5 years ago
parent
commit
00e5e8e850
2 changed files with 53 additions and 6 deletions
  1. +50
    -3
      app/js/ctrls/CTRLIO.js
  2. +3
    -3
      views/modals/export_CHR.html

+ 50
- 3
app/js/ctrls/CTRLIO.js View File

return JSON.stringify(proj); return JSON.stringify(proj);
} }


function RequestDownload(filename, datblob){
var a = document.createElement("a");
a.href = window.URL.createObjectURL(datblob);
a.download = filename;
var body = document.querySelector("body");
body.appendChild(a);
a.click();
setTimeout(function(){ // fixes firefox html removal bug
window.URL.revokeObjectURL(url);
a.remove();
}, 500);
}

function LoadFile(file){ function LoadFile(file){
if (SURF !== null){ if (SURF !== null){
var reader = new FileReader(); var reader = new FileReader();




function HANDLE_SaveProject(e){ function HANDLE_SaveProject(e){
var a = document.createElement("a");
//var a = document.createElement("a");
var file = new Blob([JSONFromProject()], {type: "text/plain"}); var file = new Blob([JSONFromProject()], {type: "text/plain"});
a.href = window.URL.createObjectURL(file);
RequestDownload("nesproject.json", file);
/*a.href = window.URL.createObjectURL(file);
a.download = "nesproject.json"; a.download = "nesproject.json";
var body = document.querySelector("body"); var body = document.querySelector("body");
body.appendChild(a); body.appendChild(a);
setTimeout(function(){ // fixes firefox html removal bug setTimeout(function(){ // fixes firefox html removal bug
window.URL.revokeObjectURL(url); window.URL.revokeObjectURL(url);
a.remove(); a.remove();
}, 500);
}, 500);*/
}


function HANDLE_ExportCHR(e){
e.preventDefault();
var bank = CTRLBanksStore.currentBank;
if (bank !== null){
var dat = null;
var size = document.querySelector('input[name="exportchr-size"]:checked').value;
switch (size){
case "full":
dat = bank.getCHR(0,0);
break;
case "current":
dat = bank.chr;
}

if (dat !== null){
var file = new Blob([dat], {type:"application/octet-stream"});
var filename = CTRLBanksStore.currentBankName.replace(/[^a-z0-9\-_.]/gi, '_').toLowerCase() + ".chr";
RequestDownload(filename, file);
}
}
GlobalEvents.emit("modal-close");
} }


function HANDLE_LoadProjectRequest(){ function HANDLE_LoadProjectRequest(){
} }


initialize(){ initialize(){
// Connecting drag/drop ability.
var e = document.querySelectorAll(".drop-zone"); var e = document.querySelectorAll(".drop-zone");
for (let i=0; i < e.length; e++){ for (let i=0; i < e.length; e++){
e[i].addEventListener("dragover", HANDLE_DragOver); e[i].addEventListener("dragover", HANDLE_DragOver);
e[i].addEventListener("drop", HANDLE_FileDrop); e[i].addEventListener("drop", HANDLE_FileDrop);
} }

// Connecting to button for export request.
var e = document.querySelectorAll(".export-chr-btn");
for (let i=0; i < e.length; i++){
e[i].addEventListener("click", HANDLE_ExportCHR);
}


CTRLPalettesStore.initialize(); CTRLPalettesStore.initialize();
CTRLBanksStore.initialize(); CTRLBanksStore.initialize();
} }

+ 3
- 3
views/modals/export_CHR.html View File

<div class="modal-content"> <div class="modal-content">
<form class="pure-form export-chr-form"> <form class="pure-form export-chr-form">
<label for="expchr-op1" class="pure-radio"> <label for="expchr-op1" class="pure-radio">
<input id="expchr-op1" type="radio" name="exportchr-amount" value="full" checked>
<input id="expchr-op1" type="radio" name="exportchr-size" value="full" checked>
Full Bank Full Bank
</label> </label>
<label for="expchr-op2" class="pure-radio"> <label for="expchr-op2" class="pure-radio">
<input id="expchr-op2" type="radio" name="exportchr-amount" value="current">
<input id="expchr-op2" type="radio" name="exportchr-size" value="current">
Current View Current View
</label> </label>
<button type="submit" class="pure-button export-chr-btn">Export CHR</button>
<button type="submit" class="pure-button export-chr-btn" emit="export-chr">Export CHR</button>
</form> </form>
</div> </div>
</div> </div>

Loading…
Cancel
Save