");
+ this.el.text(JSON.stringify(data, null, ' '));
+ return true;
+ }
+ delete() {
+ this.wrap && this.wrap.remove();
+ this.wrap = null;
+ }
+}
+
+class Notebook {
+ top: HTMLElement;
+ items: {[id:string]:NotebookItem};
+
+ constructor(top: HTMLElement) {
+ this.items = {};
+ this.top = top;
+ $(top).css('overflowY', 'auto');
+ }
+ update(obj: any) {
+ var last = null;
+ var unused = new Set
(Object.keys(this.items));
+ for (var entry of Object.entries(obj)) {
+ var id = entry[0];
+ var data = entry[1];
+ var item = this.items[id];
+ //console.log(id,data,item);
+ if (!item) {
+ this.items[id] = item = new NotebookItem();
+ }
+ if (item.setData(data)) {
+ if (!item.wrap) {
+ item.wrap = $('');
+ $(this.top).append(item.wrap);
+ }
+ item.wrap.empty().append(item.el);
+ }
+ unused.delete(id);
+ }
+ unused.forEach((id) => { this.items[id].delete(); });
+ }
+}
+
+class ScriptPlatform implements Platform {
+ mainElement;
+ htmlDiv;
+ notebook: Notebook;
+
+ constructor(mainElement:HTMLElement) {
+ this.mainElement = mainElement;
+ this.notebook = new Notebook(mainElement);
+ }
+ start() {
+ }
+ reset() {
+ }
+ pause() {
+ }
+ resume() {
+ }
+ loadROM(title, data) {
+ this.notebook.update(data);
+ }
+ isRunning() {
+ return false;
+ }
+ isDebugging() : boolean {
+ return false;
+ }
+ getToolForFilename(fn : string) : string {
+ return "js";
+ }
+ getDefaultExtension() : string {
+ return ".js";
+ }
+ getPresets() {
+ return [
+ {id:'hello.js', name:'Hello'},
+ ];
+ }
+ /*
+ showHelp() {
+ window.open("https://github.com/showdownjs/showdown/wiki/Showdown's-Script-syntax", "_help");
+ }
+ */
+}
+
+PLATFORMS['script'] = ScriptPlatform;
diff --git a/src/ui.ts b/src/ui.ts
index b2c6e885..7849a43b 100644
--- a/src/ui.ts
+++ b/src/ui.ts
@@ -72,6 +72,7 @@ var TOOL_TO_SOURCE_STYLE = {
'zmac': 'z80',
'bataribasic': 'bataribasic',
'markdown': 'markdown',
+ 'js': 'javascript',
'xasm6809': 'z80'
}
diff --git a/src/windows.ts b/src/windows.ts
index 49c446bd..fa6d0c20 100644
--- a/src/windows.ts
+++ b/src/windows.ts
@@ -60,7 +60,7 @@ export class ProjectWindows {
this.activediv = div;
this.activewnd = wnd;
$(div).show();
- this.refresh(moveCursor);
+ this.refresh(true); // needed to tell asset editor 1st time running, but that's bad
this.refreshErrors();
wnd.setVisible && wnd.setVisible(true);
this.id2showfn[id] && this.id2showfn[id](id, wnd);
diff --git a/src/worker/workermain.ts b/src/worker/workermain.ts
index 29704375..9d9cdfba 100644
--- a/src/worker/workermain.ts
+++ b/src/worker/workermain.ts
@@ -2,13 +2,16 @@
import { WorkerResult, WorkerFileUpdate, WorkerBuildStep, WorkerMessage, WorkerError, Dependency, SourceLine } from "../workertypes";
-const emglobal : any = this['window'] || this['global'] || this;
declare var WebAssembly;
declare function importScripts(path:string);
declare function postMessage(msg);
-var ENVIRONMENT_IS_WEB = typeof window === 'object';
-var ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
+const emglobal : any = this['window'] || this['global'] || this;
+const ENVIRONMENT_IS_WEB = typeof window === 'object';
+const ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
+
+//const self = emglobal.self;
+//const __WORKER__ = function() {
// WebAssembly module cache
// TODO: leaks memory even when disabled...
@@ -1328,7 +1331,6 @@ function linkSDLDZ80(step:BuildStep)
}
}
-var sdcc;
function compileSDCC(step:BuildStep) {
gatherFiles(step, {
@@ -1339,7 +1341,7 @@ function compileSDCC(step:BuildStep) {
var errors = [];
var params = step.params;
loadNative('sdcc');
- var SDCC = sdcc({
+ var SDCC = emglobal.sdcc({
instantiateWasm: moduleInstFn('sdcc'),
noInitialRun:true,
noFSInit:true,
@@ -1871,6 +1873,19 @@ function translateShowdown(step:BuildStep) {
};
}
+function runJavascript(step:BuildStep) {
+ var code = getWorkFileAsString(step.path);
+ try {
+ //eval(code);
+ var fn = new Function("'use strict';\n" + code);
+ var obj = {};
+ var out = fn.call(obj);
+ return { output:out||obj };
+ } catch (e) {
+ return { errors:[{line:(e.lineNumber-2)|0, msg:e.message||"Error"}] };
+ }
+}
+
// http://datapipe-blackbeltsystems.com/windows/flex/asm09.html
function assembleXASM6809(step:BuildStep) {
load("xasm6809");
@@ -2054,6 +2069,7 @@ var TOOLS = {
'nesasm': assembleNESASM,
'bataribasic': compileBatariBasic,
'markdown': translateShowdown,
+ 'js': runJavascript,
}
var TOOL_PRELOADFS = {
@@ -2188,3 +2204,5 @@ if (ENVIRONMENT_IS_WORKER) {
}
}
}
+
+//}();