|
|
|
@ -11,11 +11,15 @@ import 'codemirror/addon/fold/foldgutter.js';
|
|
|
|
|
//require('codemirror/addon/fold/foldgutter.js');
|
|
|
|
|
//require('codemirror/addon/fold/markdown-fold.js')
|
|
|
|
|
//require("codemirror/theme/monokai.css")
|
|
|
|
|
var current_item,
|
|
|
|
|
current_filename,
|
|
|
|
|
current_cart;
|
|
|
|
|
|
|
|
|
|
const DB_NAME = "/com.nesbox.tic/TIC-80",
|
|
|
|
|
DB_STORE = "FILE_DATA",
|
|
|
|
|
TIC_SPECIALS = ["TIC", "SCN", "OVR", "btn", "btnp", "clip", "cls", "circ", "circb", "exit", "fget", "font", "fset", "key", "keyp", "line", "map", "memcpy", "memset", "mget", "mouse", "mset", "music", "peek", "peek4", "pix", "pmem", "poke", "poke4", "print", "rect", "rectb", "reset", "sfx", "spr", "sync", "time", "tstamp", "trace", "tri", "textri"],
|
|
|
|
|
table = select("#listing").append("table"),
|
|
|
|
|
listing = select("#listing"),
|
|
|
|
|
table = listing.append("table"),
|
|
|
|
|
thead = table.append("thead").append("tr"),
|
|
|
|
|
tbody = table.append("tbody"),
|
|
|
|
|
CM_OPTS = {
|
|
|
|
@ -24,25 +28,50 @@ const DB_NAME = "/com.nesbox.tic/TIC-80",
|
|
|
|
|
theme: 'default',
|
|
|
|
|
lineNumbers: true,
|
|
|
|
|
lineWrapping: true,
|
|
|
|
|
extraKeys: {"Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); }},
|
|
|
|
|
extraKeys: {"Ctrl-S": function(cm){ save(); }},
|
|
|
|
|
foldGutter: true,
|
|
|
|
|
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
|
|
|
|
|
},
|
|
|
|
|
code = CodeMirror(document.getElementById("code"), CM_OPTS);
|
|
|
|
|
|
|
|
|
|
listing.append("button").html("save").on("click", (e, d) => {
|
|
|
|
|
if (current_filename) { save(); }
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
listing.append("button").html("save as...").on("click", (e, d) => {
|
|
|
|
|
if (current_filename) {
|
|
|
|
|
var save_filename = prompt("key", current_filename);
|
|
|
|
|
if (save_filename) {
|
|
|
|
|
current_filename = save_filename;
|
|
|
|
|
save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
thead.selectAll("th").data(["name", "size", "time", " "]).enter().append("th").html(d => d);
|
|
|
|
|
|
|
|
|
|
async function save() {
|
|
|
|
|
current_cart.code.text = code.getValue();
|
|
|
|
|
console.log("code", current_cart.code.text);
|
|
|
|
|
current_item.contents = current_cart.tobuffer();
|
|
|
|
|
current_item.timestamp = new Date();
|
|
|
|
|
console.log("save", current_item);
|
|
|
|
|
return await save_key(DB_NAME+"/"+current_filename, current_item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function filename_from_key (key) {
|
|
|
|
|
if (key.startsWith(DB_NAME+"/")) { return key.substr((DB_NAME+"/").length); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
|
try {
|
|
|
|
|
const db = await openDB(DB_NAME);
|
|
|
|
|
var objectStore = db.transaction([DB_STORE], "readonly").objectStore(DB_STORE);
|
|
|
|
|
var files = [];
|
|
|
|
|
|
|
|
|
|
await objectStore.openCursor().then(function push_item(cursor) {
|
|
|
|
|
if (!cursor) { return }
|
|
|
|
|
// console.log("cursor.value", cursor.value);
|
|
|
|
|
var filename = cursor.key.substr("/com.nesbox.tic/TIC-80/".length);
|
|
|
|
|
if (!filename.startsWith(".")) {
|
|
|
|
|
var filename = filename_from_key(cursor.key);
|
|
|
|
|
if (filename && !filename.startsWith(".")) {
|
|
|
|
|
// console.log(cursor.value.contents);
|
|
|
|
|
var blob = new Blob([cursor.value.contents]);
|
|
|
|
|
// console.log("blob", blob, {type: "application/octet-stream"});
|
|
|
|
@ -61,9 +90,16 @@ thead.selectAll("th").data(["name", "size", "time", " "]).enter().append("t
|
|
|
|
|
|
|
|
|
|
// console.log("files", files);
|
|
|
|
|
let tr = tbody.selectAll("tr").data(files).enter().append("tr");
|
|
|
|
|
tr.append("td").append("a").attr("href", "#").html(d => d.filename).on("click", (e, d) => {
|
|
|
|
|
tr.append("td").append("a").attr("href", "#").html(d => d.filename).on("click", async (e, d) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
load_key(d.key);
|
|
|
|
|
var filename = filename_from_key(d.key);
|
|
|
|
|
if (filename) {
|
|
|
|
|
current_filename = filename;
|
|
|
|
|
current_item = await load_key(DB_NAME+"/"+current_filename);
|
|
|
|
|
console.log("loaded item", current_item);
|
|
|
|
|
current_cart = tic.parsetic(current_item.contents);
|
|
|
|
|
code.setValue(current_cart.code.text);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
tr.append("td").html(d => filesize(d.size));
|
|
|
|
|
tr.append("td").html(d => d.timestamp.toLocaleString());
|
|
|
|
@ -86,24 +122,14 @@ function compareBuffers (a, b) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function load_key (key) {
|
|
|
|
|
const db = await openDB(DB_NAME);
|
|
|
|
|
var objectStore = db.transaction([DB_STORE], "readonly").objectStore(DB_STORE);
|
|
|
|
|
var files = [];
|
|
|
|
|
const db = await openDB(DB_NAME),
|
|
|
|
|
objectStore = db.transaction([DB_STORE], "readonly").objectStore(DB_STORE);
|
|
|
|
|
return await objectStore.get(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await objectStore.get(key).then((cursor) => {
|
|
|
|
|
// console.log("load_key", cursor);
|
|
|
|
|
// window.cart = cursor.contents;
|
|
|
|
|
var inputBuffer = cursor.contents;
|
|
|
|
|
var cart = tic.parsetic(inputBuffer);
|
|
|
|
|
// console.log("cart", cart);
|
|
|
|
|
// console.log("code_textarea", code_textarea);
|
|
|
|
|
code.setValue(cart.code.text);
|
|
|
|
|
// code.setValue(cart.unparse());
|
|
|
|
|
//var cart_js = cart.tojson();
|
|
|
|
|
//code.setValue(JSON.stringify(cart_js, null, 2));
|
|
|
|
|
var outputBuffer = cart.tobuffer();
|
|
|
|
|
console.log("buffers same", compareBuffers(inputBuffer, outputBuffer))
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
async function save_key (key, item) {
|
|
|
|
|
const db = await openDB(DB_NAME),
|
|
|
|
|
objectStore = db.transaction([DB_STORE], "readwrite").objectStore(DB_STORE);
|
|
|
|
|
return await objectStore.put(item, key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|