This repository has been archived by the owner on Dec 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextureGeneration.py
52 lines (42 loc) · 1.97 KB
/
TextureGeneration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from PIL import Image
from pprint import pprint
from os import listdir
from os.path import isfile, join, expanduser
oreHexColors = {}
oreHexFile = open("ore_hex_color.csv", "r")
contents = oreHexFile.read().replace("\r", "").split("\n")
header = [x.strip() for x in contents[0].split(",")]
nameIndex = header.index("Name")
oreHexColorIndex = header.index("Ore Hex Color")
# Skips first header line in file
for line in contents[1:]:
datum = line.split(",")
# Check that all fields are "populated" (so that we don't get index out of bounds errors)
if len(datum) != len(header):
continue
name = datum[nameIndex]
oreHexColor = datum[oreHexColorIndex]
oreHexColors[name] = oreHexColor
# Cool! We got all of the ore hex colors.
# Note - only works on Linux.
# TODO: Add Windows/Mac support
MINECRAFT_STONE_PATH =
VINTAGE_STORY_STONE_PATH = expanduser("~/.config/Vintagestory/assets/survival/textures/block/stone/rock")
TEMPLATES_PATH = "template"
templateList = ["{}/{}".format(TEMPLATES_PATH, f) for f in listdir(TEMPLATES_PATH) if isfile(join(TEMPLATES_PATH, f)) and ".png" in f]
stoneTypes = ["{}/{}".format(VINTAGE_STORY_STONE_PATH, f) for f in listdir(VINTAGE_STORY_STONE_PATH) if isfile(join(VINTAGE_STORY_STONE_PATH, f))]
outputFolder = "output"
pprint(oreHexColors)
pprint(templateList)
pprint(stoneTypes)
for templateImageName in templateList:
for oreName in oreHexColors:
for stoneName in stoneTypes:
with Image.open(templateImageName) as templateImage:
with Image.open(stoneName) as stoneImage:
outputFilename = "{}_{}_{}.png".format(templateImageName.rsplit("/",1)[1].split(".",1)[0], oreName, stoneName.rsplit("/",1)[1].split(".",1)[0])
templateSplit = templateImage.split()
oreColorImage = Image.new('RGBA', stoneImage.size, color="#{}".format(oreHexColors[oreName]))
oreColorImage.putalpha(templateSplit[3])
finalImage = Image.alpha_composite(stoneImage, oreColorImage) # , 100)#, templateSplit[0])
finalImage.save(outputFolder + "/" + outputFilename)