change: Updated save loading to work with unity files
This commit is contained in:
parent
e0f1cd2436
commit
e1d4537af7
3
Makefile
3
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
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user