From 4e432ca816fea157f9b5fe74679df52235912b9a Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 22 Jan 2018 20:55:57 +0900 Subject: [PATCH] example/blocks: Remove Input.gamepadButtonStates --- examples/blocks/blocks/input.go | 20 +++++++------------- examples/blocks/blocks/titlescene.go | 12 +----------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/examples/blocks/blocks/input.go b/examples/blocks/blocks/input.go index 09878b90a..3e3cd24e0 100644 --- a/examples/blocks/blocks/input.go +++ b/examples/blocks/blocks/input.go @@ -22,7 +22,7 @@ import ( type Input struct { keyStates map[ebiten.Key]int - gamepadButtonStates map[ebiten.GamepadButton]int + anyGamepadButtonPressed bool virtualGamepadButtonStates map[virtualGamepadButton]int gamepadConfig gamepadConfig } @@ -34,11 +34,8 @@ func (i *Input) StateForKey(key ebiten.Key) int { return i.keyStates[key] } -func (i *Input) StateForGamepadButton(b ebiten.GamepadButton) int { - if i.gamepadButtonStates == nil { - return 0 - } - return i.gamepadButtonStates[b] +func (i *Input) IsAnyGamepadButtonPressed() bool { + return i.anyGamepadButtonPressed } func (i *Input) stateForVirtualGamepadButton(b virtualGamepadButton) int { @@ -61,15 +58,12 @@ func (i *Input) Update() { } const gamepadID = 0 - if i.gamepadButtonStates == nil { - i.gamepadButtonStates = map[ebiten.GamepadButton]int{} - } + i.anyGamepadButtonPressed = false for b := ebiten.GamepadButton(0); b <= ebiten.GamepadButtonMax; b++ { - if !ebiten.IsGamepadButtonPressed(gamepadID, b) { - i.gamepadButtonStates[b] = 0 - continue + if ebiten.IsGamepadButtonPressed(gamepadID, b) { + i.anyGamepadButtonPressed = true + break } - i.gamepadButtonStates[b]++ } if i.virtualGamepadButtonStates == nil { diff --git a/examples/blocks/blocks/titlescene.go b/examples/blocks/blocks/titlescene.go index 65ba314f7..508dbc7b3 100644 --- a/examples/blocks/blocks/titlescene.go +++ b/examples/blocks/blocks/titlescene.go @@ -47,16 +47,6 @@ func anyGamepadAbstractButtonPressed(i *Input) bool { return false } -func anyGamepadButtonPressed(i *Input) bool { - bn := ebiten.GamepadButton(ebiten.GamepadButtonNum(0)) - for b := ebiten.GamepadButton(0); b < bn; b++ { - if i.StateForGamepadButton(b) == 1 { - return true - } - } - return false -} - func (s *TitleScene) Update(state *GameState) error { s.count++ if state.Input.StateForKey(ebiten.KeySpace) == 1 { @@ -70,7 +60,7 @@ func (s *TitleScene) Update(state *GameState) error { // If 'abstract' gamepad buttons are not set and any gamepad buttons are pressed, // go to the gamepad configuration scene. - if anyGamepadButtonPressed(state.Input) { + if state.Input.IsAnyGamepadButtonPressed() { state.SceneManager.GoTo(&GamepadScene{}) return nil }