1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-08 11:30:21 +01:00

Improve [AMC] script and color overrides

This commit is contained in:
Wouters Dorian 2015-07-23 11:00:15 +02:00
parent ec3e2896cd
commit e9b1517df8

View File

@ -11,10 +11,10 @@ predefined = {
#"^default:river_water_([a-z]+)": {'r': 39, 'g': 66, 'b': 106, 'a': 128, 't': 224}, #"^default:river_water_([a-z]+)": {'r': 39, 'g': 66, 'b': 106, 'a': 128, 't': 224},
#"^default:lava_([a-z]+)": {'r': 255, 'g': 100, 'b': 0}, #"^default:lava_([a-z]+)": {'r': 255, 'g': 100, 'b': 0},
"^default:([a-z_]*)glass": {'a': 64, 't': 16}, "^default:([a-z_]*)glass": {'a': 64, 't': 16},
"^default:torch": {'r': 255, 'g': 255}, "^default:torch": {'r': 255, 'g': 255, 'b': 0, 'a': 255},
"^default:ice": {'r': 74, 'g': 105, 'b': 159, 'a': 159}, "^default:ice": {'r': 74, 'g': 105, 'b': 159, 'a': 159},
"^default:water_([a-z]+)": {'r': 38, 'g': 68, 'b': 157}, "^default:water_([a-z]+)": {'r': 43, 'g': 97, 'b': 183, 'a': 128},
"^default:dirt_with_grass": {'r': 72, 'g': 154, 'b': 21} "^default:dirt_with_grass": {'r': 107, 'g': 134, 'b': 51, 'a': 255}
} }
predef_compiled = {} predef_compiled = {}
@ -39,26 +39,26 @@ else:
nodename = ldata[0] nodename = ldata[0]
tex = ldata[1][:-1] # Strip newline char tex = ldata[1][:-1] # Strip newline char
try: try:
r_override = None
g_override = None
b_override = None
a_override = None a_override = None
t_override = None t_override = None
compute = True compute = True
ccumul = [0, 0, 0, 0]
for k in predef_compiled: for k in predef_compiled:
if k.match(nodename) is not None: if k.match(nodename) is not None:
v = predef_compiled[k] v = predef_compiled[k]
if 'r' in v: if 'r' in v:
ccumul[0] = v['r'] r_override = ccumul[0] = v['r']
compute = False
if 'g' in v: if 'g' in v:
ccumul[1] = v['g'] g_override = ccumul[1] = v['g']
compute = False
if 'b' in v: if 'b' in v:
ccumul[2] = v['b'] b_override = ccumul[2] = v['b']
compute = False
if 'a' in v: if 'a' in v:
a_override = v['a'] a_override = a = v['a']
if 't' in v: if 't' in v:
t_override = v['t'] t_override = t = v['t']
compute = not('r' in v and 'g' in v and 'b' in v and 'a' in v)
if compute: if compute:
inp = Image.open(pngpaths[tex]) inp = Image.open(pngpaths[tex])
@ -69,6 +69,7 @@ else:
ind = inp2.load() ind = inp2.load()
inpfp.close() inpfp.close()
pixcount = 0 pixcount = 0
ccumul = [0, 0, 0, 0]
for x in range(inp.size[0]): for x in range(inp.size[0]):
for y in range(inp.size[1]): for y in range(inp.size[1]):
pxl = ind[x, y] pxl = ind[x, y]
@ -79,6 +80,12 @@ else:
if ccumul[3] > 0: if ccumul[3] > 0:
for i in range(3): for i in range(3):
ccumul[i] /= ccumul[3]/255 ccumul[i] /= ccumul[3]/255
if r_override is not None:
ccumul[0] = r_override
if g_override is not None:
ccumul[1] = g_override
if b_override is not None:
ccumul[2] = b_override
if a_override is None: if a_override is None:
a = ccumul[3]/(inp.size[0]*inp.size[1]) a = ccumul[3]/(inp.size[0]*inp.size[1])
else: else: