Extraction of other resource mappings
This commit is contained in:
@@ -178,6 +178,61 @@ func TestExtractReadsHAKAssets(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractReadsSoundBlueprintResources(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mustMkdir(t, filepath.Join(root, "src"))
|
||||
mustMkdir(t, filepath.Join(root, "assets"))
|
||||
mustMkdir(t, filepath.Join(root, "build"))
|
||||
|
||||
mustWriteFile(t, filepath.Join(root, "nwn-tool.json"), `{
|
||||
"module": {
|
||||
"name": "Test Module",
|
||||
"resref": "testmod"
|
||||
},
|
||||
"paths": {
|
||||
"source": "src",
|
||||
"assets": "assets",
|
||||
"build": "build"
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
p, err := project.Load(root)
|
||||
if err != nil {
|
||||
t.Fatalf("load project: %v", err)
|
||||
}
|
||||
if err := p.ValidateLayout(); err != nil {
|
||||
t.Fatalf("validate layout: %v", err)
|
||||
}
|
||||
if err := p.Scan(); err != nil {
|
||||
t.Fatalf("scan: %v", err)
|
||||
}
|
||||
|
||||
archiveFile, err := os.Create(filepath.Join(root, "build", "testmod.mod"))
|
||||
if err != nil {
|
||||
t.Fatalf("create mod: %v", err)
|
||||
}
|
||||
if err := erf.Write(archiveFile, erf.New("MOD ", []erf.Resource{
|
||||
{Name: "S_AL_CANDLE01", Type: 0x07F3, Data: minimalGFF(t, "UTS")},
|
||||
})); err != nil {
|
||||
t.Fatalf("write mod: %v", err)
|
||||
}
|
||||
if err := archiveFile.Close(); err != nil {
|
||||
t.Fatalf("close mod: %v", err)
|
||||
}
|
||||
|
||||
result, err := Extract(p)
|
||||
if err != nil {
|
||||
t.Fatalf("extract: %v", err)
|
||||
}
|
||||
if result.Written != 1 {
|
||||
t.Fatalf("expected 1 extracted sound blueprint, got %d", result.Written)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(root, "src", "blueprints", "sounds", "s_al_candle01.uts.json")); err != nil {
|
||||
t.Fatalf("expected extracted sound blueprint: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractDefaultOnlyReadsConfiguredModuleArchive(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mustMkdir(t, filepath.Join(root, "src", "module"))
|
||||
@@ -3368,6 +3423,20 @@ func mustWriteFile(t *testing.T, path, data string) {
|
||||
}
|
||||
}
|
||||
|
||||
func minimalGFF(t *testing.T, fileType string) []byte {
|
||||
t.Helper()
|
||||
document := gff.Document{
|
||||
FileType: fileType + " ",
|
||||
FileVersion: "V3.2",
|
||||
Root: gff.Struct{Type: 0},
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
if err := gff.Write(&buf, document); err != nil {
|
||||
t.Fatalf("write %s gff: %v", fileType, err)
|
||||
}
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func TestBuildHAKsFailsForDuplicateResourcesInSameHAK(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mustMkdir(t, filepath.Join(root, "src"))
|
||||
|
||||
Reference in New Issue
Block a user