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",
"version": "1.0.11",
"version": "1.0.13",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "diabloweb",
"version": "1.0.11",
"version": "1.0.13",
"private": true,
"dependencies": {
"@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;
}
} 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;
init_game(data.mpq, data.spawn, data.offscreen).then(
() => 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;
case "event":
call_api(data.func, ...data.params);

View File

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

View File

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