From 1bee10f999efd9038d6f2d4d0272c5b6c2199bd2 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 5 Feb 2022 22:42:14 +0900 Subject: [PATCH] internal/gamepad: move constants from internal/driver --- input.go | 2 +- internal/driver/input.go | 2 -- internal/gamepad/gamepad.go | 12 +++++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/input.go b/input.go index 21df14e37..f048707f0 100644 --- a/input.go +++ b/input.go @@ -120,7 +120,7 @@ func IsMouseButtonPressed(mouseButton MouseButton) bool { } // GamepadID represents a gamepad's identifier. -type GamepadID = driver.GamepadID +type GamepadID = gamepad.ID // GamepadSDLID returns a string with the GUID generated in the same way as SDL. // To detect devices, see also the community project of gamepad devices database: https://github.com/gabomdq/SDL_GameControllerDB diff --git a/internal/driver/input.go b/internal/driver/input.go index dc63aa1a9..b07c25fa3 100644 --- a/internal/driver/input.go +++ b/internal/driver/input.go @@ -14,8 +14,6 @@ package driver -type GamepadID int - type TouchID int type Input interface { diff --git a/internal/gamepad/gamepad.go b/internal/gamepad/gamepad.go index 8f925a58c..e6a58077e 100644 --- a/internal/gamepad/gamepad.go +++ b/internal/gamepad/gamepad.go @@ -22,6 +22,8 @@ import ( "github.com/hajimehoshi/ebiten/v2/internal/gamepaddb" ) +type ID int + const ( hatCentered = 0 hatUp = 1 @@ -45,7 +47,7 @@ type gamepads struct { var theGamepads gamepads // AppendGamepadIDs is concurrent-safe. -func AppendGamepadIDs(ids []driver.GamepadID) []driver.GamepadID { +func AppendGamepadIDs(ids []ID) []ID { return theGamepads.appendGamepadIDs(ids) } @@ -55,17 +57,17 @@ func Update() error { } // Get is concurrent-safe. -func Get(id driver.GamepadID) *Gamepad { +func Get(id ID) *Gamepad { return theGamepads.get(id) } -func (g *gamepads) appendGamepadIDs(ids []driver.GamepadID) []driver.GamepadID { +func (g *gamepads) appendGamepadIDs(ids []ID) []ID { g.m.Lock() defer g.m.Unlock() for i, gp := range g.gamepads { if gp != nil { - ids = append(ids, driver.GamepadID(i)) + ids = append(ids, ID(i)) } } return ids @@ -97,7 +99,7 @@ func (g *gamepads) update() error { return nil } -func (g *gamepads) get(id driver.GamepadID) *Gamepad { +func (g *gamepads) get(id ID) *Gamepad { g.m.Lock() defer g.m.Unlock()