mirror of
https://codeberg.org/scip/golsky.git
synced 2025-12-16 20:20:57 +01:00
fixed crash when painting outside canvas, refactor
This commit is contained in:
22
game.go
22
game.go
@@ -149,12 +149,7 @@ func (game *Game) CheckInput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if inpututil.IsKeyJustPressed(ebiten.KeyS) {
|
if inpututil.IsKeyJustPressed(ebiten.KeyS) {
|
||||||
filename := GetFilename(game.Generations)
|
game.SaveState()
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if game.Paused {
|
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
|
// Check dragging input. move the canvas with the mouse while pressing
|
||||||
// the middle mouse button, zoom in and out using the wheel.
|
// the middle mouse button, zoom in and out using the wheel.
|
||||||
func (game *Game) CheckDraggingInput() {
|
func (game *Game) CheckDraggingInput() {
|
||||||
@@ -254,8 +258,10 @@ func (game *Game) ToggleCellOnCursorPos(alive int64) {
|
|||||||
|
|
||||||
//fmt.Printf("cell at %d,%d\n", x, y)
|
//fmt.Printf("cell at %d,%d\n", x, y)
|
||||||
|
|
||||||
game.Grids[game.Index].Data[y][x] = alive
|
if x > -1 && y > -1 {
|
||||||
game.History.Data[y][x] = 1
|
game.Grids[game.Index].Data[y][x] = alive
|
||||||
|
game.History.Data[y][x] = 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw the new grid state
|
// draw the new grid state
|
||||||
|
|||||||
Reference in New Issue
Block a user