use filepath.Base
This commit is contained in:
parent
0b66b118b8
commit
23174e1f56
3 changed files with 4 additions and 2 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
type assetKey struct {
|
type assetKey struct {
|
||||||
|
@ -12,6 +13,7 @@ type assetKey struct {
|
||||||
path string
|
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 {
|
func LoadGobz(dst interface{}, assets fs.FS, path string) error {
|
||||||
f, err := assets.Open(path)
|
f, err := assets.Open(path)
|
||||||
if err != nil {
|
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.
|
// 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)
|
// This requires running on something with a disk to write to (not JS)
|
||||||
func SaveGobz(src interface{}, name string) error {
|
func SaveGobz(src interface{}, name string) error {
|
||||||
f, err := os.CreateTemp(".", name)
|
f, err := os.CreateTemp(".", filepath.Base(name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
2
main.go
2
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)
|
log.Fatalf("Couldn't save level1.gobz: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue