diff --git a/game.go b/game.go index 36b6610..105d195 100644 --- a/game.go +++ b/game.go @@ -149,12 +149,7 @@ func (game *Game) CheckInput() { } if inpututil.IsKeyJustPressed(ebiten.KeyS) { - filename := GetFilename(game.Generations) - err := game.Grids[game.Index].SaveState(filename) - if err != nil { - log.Printf("failed to save game state to %s: %s", filename, err) - } - log.Printf("saved game state to %s at generation %d\n", filename, game.Generations) + game.SaveState() } if game.Paused { @@ -164,6 +159,15 @@ func (game *Game) CheckInput() { } } +func (game *Game) SaveState() { + filename := GetFilename(game.Generations) + err := game.Grids[game.Index].SaveState(filename) + if err != nil { + log.Printf("failed to save game state to %s: %s", filename, err) + } + log.Printf("saved game state to %s at generation %d\n", filename, game.Generations) +} + // Check dragging input. move the canvas with the mouse while pressing // the middle mouse button, zoom in and out using the wheel. func (game *Game) CheckDraggingInput() { @@ -254,8 +258,10 @@ func (game *Game) ToggleCellOnCursorPos(alive int64) { //fmt.Printf("cell at %d,%d\n", x, y) - game.Grids[game.Index].Data[y][x] = alive - game.History.Data[y][x] = 1 + if x > -1 && y > -1 { + game.Grids[game.Index].Data[y][x] = alive + game.History.Data[y][x] = 1 + } } // draw the new grid state