"fix" output canvas and data export
still not sure why pixels are inverse at some point also tidied up a few things report palette switch bug
This commit is contained in:
parent
44ee5b874e
commit
648143b7a0
|
@ -62,7 +62,7 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function hexToColour(hex) {
|
function hexToColour(hex) {
|
||||||
var rgb = hex.match(/[\da-fA-F]{2}/g);
|
var rgb = hex.match(/[\da-f]{2}/gi);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
red: parseInt(rgb[0], 16),
|
red: parseInt(rgb[0], 16),
|
||||||
|
@ -121,6 +121,7 @@ $(document).ready(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// get tiles
|
// get tiles
|
||||||
|
|
||||||
bitsyData.tiles = {};
|
bitsyData.tiles = {};
|
||||||
|
|
||||||
// tile 0 (background colour only) is implicit in bitsy rather than being stored in the game data
|
// tile 0 (background colour only) is implicit in bitsy rather than being stored in the game data
|
||||||
|
@ -130,22 +131,21 @@ $(document).ready(function() {
|
||||||
bitmap: _.chunk(_.split(_.repeat(0, 64), ''), 8)
|
bitmap: _.chunk(_.split(_.repeat(0, 64), ''), 8)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// todo: handle animated tiles properly instead of discarding the second animation frame
|
||||||
var tiles = input.match(/TIL (.*)\n([01]{8}\n){8}/g);
|
var tiles = input.match(/TIL (.*)\n([01]{8}\n){8}/g);
|
||||||
|
|
||||||
if (tiles.length > 0) {
|
_.each(tiles, function(tile, i) {
|
||||||
for (var i = 0; i < tiles.length; i++) {
|
var name = tile.match(/TIL .*/)[0].replace('TIL ', '');
|
||||||
var name = tiles[i].match(/TIL .*/)[0].replace('TIL ', '');
|
|
||||||
|
|
||||||
tiles[i] = tiles[i].replace(/TIL .*\n/, '');
|
tile = tile.replace(/TIL .*\n/, '');
|
||||||
|
|
||||||
var bitmap = tiles[i].match(/[01]/g);
|
var bitmap = tile.match(/[01]/g);
|
||||||
|
|
||||||
bitsyData.tiles[name] = {
|
bitsyData.tiles[name] = {
|
||||||
name: name,
|
name: name,
|
||||||
bitmap: _.chunk(bitmap, 8)
|
bitmap: _.chunk(bitmap, 8)
|
||||||
};
|
};
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// set palette to first imported palette and redraw
|
// set palette to first imported palette and redraw
|
||||||
palette = _.first(_.sortBy(bitsyData.palettes, 'id'));
|
palette = _.first(_.sortBy(bitsyData.palettes, 'id'));
|
||||||
|
@ -197,7 +197,7 @@ $(document).ready(function() {
|
||||||
var rawData = imageData.data;
|
var rawData = imageData.data;
|
||||||
var monochrome = [];
|
var monochrome = [];
|
||||||
|
|
||||||
brightnessAdjustment = parseFloat($('#brightness').val());
|
var brightnessAdjustment = parseFloat($('#brightness').val());
|
||||||
|
|
||||||
// for each pixel
|
// for each pixel
|
||||||
for (var i = 0; i < rawData.length; i += 4) {
|
for (var i = 0; i < rawData.length; i += 4) {
|
||||||
|
@ -210,10 +210,10 @@ $(document).ready(function() {
|
||||||
|
|
||||||
var targetColour = getClosestColour(pixel, palette);
|
var targetColour = getClosestColour(pixel, palette);
|
||||||
|
|
||||||
if (targetColour.name === "background") {
|
if (targetColour.name === "background") { // ?! why is this reversed?
|
||||||
monochrome.push(0);
|
monochrome.push(1);
|
||||||
} else { // tile
|
} else { // tile
|
||||||
monochrome.push(1)
|
monochrome.push(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
rawData[i ] = targetColour.red;
|
rawData[i ] = targetColour.red;
|
||||||
|
@ -280,10 +280,10 @@ $(document).ready(function() {
|
||||||
|
|
||||||
position *= 4; // 4 values (rgba) per pixel
|
position *= 4; // 4 values (rgba) per pixel
|
||||||
|
|
||||||
if (parseInt(pixel) === 1) { // ?! wtf
|
if (parseInt(pixel) === 0) {
|
||||||
pixelColour = palette.background;
|
var pixelColour = palette.background;
|
||||||
} else {
|
} else {
|
||||||
pixelColour = palette.tile;
|
var pixelColour = palette.tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
rawData[position ] = pixelColour.red;
|
rawData[position ] = pixelColour.red;
|
||||||
|
|
Loading…
Reference in New Issue