diff --git a/js/animations/animation.js b/js/animations/animation.js index a9a3031c..7aa1d14d 100644 --- a/js/animations/animation.js +++ b/js/animations/animation.js @@ -1453,6 +1453,7 @@ const Animator = { animation.select() } new_animations.push(animation) + Blockbench.dispatchEvent('load_animation', {animation, json}); } } else if (typeof json.animation_controllers === 'object') { for (let ani_name in json.animation_controllers) { @@ -1470,6 +1471,7 @@ const Animator = { controller.select(); } new_animations.push(controller) + Blockbench.dispatchEvent('load_animation_controller', {animation_controller: controller, json}); } } return new_animations diff --git a/js/texturing/edit_texture.js b/js/texturing/edit_texture.js index a2dafa86..6090be29 100644 --- a/js/texturing/edit_texture.js +++ b/js/texturing/edit_texture.js @@ -533,21 +533,21 @@ BARS.defineActions(function() { Painter.scanCanvas(ctx, 0, 0, canvas.width, canvas.height, (x, y, pixel) => { if (pixel[3] < 4) return; - let nearest = []; + let smallest_distance = Infinity; + let nearest_color = null; + let pixel_color = {_r: pixel[0], _g: pixel[1], _b: pixel[2]}; for (let key in palette) { let color = palette[key]; - let distance = colorDistance(color, {_r: pixel[0], _g: pixel[1], _b: pixel[2]}); - if (distance < 100) { - nearest.push({distance, color}) + let distance = colorDistance(color, pixel_color); + if (distance < smallest_distance) { + smallest_distance = distance; + nearest_color = color; } } - if (!nearest.length) return; - nearest.sort((a, b) => { - return a.distance - b.distance; - }) - pixel[0] = nearest[0].color._r; - pixel[1] = nearest[0].color._g; - pixel[2] = nearest[0].color._b; + if (!nearest_color) return; + pixel[0] = nearest_color._r; + pixel[1] = nearest_color._g; + pixel[2] = nearest_color._b; }) }, {no_undo: true});