mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-11-29 14:51:17 +00:00
got rid of local/ prefix -- idk i'm kinda scared
This commit is contained in:
parent
1cb3c960ee
commit
e5c50d2a9e
@ -1,7 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import { FileData, Dependency, SourceLine, SourceFile, CodeListing, CodeListingMap, WorkerError, Segment, WorkerResult } from "./workertypes";
|
import { FileData, Dependency, SourceLine, SourceFile, CodeListing, CodeListingMap, WorkerError, Segment, WorkerResult } from "./workertypes";
|
||||||
import { getFilenamePrefix, getFolderForPath, isProbablyBinary } from "./util";
|
import { getFilenamePrefix, getFolderForPath, isProbablyBinary, getBasePlatform } from "./util";
|
||||||
import { Platform } from "./baseplatform";
|
import { Platform } from "./baseplatform";
|
||||||
|
|
||||||
type BuildResultCallback = (result:WorkerResult) => void;
|
type BuildResultCallback = (result:WorkerResult) => void;
|
||||||
@ -65,7 +65,6 @@ export class CodeProject {
|
|||||||
|
|
||||||
pushAllFiles(files:string[], fn:string) {
|
pushAllFiles(files:string[], fn:string) {
|
||||||
// look for local and preset files
|
// look for local and preset files
|
||||||
files.push('local/'+fn);
|
|
||||||
files.push(fn);
|
files.push(fn);
|
||||||
// look for files in current (main file) folder
|
// look for files in current (main file) folder
|
||||||
var dir = getFolderForPath(this.mainpath);
|
var dir = getFolderForPath(this.mainpath);
|
||||||
@ -207,11 +206,10 @@ export class CodeProject {
|
|||||||
this.filedata[path] = value; // do not update store, just cache
|
this.filedata[path] = value; // do not update store, just cache
|
||||||
addResult(path, value);
|
addResult(path, value);
|
||||||
loadNext();
|
loadNext();
|
||||||
} else if (!path.startsWith("local/")) {
|
} else {
|
||||||
// don't load local/
|
|
||||||
// found on remote fetch?
|
// found on remote fetch?
|
||||||
var preset_id = this.platform_id;
|
var preset_id = this.platform_id;
|
||||||
preset_id = preset_id.replace(/[.]\w+/,''); // remove .suffix from preset name
|
preset_id = getBasePlatform(preset_id); // remove .suffix from preset name
|
||||||
var webpath = "presets/" + preset_id + "/" + path;
|
var webpath = "presets/" + preset_id + "/" + path;
|
||||||
// try to GET file, use file ext to determine text/binary
|
// try to GET file, use file ext to determine text/binary
|
||||||
this.callbackGetRemote( webpath, (data:FileData) => {
|
this.callbackGetRemote( webpath, (data:FileData) => {
|
||||||
@ -227,9 +225,6 @@ export class CodeProject {
|
|||||||
}
|
}
|
||||||
loadNext();
|
loadNext();
|
||||||
}, isProbablyBinary(path) ? 'arraybuffer' : 'text');
|
}, isProbablyBinary(path) ? 'arraybuffer' : 'text');
|
||||||
} else {
|
|
||||||
// not gonna find it, keep going
|
|
||||||
loadNext();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ var Ver2xFileStore = function(storage, prefix:string) {
|
|||||||
}
|
}
|
||||||
this.deleteFile = function(name) {
|
this.deleteFile = function(name) {
|
||||||
storage.removeItem(prefix + name);
|
storage.removeItem(prefix + name);
|
||||||
storage.removeItem(prefix + 'local/' + name); //TODO?
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
43
src/ui.ts
43
src/ui.ts
@ -303,7 +303,7 @@ function _createNewFile(e) {
|
|||||||
if (filename.indexOf(".") < 0) {
|
if (filename.indexOf(".") < 0) {
|
||||||
filename += platform.getDefaultExtension();
|
filename += platform.getDefaultExtension();
|
||||||
}
|
}
|
||||||
var path = "local/" + filename;
|
var path = filename;
|
||||||
getSkeletonFile(path).then( (result) => {
|
getSkeletonFile(path).then( (result) => {
|
||||||
return store.setItem(path, result || "\n");
|
return store.setItem(path, result || "\n");
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
@ -334,7 +334,7 @@ function handleFileUpload(files: File[]) {
|
|||||||
alertInfo("Files uploaded.");
|
alertInfo("Files uploaded.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var path = "local/" + f.name;
|
var path = f.name;
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
reader.onload = function(e) {
|
reader.onload = function(e) {
|
||||||
var arrbuf = (<any>e.target).result as ArrayBuffer;
|
var arrbuf = (<any>e.target).result as ArrayBuffer;
|
||||||
@ -679,7 +679,6 @@ function _deleteFile(e) {
|
|||||||
var wnd = projectWindows.getActive();
|
var wnd = projectWindows.getActive();
|
||||||
if (wnd && wnd.getPath) {
|
if (wnd && wnd.getPath) {
|
||||||
var fn = projectWindows.getActiveID();
|
var fn = projectWindows.getActiveID();
|
||||||
if (repo_id || fn.startsWith("local/") || fn.startsWith("shared/")) {
|
|
||||||
bootbox.confirm("Delete '" + fn + "'?", (ok) => {
|
bootbox.confirm("Delete '" + fn + "'?", (ok) => {
|
||||||
if (ok) {
|
if (ok) {
|
||||||
store.removeItem(fn).then( () => {
|
store.removeItem(fn).then( () => {
|
||||||
@ -694,9 +693,6 @@ function _deleteFile(e) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
alertError("Can only delete local files.");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
alertError("Cannot delete the active window.");
|
alertError("Cannot delete the active window.");
|
||||||
}
|
}
|
||||||
@ -780,16 +776,15 @@ function _downloadAllFilesZipFile(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function populateExamples(sel) {
|
function populateExamples(sel) {
|
||||||
// make sure to use callback so it follows other sections
|
var files = {};
|
||||||
store.length().then( (len) => {
|
|
||||||
sel.append($("<option />").text("--------- Examples ---------").attr('disabled','true'));
|
sel.append($("<option />").text("--------- Examples ---------").attr('disabled','true'));
|
||||||
for (var i=0; i<PRESETS.length; i++) {
|
for (var i=0; i<PRESETS.length; i++) {
|
||||||
var preset = PRESETS[i];
|
var preset = PRESETS[i];
|
||||||
var name = preset.chapter ? (preset.chapter + ". " + preset.name) : preset.name;
|
var name = preset.chapter ? (preset.chapter + ". " + preset.name) : preset.name;
|
||||||
sel.append($("<option />").val(preset.id).text(name).attr('selected',(preset.id==current_project.mainPath)?'selected':null));
|
sel.append($("<option />").val(preset.id).text(name).attr('selected',(preset.id==current_project.mainPath)?'selected':null));
|
||||||
|
files[preset.id] = name;
|
||||||
}
|
}
|
||||||
// don't create new entry if example not found
|
return files;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function populateRepos(sel) {
|
function populateRepos(sel) {
|
||||||
@ -809,27 +804,19 @@ function populateRepos(sel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function populateFiles(sel:JQuery, category:string, prefix:string, callback:() => void) {
|
function populateFiles(sel:JQuery, category:string, prefix:string, foundFiles:{}, callback:() => void) {
|
||||||
store.keys().then( (keys:string[]) => {
|
store.keys().then( (keys:string[]) => {
|
||||||
var foundSelected = false;
|
|
||||||
var numFound = 0;
|
var numFound = 0;
|
||||||
if (!keys) keys = [];
|
if (!keys) keys = [];
|
||||||
for (var i = 0; i < keys.length; i++) {
|
for (var i = 0; i < keys.length; i++) {
|
||||||
var key = keys[i];
|
var key = keys[i];
|
||||||
if (key.startsWith(prefix)) {
|
if (key.startsWith(prefix) && !foundFiles[key]) {
|
||||||
if (numFound++ == 0)
|
if (numFound++ == 0)
|
||||||
sel.append($("<option />").text("------- " + category + " -------").attr('disabled','true'));
|
sel.append($("<option />").text("------- " + category + " -------").attr('disabled','true'));
|
||||||
var name = key.substring(prefix.length);
|
var name = key.substring(prefix.length);
|
||||||
sel.append($("<option />").val(key).text(name).attr('selected',(key==current_project.mainPath)?'selected':null));
|
sel.append($("<option />").val(key).text(name).attr('selected',(key==current_project.mainPath)?'selected':null));
|
||||||
if (key == current_project.mainPath) foundSelected = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// create new entry if not found, but it matches our prefix
|
|
||||||
if (!foundSelected && current_project.mainPath && current_project.mainPath.startsWith(prefix)) {
|
|
||||||
var name = current_project.mainPath.substring(prefix.length);
|
|
||||||
var key = prefix + name;
|
|
||||||
sel.append($("<option />").val(key).text(name).attr('selected','true'));
|
|
||||||
}
|
|
||||||
if (callback) { callback(); }
|
if (callback) { callback(); }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -837,18 +824,16 @@ function populateFiles(sel:JQuery, category:string, prefix:string, callback:() =
|
|||||||
function updateSelector() {
|
function updateSelector() {
|
||||||
var sel = $("#preset_select").empty();
|
var sel = $("#preset_select").empty();
|
||||||
if (!repo_id) {
|
if (!repo_id) {
|
||||||
|
// normal: populate repos, examples, and local files
|
||||||
populateRepos(sel);
|
populateRepos(sel);
|
||||||
// normal: populate local and shared files
|
var foundFiles = populateExamples(sel);
|
||||||
populateFiles(sel, "Local Files", "local/", () => {
|
populateFiles(sel, "Local Files", "", foundFiles, () => {
|
||||||
populateFiles(sel, "Shared", "shared/", () => {
|
|
||||||
populateExamples(sel);
|
|
||||||
sel.css('visibility','visible');
|
sel.css('visibility','visible');
|
||||||
});
|
});
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
sel.append($("<option />").val('/').text('Leave Repository'));
|
sel.append($("<option />").val('/').text('Leave Repository'));
|
||||||
// repo: populate all files
|
// repo: populate all files
|
||||||
populateFiles(sel, repo_id, "", () => {
|
populateFiles(sel, repo_id, "", {}, () => {
|
||||||
sel.css('visibility','visible');
|
sel.css('visibility','visible');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -905,7 +890,7 @@ function setCompileOutput(data: WorkerResult) {
|
|||||||
|
|
||||||
function loadBIOSFromProject() {
|
function loadBIOSFromProject() {
|
||||||
if (platform.loadBIOS) {
|
if (platform.loadBIOS) {
|
||||||
var biospath = 'local/' + platform_id + '.rom';
|
var biospath = platform_id + '.rom';
|
||||||
store.getItem(biospath).then( (biosdata) => {
|
store.getItem(biospath).then( (biosdata) => {
|
||||||
console.log('loading BIOS')
|
console.log('loading BIOS')
|
||||||
platform.loadBIOS('BIOS', biosdata);
|
platform.loadBIOS('BIOS', biosdata);
|
||||||
@ -1274,7 +1259,7 @@ function addFileToProject(type, ext, linefn) {
|
|||||||
var filename = prompt("Add "+type+" File to Project", "filename"+ext);
|
var filename = prompt("Add "+type+" File to Project", "filename"+ext);
|
||||||
if (filename && filename.trim().length > 0) {
|
if (filename && filename.trim().length > 0) {
|
||||||
if (!checkEnteredFilename(filename)) return;
|
if (!checkEnteredFilename(filename)) return;
|
||||||
var path = "local/" + filename;
|
var path = filename;
|
||||||
var newline = "\n" + linefn(filename) + "\n";
|
var newline = "\n" + linefn(filename) + "\n";
|
||||||
current_project.loadFiles([path], (err, result) => {
|
current_project.loadFiles([path], (err, result) => {
|
||||||
if (result && result.length) {
|
if (result && result.length) {
|
||||||
@ -1648,7 +1633,7 @@ function loadImportedURL(url : string) {
|
|||||||
setWaitDialog(true);
|
setWaitDialog(true);
|
||||||
getWithBinary(url, (data) => {
|
getWithBinary(url, (data) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
var path = 'shared/' + getFilenameForPath(url);
|
var path = 'shared/' + getFilenameForPath(url); // TODO: shared prefix?
|
||||||
// TODO: progress dialog
|
// TODO: progress dialog
|
||||||
console.log("Importing " + data.length + " bytes as " + path);
|
console.log("Importing " + data.length + " bytes as " + path);
|
||||||
store.getItem(path, (err, olddata) => {
|
store.getItem(path, (err, olddata) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user