mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-11-26 10:49:17 +00:00
convert some stuff to Promises; onunhandledrejection
This commit is contained in:
parent
10f89d0c53
commit
532fe0fe48
@ -132,6 +132,7 @@ TODO:
|
|||||||
- allow "include graphics.asm" instead of "include project/graphics.asm"
|
- allow "include graphics.asm" instead of "include project/graphics.asm"
|
||||||
- chrome looks blurry on vcs
|
- chrome looks blurry on vcs
|
||||||
- convert more stuff to Promises
|
- convert more stuff to Promises
|
||||||
|
- target ES6
|
||||||
- don't have to include bootstrap-tourist each time?
|
- don't have to include bootstrap-tourist each time?
|
||||||
- don't have to include firebase always?
|
- don't have to include firebase always?
|
||||||
- Github
|
- Github
|
||||||
@ -146,6 +147,9 @@ TODO:
|
|||||||
- CORS for some blobs?
|
- CORS for some blobs?
|
||||||
- confusing when examples load if file not found
|
- confusing when examples load if file not found
|
||||||
- don't import useless files
|
- don't import useless files
|
||||||
|
- support projects with subdirectories, file list?
|
||||||
|
- emulator needs reset shortcut for nes
|
||||||
|
- local/ files in repository?
|
||||||
|
|
||||||
|
|
||||||
WEB WORKER FORMAT
|
WEB WORKER FORMAT
|
||||||
|
@ -303,6 +303,7 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
|
|||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<p>Enter the GitHub repository URL:</p>
|
<p>Enter the GitHub repository URL:</p>
|
||||||
<p><input id="importGithubURL" size="60" placeholder="https://github.com/user/repo"></input></p>
|
<p><input id="importGithubURL" size="60" placeholder="https://github.com/user/repo"></input></p>
|
||||||
|
<p>If the project is compatible with 8bitworkshop, it should build automatically.</p>
|
||||||
<p><button type="button" class="btn btn-primary" id="importGithubButton">Import Project</button></p>
|
<p><button type="button" class="btn btn-primary" id="importGithubButton">Import Project</button></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
64
src/ui.ts
64
src/ui.ts
@ -265,15 +265,11 @@ function reloadProject(id:string) {
|
|||||||
gotoNewLocation();
|
gotoNewLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSkeletonFile(fileid:string, callback) {
|
function getSkeletonFile(fileid:string) : Promise<string> {
|
||||||
var ext = platform.getToolForFilename(fileid);
|
var ext = platform.getToolForFilename(fileid);
|
||||||
// TODO: .mame
|
// TODO: .mame
|
||||||
$.get( "presets/"+getBasePlatform(platform_id)+"/skeleton."+ext, function( text ) {
|
return $.get( "presets/"+getBasePlatform(platform_id)+"/skeleton."+ext, 'text').catch((e) => {
|
||||||
callback(null, text);
|
|
||||||
}, 'text')
|
|
||||||
.fail(() => {
|
|
||||||
alert("Could not load skeleton for " + platform_id + "/" + ext + "; using blank file");
|
alert("Could not load skeleton for " + platform_id + "/" + ext + "; using blank file");
|
||||||
callback(null, '\n');
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,15 +290,10 @@ function _createNewFile(e) {
|
|||||||
filename += platform.getDefaultExtension();
|
filename += platform.getDefaultExtension();
|
||||||
}
|
}
|
||||||
var path = "local/" + filename;
|
var path = "local/" + filename;
|
||||||
getSkeletonFile(path, function(err, result) {
|
getSkeletonFile(path).then( (result) => {
|
||||||
if (result) {
|
return store.setItem(path, result || "\n");
|
||||||
store.setItem(path, result, function(err, result) {
|
}).then(() => {
|
||||||
if (err)
|
reloadProject("local/" + filename);
|
||||||
alert(err+"");
|
|
||||||
if (result != null)
|
|
||||||
reloadProject("local/" + filename);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -639,9 +630,9 @@ 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 (fn.startsWith("local/") || fn.startsWith("shared/")) {
|
if (repo_id || fn.startsWith("local/") || fn.startsWith("shared/")) {
|
||||||
if (confirm("Delete '" + fn + "'?")) {
|
if (confirm("Delete '" + fn + "'?")) {
|
||||||
store.removeItem(fn, () => {
|
store.removeItem(fn).then( () => {
|
||||||
// if we delete what is selected
|
// if we delete what is selected
|
||||||
if (qs['file'] == fn) {
|
if (qs['file'] == fn) {
|
||||||
unsetLastPreset();
|
unsetLastPreset();
|
||||||
@ -668,14 +659,14 @@ function _renameFile(e) {
|
|||||||
var data = current_project.getFile(wnd.getPath());
|
var data = current_project.getFile(wnd.getPath());
|
||||||
if (newfn && data) {
|
if (newfn && data) {
|
||||||
if (!checkEnteredFilename(newfn)) return;
|
if (!checkEnteredFilename(newfn)) return;
|
||||||
store.removeItem(fn, () => {
|
store.removeItem(fn).then( () => {
|
||||||
store.setItem(newfn, data, () => {
|
return store.setItem(newfn, data);
|
||||||
alert("Renamed " + fn + " to " + newfn);
|
}).then( () => {
|
||||||
updateSelector();
|
alert("Renamed " + fn + " to " + newfn);
|
||||||
if (fn == current_project.mainPath) {
|
updateSelector();
|
||||||
reloadProject(newfn);
|
if (fn == current_project.mainPath) {
|
||||||
}
|
reloadProject(newfn);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -721,21 +712,17 @@ function _downloadProjectZipFile(e) {
|
|||||||
function _downloadAllFilesZipFile(e) {
|
function _downloadAllFilesZipFile(e) {
|
||||||
loadScript('lib/jszip.min.js', () => {
|
loadScript('lib/jszip.min.js', () => {
|
||||||
var zip = new JSZip();
|
var zip = new JSZip();
|
||||||
var count = 0;
|
|
||||||
store.keys( (err, keys : string[]) => {
|
store.keys( (err, keys : string[]) => {
|
||||||
if (err) throw err;
|
return Promise.all(keys.map( (path) => {
|
||||||
keys.forEach((path) => {
|
return store.getItem(path).then( (text) => {
|
||||||
// TODO: handle binary files
|
|
||||||
store.getItem(path, (err, text) => {
|
|
||||||
if (text) {
|
if (text) {
|
||||||
zip.file(path, text);
|
zip.file(path, text);
|
||||||
}
|
}
|
||||||
if (++count == keys.length) {
|
|
||||||
zip.generateAsync({type:"blob"}).then( (content) => {
|
|
||||||
saveAs(content, platform_id + "-all.zip");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
})).then(() => {
|
||||||
|
return zip.generateAsync({type:"blob"});
|
||||||
|
}).then( (content) => {
|
||||||
|
return saveAs(content, platform_id + "-all.zip");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -743,7 +730,7 @@ function _downloadAllFilesZipFile(e) {
|
|||||||
|
|
||||||
function populateExamples(sel) {
|
function populateExamples(sel) {
|
||||||
// make sure to use callback so it follows other sections
|
// make sure to use callback so it follows other sections
|
||||||
store.length(function(err, len) {
|
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];
|
||||||
@ -1484,7 +1471,7 @@ var qs = (function (a : string[]) {
|
|||||||
|
|
||||||
// catch errors
|
// catch errors
|
||||||
function installErrorHandler() {
|
function installErrorHandler() {
|
||||||
if (typeof window.onerror == "object") {
|
if (typeof window.onerror == "object") {
|
||||||
window.onerror = function (msgevent, url, line, col, error) {
|
window.onerror = function (msgevent, url, line, col, error) {
|
||||||
var msgstr = msgevent+"";
|
var msgstr = msgevent+"";
|
||||||
console.log(msgevent, url, line, col, error);
|
console.log(msgevent, url, line, col, error);
|
||||||
@ -1499,7 +1486,8 @@ function installErrorHandler() {
|
|||||||
}
|
}
|
||||||
_pause();
|
_pause();
|
||||||
};
|
};
|
||||||
}
|
window.onunhandledrejection = window.onerror;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function uninstallErrorHandler() {
|
function uninstallErrorHandler() {
|
||||||
|
Loading…
Reference in New Issue
Block a user