Skip to content

Instantly share code, notes, and snippets.

@Nick-Riggs
Created October 26, 2017 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nick-Riggs/fa016749c25dc75f9f19d859c59fff63 to your computer and use it in GitHub Desktop.
Save Nick-Riggs/fa016749c25dc75f9f19d859c59fff63 to your computer and use it in GitHub Desktop.
const basePath = "D:\\tagpro-texture-packs";
const fs = require("fs");
const path = require("path");
const PNG = require("pngjs").PNG;
const redTilePos = {
x: 14 * 40,
y: 4 * 40
};
const yellowTilePos = {
x: 13 * 40,
y: 5 * 40
};
for (const name of fs.readdirSync(basePath)) {
const texturePath = path.join(basePath, name, "tiles.png");
if (!fs.existsSync(texturePath)) {
continue;
}
fs.createReadStream(texturePath).pipe(new PNG()).on("parsed", function() {
for (let x = 0; x !== 40; x++) {
for (let y = 0; y !== 40; y++) {
const sourceX = redTilePos.x + x;
const sourceY = redTilePos.y + y;
const sourceIndex = (this.width * sourceY + sourceX) << 2;
const red = this.data[sourceIndex];
const green = this.data[sourceIndex + 1];
const blue = this.data[sourceIndex + 2];
const alpha = this.data[sourceIndex + 3];
const destX = yellowTilePos.x + x;
const destY = yellowTilePos.y + y;
const destIndex = (this.width * destY + destX) << 2;
this.data[destIndex] = red;
this.data[destIndex + 1] = red;
this.data[destIndex + 2] = blue;
this.data[destIndex + 3] = alpha;
}
}
this.pack().pipe(fs.createWriteStream(path.join(basePath, name, "tiles.png")));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment