Pushing current web edits

This commit is contained in:
Guy Perfect 2025-03-23 07:26:43 -05:00
parent ecbd103917
commit 483714c0d6
2 changed files with 37 additions and 12 deletions

View File

@ -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);

View File

@ -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.");