|
@@ -237,7 +237,13 @@ const game = {
|
|
game.lang = {}; // Clear previously loaded language
|
|
game.lang = {}; // Clear previously loaded language
|
|
|
|
|
|
fetch(url, { mode: 'same-origin' })
|
|
fetch(url, { mode: 'same-origin' })
|
|
- .then((response) => response.text())
|
|
|
|
|
|
+ .then((response) => {
|
|
|
|
+ if (!response.ok)
|
|
|
|
+ throw new Error(
|
|
|
|
+ 'Game error: translation not found "' + url[0] + '".'
|
|
|
|
+ );
|
|
|
|
+ return response.text();
|
|
|
|
+ })
|
|
.then((text) => {
|
|
.then((text) => {
|
|
const lines = text.split('\n');
|
|
const lines = text.split('\n');
|
|
game.loadHandler.type.lang.length = lines.length;
|
|
game.loadHandler.type.lang.length = lines.length;
|
|
@@ -246,7 +252,7 @@ const game = {
|
|
try {
|
|
try {
|
|
const msg = line.split('=');
|
|
const msg = line.split('=');
|
|
if (msg.length !== 2)
|
|
if (msg.length !== 2)
|
|
- throw Error('Game error: sintax error in i18y file');
|
|
|
|
|
|
+ throw Error('Game error: sintax error in i18y file.');
|
|
game.lang[msg[0].trim()] = msg[1].trim();
|
|
game.lang[msg[0].trim()] = msg[1].trim();
|
|
} catch (error) {
|
|
} catch (error) {
|
|
console.error(error.message);
|
|
console.error(error.message);
|
|
@@ -255,6 +261,7 @@ const game = {
|
|
});
|
|
});
|
|
})
|
|
})
|
|
.catch((error) => {
|
|
.catch((error) => {
|
|
|
|
+ game.loadHandler.cachedOneFile('lang');
|
|
console.error(error);
|
|
console.error(error);
|
|
});
|
|
});
|
|
},
|
|
},
|
|
@@ -279,12 +286,21 @@ const game = {
|
|
|
|
|
|
urls.forEach((url) => {
|
|
urls.forEach((url) => {
|
|
fetch(url[1][1], { mode: 'same-origin' })
|
|
fetch(url[1][1], { mode: 'same-origin' })
|
|
- .then((response) => response.blob())
|
|
|
|
|
|
+ .then((response) => {
|
|
|
|
+ // Since 4xx and 5xx responses aren't network errors, there's nothing to catch. Throw error manually.
|
|
|
|
+ if (!response.ok)
|
|
|
|
+ throw new Error(
|
|
|
|
+ 'Game error: audio not found "' + url[0] + '".'
|
|
|
|
+ );
|
|
|
|
+ return response.blob();
|
|
|
|
+ })
|
|
.then((data) => {
|
|
.then((data) => {
|
|
game.audio[url[0]] = new Audio(URL.createObjectURL(data));
|
|
game.audio[url[0]] = new Audio(URL.createObjectURL(data));
|
|
game.loadHandler.cachedOneFile('audio');
|
|
game.loadHandler.cachedOneFile('audio');
|
|
})
|
|
})
|
|
|
|
+ // Fetch promises only reject with a TypeError when a network error occurs.
|
|
.catch((error) => {
|
|
.catch((error) => {
|
|
|
|
+ game.loadHandler.cachedOneFile('audio');
|
|
console.error(error);
|
|
console.error(error);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
@@ -310,20 +326,30 @@ const game = {
|
|
game.loadHandler.max += urls.length;
|
|
game.loadHandler.max += urls.length;
|
|
|
|
|
|
urls.forEach((url) => {
|
|
urls.forEach((url) => {
|
|
- const img = new Image();
|
|
|
|
- img.onload = () => {
|
|
|
|
- game.image[url[0]] = img;
|
|
|
|
- game.loadHandler.cachedOneFile('image');
|
|
|
|
- };
|
|
|
|
- img.onerror = () => {
|
|
|
|
|
|
+ try {
|
|
|
|
+ const img = new Image();
|
|
|
|
+ img.onload = () => {
|
|
|
|
+ game.image[url[0]] = img;
|
|
|
|
+ game.loadHandler.cachedOneFile('image');
|
|
|
|
+ };
|
|
|
|
+ img.onerror = () => {
|
|
|
|
+ console.error(
|
|
|
|
+ 'Game error: image not found "' +
|
|
|
|
+ url[0] +
|
|
|
|
+ '". Loading fallback image.'
|
|
|
|
+ );
|
|
|
|
+ // loads fallback image
|
|
|
|
+ game.image[url[0]] = img;
|
|
|
|
+ img.src = fallbackImgUrl;
|
|
|
|
+ game.loadHandler.cachedOneFile('image');
|
|
|
|
+ };
|
|
|
|
+ img.src = url[1];
|
|
|
|
+ } catch (error) {
|
|
|
|
+ // game.loadHandler.cachedOneFile('image');
|
|
console.error(
|
|
console.error(
|
|
- 'Game error: image "' + url[0] + '" not found in sourse files.'
|
|
|
|
|
|
+ 'Game error: unkown image error "' + url[0] + '" - ' + error
|
|
);
|
|
);
|
|
- game.image[url[0]] = img;
|
|
|
|
- img.src = fallbackImgUrl;
|
|
|
|
- game.loadHandler.cachedOneFile('image');
|
|
|
|
- };
|
|
|
|
- img.src = url[1];
|
|
|
|
|
|
+ }
|
|
});
|
|
});
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -354,7 +380,12 @@ const game = {
|
|
game.loadHandler.cachedOneFile('sprite');
|
|
game.loadHandler.cachedOneFile('sprite');
|
|
};
|
|
};
|
|
img.onerror = () => {
|
|
img.onerror = () => {
|
|
- console.error('Game error: sprite not found');
|
|
|
|
|
|
+ console.error(
|
|
|
|
+ 'Game error: sprite not found "' +
|
|
|
|
+ url[0] +
|
|
|
|
+ '". Loading fallback image.'
|
|
|
|
+ );
|
|
|
|
+ // loads fallback sprite
|
|
game.sprite[url[0]] = img;
|
|
game.sprite[url[0]] = img;
|
|
img.src = fallbackImgUrl;
|
|
img.src = fallbackImgUrl;
|
|
img.frames = 1;
|
|
img.frames = 1;
|
|
@@ -363,7 +394,10 @@ const game = {
|
|
img.src = url[1];
|
|
img.src = url[1];
|
|
img.frames = url[2];
|
|
img.frames = url[2];
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.error(error);
|
|
|
|
|
|
+ // game.loadHandler.cachedOneFile('sprite');
|
|
|
|
+ console.error(
|
|
|
|
+ 'Game error: unkown sprite error "' + url[0] + '" - ' + error
|
|
|
|
+ );
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -391,7 +425,11 @@ const game = {
|
|
*/
|
|
*/
|
|
image: function (x, y, img, scale, alpha) {
|
|
image: function (x, y, img, scale, alpha) {
|
|
if (x == undefined || y == undefined || img == undefined)
|
|
if (x == undefined || y == undefined || img == undefined)
|
|
- console.error('Game error: missing parameters.');
|
|
|
|
|
|
+ console.error(
|
|
|
|
+ 'Game error: Could not render image "' +
|
|
|
|
+ img +
|
|
|
|
+ '". Missing required parameters.'
|
|
|
|
+ );
|
|
else if (game.image[img] == undefined)
|
|
else if (game.image[img] == undefined)
|
|
console.error('Game error: image not found in cache: ' + img + '.');
|
|
console.error('Game error: image not found in cache: ' + img + '.');
|
|
else {
|
|
else {
|
|
@@ -446,9 +484,13 @@ const game = {
|
|
*/
|
|
*/
|
|
sprite: function (x, y, img, curFrame, scale, alpha) {
|
|
sprite: function (x, y, img, curFrame, scale, alpha) {
|
|
if (x == undefined || y == undefined || img == undefined)
|
|
if (x == undefined || y == undefined || img == undefined)
|
|
- console.error('Game error: missing parameters.');
|
|
|
|
|
|
+ console.error(
|
|
|
|
+ 'Game error: Could not render sprite "' +
|
|
|
|
+ img +
|
|
|
|
+ '". Missing required parameters.'
|
|
|
|
+ );
|
|
else if (game.sprite[img] == undefined)
|
|
else if (game.sprite[img] == undefined)
|
|
- console.error('Game error: sprite not found in cache: ' + img + '.');
|
|
|
|
|
|
+ console.error('Game error: sprite not found in cache "' + img + '".');
|
|
else {
|
|
else {
|
|
const med = {
|
|
const med = {
|
|
typeOfMedia: 'sprite',
|
|
typeOfMedia: 'sprite',
|
|
@@ -506,7 +548,9 @@ const game = {
|
|
text == undefined ||
|
|
text == undefined ||
|
|
style == undefined
|
|
style == undefined
|
|
) {
|
|
) {
|
|
- console.error('Game error: missing parameters.');
|
|
|
|
|
|
+ console.error(
|
|
|
|
+ 'Game error: Could not render text. Missing required parameters.'
|
|
|
|
+ );
|
|
} else {
|
|
} else {
|
|
const med = {
|
|
const med = {
|
|
typeOfMedia: 'text',
|
|
typeOfMedia: 'text',
|
|
@@ -582,7 +626,9 @@ const game = {
|
|
lineWidth
|
|
lineWidth
|
|
) {
|
|
) {
|
|
if (x == undefined || y == undefined || width == undefined)
|
|
if (x == undefined || y == undefined || width == undefined)
|
|
- console.error('Game error: missing parameters.');
|
|
|
|
|
|
+ console.error(
|
|
|
|
+ 'Game error: Could not render rectangle. Missing required parameters.'
|
|
|
|
+ );
|
|
else {
|
|
else {
|
|
const med = {
|
|
const med = {
|
|
typeOfMedia: 'rect',
|
|
typeOfMedia: 'rect',
|
|
@@ -647,7 +693,9 @@ const game = {
|
|
*/
|
|
*/
|
|
line: function (x0, y0, x1, y1, lineWidth, lineColor, alpha) {
|
|
line: function (x0, y0, x1, y1, lineWidth, lineColor, alpha) {
|
|
if (x0 == undefined || y0 == undefined)
|
|
if (x0 == undefined || y0 == undefined)
|
|
- console.error('Game error: missing parameters.');
|
|
|
|
|
|
+ console.error(
|
|
|
|
+ 'Game error: Could not render line. Missing required parameters.'
|
|
|
|
+ );
|
|
else {
|
|
else {
|
|
const med = {
|
|
const med = {
|
|
typeOfMedia: 'line',
|
|
typeOfMedia: 'line',
|
|
@@ -737,7 +785,9 @@ const game = {
|
|
alpha
|
|
alpha
|
|
) {
|
|
) {
|
|
if (x == undefined || y == undefined || diameter == undefined)
|
|
if (x == undefined || y == undefined || diameter == undefined)
|
|
- console.error('Game error: missing parameters.');
|
|
|
|
|
|
+ console.error(
|
|
|
|
+ 'Game error: Could not render circle. Missing required parameters.'
|
|
|
|
+ );
|
|
else {
|
|
else {
|
|
const med = {
|
|
const med = {
|
|
typeOfMedia: 'arc',
|
|
typeOfMedia: 'arc',
|
|
@@ -827,7 +877,9 @@ const game = {
|
|
angleStart == undefined ||
|
|
angleStart == undefined ||
|
|
angleEnd == undefined
|
|
angleEnd == undefined
|
|
)
|
|
)
|
|
- console.error('Game error: missing parameters.');
|
|
|
|
|
|
+ console.error(
|
|
|
|
+ 'Game error: Could not render arc. Missing required parameters.'
|
|
|
|
+ );
|
|
else {
|
|
else {
|
|
const med = {
|
|
const med = {
|
|
typeOfMedia: 'arc',
|
|
typeOfMedia: 'arc',
|