Normalize feat names (#8)
Reviewed-on: https://gitea.westgate.pw/ShadowsOverWestgate/sow-tools/pulls/8 Co-authored-by: vickydotbat <vickydotbat@tutamail.com> Co-committed-by: vickydotbat <vickydotbat@tutamail.com>
This commit is contained in:
@@ -1355,6 +1355,7 @@ type featGeneratedContext struct {
|
||||
dataDir string
|
||||
lockData map[string]int
|
||||
supplementalID map[string]int
|
||||
baseDialog *legacyTLKData
|
||||
tlkStateKeys map[string]struct{}
|
||||
existingFeat map[string]struct{}
|
||||
datasets map[string]nativeDataset
|
||||
@@ -1384,6 +1385,10 @@ func newFeatGeneratedContext(dataset nativeDataset, lockData map[string]int) (*f
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
baseDialog, err := loadBaseDialogData(filepath.Join(sourceDir, "base_dialog.json"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tlkState, err := loadTLKState(filepath.Join(sourceDir, tlkStateFile))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1415,6 +1420,7 @@ func newFeatGeneratedContext(dataset nativeDataset, lockData map[string]int) (*f
|
||||
dataDir: dataDir,
|
||||
lockData: lockCopy,
|
||||
supplementalID: supplementalID,
|
||||
baseDialog: baseDialog,
|
||||
tlkStateKeys: tlkStateKeys,
|
||||
existingFeat: existingFeat,
|
||||
datasets: datasetMap,
|
||||
@@ -1870,10 +1876,8 @@ func buildFamilyExpansionGeneratedModule(path string, obj map[string]any, ctx *f
|
||||
return nil, fmt.Errorf("generated feat file %s: %w", path, err)
|
||||
}
|
||||
childToken := childTokenFromExpandedKey(featKey, spec.FamilyKey)
|
||||
displayName := displayNameForGeneratedSource(spec.ChildSource.Dataset, row)
|
||||
if spec.IdentitySource == "child_source_value" && childToken != "" && normalizeKeyIdentity(childToken) != normalizeKeyIdentity(slug) {
|
||||
displayName = displayNameFromSlug(childToken)
|
||||
}
|
||||
displayName := ctx.displayNameForGeneratedSource(spec.ChildSource.Dataset, row)
|
||||
titleChildName := applyFamilyExpansionTitleStyle(displayName, spec.TitleStyle)
|
||||
labelSuffix := upperSnake(displayName)
|
||||
override := map[string]any{
|
||||
"key": featKey,
|
||||
@@ -1902,7 +1906,7 @@ func buildFamilyExpansionGeneratedModule(path string, obj map[string]any, ctx *f
|
||||
override["FEAT"] = map[string]any{
|
||||
"tlk": map[string]any{
|
||||
"key": featKey + ".name",
|
||||
"text": fmt.Sprintf("%s (%s)", spec.NamePrefix, displayName),
|
||||
"text": fmt.Sprintf("%s (%s)", spec.NamePrefix, titleChildName),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -2160,7 +2164,10 @@ func displayNameForBaseitem(row map[string]any) string {
|
||||
return "Unknown Weapon"
|
||||
}
|
||||
|
||||
func displayNameForGeneratedSource(dataset string, row map[string]any) string {
|
||||
func (c *featGeneratedContext) displayNameForGeneratedSource(dataset string, row map[string]any) string {
|
||||
if text, ok := c.displayTextFromGeneratedValue(row["Name"]); ok {
|
||||
return text
|
||||
}
|
||||
switch dataset {
|
||||
case "skills":
|
||||
return displayNameForSkill(row)
|
||||
@@ -2183,6 +2190,64 @@ func displayNameForGeneratedSource(dataset string, row map[string]any) string {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *featGeneratedContext) displayTextFromGeneratedValue(value any) (string, bool) {
|
||||
if text, ok := displayTextFromValue(value); ok {
|
||||
return text, true
|
||||
}
|
||||
if c == nil || c.baseDialog == nil {
|
||||
return "", false
|
||||
}
|
||||
key := ""
|
||||
switch typed := value.(type) {
|
||||
case string:
|
||||
if !isNumericText(typed) {
|
||||
return "", false
|
||||
}
|
||||
key = strings.TrimSpace(typed)
|
||||
case int:
|
||||
key = strconv.Itoa(typed)
|
||||
case float64:
|
||||
if typed != float64(int(typed)) {
|
||||
return "", false
|
||||
}
|
||||
key = strconv.Itoa(int(typed))
|
||||
default:
|
||||
return "", false
|
||||
}
|
||||
entry, ok := c.baseDialog.Entries[key]
|
||||
if !ok || strings.TrimSpace(entry.Text) == "" {
|
||||
return "", false
|
||||
}
|
||||
return normalizeDisplayName(strings.TrimSpace(entry.Text)), true
|
||||
}
|
||||
|
||||
func applyFamilyExpansionTitleStyle(displayName string, style familyExpansionTitleStyle) string {
|
||||
if style.ChildParenthetical == "comma" {
|
||||
displayName = flattenGeneratedTitleChildParenthetical(displayName)
|
||||
}
|
||||
if style.ChildCase == "lower" {
|
||||
displayName = strings.ToLower(displayName)
|
||||
}
|
||||
return displayName
|
||||
}
|
||||
|
||||
func flattenGeneratedTitleChildParenthetical(text string) string {
|
||||
text = strings.TrimSpace(text)
|
||||
if !strings.HasSuffix(text, ")") || strings.Count(text, "(") != 1 || strings.Count(text, ")") != 1 {
|
||||
return text
|
||||
}
|
||||
open := strings.LastIndex(text, "(")
|
||||
if open <= 0 || open >= len(text)-2 {
|
||||
return text
|
||||
}
|
||||
prefix := strings.TrimSpace(text[:open])
|
||||
suffix := strings.TrimSpace(strings.TrimSuffix(text[open+1:], ")"))
|
||||
if prefix == "" || suffix == "" {
|
||||
return text
|
||||
}
|
||||
return prefix + ", " + suffix
|
||||
}
|
||||
|
||||
func displayNameForRaceFile(obj map[string]any) string {
|
||||
core, ok := obj["core"].(map[string]any)
|
||||
if ok {
|
||||
|
||||
Reference in New Issue
Block a user