ebiten: rename Gamepad(Axis|Button)Num -> Gamepad(Axis|Button)Count

This commit is contained in:
Hajime Hoshi 2022-07-13 01:27:14 +09:00
parent 2203c3c448
commit 5f17264c74
3 changed files with 25 additions and 11 deletions

View File

@ -123,7 +123,7 @@ func (c *gamepadConfig) initializeIfNeeded() {
// For example, on PS4 controllers, L2/R2's axes valuse can be -1.0. // For example, on PS4 controllers, L2/R2's axes valuse can be -1.0.
if c.defaultAxesValues == nil { if c.defaultAxesValues == nil {
c.defaultAxesValues = map[int]float64{} c.defaultAxesValues = map[int]float64{}
na := ebiten.GamepadAxisNum(c.gamepadID) na := ebiten.GamepadAxisCount(c.gamepadID)
for a := 0; a < na; a++ { for a := 0; a < na; a++ {
c.defaultAxesValues[a] = ebiten.GamepadAxisValue(c.gamepadID, a) c.defaultAxesValues[a] = ebiten.GamepadAxisValue(c.gamepadID, a)
} }
@ -149,7 +149,7 @@ func (c *gamepadConfig) Scan(b virtualGamepadButton) bool {
delete(c.buttons, b) delete(c.buttons, b)
delete(c.axes, b) delete(c.axes, b)
ebn := ebiten.GamepadButton(ebiten.GamepadButtonNum(c.gamepadID)) ebn := ebiten.GamepadButton(ebiten.GamepadButtonCount(c.gamepadID))
for eb := ebiten.GamepadButton(0); eb < ebn; eb++ { for eb := ebiten.GamepadButton(0); eb < ebn; eb++ {
if _, ok := c.assignedButtons[eb]; ok { if _, ok := c.assignedButtons[eb]; ok {
continue continue
@ -161,7 +161,7 @@ func (c *gamepadConfig) Scan(b virtualGamepadButton) bool {
} }
} }
na := ebiten.GamepadAxisNum(c.gamepadID) na := ebiten.GamepadAxisCount(c.gamepadID)
for a := 0; a < na; a++ { for a := 0; a < na; a++ {
v := ebiten.GamepadAxisValue(c.gamepadID, a) v := ebiten.GamepadAxisValue(c.gamepadID, a)
const delta = 0.25 const delta = 0.25

View File

@ -63,13 +63,13 @@ func (g *Game) Update() error {
g.axes = map[ebiten.GamepadID][]string{} g.axes = map[ebiten.GamepadID][]string{}
g.pressedButtons = map[ebiten.GamepadID][]string{} g.pressedButtons = map[ebiten.GamepadID][]string{}
for id := range g.gamepadIDs { for id := range g.gamepadIDs {
maxAxis := ebiten.GamepadAxisNum(id) maxAxis := ebiten.GamepadAxisCount(id)
for a := 0; a < maxAxis; a++ { for a := 0; a < maxAxis; a++ {
v := ebiten.GamepadAxisValue(id, a) v := ebiten.GamepadAxisValue(id, a)
g.axes[id] = append(g.axes[id], fmt.Sprintf("%d:%+0.2f", a, v)) g.axes[id] = append(g.axes[id], fmt.Sprintf("%d:%+0.2f", a, v))
} }
maxButton := ebiten.GamepadButton(ebiten.GamepadButtonNum(id)) maxButton := ebiten.GamepadButton(ebiten.GamepadButtonCount(id))
for b := ebiten.GamepadButton(id); b < maxButton; b++ { for b := ebiten.GamepadButton(id); b < maxButton; b++ {
if ebiten.IsGamepadButtonPressed(id, b) { if ebiten.IsGamepadButtonPressed(id, b) {
g.pressedButtons[id] = append(g.pressedButtons[id], strconv.Itoa(int(b))) g.pressedButtons[id] = append(g.pressedButtons[id], strconv.Itoa(int(b)))

View File

@ -168,10 +168,10 @@ func GamepadIDs() []GamepadID {
return AppendGamepadIDs(nil) return AppendGamepadIDs(nil)
} }
// GamepadAxisNum returns the number of axes of the gamepad (id). // GamepadAxisCount returns the number of axes of the gamepad (id).
// //
// GamepadAxisNum is concurrent-safe. // GamepadAxisCount is concurrent-safe.
func GamepadAxisNum(id GamepadID) int { func GamepadAxisCount(id GamepadID) int {
g := gamepad.Get(id) g := gamepad.Get(id)
if g == nil { if g == nil {
return 0 return 0
@ -179,6 +179,13 @@ func GamepadAxisNum(id GamepadID) int {
return g.AxisCount() return g.AxisCount()
} }
// GamepadAxisNum returns the number of axes of the gamepad (id).
//
// Deprecated: as of v2.4. Use GamepadAxisCount instead.
func GamepadAxisNum(id GamepadID) int {
return GamepadAxisCount(id)
}
// GamepadAxisValue returns a float value [-1.0 - 1.0] of the given gamepad (id)'s axis (axis). // GamepadAxisValue returns a float value [-1.0 - 1.0] of the given gamepad (id)'s axis (axis).
// //
// GamepadAxisValue is concurrent-safe. // GamepadAxisValue is concurrent-safe.
@ -197,10 +204,10 @@ func GamepadAxis(id GamepadID, axis int) float64 {
return GamepadAxisValue(id, axis) return GamepadAxisValue(id, axis)
} }
// GamepadButtonNum returns the number of the buttons of the given gamepad (id). // GamepadButtonCount returns the number of the buttons of the given gamepad (id).
// //
// GamepadButtonNum is concurrent-safe. // GamepadButtonCount is concurrent-safe.
func GamepadButtonNum(id GamepadID) int { func GamepadButtonCount(id GamepadID) int {
g := gamepad.Get(id) g := gamepad.Get(id)
if g == nil { if g == nil {
return 0 return 0
@ -210,6 +217,13 @@ func GamepadButtonNum(id GamepadID) int {
return g.ButtonCount() + g.HatCount()*4 return g.ButtonCount() + g.HatCount()*4
} }
// GamepadButtonNum returns the number of the buttons of the given gamepad (id).
//
// Deprecated: as of v2.4. Use GamepadButtonCount instead.
func GamepadButtonNum(id GamepadID) int {
return GamepadButtonCount(id)
}
// IsGamepadButtonPressed reports whether the given button of the gamepad (id) is pressed or not. // IsGamepadButtonPressed reports whether the given button of the gamepad (id) is pressed or not.
// //
// If you want to know whether the given button of gamepad (id) started being pressed in the current frame, // If you want to know whether the given button of gamepad (id) started being pressed in the current frame,