Skip to content

Commit 797e865

Browse files
committed
support for listeners on scale, sensitivity, volume
1 parent a2af8c0 commit 797e865

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/build.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// gulpfile.ts/wasm.ts --> generateBuildInfo
55

66
export const Build = {
7-
short: "0.73.2",
8-
version: "0.73.2 (40eefa1795cae0673481705edc30f239)",
9-
buildSeed: 1650619479904,
7+
short: "0.73.4",
8+
version: "0.73.4 (187fc112dd3c66ac30885526e9cdd0cb)",
9+
buildSeed: 1654072258715,
1010
};

src/js-dos.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,15 @@ export class DosInstance {
4141

4242
storage: Storage;
4343

44+
volume: number;
45+
4446
private clickToStart: boolean;
4547
private unbindControls: () => void = () => {/**/};
4648
private storedLayersConfig: LayersConfig | LegacyLayersConfig | null = null;
4749
private onMobileControlsChanged: (visible: boolean) => void;
50+
private onSensitivityChanged: ((sensitivity: number) => void)[] = [];
51+
private onScaleChanged: ((scale: number) => void)[] = [];
52+
private onVolumeChanged: ((scale: number) => void)[] = [];
4853

4954
constructor(root: HTMLDivElement, emulatorsUi: EmulatorsUi, options: DosOptions) {
5055
this.options = options;
@@ -66,6 +71,9 @@ export class DosInstance {
6671
const sensitivityValue = Number.parseFloat(this.storage.getItem("sensitivity") ?? "1.0");
6772
this.sensitivity = Number.isNaN(sensitivityValue) ? 1.0 : sensitivityValue;
6873

74+
const volumeValue = Number.parseFloat(this.storage.getItem("volume") ?? "1.0");
75+
this.volume = Number.isNaN(volumeValue) ? 1.0 : volumeValue;
76+
6977
this.onMobileControlsChanged = () => {/**/};
7078

7179
if (this.emulatorFunction === "backend" && this.createTransportLayer === undefined) {
@@ -221,6 +229,9 @@ export class DosInstance {
221229
if (this.mobileControls) {
222230
await this.setLayersConfig(this.layersConfig);
223231
}
232+
for (const next of this.onScaleChanged) {
233+
next(this.scaleControls);
234+
}
224235
}
225236

226237
public async setSensitivity(sensitivity: number) {
@@ -230,6 +241,16 @@ export class DosInstance {
230241
this.sensitivity = sensitivity;
231242
this.storage.setItem("sensitivity", sensitivity + "");
232243
await this.setLayersConfig(this.layersConfig);
244+
for (const next of this.onSensitivityChanged) {
245+
next(this.sensitivity);
246+
}
247+
}
248+
249+
public async setVolume(volume: number) {
250+
this.volume = volume;
251+
for (const next of this.onVolumeChanged) {
252+
next(this.volume);
253+
}
233254
}
234255

235256
public async setAutolock(autolock: boolean) {
@@ -244,6 +265,30 @@ export class DosInstance {
244265
this.onMobileControlsChanged = handler;
245266
}
246267

268+
public registerOnSensitivityChanged = (handler: (sensitivity: number) => void) => {
269+
this.onSensitivityChanged.push(handler);
270+
};
271+
272+
public removeOnSensitivityChanged = (handler: (sensitivity: number) => void) => {
273+
this.onSensitivityChanged = this.onSensitivityChanged.filter((n) => n !== handler);
274+
};
275+
276+
public registerOnScaleChanged = (handler: (scale: number) => void) => {
277+
this.onScaleChanged.push(handler);
278+
};
279+
280+
public removeOnScaleChanged = (handler: (scale: number) => void) => {
281+
this.onScaleChanged = this.onScaleChanged.filter((n) => n !== handler);
282+
};
283+
284+
public registerOnVolumeChanged = (handler: (volume: number) => void) => {
285+
this.onVolumeChanged.push(handler);
286+
};
287+
288+
public removeOnVolumeChanged = (handler: (volume: number) => void) => {
289+
this.onVolumeChanged = this.onVolumeChanged.filter((n) => n !== handler);
290+
};
291+
247292
private async runBundle(bundleUrl: string, optionalChangesUrl: string | undefined, persistKey: string) {
248293
const emulatorsUi = this.emulatorsUi;
249294
if (this.emulatorFunction === "janus") {

0 commit comments

Comments
 (0)