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:
18
game.go
18
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,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) {
|
||||
|
||||
Reference in New Issue
Block a user