
// Использует Image Magick для автоматической перекраски текстур

const fs = require('fs')
const root_main = './src/main/resources/assets/overdrive_that_matters/textures/'
const child_process = require('child_process')

const colors = [
	['white', [255, 255, 255]],
	['orange', [245, 116, 16]],
	['magenta', [186, 63, 175]],
	['light_blue', [59, 180, 219]],
	['yellow', [252, 199, 36]],
	['lime', [111, 187, 24]],
	['pink', [243, 139, 170]],
	['gray', [62, 66, 70]],
	['light_gray', [140, 140, 131]],
	['cyan', [22, 134, 145]],
	['purple', [116, 38, 169]],
	['blue', [51, 53, 155]],
	['brown', [114, 71, 40]],
	['green', [84, 109, 28]],
	['red', [156, 37, 34]],
	['black', [31, 31, 35]],
]

process.stderr.setMaxListeners(400)
process.stdout.setMaxListeners(400)

const texA = `block/decorative/tritanium_striped_block_colorless_base`
const texB = `block/decorative/tritanium_striped_block_colorless_stripe`

for (const colorA of colors) {
	for (const colorB of colors) {
		if (colorA === colorB) {
			continue
		}

		const width = 16
		const height = 16

		const nameA = colorA[0]
		const rgbA = colorA[1]

		const nameB = colorB[0]
		const rgbB = colorB[1]

		const magick = child_process.spawn('magick', [
			'convert',

			'-size', `${width}x${height}`,

			'(',
				`${root_main}${texA}.png`,
				`xc:rgb(${rgbA[0]}, ${rgbA[1]}, ${rgbA[2]})`,
				'-compose', 'Multiply',
				'-composite',
			')',

			'(',
				`${root_main}${texB}.png`,
				`xc:rgb(${rgbB[0]}, ${rgbB[1]}, ${rgbB[2]})`,
				'-channel', 'rgb',
				'-compose', 'Multiply',
				'-composite',
			')',
			
			'-channel', 'rgba',
			'-compose', 'Over',
			'-composite',

			//'-layers', 'merge',
			`${root_main}/block/decorative/stripe/tritanium_striped_block_${nameA}_${nameB}.png`])

		magick.stdout.pipe(process.stdout)
		magick.stderr.pipe(process.stderr)
	}
}
