don't create duplicate tiles
This commit is contained in:
parent
948fccb5a3
commit
e0420606d9
|
@ -289,7 +289,17 @@ $(document).ready(function() {
|
||||||
var tilesForMatch = bitsyData.tiles;
|
var tilesForMatch = bitsyData.tiles;
|
||||||
|
|
||||||
// if we want to always create new tiles, don't bother trying to check matches
|
// if we want to always create new tiles, don't bother trying to check matches
|
||||||
if (tileMatchThreshold < 64) {
|
if (tileMatchThreshold === 64) {
|
||||||
|
// even if we want to "always create new tiles" we still don't want to create duplicates
|
||||||
|
var bestMatch = _.find(bitsyData.tiles, function(tile) {
|
||||||
|
return tile.bitmap === pseudoTile;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (bestMatch) {
|
||||||
|
console.debug(pseudoTile === bestMatch.bitmap);
|
||||||
|
bestMatch.match = 64;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
_.each(tilesForMatch, function(tile) {
|
_.each(tilesForMatch, function(tile) {
|
||||||
tile.match = 0;
|
tile.match = 0;
|
||||||
|
|
||||||
|
@ -313,18 +323,18 @@ $(document).ready(function() {
|
||||||
tile.match /= 2;
|
tile.match /= 2;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// what if there are several equally good matches?
|
||||||
|
// find highest match amount and find all of them
|
||||||
|
var bestMatchAmount = _.last(_.sortBy(tilesForMatch, ['match'])).match;
|
||||||
|
var bestMatches = _.filter(tilesForMatch, {'match': bestMatchAmount});
|
||||||
|
|
||||||
|
// sort by name in ascending order
|
||||||
|
// earlier names are preferable
|
||||||
|
var bestMatch = _.first(_.sortBy(bestMatches, 'name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// what if there are several equally good matches?
|
if ( ! bestMatch || bestMatch.match < tileMatchThreshold) {
|
||||||
// find highest match amount and find all of them
|
|
||||||
var bestMatchAmount = _.last(_.sortBy(tilesForMatch, ['match'])).match;
|
|
||||||
var bestMatches = _.filter(tilesForMatch, {'match': bestMatchAmount});
|
|
||||||
|
|
||||||
// sort by name in ascending order
|
|
||||||
// earlier names are preferable
|
|
||||||
var bestMatch = _.first(_.sortBy(bestMatches, 'name'));
|
|
||||||
|
|
||||||
if (tileMatchThreshold === 64 || bestMatch.match <= tileMatchThreshold) {
|
|
||||||
// turn pseudo-tile into a real tile and add it to the tile data
|
// turn pseudo-tile into a real tile and add it to the tile data
|
||||||
|
|
||||||
var name = newTileName();
|
var name = newTileName();
|
||||||
|
@ -386,10 +396,11 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var renderDebounced = _.debounce(render, 30);
|
var renderDebounced = _.debounce(render, 30);
|
||||||
|
var renderThrottled = _.throttle(render, 30);
|
||||||
|
|
||||||
$croppie.on('update', renderDebounced);
|
$croppie.on('update', renderDebounced);
|
||||||
|
|
||||||
$('#brightness').on('change', renderDebounced);
|
$('#brightness').on('change', renderThrottled);
|
||||||
|
|
||||||
$('#brightness').on('dblclick', function() {
|
$('#brightness').on('dblclick', function() {
|
||||||
$(this).val(0);
|
$(this).val(0);
|
||||||
|
@ -441,7 +452,7 @@ $(document).ready(function() {
|
||||||
|
|
||||||
tileMatchThreshold = newValue;
|
tileMatchThreshold = newValue;
|
||||||
|
|
||||||
renderDebounced();
|
renderThrottled();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#save').on('click touchend', function() {
|
$('#save').on('click touchend', function() {
|
||||||
|
|
Loading…
Reference in New Issue