From fdd869653afaa80b3d82b76fde6395efc49261c6 Mon Sep 17 00:00:00 2001 From: synth-ruiner Date: Wed, 27 Dec 2017 20:39:35 +0000 Subject: [PATCH] don't change palette on game data update if not necessary --- includes/script.js | 16 +++++++++++++--- readme.md | 4 ---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/includes/script.js b/includes/script.js index 561bbe0..eb0ad40 100644 --- a/includes/script.js +++ b/includes/script.js @@ -97,6 +97,8 @@ $(document).ready(function() { bitsyData.palettes = {}; + // do palettes always go 0..n? + // will this cause problems if not? _.each(palettes, function(palette, n) { var thisPalette = {}; var name = ""; @@ -156,8 +158,16 @@ $(document).ready(function() { bitsyData.tiles[name] = newTile; }); - // set palette to first imported palette and redraw - palette = _.first(_.sortBy(bitsyData.palettes, 'id')); + if (_.find(bitsyData.palettes, {'id': palette.id})) { + // user has already selected a palette, leave it be + + // if we just set the palette to the newly imported palette with the same ID, + // we will lose any changes the user has made to the palettes + // is this a big issue considering that the palettes cannot be currently saved anyway? + } else { + // set palette to first imported palette and redraw + palette = _.first(_.sortBy(bitsyData.palettes, 'id')); + } renderResult(); @@ -179,7 +189,7 @@ $(document).ready(function() { ); }); - $('tr.palette input[type="radio"]').eq(0).trigger('click'); + $('input[name="id"][value="' + palette.id + '"]').siblings(':radio').trigger('click'); } function readFile(input) { diff --git a/readme.md b/readme.md index ea6435c..76027d2 100644 --- a/readme.md +++ b/readme.md @@ -40,10 +40,6 @@ croppie.js:182 (mine) if (src.match(/^(file|https)?:\/\/|^\/\//)) { ``` -## known bugs - -* keyup on game data input sets palette to pal 0 even if game data has not changed - ## to do * allow user to save output as image, or tweet it :) *user can currently right-click -> Save As but the 128x128 size is not great*