Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bed1ff975f | ||
|
|
7589c5f220 |
@@ -501,9 +501,6 @@ func writeManagedFile(path string, data []byte) (writeState, error) {
|
|||||||
if bytes.Equal(existing, data) {
|
if bytes.Equal(existing, data) {
|
||||||
return writeSkipped, nil
|
return writeSkipped, nil
|
||||||
}
|
}
|
||||||
if areaGFFJSONEqualIgnoringRootVersion(path, existing, data) {
|
|
||||||
return writeSkipped, nil
|
|
||||||
}
|
|
||||||
if err := os.WriteFile(path, data, 0o644); err != nil {
|
if err := os.WriteFile(path, data, 0o644); err != nil {
|
||||||
return writeSkipped, fmt.Errorf("overwrite %s: %w", path, err)
|
return writeSkipped, fmt.Errorf("overwrite %s: %w", path, err)
|
||||||
}
|
}
|
||||||
@@ -519,38 +516,6 @@ func writeManagedFile(path string, data []byte) (writeState, error) {
|
|||||||
return writeNew, nil
|
return writeNew, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func areaGFFJSONEqualIgnoringRootVersion(path string, existing, extracted []byte) bool {
|
|
||||||
if !strings.HasSuffix(strings.ToLower(filepath.Base(path)), ".are.json") {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
var left, right gff.Document
|
|
||||||
if err := json.Unmarshal(existing, &left); err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if err := json.Unmarshal(extracted, &right); err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
removeRootField(&left.Root, "Version")
|
|
||||||
removeRootField(&right.Root, "Version")
|
|
||||||
|
|
||||||
leftRaw, err := json.Marshal(left)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
rightRaw, err := json.Marshal(right)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return bytes.Equal(leftRaw, rightRaw)
|
|
||||||
}
|
|
||||||
|
|
||||||
func removeRootField(s *gff.Struct, label string) {
|
|
||||||
s.Fields = slices.DeleteFunc(s.Fields, func(field gff.Field) bool {
|
|
||||||
return field.Label == label
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func cleanupStaleFiles(p *project.Project, desired map[string]struct{}, scope extractionScope) (int, []error) {
|
func cleanupStaleFiles(p *project.Project, desired map[string]struct{}, scope extractionScope) (int, []error) {
|
||||||
candidates := make([]string, 0, len(p.Inventory.SourceFiles)+len(p.Inventory.ScriptFiles)+len(p.Inventory.AssetFiles))
|
candidates := make([]string, 0, len(p.Inventory.SourceFiles)+len(p.Inventory.ScriptFiles)+len(p.Inventory.AssetFiles))
|
||||||
if scope.Source && safeCleanupRoot(p.SourceDir(), p.Root) {
|
if scope.Source && safeCleanupRoot(p.SourceDir(), p.Root) {
|
||||||
|
|||||||
@@ -134,113 +134,6 @@ func TestBuildThenExtract(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExtractSkipsAreaWhenOnlyRootVersionChanges(t *testing.T) {
|
|
||||||
root := t.TempDir()
|
|
||||||
mustMkdir(t, filepath.Join(root, "src", "module"))
|
|
||||||
mustMkdir(t, filepath.Join(root, "src", "areas"))
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
mustWriteFile(t, filepath.Join(root, "src", "module", "module.ifo.json"), `{
|
|
||||||
"file_type": "IFO ",
|
|
||||||
"file_version": "V3.2",
|
|
||||||
"root": {
|
|
||||||
"struct_type": 0,
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"label": "Mod_Name",
|
|
||||||
"type": "CExoString",
|
|
||||||
"value": "Test Module"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
mustWriteFile(t, filepath.Join(root, "src", "areas", "area001.are.json"), `{
|
|
||||||
"file_type": "ARE ",
|
|
||||||
"file_version": "V3.2",
|
|
||||||
"root": {
|
|
||||||
"struct_type": 0,
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"label": "Version",
|
|
||||||
"type": "DWord",
|
|
||||||
"value": 2
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "Tag",
|
|
||||||
"type": "CExoString",
|
|
||||||
"value": "area001"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
if _, err := BuildModule(p); err != nil {
|
|
||||||
t.Fatalf("build module: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mustWriteFile(t, filepath.Join(root, "src", "areas", "area001.are.json"), `{
|
|
||||||
"file_type": "ARE ",
|
|
||||||
"file_version": "V3.2",
|
|
||||||
"root": {
|
|
||||||
"struct_type": 0,
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"label": "Version",
|
|
||||||
"type": "DWord",
|
|
||||||
"value": 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "Tag",
|
|
||||||
"type": "CExoString",
|
|
||||||
"value": "area001"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
if err := p.Scan(); err != nil {
|
|
||||||
t.Fatalf("rescan: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := Extract(p)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("extract: %v", err)
|
|
||||||
}
|
|
||||||
if result.Overwritten != 0 {
|
|
||||||
t.Fatalf("Version-only area extraction must not overwrite, got %d overwritten", result.Overwritten)
|
|
||||||
}
|
|
||||||
|
|
||||||
document := readGFFJSON(t, filepath.Join(root, "src", "areas", "area001.are.json"))
|
|
||||||
if got, want := fieldValue(t, document.Root, "Version"), gff.DWordValue(1); got != want {
|
|
||||||
t.Fatalf("expected existing Version %#v to remain, got %#v", want, got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExtractReadsHAKAssets(t *testing.T) {
|
func TestExtractReadsHAKAssets(t *testing.T) {
|
||||||
root := t.TempDir()
|
root := t.TempDir()
|
||||||
mustMkdir(t, filepath.Join(root, "src"))
|
mustMkdir(t, filepath.Join(root, "src"))
|
||||||
|
|||||||
Reference in New Issue
Block a user