Family Expansions
This commit is contained in:
@@ -361,7 +361,7 @@ func (c *tlkCompiler) finish(outputDir string) (int, error) {
|
||||
}
|
||||
c.state.Entries[key] = mapping
|
||||
}
|
||||
pruneRetiredGeneratedFeatTLKEntries(c.state.Entries)
|
||||
pruneRetiredGeneratedFeatTLKEntries(filepath.Dir(c.statePath), c.state.Entries)
|
||||
|
||||
if err := saveTLKState(c.statePath, c.state); err != nil {
|
||||
return 0, err
|
||||
@@ -389,32 +389,21 @@ func (c *tlkCompiler) finish(outputDir string) (int, error) {
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
var generatedFeatTLKPrefixes = []string{
|
||||
"feat:skillfocus_",
|
||||
"feat:greaterskillfocus_",
|
||||
"feat:weaponfocus_",
|
||||
"feat:weaponspecialization_",
|
||||
"feat:greaterweaponfocus_",
|
||||
"feat:greaterweaponspecialization_",
|
||||
"feat:improvedcritical_",
|
||||
"feat:overwhelmingcritical_",
|
||||
"feat:weaponproficiencycommoner_",
|
||||
}
|
||||
|
||||
func pruneRetiredGeneratedFeatTLKEntries(entries map[string]tlkStateMapping) {
|
||||
func pruneRetiredGeneratedFeatTLKEntries(sourceDir string, entries map[string]tlkStateMapping) {
|
||||
prefixes := collectGeneratedFeatTLKPrefixes(sourceDir)
|
||||
for key, mapping := range entries {
|
||||
if !mapping.Retired || !isRetiredGeneratedFeatTLKKey(key) {
|
||||
if !mapping.Retired || !isRetiredGeneratedFeatTLKKey(key, prefixes) {
|
||||
continue
|
||||
}
|
||||
delete(entries, key)
|
||||
}
|
||||
}
|
||||
|
||||
func isRetiredGeneratedFeatTLKKey(key string) bool {
|
||||
func isRetiredGeneratedFeatTLKKey(key string, prefixes []string) bool {
|
||||
if !strings.HasPrefix(key, "feat:") {
|
||||
return false
|
||||
}
|
||||
for _, prefix := range generatedFeatTLKPrefixes {
|
||||
for _, prefix := range prefixes {
|
||||
if strings.HasPrefix(key, prefix) {
|
||||
return true
|
||||
}
|
||||
@@ -422,6 +411,34 @@ func isRetiredGeneratedFeatTLKKey(key string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func collectGeneratedFeatTLKPrefixes(sourceDir string) []string {
|
||||
featGeneratedDir := filepath.Join(sourceDir, "data", "feat", "generated")
|
||||
paths, err := collectModulePaths(featGeneratedDir)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
prefixes := make([]string, 0, len(paths))
|
||||
seen := map[string]struct{}{}
|
||||
for _, path := range paths {
|
||||
obj, err := loadJSONObject(path)
|
||||
if err != nil || !isFamilyExpansionObject(obj) {
|
||||
continue
|
||||
}
|
||||
spec, err := parseFamilyExpansionSpec(path, obj)
|
||||
if err != nil || spec.FamilyKey == "" {
|
||||
continue
|
||||
}
|
||||
prefix := "feat:" + spec.FamilyKey + "_"
|
||||
if _, ok := seen[prefix]; ok {
|
||||
continue
|
||||
}
|
||||
seen[prefix] = struct{}{}
|
||||
prefixes = append(prefixes, prefix)
|
||||
}
|
||||
slices.Sort(prefixes)
|
||||
return prefixes
|
||||
}
|
||||
|
||||
func writeTLKBinary(path string, entries []tlkEntryData, language string) error {
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
return fmt.Errorf("create tlk output parent: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user