Sidecar generation
This commit is contained in:
@@ -290,6 +290,62 @@ func TestBuildNativeEncodesConfiguredAlignmentHexLists(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildNativeEncodesConfiguredAlignmentSetMasks(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "classes", "core", "modules"))
|
||||
writeFile(t, filepath.Join(root, "topdata", "base_dialog.json"), "{}\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "classes", "core", "base.json"), `{
|
||||
"output": "classes.2da",
|
||||
"columns": ["Label", "PreferredAlignments"],
|
||||
"rows": [
|
||||
{"id": 0, "key": "classes:barbarian", "Label": "Barbarian"},
|
||||
{"id": 1, "key": "classes:paladin", "Label": "Paladin"},
|
||||
{"id": 2, "key": "classes:fighter", "Label": "Fighter"}
|
||||
]
|
||||
}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "classes", "core", "lock.json"), `{"classes:barbarian":0,"classes:paladin":1,"classes:fighter":2}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "classes", "core", "modules", "10_alignments.json"), `{
|
||||
"overrides": [
|
||||
{
|
||||
"key": "classes:barbarian",
|
||||
"PreferredAlignments": {"alignments": ["ng", "cg", "tn", "cn", "ne", "ce"]}
|
||||
},
|
||||
{
|
||||
"key": "classes:paladin",
|
||||
"PreferredAlignments": {"alignments": ["lg"]}
|
||||
},
|
||||
{
|
||||
"key": "classes:fighter",
|
||||
"PreferredAlignments": "0x00"
|
||||
}
|
||||
]
|
||||
}`+"\n")
|
||||
|
||||
proj := testProject(root)
|
||||
proj.Config.TopData.ValueEncodings = []project.TopDataValueEncodingConfig{
|
||||
{Dataset: "*", Column: "PreferredAlignments", Mode: "alignment_set_mask", Min: 0, Max: 511, HexWidth: 3},
|
||||
}
|
||||
|
||||
result, err := BuildNativeWithOptions(proj, NativeBuildOptions{BuildWiki: false}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("BuildNativeWithOptions failed: %v", err)
|
||||
}
|
||||
raw, err := os.ReadFile(filepath.Join(result.Output2DADir, "classes.2da"))
|
||||
if err != nil {
|
||||
t.Fatalf("read classes.2da: %v", err)
|
||||
}
|
||||
got := string(raw)
|
||||
for _, want := range []string{
|
||||
"0\tBarbarian\t0x1F8\n",
|
||||
"1\tPaladin\t0x001\n",
|
||||
"2\tFighter\t0x000\n",
|
||||
} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Fatalf("expected compiled classes.2da to contain %q, got:\n%s", want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildNativeEncodesConfiguredIDHexLists(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "feat"))
|
||||
@@ -348,6 +404,109 @@ func TestBuildNativeEncodesConfiguredIDHexLists(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildNativeEncodesConfiguredExternalHexListsAndPackedIDs(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "feat"))
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "modules"))
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "baseitems", "modules"))
|
||||
writeFile(t, filepath.Join(root, "topdata", "base_dialog.json"), "{}\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "feat", "base.json"), `{
|
||||
"output": "feat.2da",
|
||||
"columns": ["LABEL"],
|
||||
"rows": [
|
||||
{"id": 1, "key": "feat:first", "LABEL": "First"},
|
||||
{"id": 2, "key": "feat:second", "LABEL": "Second"},
|
||||
{"id": 3, "key": "feat:third", "LABEL": "Third"},
|
||||
{"id": 7, "key": "feat:seventh", "LABEL": "Seventh"}
|
||||
]
|
||||
}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "feat", "lock.json"), `{
|
||||
"feat:first": 1,
|
||||
"feat:second": 2,
|
||||
"feat:third": 3,
|
||||
"feat:seventh": 7
|
||||
}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "base.json"), `{
|
||||
"output": "racialtypes.2da",
|
||||
"columns": ["Label", "AvailableSkinColors"],
|
||||
"rows": [
|
||||
{"id": 6, "key": "racialtypes:human", "Label": "Human"}
|
||||
]
|
||||
}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "lock.json"), `{"racialtypes:human":6}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "modules", "10_human.json"), `{
|
||||
"overrides": [
|
||||
{
|
||||
"key": "racialtypes:human",
|
||||
"AvailableSkinColors": {"list": [1, 2, 3, 5, {"range": [7, 9]}]}
|
||||
}
|
||||
]
|
||||
}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "baseitems", "base.json"), `{
|
||||
"output": "baseitems.2da",
|
||||
"columns": ["Label", "ProficiencyFeats"],
|
||||
"rows": [
|
||||
{"id": 42, "key": "baseitems:testclub", "Label": "Test Club"}
|
||||
]
|
||||
}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "baseitems", "lock.json"), `{"baseitems:testclub":42}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "baseitems", "modules", "10_testclub.json"), `{
|
||||
"overrides": [
|
||||
{
|
||||
"key": "baseitems:testclub",
|
||||
"ProficiencyFeats": {"ids": ["feat:first", "feat:second", "feat:third", "feat:seventh"]}
|
||||
}
|
||||
]
|
||||
}`+"\n")
|
||||
|
||||
proj := testProject(root)
|
||||
proj.Config.TopData.ValueEncodings = []project.TopDataValueEncodingConfig{
|
||||
{Dataset: "racialtypes/core", Column: "AvailableSkinColors", Mode: "external_hex_list", Min: 0, Max: 255, HexWidth: 2},
|
||||
{Dataset: "*", Column: "ProficiencyFeats", Mode: "id_hex_list", Min: 0, Max: 65535, HexWidth: 4},
|
||||
}
|
||||
|
||||
result, err := BuildNativeWithOptions(proj, NativeBuildOptions{BuildWiki: false}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("BuildNativeWithOptions failed: %v", err)
|
||||
}
|
||||
racialtypesRaw, err := os.ReadFile(filepath.Join(result.Output2DADir, "racialtypes.2da"))
|
||||
if err != nil {
|
||||
t.Fatalf("read racialtypes.2da: %v", err)
|
||||
}
|
||||
if got := string(racialtypesRaw); !strings.Contains(got, "6\tHuman\thuman\n") {
|
||||
t.Fatalf("expected compiled racialtypes.2da to contain a sidecar reference, got:\n%s", got)
|
||||
}
|
||||
sidecarOutputName := sidecarOutputName("racialtypes.2da", "AvailableSkinColors")
|
||||
if stem := outputStem(sidecarOutputName); len(stem) > 16 {
|
||||
t.Fatalf("expected generated sidecar stem to fit NWN resource limit, got %q", stem)
|
||||
}
|
||||
sidecarRaw, err := os.ReadFile(filepath.Join(result.Output2DADir, sidecarOutputName))
|
||||
if err != nil {
|
||||
t.Fatalf("read %s: %v", sidecarOutputName, err)
|
||||
}
|
||||
for _, want := range []string{
|
||||
"Label\tValue\n",
|
||||
"0\thuman\t0x01\n",
|
||||
"1\thuman\t0x02\n",
|
||||
"2\thuman\t0x03\n",
|
||||
"3\thuman\t0x05\n",
|
||||
"4\thuman\t0x07\n",
|
||||
"5\thuman\t0x08\n",
|
||||
"6\thuman\t0x09\n",
|
||||
} {
|
||||
if got := string(sidecarRaw); !strings.Contains(got, want) {
|
||||
t.Fatalf("expected sidecar 2da to contain %q, got:\n%s", want, got)
|
||||
}
|
||||
}
|
||||
baseitemsRaw, err := os.ReadFile(filepath.Join(result.Output2DADir, "baseitems.2da"))
|
||||
if err != nil {
|
||||
t.Fatalf("read baseitems.2da: %v", err)
|
||||
}
|
||||
if got := string(baseitemsRaw); !strings.Contains(got, "0x0001000200030007") {
|
||||
t.Fatalf("expected compiled baseitems.2da to contain packed IDs, got:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildNativeAppliesWildcardConfiguredValueEncodings(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "feat"))
|
||||
@@ -1118,6 +1277,7 @@ func TestResolveNativeDatasetPreservesScalarTableReferenceBehavior(t *testing.T)
|
||||
tableRegistry,
|
||||
nil,
|
||||
project.TopDataClassFeatInjectionConfig{},
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("resolveNativeDataset failed: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user