using switch in input checks

This commit is contained in:
2024-06-11 19:39:46 +02:00
parent 927e47dc92
commit d66fb489fe
2 changed files with 22 additions and 38 deletions

View File

@@ -1,7 +1,6 @@
- add all other options like size etc - add all other options like size etc
- add gif export - add gif export
- add toolbar (not working yet, see branch trackui) - add toolbar (not working yet, see branch trackui)
- turn input ifs to switch
- only draw visible part of the world - only draw visible part of the world
- print current mode to the bottom like pause, insert and mark - print current mode to the bottom like pause, insert and mark
- add https://www.ibiblio.org/lifepatterns/october1970.html - add https://www.ibiblio.org/lifepatterns/october1970.html

View File

@@ -174,50 +174,40 @@ func (scene *ScenePlay) CheckExit() error {
} }
func (scene *ScenePlay) CheckInput() { func (scene *ScenePlay) CheckInput() {
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) { // primary functions, always available
switch {
case inpututil.IsKeyJustPressed(ebiten.KeyEscape):
scene.SetNext(Menu) scene.SetNext(Menu)
} case inpututil.IsKeyJustPressed(ebiten.KeyO):
if inpututil.IsKeyJustPressed(ebiten.KeyO) {
scene.SetNext(Options) scene.SetNext(Options)
} case inpututil.IsKeyJustPressed(ebiten.KeyC):
if inpututil.IsKeyJustPressed(ebiten.KeyC) {
scene.Config.Markmode = true scene.Config.Markmode = true
scene.Config.Drawmode = false scene.Config.Drawmode = false
scene.Config.Paused = true scene.Config.Paused = true
} case inpututil.IsKeyJustPressed(ebiten.KeyI):
if inpututil.IsKeyJustPressed(ebiten.KeyI) {
scene.Config.Drawmode = true scene.Config.Drawmode = true
scene.Config.Paused = true scene.Config.Paused = true
} }
if scene.Config.Markmode { if scene.Config.Markmode {
// no need to check any more input in mark mode
return return
} }
if inpututil.IsKeyJustPressed(ebiten.KeySpace) || inpututil.IsKeyJustPressed(ebiten.KeyEnter) { switch {
case inpututil.IsKeyJustPressed(ebiten.KeySpace) || inpututil.IsKeyJustPressed(ebiten.KeyEnter):
scene.Config.TogglePaused() scene.Config.TogglePaused()
} case inpututil.IsKeyJustPressed(ebiten.KeyPageDown):
if inpututil.IsKeyJustPressed(ebiten.KeyPageDown) {
if scene.TPG < 120 { if scene.TPG < 120 {
scene.TPG++ scene.TPG++
} }
} case inpututil.IsKeyJustPressed(ebiten.KeyPageUp):
if inpututil.IsKeyJustPressed(ebiten.KeyPageUp) {
if scene.TPG >= 1 { if scene.TPG >= 1 {
scene.TPG-- scene.TPG--
} }
} case inpututil.IsKeyJustPressed(ebiten.KeyS):
if inpututil.IsKeyJustPressed(ebiten.KeyS) {
scene.SaveState() scene.SaveState()
} case inpututil.IsKeyJustPressed(ebiten.KeyD):
if inpututil.IsKeyJustPressed(ebiten.KeyD) {
scene.Config.Debug = !scene.Config.Debug scene.Config.Debug = !scene.Config.Debug
} }
@@ -230,15 +220,12 @@ func (scene *ScenePlay) CheckInput() {
func (scene *ScenePlay) CheckDrawingInput() { func (scene *ScenePlay) CheckDrawingInput() {
if scene.Config.Drawmode { if scene.Config.Drawmode {
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) { switch {
case ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft):
scene.ToggleCellOnCursorPos(Alive) scene.ToggleCellOnCursorPos(Alive)
} case ebiten.IsMouseButtonPressed(ebiten.MouseButtonRight):
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonRight) {
scene.ToggleCellOnCursorPos(Dead) scene.ToggleCellOnCursorPos(Dead)
} case inpututil.IsKeyJustPressed(ebiten.KeyEscape):
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
scene.Config.Drawmode = false scene.Config.Drawmode = false
} }
} }
@@ -282,16 +269,14 @@ func (scene *ScenePlay) CheckDraggingInput() {
} }
// also support the arrow keys to move the canvas // also support the arrow keys to move the canvas
if ebiten.IsKeyPressed(ebiten.KeyArrowLeft) { switch {
case ebiten.IsKeyPressed(ebiten.KeyArrowLeft):
scene.Camera.Position[0] -= 1 scene.Camera.Position[0] -= 1
} case ebiten.IsKeyPressed(ebiten.KeyArrowRight):
if ebiten.IsKeyPressed(ebiten.KeyArrowRight) {
scene.Camera.Position[0] += 1 scene.Camera.Position[0] += 1
} case ebiten.IsKeyPressed(ebiten.KeyArrowUp):
if ebiten.IsKeyPressed(ebiten.KeyArrowUp) {
scene.Camera.Position[1] -= 1 scene.Camera.Position[1] -= 1
} case ebiten.IsKeyPressed(ebiten.KeyArrowDown):
if ebiten.IsKeyPressed(ebiten.KeyArrowDown) {
scene.Camera.Position[1] += 1 scene.Camera.Position[1] += 1
} }