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

@@ -46,6 +46,19 @@ function JSONFromProject(){
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){
if (SURF !== null){
var reader = new FileReader();
@@ -81,9 +94,10 @@ function HANDLE_FileDrop(e){


function HANDLE_SaveProject(e){
var a = document.createElement("a");
//var a = document.createElement("a");
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";
var body = document.querySelector("body");
body.appendChild(a);
@@ -91,7 +105,31 @@ function HANDLE_SaveProject(e){
setTimeout(function(){ // fixes firefox html removal bug
window.URL.revokeObjectURL(url);
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(){
@@ -150,11 +188,20 @@ class CTRLIO{
}

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

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

@@ -2,14 +2,14 @@
<div class="modal-content">
<form class="pure-form export-chr-form">
<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
</label>
<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
</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>
</div>
</div>

Loading…
Cancel
Save