diff --git a/engine/asset.go b/engine/asset.go index 40fd21e..b663fba 100644 --- a/engine/asset.go +++ b/engine/asset.go @@ -5,6 +5,7 @@ import ( "encoding/gob" "io/fs" "os" + "path/filepath" ) type assetKey struct { @@ -12,6 +13,7 @@ type assetKey struct { path string } +// LoadGobz gunzips and gob-decodes a component from a file from a FS. func LoadGobz(dst interface{}, assets fs.FS, path string) error { f, err := assets.Open(path) if err != nil { @@ -28,7 +30,7 @@ func LoadGobz(dst interface{}, assets fs.FS, path string) error { // SaveGobz takes an object, gob-encodes it, gzips it, and writes to disk. // This requires running on something with a disk to write to (not JS) func SaveGobz(src interface{}, name string) error { - f, err := os.CreateTemp(".", name) + f, err := os.CreateTemp(".", filepath.Base(name)) if err != nil { return err } diff --git a/game/assets/level1.gobz b/game/assets/level1.gobz index 6edfbdb..60736db 100644 Binary files a/game/assets/level1.gobz and b/game/assets/level1.gobz differ diff --git a/main.go b/main.go index c481d72..057e317 100644 --- a/main.go +++ b/main.go @@ -145,7 +145,7 @@ func writeLevel1() { }, } - if err := engine.SaveGobz(level1, "level1.gobz"); err != nil { + if err := engine.SaveGobz(level1, "game/assets/level1.gobz"); err != nil { log.Fatalf("Couldn't save level1.gobz: %v", err) }