Hojoo wrote: ↑Sat Nov 19, 2022 6:40 pm
I'm working to fully understand it, but the code is so much more compact this way.
The only thing still breaking is tints that match other tints, because this is how I used to have it under the Call action:
Code: Select all
label set_tints:
...
if brows_color == 1:
$ brows_tint = hair_tint ## <--
elif brows_color == 2:
$ brows_tint = "#554237"
if horns_color == 1:
$ horns_tint = body_tint ## <--
elif horns_color == 2:
$ horns_tint = "#554237"
Is there a formatting for putting those back in?
Basically the function returns list of arguments for
ConditionSwitch, for example:
[“body_color == 0”, Transform(img, matrixcolor=TintMatrix(“#d48c5f”)), “body_color == 1”, Transform(img, matrixcolor=TintMatrix(“#b09a93”)), etc]
Possibly for matching colors you can use another ConditionSwitch, I guess that’s what you were trying to do in your code, but not sure if nested ConditionSwitch works:
Code: Select all
def gen_cs_arg_brows(img):
args = []
brows_tints = [“hair”, "#554237"]
for i, brows_tint in enumerate(brows_tints):
args.append(f"brows_color == {i}")
if brows_tints == “hair”:
args.append(ConditionSwitch(*gen_cs_arg_hair(img)))
else:
args.append(Transform(img, matrixcolor=TintMatrix(brows_tint)))
return args
Note, that I changed indexes for brows_color from 1,2 to 0,1.
Alternatively, you can combine conditions.
Code: Select all
def gen_cs_arg_brows(img):
args = []
hair_tints = ["#ffffff", "#eac5ae", "#A0A0A0", "#767676", "#494949", "#1C1C1C"]
brows_tints = hair_tints + ["#554237"]
brows_conditions = [f"brows_color == 0 and hair_color == {i}" for i in range(0, len(hair_tints))] + [“ brows_color == 1”]
for i, brows_tint in enumerate(brows_tints):
args.append(brows_conditions[i])
args.append(Transform(img, matrixcolor=TintMatrix(brows_tint)))
return args
You can also combine functions into one, so you don’t have to repeat some lines.