Accessories unhardcoded
This commit is contained in:
+180
-36
@@ -74,7 +74,7 @@ func applyAutogenConsumers(p *project.Project, collected []nativeCollectedDatase
|
||||
case "parts_rows":
|
||||
result = augmentWithAutogeneratedParts(result, autogenPartsInventory(entries))
|
||||
case "head_visualeffects":
|
||||
result, err = augmentWithAutogeneratedHeadVisualeffects(result, entries)
|
||||
result, err = augmentWithAutogeneratedHeadVisualeffects(result, entries, consumer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -660,11 +660,12 @@ func augmentWithAutogeneratedCachedModels(collected []nativeCollectedDataset, en
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func augmentWithAutogeneratedHeadVisualeffects(collected []nativeCollectedDataset, entries []autogenManifestEntry) ([]nativeCollectedDataset, error) {
|
||||
func augmentWithAutogeneratedHeadVisualeffects(collected []nativeCollectedDataset, entries []autogenManifestEntry, consumer project.AutogenConsumerConfig) ([]nativeCollectedDataset, error) {
|
||||
if len(entries) == 0 {
|
||||
return collected, nil
|
||||
}
|
||||
|
||||
policy := resolveHeadVisualeffectsPolicy(consumer)
|
||||
result := append([]nativeCollectedDataset(nil), collected...)
|
||||
for i, dataset := range result {
|
||||
if dataset.Dataset.Name != "visualeffects" {
|
||||
@@ -714,12 +715,12 @@ func augmentWithAutogeneratedHeadVisualeffects(collected []nativeCollectedDatase
|
||||
}
|
||||
|
||||
for _, entry := range entries {
|
||||
key, label, ok := headVisualeffectIdentity(entry)
|
||||
key, label, modelStem, groupPolicy, ok := headVisualeffectIdentity(dataset.Dataset.Name, entry, policy)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if existing, exists := rowByKey[key]; exists {
|
||||
applyDiscoveredHeadVisualeffectDefaults(existing, dataset.Columns, entry.ModelStem, label)
|
||||
applyDiscoveredHeadVisualeffectDefaults(existing, dataset.Columns, modelStem, label, policy, groupPolicy)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -732,7 +733,7 @@ func augmentWithAutogeneratedHeadVisualeffects(collected []nativeCollectedDatase
|
||||
}
|
||||
lockData[key] = rowID
|
||||
}
|
||||
newRow := createDefaultHeadVisualeffectRow(dataset.Columns, rowID, key, label, entry.ModelStem)
|
||||
newRow := createDefaultHeadVisualeffectRow(dataset.Columns, rowID, key, label, modelStem, policy, groupPolicy)
|
||||
rows = append(rows, newRow)
|
||||
rowByKey[key] = newRow
|
||||
}
|
||||
@@ -755,25 +756,150 @@ func nextAvailableAutogenID(used map[int]struct{}) int {
|
||||
}
|
||||
}
|
||||
|
||||
func headVisualeffectIdentity(entry autogenManifestEntry) (string, string, bool) {
|
||||
groupPrefix := map[string]string{
|
||||
"head_accessories": "headaccessory",
|
||||
"head_features": "headfeature",
|
||||
}
|
||||
prefix, ok := groupPrefix[entry.Group]
|
||||
if !ok || strings.TrimSpace(entry.ModelStem) == "" {
|
||||
return "", "", false
|
||||
}
|
||||
stem := strings.TrimPrefix(entry.ModelStem, "hfx_")
|
||||
stem = strings.TrimPrefix(stem, "vfx_")
|
||||
stem = strings.TrimSpace(stem)
|
||||
if stem == "" {
|
||||
return "", "", false
|
||||
}
|
||||
return "visualeffects:" + prefix + "_" + stem, prefix + "_" + strings.ToUpper(stem), true
|
||||
type headVisualeffectsPolicy struct {
|
||||
Groups map[string]headVisualeffectsGroupPolicy
|
||||
StripModelPrefixes []string
|
||||
KeyFormat string
|
||||
LabelFormat string
|
||||
ModelColumn string
|
||||
RowDefaults map[string]string
|
||||
}
|
||||
|
||||
func createDefaultHeadVisualeffectRow(columns []string, rowID int, key, label, modelStem string) map[string]any {
|
||||
type headVisualeffectsGroupPolicy struct {
|
||||
Prefix string
|
||||
ModelColumns []string
|
||||
RowDefaults map[string]string
|
||||
}
|
||||
|
||||
func resolveHeadVisualeffectsPolicy(consumer project.AutogenConsumerConfig) headVisualeffectsPolicy {
|
||||
policy := defaultHeadVisualeffectsPolicy()
|
||||
cfg := consumer.HeadVisualeffects
|
||||
for group, groupCfg := range cfg.Groups {
|
||||
group = strings.TrimSpace(group)
|
||||
prefix := strings.TrimSpace(groupCfg.Prefix)
|
||||
if group == "" || prefix == "" {
|
||||
continue
|
||||
}
|
||||
groupPolicy := headVisualeffectsGroupPolicy{
|
||||
Prefix: prefix,
|
||||
ModelColumns: normalizeHeadVisualeffectsModelColumns(groupCfg.ModelColumn, groupCfg.ModelColumns),
|
||||
RowDefaults: normalizeHeadVisualeffectsRowDefaults(groupCfg.RowDefaults),
|
||||
}
|
||||
policy.Groups[group] = groupPolicy
|
||||
}
|
||||
if len(cfg.StripModelPrefixes) > 0 {
|
||||
policy.StripModelPrefixes = append([]string(nil), cfg.StripModelPrefixes...)
|
||||
}
|
||||
if strings.TrimSpace(cfg.KeyFormat) != "" {
|
||||
policy.KeyFormat = strings.TrimSpace(cfg.KeyFormat)
|
||||
}
|
||||
if strings.TrimSpace(cfg.LabelFormat) != "" {
|
||||
policy.LabelFormat = strings.TrimSpace(cfg.LabelFormat)
|
||||
}
|
||||
if strings.TrimSpace(cfg.ModelColumn) != "" {
|
||||
policy.ModelColumn = strings.TrimSpace(cfg.ModelColumn)
|
||||
}
|
||||
mergeStringMap(policy.RowDefaults, normalizeHeadVisualeffectsRowDefaults(cfg.RowDefaults))
|
||||
return policy
|
||||
}
|
||||
|
||||
func defaultHeadVisualeffectsPolicy() headVisualeffectsPolicy {
|
||||
return headVisualeffectsPolicy{
|
||||
Groups: map[string]headVisualeffectsGroupPolicy{
|
||||
"head_accessories": {Prefix: "headaccessory"},
|
||||
"head_decorations": {Prefix: "headdecoration"},
|
||||
"head_features": {Prefix: "headfeature"},
|
||||
},
|
||||
StripModelPrefixes: []string{"hfx_", "vfx_"},
|
||||
KeyFormat: "{dataset}:{prefix}_{stem}",
|
||||
LabelFormat: "{prefix}_{stem_upper}",
|
||||
ModelColumn: "Imp_HeadCon_Node",
|
||||
RowDefaults: map[string]string{
|
||||
"Type_FD": "D",
|
||||
"OrientWithGround": "0",
|
||||
"OrientWithObject": "1",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeHeadVisualeffectsModelColumns(modelColumn string, modelColumns []string) []string {
|
||||
var result []string
|
||||
if column := strings.TrimSpace(modelColumn); column != "" {
|
||||
result = append(result, column)
|
||||
}
|
||||
for _, column := range modelColumns {
|
||||
column = strings.TrimSpace(column)
|
||||
if column == "" {
|
||||
continue
|
||||
}
|
||||
if !slices.Contains(result, column) {
|
||||
result = append(result, column)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func normalizeHeadVisualeffectsRowDefaults(defaults map[string]string) map[string]string {
|
||||
result := map[string]string{}
|
||||
for column, value := range defaults {
|
||||
column = strings.TrimSpace(column)
|
||||
if column == "" {
|
||||
continue
|
||||
}
|
||||
result[column] = value
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func mergeStringMap(target map[string]string, source map[string]string) {
|
||||
for key, value := range source {
|
||||
target[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
func headVisualeffectIdentity(dataset string, entry autogenManifestEntry, policy headVisualeffectsPolicy) (string, string, string, headVisualeffectsGroupPolicy, bool) {
|
||||
group, ok := policy.Groups[entry.Group]
|
||||
if !ok || strings.TrimSpace(entry.ModelStem) == "" {
|
||||
return "", "", "", headVisualeffectsGroupPolicy{}, false
|
||||
}
|
||||
modelStem := strings.TrimSpace(entry.ModelStem)
|
||||
stem := modelStem
|
||||
for _, prefix := range policy.StripModelPrefixes {
|
||||
prefix = strings.TrimSpace(prefix)
|
||||
if prefix == "" {
|
||||
continue
|
||||
}
|
||||
stem = strings.TrimPrefix(stem, prefix)
|
||||
}
|
||||
stem = strings.TrimSpace(stem)
|
||||
if stem == "" {
|
||||
return "", "", "", headVisualeffectsGroupPolicy{}, false
|
||||
}
|
||||
values := map[string]string{
|
||||
"dataset": dataset,
|
||||
"group": entry.Group,
|
||||
"prefix": group.Prefix,
|
||||
"stem": stem,
|
||||
"stem_upper": strings.ToUpper(stem),
|
||||
"model_stem": modelStem,
|
||||
}
|
||||
key := expandHeadVisualeffectsFormat(policy.KeyFormat, values)
|
||||
label := expandHeadVisualeffectsFormat(policy.LabelFormat, values)
|
||||
if strings.TrimSpace(key) == "" || strings.TrimSpace(label) == "" {
|
||||
return "", "", "", headVisualeffectsGroupPolicy{}, false
|
||||
}
|
||||
return key, label, modelStem, group, true
|
||||
}
|
||||
|
||||
func expandHeadVisualeffectsFormat(format string, values map[string]string) string {
|
||||
result := format
|
||||
for key, value := range values {
|
||||
result = strings.ReplaceAll(result, "{"+key+"}", value)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func createDefaultHeadVisualeffectRow(columns []string, rowID int, key, label, modelStem string, policy headVisualeffectsPolicy, group headVisualeffectsGroupPolicy) map[string]any {
|
||||
row := map[string]any{
|
||||
"id": rowID,
|
||||
"key": key,
|
||||
@@ -782,28 +908,36 @@ func createDefaultHeadVisualeffectRow(columns []string, rowID int, key, label, m
|
||||
row[column] = nullValue
|
||||
}
|
||||
row["Label"] = label
|
||||
row["Type_FD"] = "D"
|
||||
row["OrientWithGround"] = "0"
|
||||
row["Imp_HeadCon_Node"] = modelStem
|
||||
row["OrientWithObject"] = "1"
|
||||
for column, value := range policy.RowDefaults {
|
||||
row[column] = value
|
||||
}
|
||||
for column, value := range group.RowDefaults {
|
||||
row[column] = value
|
||||
}
|
||||
for _, column := range headVisualeffectModelColumns(policy, group) {
|
||||
row[column] = modelStem
|
||||
}
|
||||
return row
|
||||
}
|
||||
|
||||
func applyDiscoveredHeadVisualeffectDefaults(row map[string]any, columns []string, modelStem, label string) {
|
||||
func applyDiscoveredHeadVisualeffectDefaults(row map[string]any, columns []string, modelStem, label string, policy headVisualeffectsPolicy, group headVisualeffectsGroupPolicy) {
|
||||
if isNullLikeValue(row["Label"]) {
|
||||
row["Label"] = label
|
||||
}
|
||||
if isNullLikeValue(row["Type_FD"]) {
|
||||
row["Type_FD"] = "D"
|
||||
for column, value := range policy.RowDefaults {
|
||||
if isNullLikeValue(row[column]) {
|
||||
row[column] = value
|
||||
}
|
||||
}
|
||||
if isNullLikeValue(row["OrientWithGround"]) {
|
||||
row["OrientWithGround"] = "0"
|
||||
for column, value := range group.RowDefaults {
|
||||
if isNullLikeValue(row[column]) {
|
||||
row[column] = value
|
||||
}
|
||||
}
|
||||
if isNullLikeValue(row["Imp_HeadCon_Node"]) {
|
||||
row["Imp_HeadCon_Node"] = modelStem
|
||||
}
|
||||
if isNullLikeValue(row["OrientWithObject"]) {
|
||||
row["OrientWithObject"] = "1"
|
||||
for _, column := range headVisualeffectModelColumns(policy, group) {
|
||||
if isNullLikeValue(row[column]) {
|
||||
row[column] = modelStem
|
||||
}
|
||||
}
|
||||
for _, column := range columns {
|
||||
if _, ok := row[column]; !ok {
|
||||
@@ -812,6 +946,16 @@ func applyDiscoveredHeadVisualeffectDefaults(row map[string]any, columns []strin
|
||||
}
|
||||
}
|
||||
|
||||
func headVisualeffectModelColumns(policy headVisualeffectsPolicy, group headVisualeffectsGroupPolicy) []string {
|
||||
if len(group.ModelColumns) > 0 {
|
||||
return group.ModelColumns
|
||||
}
|
||||
if strings.TrimSpace(policy.ModelColumn) == "" {
|
||||
return nil
|
||||
}
|
||||
return []string{policy.ModelColumn}
|
||||
}
|
||||
|
||||
func formatAutogenManifest(root string, producer project.AutogenProducerConfig, repo, ref string, entries []autogenManifestEntry) ([]byte, error) {
|
||||
manifest := autogenManifest{
|
||||
ID: producer.ID,
|
||||
|
||||
Reference in New Issue
Block a user