fixed crash when painting outside canvas, refactor

This commit is contained in:
2024-05-24 17:08:46 +02:00
parent b562139787
commit a72ecf06e0

18
game.go
View File

@@ -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,9 +258,11 @@ func (game *Game) ToggleCellOnCursorPos(alive int64) {
//fmt.Printf("cell at %d,%d\n", x, y)
if x > -1 && y > -1 {
game.Grids[game.Index].Data[y][x] = alive
game.History.Data[y][x] = 1
}
}
// draw the new grid state
func (game *Game) Draw(screen *ebiten.Image) {