ECL, default scale, and preferred alignment entries
This commit is contained in:
@@ -250,6 +250,87 @@ func TestBuildNativeEncodesConfiguredPackedHexLists(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildNativeEncodesConfiguredAlignmentHexLists(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "modules"))
|
||||
writeFile(t, filepath.Join(root, "topdata", "base_dialog.json"), "{}\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "base.json"), `{
|
||||
"output": "racialtypes.2da",
|
||||
"columns": ["Label", "PreferredAlignments"],
|
||||
"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",
|
||||
"PreferredAlignments": {"list": ["le", "CG", "tn"]}
|
||||
}
|
||||
]
|
||||
}`+"\n")
|
||||
|
||||
proj := testProject(root)
|
||||
proj.Config.TopData.ValueEncodings = []project.TopDataValueEncodingConfig{
|
||||
{Dataset: "racialtypes/core", Column: "PreferredAlignments", Mode: "alignment_hex_list", Min: 0, Max: 31, HexWidth: 2},
|
||||
}
|
||||
|
||||
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, "racialtypes.2da"))
|
||||
if err != nil {
|
||||
t.Fatalf("read racialtypes.2da: %v", err)
|
||||
}
|
||||
got := string(raw)
|
||||
if !strings.Contains(got, "0x120C01") {
|
||||
t.Fatalf("expected compiled racialtypes.2da to contain encoded alignments, got:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildNativeAppliesConfiguredValueDefaults(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "modules"))
|
||||
writeFile(t, filepath.Join(root, "topdata", "base_dialog.json"), "{}\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "base.json"), `{
|
||||
"output": "racialtypes.2da",
|
||||
"columns": ["Label", "ECL", "DefaultScale"],
|
||||
"rows": [
|
||||
{"id": 6, "key": "racialtypes:human", "Label": "Human"},
|
||||
{"id": 7, "key": "racialtypes:elf", "Label": "Elf", "ECL": null, "DefaultScale": null},
|
||||
{"id": 8, "key": "racialtypes:drow", "Label": "Drow", "ECL": 2, "DefaultScale": "0.95"}
|
||||
]
|
||||
}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "lock.json"), `{"racialtypes:human":6,"racialtypes:elf":7,"racialtypes:drow":8}`+"\n")
|
||||
|
||||
proj := testProject(root)
|
||||
proj.Config.TopData.ValueDefaults = []project.TopDataValueDefaultConfig{
|
||||
{Dataset: "racialtypes/core", Column: "ECL", Value: 0},
|
||||
{Dataset: "racialtypes/core", Column: "DefaultScale", Value: 1},
|
||||
}
|
||||
|
||||
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, "racialtypes.2da"))
|
||||
if err != nil {
|
||||
t.Fatalf("read racialtypes.2da: %v", err)
|
||||
}
|
||||
got := string(raw)
|
||||
for _, want := range []string{
|
||||
"6\tHuman\t0\t1\n",
|
||||
"7\tElf\t0\t1\n",
|
||||
"8\tDrow\t2\t0.95\n",
|
||||
} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Fatalf("expected compiled racialtypes.2da to contain %q, got:\n%s", want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateProjectRejectsInvalidConfiguredPackedHexList(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "modules"))
|
||||
@@ -285,6 +366,41 @@ func TestValidateProjectRejectsInvalidConfiguredPackedHexList(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateProjectRejectsInvalidConfiguredAlignmentHexList(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "modules"))
|
||||
writeFile(t, filepath.Join(root, "topdata", "base_dialog.json"), "{}\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "base.json"), `{
|
||||
"output": "racialtypes.2da",
|
||||
"columns": ["Label", "PreferredAlignments"],
|
||||
"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",
|
||||
"PreferredAlignments": {"list": ["lawful evil"]}
|
||||
}
|
||||
]
|
||||
}`+"\n")
|
||||
|
||||
proj := testProject(root)
|
||||
proj.Config.TopData.ValueEncodings = []project.TopDataValueEncodingConfig{
|
||||
{Dataset: "racialtypes/core", Column: "PreferredAlignments", Mode: "alignment_hex_list", Min: 0, Max: 31, HexWidth: 2},
|
||||
}
|
||||
|
||||
report := ValidateProject(proj)
|
||||
if !report.HasErrors() {
|
||||
t.Fatalf("expected invalid alignment list to fail validation, got:\n%s", diagnosticsText(report.Diagnostics))
|
||||
}
|
||||
if !diagnosticsContain(report.Diagnostics, `alignment code "lawful evil" must use two letters`) {
|
||||
t.Fatalf("expected invalid alignment diagnostic, got:\n%s", diagnosticsText(report.Diagnostics))
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeConfiguredPackedHexListSupportsAllExcept(t *testing.T) {
|
||||
encoding := project.TopDataValueEncodingConfig{
|
||||
Dataset: "racialtypes/core",
|
||||
|
||||
Reference in New Issue
Block a user