List/range support
This commit is contained in:
@@ -151,15 +151,16 @@ type EffectiveMusicDataset struct {
|
||||
}
|
||||
|
||||
type EffectiveTopDataConfig struct {
|
||||
Source string `json:"source" yaml:"source"`
|
||||
Build string `json:"build" yaml:"build"`
|
||||
ReferenceBuilder string `json:"reference_builder" yaml:"reference_builder"`
|
||||
Assets string `json:"assets" yaml:"assets"`
|
||||
Compiled2DADir string `json:"compiled_2da_dir" yaml:"compiled_2da_dir"`
|
||||
CompiledTLK string `json:"compiled_tlk" yaml:"compiled_tlk"`
|
||||
PackageHAK string `json:"package_hak" yaml:"package_hak"`
|
||||
PackageTLK string `json:"package_tlk" yaml:"package_tlk"`
|
||||
Wiki TopDataWikiConfig `json:"wiki" yaml:"wiki"`
|
||||
Source string `json:"source" yaml:"source"`
|
||||
Build string `json:"build" yaml:"build"`
|
||||
ReferenceBuilder string `json:"reference_builder" yaml:"reference_builder"`
|
||||
Assets string `json:"assets" yaml:"assets"`
|
||||
Compiled2DADir string `json:"compiled_2da_dir" yaml:"compiled_2da_dir"`
|
||||
CompiledTLK string `json:"compiled_tlk" yaml:"compiled_tlk"`
|
||||
PackageHAK string `json:"package_hak" yaml:"package_hak"`
|
||||
PackageTLK string `json:"package_tlk" yaml:"package_tlk"`
|
||||
ValueEncodings []TopDataValueEncodingConfig `json:"value_encodings" yaml:"value_encodings"`
|
||||
Wiki TopDataWikiConfig `json:"wiki" yaml:"wiki"`
|
||||
}
|
||||
|
||||
type EffectiveAutogenConfig struct {
|
||||
@@ -237,6 +238,7 @@ func (p *Project) EffectiveConfig() EffectiveConfig {
|
||||
CompiledTLK: defaultString(p.Config.TopData.CompiledTLK, DefaultTopDataCompiledTLK),
|
||||
PackageHAK: defaultString(p.Config.TopData.PackageHAK, DefaultTopDataPackageHAK),
|
||||
PackageTLK: defaultString(p.Config.TopData.PackageTLK, DefaultTopDataPackageTLK),
|
||||
ValueEncodings: cloneTopDataValueEncodings(p.Config.TopData.ValueEncodings),
|
||||
Wiki: TopDataWikiConfig{
|
||||
OutputRoot: defaultString(p.Config.TopData.Wiki.OutputRoot, DefaultTopDataWikiOutputRoot),
|
||||
PagesDir: defaultString(p.Config.TopData.Wiki.PagesDir, DefaultTopDataWikiPagesDir),
|
||||
@@ -406,6 +408,15 @@ func (p *Project) EffectiveConfig() EffectiveConfig {
|
||||
return effective
|
||||
}
|
||||
|
||||
func cloneTopDataValueEncodings(values []TopDataValueEncodingConfig) []TopDataValueEncodingConfig {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
out := make([]TopDataValueEncodingConfig, len(values))
|
||||
copy(out, values)
|
||||
return out
|
||||
}
|
||||
|
||||
func (p *Project) EffectiveConfigJSON() ([]byte, error) {
|
||||
return json.MarshalIndent(p.EffectiveConfig(), "", " ")
|
||||
}
|
||||
|
||||
@@ -206,15 +206,25 @@ type MusicDatasetConfig struct {
|
||||
}
|
||||
|
||||
type TopDataConfig struct {
|
||||
Source string `json:"source" yaml:"source"`
|
||||
Build string `json:"build" yaml:"build"`
|
||||
ReferenceBuilder string `json:"reference_builder" yaml:"reference_builder"`
|
||||
Assets string `json:"assets" yaml:"assets"`
|
||||
Compiled2DADir string `json:"compiled_2da_dir" yaml:"compiled_2da_dir"`
|
||||
CompiledTLK string `json:"compiled_tlk" yaml:"compiled_tlk"`
|
||||
PackageHAK string `json:"package_hak" yaml:"package_hak"`
|
||||
PackageTLK string `json:"package_tlk" yaml:"package_tlk"`
|
||||
Wiki TopDataWikiConfig `json:"wiki" yaml:"wiki"`
|
||||
Source string `json:"source" yaml:"source"`
|
||||
Build string `json:"build" yaml:"build"`
|
||||
ReferenceBuilder string `json:"reference_builder" yaml:"reference_builder"`
|
||||
Assets string `json:"assets" yaml:"assets"`
|
||||
Compiled2DADir string `json:"compiled_2da_dir" yaml:"compiled_2da_dir"`
|
||||
CompiledTLK string `json:"compiled_tlk" yaml:"compiled_tlk"`
|
||||
PackageHAK string `json:"package_hak" yaml:"package_hak"`
|
||||
PackageTLK string `json:"package_tlk" yaml:"package_tlk"`
|
||||
ValueEncodings []TopDataValueEncodingConfig `json:"value_encodings" yaml:"value_encodings"`
|
||||
Wiki TopDataWikiConfig `json:"wiki" yaml:"wiki"`
|
||||
}
|
||||
|
||||
type TopDataValueEncodingConfig struct {
|
||||
Dataset string `json:"dataset" yaml:"dataset"`
|
||||
Column string `json:"column" yaml:"column"`
|
||||
Mode string `json:"mode" yaml:"mode"`
|
||||
Min int `json:"min" yaml:"min"`
|
||||
Max int `json:"max" yaml:"max"`
|
||||
HexWidth int `json:"hex_width" yaml:"hex_width"`
|
||||
}
|
||||
|
||||
type TopDataWikiConfig struct {
|
||||
@@ -559,6 +569,7 @@ func (p *Project) ValidateLayout() error {
|
||||
failures = append(failures, validateRelativePath("outputs.hak_manifest", effective.Outputs.HAKManifest)...)
|
||||
failures = append(failures, validateRelativePath("outputs.hak_archive", effective.Outputs.HAKArchive)...)
|
||||
failures = append(failures, validateGeneratedConfig(effective.Generated)...)
|
||||
failures = append(failures, validateTopDataValueEncodings(effective.TopData.ValueEncodings)...)
|
||||
failures = append(failures, validateRelativePath("scripts.cache", effective.Scripts.Cache)...)
|
||||
failures = append(failures, validateRelativePath("scripts.source_dir", effective.Scripts.SourceDir)...)
|
||||
failures = append(failures, validateRelativePath("topdata.compiled_2da_dir", effective.TopData.Compiled2DADir)...)
|
||||
@@ -697,6 +708,52 @@ func (p *Project) ValidateLayout() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateTopDataValueEncodings(encodings []TopDataValueEncodingConfig) []error {
|
||||
failures := []error{}
|
||||
seen := map[string]struct{}{}
|
||||
for index, encoding := range encodings {
|
||||
prefix := fmt.Sprintf("topdata.value_encodings[%d]", index)
|
||||
dataset := strings.TrimSpace(encoding.Dataset)
|
||||
column := strings.TrimSpace(encoding.Column)
|
||||
if dataset == "" {
|
||||
failures = append(failures, fmt.Errorf("%s.dataset is required", prefix))
|
||||
}
|
||||
if column == "" {
|
||||
failures = append(failures, fmt.Errorf("%s.column is required", prefix))
|
||||
}
|
||||
switch strings.TrimSpace(encoding.Mode) {
|
||||
case "packed_hex_list":
|
||||
default:
|
||||
failures = append(failures, fmt.Errorf("%s.mode %q is not supported", prefix, encoding.Mode))
|
||||
}
|
||||
if encoding.Min < 0 {
|
||||
failures = append(failures, fmt.Errorf("%s.min must be zero or greater", prefix))
|
||||
}
|
||||
if encoding.Max < encoding.Min {
|
||||
failures = append(failures, fmt.Errorf("%s.max must be greater than or equal to min", prefix))
|
||||
}
|
||||
if encoding.HexWidth <= 0 {
|
||||
failures = append(failures, fmt.Errorf("%s.hex_width must be greater than zero", prefix))
|
||||
} else if encoding.Max >= intPow(16, encoding.HexWidth) {
|
||||
failures = append(failures, fmt.Errorf("%s.max does not fit in hex_width %d", prefix, encoding.HexWidth))
|
||||
}
|
||||
key := filepath.ToSlash(dataset) + "\x00" + strings.ToLower(column)
|
||||
if _, ok := seen[key]; ok {
|
||||
failures = append(failures, fmt.Errorf("%s duplicates an earlier dataset/column encoding", prefix))
|
||||
}
|
||||
seen[key] = struct{}{}
|
||||
}
|
||||
return failures
|
||||
}
|
||||
|
||||
func intPow(base, exponent int) int {
|
||||
result := 1
|
||||
for i := 0; i < exponent; i++ {
|
||||
result *= base
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func validateExtractMergeConfig(config ExtractMergeConfig) []error {
|
||||
var failures []error
|
||||
seenTargets := map[string]struct{}{}
|
||||
|
||||
@@ -125,6 +125,83 @@ validation:
|
||||
}
|
||||
}
|
||||
|
||||
func TestEffectiveConfigIncludesTopDataValueEncodings(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
writeProjectFile(t, filepath.Join(root, ConfigFile), `
|
||||
module:
|
||||
name: Test Module
|
||||
resref: testmod
|
||||
topdata:
|
||||
source: topdata
|
||||
value_encodings:
|
||||
- dataset: racialtypes/core
|
||||
column: AvailableSkinColors
|
||||
mode: packed_hex_list
|
||||
min: 0
|
||||
max: 175
|
||||
hex_width: 2
|
||||
`)
|
||||
|
||||
proj, err := Load(root)
|
||||
if err != nil {
|
||||
t.Fatalf("Load returned error: %v", err)
|
||||
}
|
||||
|
||||
encodings := proj.EffectiveConfig().TopData.ValueEncodings
|
||||
if len(encodings) != 1 {
|
||||
t.Fatalf("expected one topdata value encoding, got %#v", encodings)
|
||||
}
|
||||
got := encodings[0]
|
||||
if got.Dataset != "racialtypes/core" ||
|
||||
got.Column != "AvailableSkinColors" ||
|
||||
got.Mode != "packed_hex_list" ||
|
||||
got.Min != 0 ||
|
||||
got.Max != 175 ||
|
||||
got.HexWidth != 2 {
|
||||
t.Fatalf("unexpected topdata value encoding: %#v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateLayoutRejectsInvalidTopDataValueEncodings(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mkdirAll(t, filepath.Join(root, "topdata"))
|
||||
mkdirAll(t, filepath.Join(root, "build"))
|
||||
|
||||
proj := &Project{
|
||||
Root: root,
|
||||
Config: Config{
|
||||
Module: ModuleConfig{Name: "Test", ResRef: "test"},
|
||||
Paths: PathConfig{Build: "build"},
|
||||
TopData: TopDataConfig{
|
||||
Source: "topdata",
|
||||
ValueEncodings: []TopDataValueEncodingConfig{
|
||||
{Dataset: "racialtypes/core", Column: "AvailableSkinColors", Mode: "packed_hex_list", Min: 0, Max: 256, HexWidth: 2},
|
||||
{Dataset: "racialtypes/core", Column: "AvailableSkinColors", Mode: "packed_hex_list", Min: 0, Max: 175, HexWidth: 2},
|
||||
{Dataset: "", Column: "AvailableHeadsMale", Mode: "unknown", Min: -1, Max: 999, HexWidth: 0},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := proj.ValidateLayout()
|
||||
if err == nil {
|
||||
t.Fatal("expected invalid topdata value encoding validation error")
|
||||
}
|
||||
text := err.Error()
|
||||
for _, want := range []string{
|
||||
"topdata.value_encodings[0].max does not fit in hex_width 2",
|
||||
"topdata.value_encodings[1] duplicates an earlier dataset/column encoding",
|
||||
"topdata.value_encodings[2].dataset is required",
|
||||
"topdata.value_encodings[2].mode \"unknown\" is not supported",
|
||||
"topdata.value_encodings[2].min must be zero or greater",
|
||||
"topdata.value_encodings[2].hex_width must be greater than zero",
|
||||
} {
|
||||
if !strings.Contains(text, want) {
|
||||
t.Fatalf("expected validation error %q, got %v", want, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestScanUsesYAMLMusicConvertExtensionsWithinConfiguredDatasetRoots(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
if err := os.MkdirAll(filepath.Join(root, "assets", "audio", "westgate"), 0o755); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user