Skip to content

Commit

Permalink
Missing colours severe bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
gd-codes committed Jun 24, 2024
1 parent 6cdd79e commit 0b318b1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
7 changes: 6 additions & 1 deletion scripts/functionWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ function getSurvivalGuideTableData(uid) {
}
var cindexns = [];
for (let ct of pal) {
cindexns.push(ColourTokens.indexOf(ct));
let index = ColourTokens.indexOf(ct);
if (index === -1) {
alert("Unexpected Error\n\nSome colours in the palette are invalid (Is this image data restored from an older session?). Please re-upload the image and try in a new form.");
throw new Error(`Missing colour ${ct}`);
}
cindexns.push(index);
}

return { uid,
Expand Down
3 changes: 3 additions & 0 deletions scripts/imageProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ function analyseImage(uid, image, area, palette, is3D, dither) {
p.push(darkPixel(clr.rgb));
p.push(lightPixel(clr.rgb));
}
} else {
alert("Unexpected Error\n\nSome colours in the palette are invalid (Is this image data restored from an older session?). Please re-upload the image and try in a new form.");
throw new Error(`Missing colour ${cn}`);
}
}
// Resize the image to fit number of pixels in minceraft maps, using browser canvas
Expand Down
19 changes: 11 additions & 8 deletions scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ function submitImgFormHandler(uid, event) {
// Read the uploaded image data from stored base64 URI, and disable the form and begin analysis
var image = new Image();
image.onload = function() {
var analysis = analyseImage(uid, image, area, palette, d3, dither);
if (!analysis) {
try {
analyseImage(uid, image, area, palette, d3, dither);
$("form#imageForm_"+uid+" :input").prop('disabled', true);
$("form#imageForm_"+uid+" :radio").prop('disabled', true);
$("form#imageForm_"+uid+" :checkbox").prop('disabled', true);
Expand All @@ -534,10 +534,8 @@ function submitImgFormHandler(uid, event) {
makeTabLabelContent(uid)
);
deleteSurvivalGuide(uid, true);

} else {
alert("Error\n\nAn unknown error occurred while processing");
console.error("Error processing image "+uid);
} catch (error) {
console.error(error);
}
$("#spinnerModal").addClass('d-none'); $("#spinnerModal").removeClass('d-block');
}
Expand Down Expand Up @@ -960,8 +958,13 @@ function createSurvivalGuide(uid, area) {
$("#survGuidePlaceholderText").addClass('d-none');

// Add the html string to DOM
$("#guideTab_"+uid).html(
ejs.render(EJStemplates.survivalGuide, getSurvivalGuideTableData(uid)));
try {
$("#guideTab_"+uid).html(
ejs.render(EJStemplates.survivalGuide, getSurvivalGuideTableData(uid)));
} catch (err) {
console.error(err);
return;
}

$(`#guidePageBar_${uid} li.page-item`).click(function() {
switchActiveGuidePage(this);
Expand Down
2 changes: 1 addition & 1 deletion sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Service Worker to enable the webpage to be used even offline, once installed
Cached site should require only ~ 3 MB space
*/

const CURRENT_CACHE_VERSION = 'mapart-cache-5.2.0';
const CURRENT_CACHE_VERSION = 'mapart-cache-5.2.1';

const CACHE_URLS_LOCAL = [
/* Important : `/` doesn't automatically fetch `/index.html` locally, explicitly cache it
Expand Down

0 comments on commit 0b318b1

Please sign in to comment.