List/range support
This commit is contained in:
@@ -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{}{}
|
||||
|
||||
Reference in New Issue
Block a user