gobdumper... meh

This commit is contained in:
Josh Deprez 2021-08-25 15:39:01 +10:00
parent 633d431a98
commit 8f05192d78
2 changed files with 0 additions and 53 deletions

View file

@ -1,13 +1,9 @@
package engine
import (
"compress/gzip"
"encoding/gob"
"errors"
"fmt"
"math"
"os"
"time"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
@ -17,14 +13,9 @@ var (
_ Drawer = PerfDisplay{}
_ DrawOrderer = PerfDisplay{}
_ Hider = &PerfDisplay{}
_ Disabler = &GobDumper{}
_ Prepper = &GobDumper{}
_ Updater = &GobDumper{}
)
func init() {
gob.Register(&GobDumper{})
gob.Register(&PerfDisplay{})
}
@ -76,44 +67,3 @@ func (PerfDisplay) DrawOrder() float64 {
// Always draw on top
return math.MaxFloat64
}
// GobDumper waits for a given key combo, then dumps the game into a gob file
// in the current directory.
type GobDumper struct {
Disabled
KeyCombo []ebiten.Key
game *Game
}
// Prepare simply stores the reference to the Game.
func (d *GobDumper) Prepare(g *Game) { d.game = g }
// Update waits for the key combo, then dumps the game state into a gzipped gob.
func (d *GobDumper) Update() error {
if d.Disabled {
return nil
}
for _, key := range d.KeyCombo {
if !ebiten.IsKeyPressed(key) {
return nil
}
}
if d.game == nil {
return errors.New("nil d.game in GobDumper.Update")
}
f, err := os.Create(time.Now().Format("20060102030405.gob.gz"))
if err != nil {
return err
}
defer f.Close()
gz := gzip.NewWriter(f)
defer gz.Close()
if err := gob.NewEncoder(gz).Encode(d.game); err != nil {
return err
}
if err := gz.Close(); err != nil {
return err
}
return f.Close()
}

View file

@ -119,9 +119,6 @@ func main() {
Root: &engine.Scene{
ID: "root",
Components: []interface{}{
&engine.GobDumper{
KeyCombo: []ebiten.Key{ebiten.KeyControl, ebiten.KeyD},
},
&engine.Camera{
ID: "game_camera",
Scene: &engine.SceneRef{Path: "assets/level1.gobz"},