Automatic spellknown/spellgain null-filling (#12)

Implemented on branches `feature/topdata-row-extensions` in both `toolkit` and `module`.

**Scope Audited**
- Toolkit native topdata collection/build path.
- Project config/effective config validation.
- Module `nwn-tool.yaml` topdata config and topdata README.

**Changes Made**
- Added `topdata.row_extensions` config with `repeat_last` support.
- Added glob dataset matching and build-time row extension for plain native datasets in [native.go](/home/vicky/Projects/nwnee-shadowsoverwestgate/toolkit/internal/topdata/native.go:641).
- Extension copies emitted columns from the highest authored `Level`, increments `Level`, and assigns sequential `id`s through target level.
- Enabled rules for `classes/spellsgained/*` and `classes/spellsknown/*` to level 60 in [nwn-tool.yaml](/home/vicky/Projects/nwnee-shadowsoverwestgate/module/nwn-tool.yaml:90).
- Updated toolkit/module docs.

**Configuration / Compatibility**
- New public config type: `TopDataRowExtensionConfig` in [project.go](/home/vicky/Projects/nwnee-shadowsoverwestgate/toolkit/internal/project/project.go:233).
- Existing behavior is unchanged unless a repo opts into `topdata.row_extensions`.
- Source JSON and lockfiles are not updated for generated extension rows.

**Tests / Validation**
- Added project config tests for loading and validation.
- Added native topdata tests for extension behavior, glob application, preserving manually authored rows, unmatched datasets, and failure cases.
- Ran:
  - `go test ./internal/project ./internal/topdata`
  - `go test ./internal/topdata -run TestBuildNativeKeepsGeneratedIDsStableAcrossRepeatedBuilds`
  - `/tmp/sow-toolkit-rowext config validate` in `module`
  - `/tmp/sow-toolkit-rowext validate-topdata` in `module`
  - `/tmp/sow-toolkit-rowext build-topdata --force`, then inspected generated rows: `cls_spgn_acolyte.2da` now reaches row `59` / level `60`.

**Remaining Notes**
- `validate-topdata` still reports the pre-existing portrait lock warnings for `cotbl/cotbl_` and `lantern/lantern_`.
- `build-topdata --force` briefly rewrote three spellbook JSON files as a side effect; I reverted those, leaving only the intended YAML/docs changes in `module`.

Reviewed-on: https://gitea.westgate.pw/ShadowsOverWestgate/sow-tools/pulls/12
Co-authored-by: vickydotbat <vickydotbat@tutamail.com>
Co-committed-by: vickydotbat <vickydotbat@tutamail.com>
This commit is contained in:
2026-05-26 19:54:48 +02:00
committed by archvillainette
parent b7587cfd05
commit 88be9e95d3
6 changed files with 409 additions and 0 deletions
+38
View File
@@ -218,6 +218,7 @@ type TopDataConfig struct {
ValueEncodings []TopDataValueEncodingConfig `json:"value_encodings" yaml:"value_encodings"`
ValueDefaults []TopDataValueDefaultConfig `json:"value_defaults" yaml:"value_defaults"`
RowGeneration []TopDataRowGenerationConfig `json:"row_generation" yaml:"row_generation"`
RowExtensions []TopDataRowExtensionConfig `json:"row_extensions" yaml:"row_extensions"`
ClassFeatInjections TopDataClassFeatInjectionConfig `json:"class_feat_injections" yaml:"class_feat_injections"`
Wiki TopDataWikiConfig `json:"wiki" yaml:"wiki"`
}
@@ -229,6 +230,13 @@ type TopDataRowGenerationConfig struct {
MinimumRow int `json:"minimum_row,omitempty" yaml:"minimum_row,omitempty"`
}
type TopDataRowExtensionConfig struct {
Dataset string `json:"dataset" yaml:"dataset"`
Mode string `json:"mode" yaml:"mode"`
LevelColumn string `json:"level_column" yaml:"level_column"`
TargetLevel int `json:"target_level" yaml:"target_level"`
}
type TopDataClassFeatInjectionConfig struct {
GlobalFeats []TopDataClassFeatGlobalRule `json:"global_feats" yaml:"global_feats"`
ClassSkillMasterfeats []TopDataClassFeatMasterfeatRule `json:"class_skill_masterfeats" yaml:"class_skill_masterfeats"`
@@ -631,6 +639,7 @@ func (p *Project) ValidateLayout() error {
failures = append(failures, validateTopDataValueEncodings(effective.TopData.ValueEncodings)...)
failures = append(failures, validateTopDataValueDefaults(effective.TopData.ValueDefaults)...)
failures = append(failures, validateTopDataRowGeneration(effective.TopData.RowGeneration)...)
failures = append(failures, validateTopDataRowExtensions(effective.TopData.RowExtensions)...)
failures = append(failures, validateTopDataClassFeatInjections(effective.TopData.ClassFeatInjections)...)
failures = append(failures, validateRelativePath("scripts.cache", effective.Scripts.Cache)...)
failures = append(failures, validateRelativePath("scripts.source_dir", effective.Scripts.SourceDir)...)
@@ -873,6 +882,35 @@ func validateTopDataRowGeneration(rules []TopDataRowGenerationConfig) []error {
return failures
}
func validateTopDataRowExtensions(rules []TopDataRowExtensionConfig) []error {
failures := []error{}
seen := map[string]struct{}{}
for index, rule := range rules {
prefix := fmt.Sprintf("topdata.row_extensions[%d]", index)
dataset := strings.TrimSpace(rule.Dataset)
if dataset == "" {
failures = append(failures, fmt.Errorf("%s.dataset is required", prefix))
}
switch strings.TrimSpace(rule.Mode) {
case "repeat_last":
default:
failures = append(failures, fmt.Errorf("%s.mode %q is not supported", prefix, rule.Mode))
}
if strings.TrimSpace(rule.LevelColumn) == "" {
failures = append(failures, fmt.Errorf("%s.level_column is required", prefix))
}
if rule.TargetLevel <= 0 {
failures = append(failures, fmt.Errorf("%s.target_level must be greater than zero", prefix))
}
key := filepath.ToSlash(dataset)
if _, ok := seen[key]; ok {
failures = append(failures, fmt.Errorf("%s duplicates an earlier dataset row extension rule", prefix))
}
seen[key] = struct{}{}
}
return failures
}
func validateTopDataClassFeatInjections(config TopDataClassFeatInjectionConfig) []error {
failures := []error{}
for index, rule := range config.GlobalFeats {