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)
|
all: $(SAVES)
|
||||||
|
|
||||||
imperial-save: compile
|
imperial-save: compile
|
||||||
mkdir imperial-save
|
|
||||||
./spatial-db load worldsave "saves/Imperialcity v14.1/region" --output "imperial-save"
|
./spatial-db load worldsave "saves/Imperialcity v14.1/region" --output "imperial-save"
|
||||||
|
|
||||||
skygrid-save: compile
|
skygrid-save: compile
|
||||||
mkdir skygrid-save
|
|
||||||
./spatial-db load worldsave "saves/SkyGrid/region" --output "skygrid-save"
|
./spatial-db load worldsave "saves/SkyGrid/region" --output "skygrid-save"
|
||||||
|
|
||||||
witchcraft-save: compile
|
witchcraft-save: compile
|
||||||
mkdir witchcraft-save
|
|
||||||
./spatial-db load worldsave "saves/Witchcraft/region" --output "witchcraft-save"
|
./spatial-db load worldsave "saves/Witchcraft/region" --output "witchcraft-save"
|
||||||
|
|
||||||
.PHONY: compile
|
.PHONY: compile
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package loading
|
package loading
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.nicholasnovak.io/nnovak/spatial-db/storage"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -32,6 +32,13 @@ var LoadSaveDirCommand = &cobra.Command{
|
|||||||
|
|
||||||
log.Infof("Loading save directory of %s", args[0])
|
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 {
|
for regionIndex, regionFile := range regionFiles {
|
||||||
if regionFile.IsDir() {
|
if regionFile.IsDir() {
|
||||||
continue
|
continue
|
||||||
@ -58,22 +65,9 @@ var LoadSaveDirCommand = &cobra.Command{
|
|||||||
|
|
||||||
// Save each chunk to a separate file
|
// Save each chunk to a separate file
|
||||||
for _, chunk := range chunks {
|
for _, chunk := range chunks {
|
||||||
chunkFilename := chunk.Pos.ToFileName()
|
if err := u.WriteChunk(chunk); err != nil {
|
||||||
|
|
||||||
outfile, err := os.OpenFile(
|
|
||||||
filepath.Join(saveOutputDir, chunkFilename),
|
|
||||||
os.O_WRONLY|os.O_CREATE|os.O_APPEND,
|
|
||||||
0664,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.NewEncoder(outfile).Encode(chunk); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
outfile.Close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user