79 lines
4.4 KiB
Python
79 lines
4.4 KiB
Python
"""Reuse the maintained native creation profile for correlated new-character UI."""
|
|
import hashlib,json,re
|
|
from pathlib import Path
|
|
import character_creation as contract
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
|
|
def profile(header=None):
|
|
raw=Path(header or ROOT/'include/gateway/character_creation_profile.hpp').read_bytes();text=raw.decode();tables={}
|
|
for name in ['Conversions','Choices','Sections','FacialHair','HairGeosets']:
|
|
m=re.search(r'inline constexpr std::array<[^,]+,(\d+)> '+name+r'\{\{(.*?)\}\};',text,re.S)
|
|
if not m:raise ValueError('Maintained profile array missing: '+name)
|
|
rows=[list(map(int,x.split(','))) for x in re.findall(r'\{([^{}]+)\}',m.group(2))]
|
|
if len(rows)!=int(m.group(1)):raise ValueError('Maintained profile row count differs')
|
|
tables[name]=rows
|
|
conversion_keys=['ID','ChrRacesID','Sex','OptionID','Data','ChrCustomizationChoiceID','DependentOptionID','DependentData','Field_3_4_0_45166_007']
|
|
schema=contract.AppearanceSchema([dict(zip(conversion_keys,r)) for r in tables['Conversions']],
|
|
[dict(zip(['ID','ChrCustomizationOptionID'],r)) for r in tables['Choices']],
|
|
[dict(zip(['id','race','sex','section','variation','color','flags'],r)) for r in tables['Sections']],
|
|
[dict(zip(['race','sex','variation'],r)) for r in tables['FacialHair']],
|
|
[dict(zip(['race','sex','variation'],r)) for r in tables['HairGeosets']])
|
|
return schema,hashlib.sha256(raw).hexdigest()
|
|
|
|
def groups(header=None):
|
|
schema,pin=profile(header);data={};held=[]
|
|
keys=sorted({(r,s) for r,s,c in schema.relations})
|
|
for race,sex in keys:
|
|
fields={};relations=[]
|
|
for (r,s,choice),rs in schema.relations.items():
|
|
if (r,s)!=(race,sex):continue
|
|
option=schema.choices[choice]
|
|
for field,value,dependent,dvalue in rs:
|
|
if option in fields and fields[option]!=field:raise ValueError('Cross-axis native option needs a new explicit contract')
|
|
if dependent and (field,dependent)!=(2,1):raise ValueError('New cross-axis dependency needs explicit grouping')
|
|
fields[option]=field;relations.append((field,value,dependent,dvalue,option,choice))
|
|
def forward(values):
|
|
out={}
|
|
for field,value,dependent,dvalue,option,choice in relations:
|
|
if values.get(field)!=value or dependent and values.get(dependent)!=dvalue:continue
|
|
if option in out and out[option]!=choice:return None
|
|
out[option]=choice
|
|
if set(values)-{fields[o] for o in out}:return None
|
|
return [v for pair in sorted(out.items()) for v in pair]
|
|
domains=[sorted({(color,variation) for r,s,section,variation,color in schema.sections if (r,s,section)==(race,sex,1) and (race,sex,0,0,color) in schema.sections
|
|
and schema.creator_skin_allowed(race,sex,color)}),
|
|
sorted({(variation,color) for r,s,section,variation,color in schema.sections if (r,s,section)==(race,sex,3) and (race,sex,variation) in schema.hair}),
|
|
sorted({(value,) for r,s,value in schema.facial if (r,s)==(race,sex)})]
|
|
rowgroups=[]
|
|
for axis,domain in enumerate(domains):
|
|
rows=[]
|
|
for values in domain:
|
|
mapping=dict(zip(([1,2],[3,4],[5])[axis],values));choices=forward(mapping)
|
|
if choices:rows.append([list(values),choices])
|
|
# Reuse the sole explicit NEW-character canonicalization from the backend:
|
|
# Tauren male Source facial0/7 have identical native projection; choose0.
|
|
if (race,sex,axis)==(6,0,2):
|
|
zero=next((r for r in rows if r[0]==[0]),None)
|
|
rows=[r for r in rows if not(r[0]==[7] and zero and r[1]==zero[1])]
|
|
rowgroups.append(rows)
|
|
if any(not rows for rows in rowgroups):held.append([race,sex]);continue
|
|
data[race*2+sex]={'fields':fields,'groups':rowgroups}
|
|
return data,dict(profile_sha256=pin,race_sex_groups=len(data),held_race_sex=held,held_signed_rows=schema.held_conversion_rows,rows=sum(len(rs) for d in data.values() for rs in d['groups']))
|
|
|
|
def lua(value):
|
|
if isinstance(value,dict):return '{'+','.join('['+str(k)+']='+lua(v) for k,v in sorted(value.items()))+'}'
|
|
if isinstance(value,(list,tuple)):return '{'+','.join(lua(v) for v in value)+'}'
|
|
if isinstance(value,int):return str(value)
|
|
raise ValueError('Numeric profile only')
|
|
|
|
def render_solver(rendered):
|
|
return (ROOT/'ops/source_appearance_groups.lua').read_text().replace('-- PROFILE_DATA', 'local GW_SourceAppearanceGroups = '+lua(rendered)+';')
|
|
|
|
def helper(header=None):
|
|
data,report=groups(header)
|
|
rendered={k:[v['fields'],*v['groups']] for k,v in data.items()}
|
|
return render_solver(rendered) + '''local function GW_SourceFilterCustomizations(data)
|
|
return GW_SourceCorrelateCustomizations(data, GW_SourcePreferredChoice);
|
|
end
|
|
''',report
|