From 483714c0d6367ce575f603975c34fe461a144c99 Mon Sep 17 00:00:00 2001 From: Guy Perfect Date: Sun, 23 Mar 2025 07:26:43 -0500 Subject: [PATCH] Pushing current web edits --- web/Core.js | 6 ++++++ web/VB.js | 43 +++++++++++++++++++++++++++++++------------ 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/web/Core.js b/web/Core.js index cb261bc..7fe8b5e 100644 --- a/web/Core.js +++ b/web/Core.js @@ -293,6 +293,12 @@ new class Core { }, [ output.buffer ]); } + // Reset simulation state + reset(message) { + this.vbReset(message.sim); + this.dom.postMessage({ promised: true }); + } + // Specify anaglyph colors setAnaglyph(message) { this.SetAnaglyph(message.sim, message.left, message.right); diff --git a/web/VB.js b/web/VB.js index e1dc088..51e471f 100644 --- a/web/VB.js +++ b/web/VB.js @@ -436,8 +436,17 @@ class Sim extends HTMLElement { response.lines.map(l=>new DasmLine(GUARD, l)); } + // Reset simulation state + reset() { + return this.#core.toCore({ + command : "reset", + promised: true, + sim : this.#pointer + }); + } + // Specify anaglyph colors - async setAnaglyph(left, right) { + setAnaglyph(left, right) { // Error checking if (!Number.isSafeInteger(left ) || left < 0 || left > 0xFFFFFF) @@ -455,7 +464,7 @@ class Sim extends HTMLElement { this.#anaglyph[1] = right; // Send the colors to the core - await this.#core.toCore({ + return this.#core.toCore({ command : "setAnaglyph", promised: true, sim : this.#pointer, @@ -475,7 +484,7 @@ class Sim extends HTMLElement { } // Specify new game pad keys - async setKeys(keys) { + setKeys(keys) { // Error checking if (!Number.isSafeInteger(keys) || keys < 0 || keys > 0xFFFF) @@ -487,7 +496,7 @@ class Sim extends HTMLElement { this.#keys = keys; // Send the keys to the core - await this.#core.toCore({ + return this.#core.toCore({ command : "setKeys", promised: true, sim : this.#pointer, @@ -496,7 +505,7 @@ class Sim extends HTMLElement { } // Specify audio panning - async setPanning(panning) { + setPanning(panning) { // Error checking if (!Number.isFinite(panning) ||panning < -1 || panning > +1) { @@ -508,7 +517,7 @@ class Sim extends HTMLElement { this.#panning = panning; // Send the panning to the core - await this.#core.toCore({ + return this.#core.toCore({ command : "setPanning", promised: true, sim : this.#pointer, @@ -529,7 +538,7 @@ class Sim extends HTMLElement { } // Specify audio volume - async setVolume(volume) { + setVolume(volume) { // Error checking if (!Number.isFinite(volume) ||volume < 0 || volume > 10) { @@ -541,7 +550,7 @@ class Sim extends HTMLElement { this.#volume = volume; // Send the volume to the core - await this.#core.toCore({ + return this.#core.toCore({ command : "setVolume", promised: true, sim : this.#pointer, @@ -596,7 +605,7 @@ class VB { #commands; // Computed method table #core; // Core worker #proxy; // Self proxy for sim access - #sims; // All sims + #sims; // Mapping of Sim|pointer -> proxy #state; // Operations state @@ -683,8 +692,8 @@ class VB { ///////////////////////////// Static Methods ////////////////////////////// // Create a core instance - static async create(options) { - return await new VB(GUARD).#construct(options); + static create(options) { + return new VB(GUARD).#construct(options); } @@ -769,6 +778,16 @@ class VB { + /////////////////////////////// Properties //////////////////////////////// + + // Number of managed simulations + get size() { return this.#sims.size / 2; } + + // Managed simulations + get sims() { return [... this.#sims.keys()].filter(s=>s instanceof Sim); } + + + ///////////////////////////// Public Methods ////////////////////////////// // Create one or more sims @@ -809,7 +828,7 @@ class VB { if ( !Array.isArray(sims) || sims.length == 0 || - sims.find(s=>!this.#sims.has(s)) + sims.some(s=>!this.#sims.has(s)) ) { throw new TypeError("Must specify a Sim or array of Sims " + "that belong to this core.");