fix quests loading in shareware

This commit is contained in:
d07riv
2019-08-03 16:44:00 +03:00
parent 9c7e156f85
commit dce65c725e
8 changed files with 30 additions and 6 deletions

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "diabloweb", "name": "diabloweb",
"version": "1.0.11", "version": "1.0.13",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@@ -1,6 +1,6 @@
{ {
"name": "diabloweb", "name": "diabloweb",
"version": "1.0.11", "version": "1.0.13",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@babel/core": "7.4.3", "@babel/core": "7.4.3",

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@@ -191,7 +191,10 @@ function call_api(func, ...params) {
audioTransfer = null; audioTransfer = null;
} }
} catch (e) { } catch (e) {
worker.postMessage({action: "error", error: e.message || (e.constructor && e.constructor.name), stack: e.stack}); if (typeof e === "string") {
worker.postMessage({action: ""})
}
worker.postMessage({action: "error", error: e.toString(), stack: e.stack});
} }
} }
@@ -274,7 +277,7 @@ worker.addEventListener("message", ({data}) => {
files = data.files; files = data.files;
init_game(data.mpq, data.spawn, data.offscreen).then( init_game(data.mpq, data.spawn, data.offscreen).then(
() => worker.postMessage({action: "loaded"}), () => worker.postMessage({action: "loaded"}),
e => worker.postMessage({action: "failed", error: e.message || e.name || (e.constructor && e.constructor.name), stack: e.stack})); e => worker.postMessage({action: "failed", error: e.toString(), stack: e.stack}));
break; break;
case "event": case "event":
call_api(data.func, ...data.params); call_api(data.func, ...data.params);

View File

@@ -94,6 +94,7 @@ async function do_load_game(api, audio, mpq) {
api.openKeyboard(data.open); api.openKeyboard(data.open);
break; break;
case "error": case "error":
audio.stop_all();
api.onError(data.error, data.stack); api.onError(data.error, data.stack);
break; break;
case "failed": case "failed":

View File

@@ -15,11 +15,18 @@ export default function init_sound() {
return no_sound(); return no_sound();
} }
const context = new AudioContext(); let context = null;
try {
context = new AudioContext();
} catch (e) {
}
const sounds = new Map(); const sounds = new Map();
return { return {
create_sound(id, data, length, channels, rate) { create_sound(id, data, length, channels, rate) {
if (!context) {
return;
}
const buffer = context.createBuffer(channels, length, rate); const buffer = context.createBuffer(channels, length, rate);
for (let i = 0; i < channels; ++i) { for (let i = 0; i < channels; ++i) {
buffer.copyToChannel(data.subarray(i * length, i * length + length), i); buffer.copyToChannel(data.subarray(i * length, i * length + length), i);
@@ -31,6 +38,9 @@ export default function init_sound() {
}); });
}, },
duplicate_sound(id, srcId) { duplicate_sound(id, srcId) {
if (!context) {
return;
}
const src = sounds.get(srcId); const src = sounds.get(srcId);
if (!src) { if (!src) {
return; return;
@@ -77,5 +87,15 @@ export default function init_sound() {
} }
sounds.delete(id); sounds.delete(id);
}, },
stop_all() {
for (let [, sound] of sounds) {
if (sound.source) {
sound.source.stop();
}
}
sounds.clear();
context = null;
}
}; };
} }