diff --git a/Makefile b/Makefile index 40b16a9..2d9367f 100644 --- a/Makefile +++ b/Makefile @@ -5,15 +5,12 @@ SAVES += witchcraft-save all: $(SAVES) imperial-save: compile - mkdir imperial-save ./spatial-db load worldsave "saves/Imperialcity v14.1/region" --output "imperial-save" skygrid-save: compile - mkdir skygrid-save ./spatial-db load worldsave "saves/SkyGrid/region" --output "skygrid-save" witchcraft-save: compile - mkdir witchcraft-save ./spatial-db load worldsave "saves/Witchcraft/region" --output "witchcraft-save" .PHONY: compile diff --git a/loading/load_save.go b/loading/load_save.go index f393bf0..b3ae081 100644 --- a/loading/load_save.go +++ b/loading/load_save.go @@ -1,11 +1,11 @@ package loading import ( - "encoding/json" "os" "path/filepath" "strings" + "git.nicholasnovak.io/nnovak/spatial-db/storage" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -32,6 +32,13 @@ var LoadSaveDirCommand = &cobra.Command{ log.Infof("Loading save directory of %s", args[0]) + u, err := storage.CreateUnityFile(saveOutputDir) + if err != nil { + return err + } + defer u.Close() + defer u.WriteMetadataFile(saveOutputDir + ".metadata") + for regionIndex, regionFile := range regionFiles { if regionFile.IsDir() { continue @@ -58,22 +65,9 @@ var LoadSaveDirCommand = &cobra.Command{ // Save each chunk to a separate file for _, chunk := range chunks { - chunkFilename := chunk.Pos.ToFileName() - - outfile, err := os.OpenFile( - filepath.Join(saveOutputDir, chunkFilename), - os.O_WRONLY|os.O_CREATE|os.O_APPEND, - 0664, - ) - if err != nil { + if err := u.WriteChunk(chunk); err != nil { return err } - - if err := json.NewEncoder(outfile).Encode(chunk); err != nil { - return err - } - - outfile.Close() } }