Fix type extensions 2
This commit is contained in:
@@ -109,9 +109,17 @@ var extensionTypes = map[string]uint16{
|
|||||||
"ptt": 0x0812,
|
"ptt": 0x0812,
|
||||||
"ltr": 0x0813,
|
"ltr": 0x0813,
|
||||||
"shd": 0x0815,
|
"shd": 0x0815,
|
||||||
|
"mdb": 0x0816,
|
||||||
"mtr": 0x0818,
|
"mtr": 0x0818,
|
||||||
|
"jpg": 0x081C,
|
||||||
"lod": 0x081E,
|
"lod": 0x081E,
|
||||||
"png": 0x083E,
|
"png": 0x083E,
|
||||||
|
"lyt": 0x0BB8,
|
||||||
|
"vis": 0x0BB9,
|
||||||
|
"mdx": 0x0BC0,
|
||||||
|
"wlk": 0x0BCC,
|
||||||
|
"xml": 0x0BCD,
|
||||||
|
"gr2": 0x0FA3,
|
||||||
}
|
}
|
||||||
|
|
||||||
var typeExtensions = map[uint16]string{
|
var typeExtensions = map[uint16]string{
|
||||||
@@ -164,9 +172,17 @@ var typeExtensions = map[uint16]string{
|
|||||||
0x0812: "ptt",
|
0x0812: "ptt",
|
||||||
0x0813: "ltr",
|
0x0813: "ltr",
|
||||||
0x0815: "shd",
|
0x0815: "shd",
|
||||||
|
0x0816: "mdb",
|
||||||
0x0818: "mtr",
|
0x0818: "mtr",
|
||||||
|
0x081C: "jpg",
|
||||||
0x081E: "lod",
|
0x081E: "lod",
|
||||||
0x083E: "png",
|
0x083E: "png",
|
||||||
|
0x0BB8: "lyt",
|
||||||
|
0x0BB9: "vis",
|
||||||
|
0x0BC0: "mdx",
|
||||||
|
0x0BCC: "wlk",
|
||||||
|
0x0BCD: "xml",
|
||||||
|
0x0FA3: "gr2",
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -337,6 +353,10 @@ func ResourceTypeForExtension(extension string) (uint16, bool) {
|
|||||||
return resourceType, ok
|
return resourceType, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HAKResourceTypeForExtension(extension string) (uint16, bool) {
|
||||||
|
return ResourceTypeForExtension(extension)
|
||||||
|
}
|
||||||
|
|
||||||
func ExtensionForResourceType(resourceType uint16) (string, bool) {
|
func ExtensionForResourceType(resourceType uint16) (string, bool) {
|
||||||
extension, ok := typeExtensions[resourceType]
|
extension, ok := typeExtensions[resourceType]
|
||||||
return extension, ok
|
return extension, ok
|
||||||
|
|||||||
@@ -56,3 +56,44 @@ func TestExtensionMappingsKeep2DAAndTLKDistinct(t *testing.T) {
|
|||||||
t.Fatal("expected 2da and tlk resource types to stay distinct")
|
t.Fatal("expected 2da and tlk resource types to stay distinct")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHAKResourceTypeForExtensionSupportsPNG(t *testing.T) {
|
||||||
|
if resourceType, ok := HAKResourceTypeForExtension("png"); !ok || resourceType != 0x083E {
|
||||||
|
t.Fatalf("expected png to stay valid for HAK generation, got ok=%v type=0x%04X", ok, resourceType)
|
||||||
|
}
|
||||||
|
if resourceType, ok := HAKResourceTypeForExtension("2da"); !ok || resourceType != 0x07E1 {
|
||||||
|
t.Fatalf("expected 2da to stay valid for HAK generation, got ok=%v type=0x%04X", ok, resourceType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExtensionMappingsSupportModernAssetTypes(t *testing.T) {
|
||||||
|
cases := map[string]uint16{
|
||||||
|
"mtr": 0x0818,
|
||||||
|
"shd": 0x0815,
|
||||||
|
"txi": 0x07E6,
|
||||||
|
"jpg": 0x081C,
|
||||||
|
"mdb": 0x0816,
|
||||||
|
"lyt": 0x0BB8,
|
||||||
|
"vis": 0x0BB9,
|
||||||
|
"mdx": 0x0BC0,
|
||||||
|
"xml": 0x0BCD,
|
||||||
|
"wlk": 0x0BCC,
|
||||||
|
"gr2": 0x0FA3,
|
||||||
|
}
|
||||||
|
for ext, wantType := range cases {
|
||||||
|
gotType, ok := ResourceTypeForExtension(ext)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("expected %s to resolve to a resource type", ext)
|
||||||
|
}
|
||||||
|
if gotType != wantType {
|
||||||
|
t.Fatalf("expected %s type 0x%04X, got 0x%04X", ext, wantType, gotType)
|
||||||
|
}
|
||||||
|
gotExt, ok := ExtensionForResourceType(wantType)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("expected type 0x%04X to resolve back to an extension", wantType)
|
||||||
|
}
|
||||||
|
if gotExt != ext {
|
||||||
|
t.Fatalf("expected type 0x%04X to resolve to %s, got %s", wantType, ext, gotExt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -526,9 +526,9 @@ func resourceFromJSON(path string, moduleHakOrder []string) (erf.Resource, error
|
|||||||
|
|
||||||
func pathResource(path string) (erf.Resource, error) {
|
func pathResource(path string) (erf.Resource, error) {
|
||||||
extension := strings.TrimPrefix(strings.ToLower(filepath.Ext(path)), ".")
|
extension := strings.TrimPrefix(strings.ToLower(filepath.Ext(path)), ".")
|
||||||
resourceType, ok := erf.ResourceTypeForExtension(extension)
|
resourceType, ok := erf.HAKResourceTypeForExtension(extension)
|
||||||
if !ok {
|
if !ok {
|
||||||
return erf.Resource{}, fmt.Errorf("unsupported resource extension %q", filepath.Ext(path))
|
return erf.Resource{}, fmt.Errorf("unsupported HAK resource extension %q", filepath.Ext(path))
|
||||||
}
|
}
|
||||||
name := strings.ToLower(strings.TrimSuffix(filepath.Base(path), filepath.Ext(path)))
|
name := strings.ToLower(strings.TrimSuffix(filepath.Base(path), filepath.Ext(path)))
|
||||||
info, err := os.Stat(path)
|
info, err := os.Stat(path)
|
||||||
@@ -545,9 +545,9 @@ func pathResource(path string) (erf.Resource, error) {
|
|||||||
|
|
||||||
func rawResource(path string) (erf.Resource, error) {
|
func rawResource(path string) (erf.Resource, error) {
|
||||||
extension := strings.TrimPrefix(strings.ToLower(filepath.Ext(path)), ".")
|
extension := strings.TrimPrefix(strings.ToLower(filepath.Ext(path)), ".")
|
||||||
resourceType, ok := erf.ResourceTypeForExtension(extension)
|
resourceType, ok := erf.HAKResourceTypeForExtension(extension)
|
||||||
if !ok {
|
if !ok {
|
||||||
return erf.Resource{}, fmt.Errorf("unsupported resource extension %q", filepath.Ext(path))
|
return erf.Resource{}, fmt.Errorf("unsupported HAK resource extension %q", filepath.Ext(path))
|
||||||
}
|
}
|
||||||
name := strings.ToLower(strings.TrimSuffix(filepath.Base(path), filepath.Ext(path)))
|
name := strings.ToLower(strings.TrimSuffix(filepath.Base(path), filepath.Ext(path)))
|
||||||
data, err := os.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
|
|||||||
@@ -473,7 +473,7 @@ func TestBuildBuildsTopPackageAndInjectsHAKList(t *testing.T) {
|
|||||||
"rows": [{"id": 0, "Label": "TEST_LABEL"}]
|
"rows": [{"id": 0, "Label": "TEST_LABEL"}]
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
mustWriteFile(t, filepath.Join(root, "topdata", "assets", "gui", "testicon.tga"), "icon-data")
|
mustWriteFile(t, filepath.Join(root, "topdata", "assets", "gui", "testicon.png"), "icon-data")
|
||||||
|
|
||||||
p, err := project.Load(root)
|
p, err := project.Load(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ var SourceExtensions = []string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var AssetExtensions = []string{
|
var AssetExtensions = []string{
|
||||||
".2da", ".bik", ".bmp", ".dds", ".dwk", ".itp", ".jpg", ".lod", ".lyt", ".mdl", ".mdx", ".mtr", ".plt", ".png", ".pwk", ".set", ".shd", ".tga", ".txi", ".uti", ".vis", ".wav", ".wok",
|
".2da", ".bik", ".bmp", ".dds", ".dwk", ".gr2", ".itp", ".jpg", ".lod", ".lyt", ".mdb", ".mdl", ".mdx", ".mtr", ".plt", ".png", ".pwk", ".set", ".shd", ".tga", ".txi", ".uti", ".vis", ".wav", ".wlk", ".wok", ".xml",
|
||||||
}
|
}
|
||||||
|
|
||||||
type Project struct {
|
type Project struct {
|
||||||
|
|||||||
@@ -156,9 +156,9 @@ func collectTopPackageResources(p *project.Project, compiled2DADir string) ([]er
|
|||||||
|
|
||||||
func topPackageResourceFromPath(path string) (erf.Resource, error) {
|
func topPackageResourceFromPath(path string) (erf.Resource, error) {
|
||||||
extension := strings.TrimPrefix(strings.ToLower(filepath.Ext(path)), ".")
|
extension := strings.TrimPrefix(strings.ToLower(filepath.Ext(path)), ".")
|
||||||
resourceType, ok := erf.ResourceTypeForExtension(extension)
|
resourceType, ok := erf.HAKResourceTypeForExtension(extension)
|
||||||
if !ok {
|
if !ok {
|
||||||
return erf.Resource{}, fmt.Errorf("unsupported top package resource extension %q", filepath.Ext(path))
|
return erf.Resource{}, fmt.Errorf("unsupported top package HAK resource extension %q", filepath.Ext(path))
|
||||||
}
|
}
|
||||||
info, err := os.Stat(path)
|
info, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -988,11 +988,11 @@ func validateTopPackageAssets(sourceDir, dataDir string, report *ValidationRepor
|
|||||||
}
|
}
|
||||||
base := strings.ToLower(strings.TrimSuffix(filepath.Base(path), filepath.Ext(path)))
|
base := strings.ToLower(strings.TrimSuffix(filepath.Base(path), filepath.Ext(path)))
|
||||||
ext := strings.TrimPrefix(strings.ToLower(filepath.Ext(path)), ".")
|
ext := strings.TrimPrefix(strings.ToLower(filepath.Ext(path)), ".")
|
||||||
if _, ok := erf.ResourceTypeForExtension(ext); !ok {
|
if _, ok := erf.HAKResourceTypeForExtension(ext); !ok {
|
||||||
report.Diagnostics = append(report.Diagnostics, Diagnostic{
|
report.Diagnostics = append(report.Diagnostics, Diagnostic{
|
||||||
Severity: SeverityError,
|
Severity: SeverityError,
|
||||||
Path: path,
|
Path: path,
|
||||||
Message: fmt.Sprintf("unsupported topdata asset resource extension %q", filepath.Ext(path)),
|
Message: fmt.Sprintf("unsupported topdata asset HAK resource extension %q", filepath.Ext(path)),
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user