feat: extract set_fields rule forces Int fields on gff_json merge targets (#40)
Adds a `set_fields` option to `extract.merge.gff_json` rules: forces existing Int fields to a fixed value on every extract, applied after preserve_fields/merge_lists so the forced value always wins. Fields absent from the document stay absent. Rule targets can now be globs (e.g. `areas/*.are.json`). Motivation: sow-module area weather chances must stay 0 (scripted regional weather owns weather); this makes the extract pipeline enforce it instead of a post-extract script. Covered by `TestExtractSetsConfiguredGFFJSONFields`; `make check` passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Reviewed-on: #40 Co-authored-by: vickydotbat <vickydotbat@tutamail.com> Co-committed-by: vickydotbat <vickydotbat@tutamail.com>
This commit was merged in pull request #40.
This commit is contained in:
@@ -3503,6 +3503,100 @@ extract:
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractSetsConfiguredGFFJSONFields(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mustMkdir(t, filepath.Join(root, "src", "module"))
|
||||
mustMkdir(t, filepath.Join(root, "src", "areas"))
|
||||
mustMkdir(t, filepath.Join(root, "assets"))
|
||||
mustMkdir(t, filepath.Join(root, "build"))
|
||||
|
||||
mustWriteFile(t, filepath.Join(root, "nwn-tool.yaml"), `
|
||||
module:
|
||||
name: Test Module
|
||||
resref: testmod
|
||||
paths:
|
||||
source: src
|
||||
assets: assets
|
||||
build: build
|
||||
extract:
|
||||
merge:
|
||||
gff_json:
|
||||
- target: areas/*.are.json
|
||||
set_fields:
|
||||
- field: ChanceRain
|
||||
value: 0
|
||||
- field: ChanceSnow
|
||||
value: 0
|
||||
`)
|
||||
|
||||
mustWriteFile(t, filepath.Join(root, "src", "module", "module.ifo.json"), `{
|
||||
"file_type": "IFO ",
|
||||
"file_version": "V3.2",
|
||||
"root": {
|
||||
"struct_type": 0,
|
||||
"fields": [
|
||||
{
|
||||
"label": "Mod_Name",
|
||||
"type": "CExoString",
|
||||
"value": "Test Module"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
`)
|
||||
mustWriteFile(t, filepath.Join(root, "src", "areas", "area_a.are.json"), `{
|
||||
"file_type": "ARE ",
|
||||
"file_version": "V3.2",
|
||||
"root": {
|
||||
"struct_type": 0,
|
||||
"fields": [
|
||||
{
|
||||
"label": "ChanceRain",
|
||||
"type": "Int",
|
||||
"value": 40
|
||||
},
|
||||
{
|
||||
"label": "WindPower",
|
||||
"type": "Int",
|
||||
"value": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
p, err := project.Load(root)
|
||||
if err != nil {
|
||||
t.Fatalf("load project: %v", err)
|
||||
}
|
||||
if err := p.ValidateLayout(); err != nil {
|
||||
t.Fatalf("validate layout: %v", err)
|
||||
}
|
||||
if err := p.Scan(); err != nil {
|
||||
t.Fatalf("scan: %v", err)
|
||||
}
|
||||
if _, err := BuildModule(p); err != nil {
|
||||
t.Fatalf("build module: %v", err)
|
||||
}
|
||||
if err := p.Scan(); err != nil {
|
||||
t.Fatalf("rescan before extract: %v", err)
|
||||
}
|
||||
if _, err := Extract(p); err != nil {
|
||||
t.Fatalf("extract: %v", err)
|
||||
}
|
||||
|
||||
document := readGFFJSON(t, filepath.Join(root, "src", "areas", "area_a.are.json"))
|
||||
if got, want := fieldValue(t, document.Root, "ChanceRain"), gff.IntValue(0); got != want {
|
||||
t.Fatalf("expected forced ChanceRain %#v, got %#v", want, got)
|
||||
}
|
||||
if got, want := fieldValue(t, document.Root, "WindPower"), gff.IntValue(2); got != want {
|
||||
t.Fatalf("expected untouched WindPower %#v, got %#v", want, got)
|
||||
}
|
||||
if _, ok := gffField(document.Root, "ChanceSnow"); ok {
|
||||
t.Fatalf("expected absent ChanceSnow to stay absent")
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractNormalizesResourceNamesToLowercase(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mustMkdir(t, filepath.Join(root, "src", "blueprints", "items"))
|
||||
|
||||
Reference in New Issue
Block a user