@@ -2,6 +2,7 @@ package topdata
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.westgate.pw/ShadowsOverWestgate/sow-tools/internal/erf"
|
||||
"git.westgate.pw/ShadowsOverWestgate/sow-tools/internal/gff"
|
||||
"git.westgate.pw/ShadowsOverWestgate/sow-tools/internal/project"
|
||||
)
|
||||
|
||||
@@ -215,10 +217,15 @@ func collectTopPackageResources(p *project.Project, compiled2DADir string) ([]er
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if skipTopPackageAsset(rel) {
|
||||
return nil
|
||||
var resource erf.Resource
|
||||
if strings.HasSuffix(strings.ToLower(rel), ".itp.json") {
|
||||
resource, err = topPackageITPResourceFromJSON(path)
|
||||
} else {
|
||||
if skipTopPackageAsset(rel) {
|
||||
return nil
|
||||
}
|
||||
resource, err = topPackageResourceFromPath(path)
|
||||
}
|
||||
resource, err := topPackageResourceFromPath(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -251,6 +258,27 @@ func collectTopPackageResources(p *project.Project, compiled2DADir string) ([]er
|
||||
return resources, assetFiles, nil
|
||||
}
|
||||
|
||||
func topPackageITPResourceFromJSON(path string) (erf.Resource, error) {
|
||||
raw, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return erf.Resource{}, fmt.Errorf("read %s: %w", path, err)
|
||||
}
|
||||
var document gff.Document
|
||||
if err := json.Unmarshal(raw, &document); err != nil {
|
||||
return erf.Resource{}, fmt.Errorf("parse %s: %w", path, err)
|
||||
}
|
||||
if document.FileType != "ITP " {
|
||||
return erf.Resource{}, fmt.Errorf("%s: file_type must be ITP", path)
|
||||
}
|
||||
var payload bytes.Buffer
|
||||
if err := gff.Write(&payload, document); err != nil {
|
||||
return erf.Resource{}, fmt.Errorf("compile %s: %w", path, err)
|
||||
}
|
||||
resourceType, _ := erf.HAKResourceTypeForExtension("itp")
|
||||
name := strings.TrimSuffix(filepath.Base(path), ".itp.json")
|
||||
return erf.Resource{Name: strings.ToLower(name), Type: resourceType, Data: payload.Bytes(), Size: int64(payload.Len())}, nil
|
||||
}
|
||||
|
||||
func shouldSkipTopDataSourceDir(path string, skipDirs map[string]struct{}) bool {
|
||||
_, ok := skipDirs[filepath.Clean(path)]
|
||||
return ok
|
||||
|
||||
Reference in New Issue
Block a user