mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +01:00
parent
cdf2335f5a
commit
fb3a022327
@ -163,6 +163,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
|||||||
standard = " (Standard Layout)"
|
standard = " (Standard Layout)"
|
||||||
}
|
}
|
||||||
str += fmt.Sprintf("Gamepad (ID: %d, SDL ID: %s)%s:\n", id, ebiten.GamepadSDLID(id), standard)
|
str += fmt.Sprintf("Gamepad (ID: %d, SDL ID: %s)%s:\n", id, ebiten.GamepadSDLID(id), standard)
|
||||||
|
str += fmt.Sprintf(" Name: %s\n", ebiten.GamepadName(id))
|
||||||
str += fmt.Sprintf(" Axes: %s\n", strings.Join(g.axes[id], ", "))
|
str += fmt.Sprintf(" Axes: %s\n", strings.Join(g.axes[id], ", "))
|
||||||
str += fmt.Sprintf(" Buttons: %s\n", strings.Join(g.pressedButtons[id], ", "))
|
str += fmt.Sprintf(" Buttons: %s\n", strings.Join(g.pressedButtons[id], ", "))
|
||||||
if ebiten.IsStandardGamepadLayoutAvailable(id) {
|
if ebiten.IsStandardGamepadLayoutAvailable(id) {
|
||||||
|
@ -163,6 +163,9 @@ func (g *Gamepad) update() {
|
|||||||
|
|
||||||
func (g *Gamepad) Name() string {
|
func (g *Gamepad) Name() string {
|
||||||
// This is immutable and doesn't have to be protected by a mutex.
|
// This is immutable and doesn't have to be protected by a mutex.
|
||||||
|
if name := gamepaddb.Name(g.sdlID); name != "" {
|
||||||
|
return name
|
||||||
|
}
|
||||||
return g.name
|
return g.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,6 +126,7 @@ type mapping struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
gamepadNames = map[string]string{}
|
||||||
gamepadButtonMappings = map[string]map[driver.StandardGamepadButton]*mapping{}
|
gamepadButtonMappings = map[string]map[driver.StandardGamepadButton]*mapping{}
|
||||||
gamepadAxisMappings = map[string]map[driver.StandardGamepadAxis]*mapping{}
|
gamepadAxisMappings = map[string]map[driver.StandardGamepadAxis]*mapping{}
|
||||||
mappingsM sync.RWMutex
|
mappingsM sync.RWMutex
|
||||||
@ -203,6 +204,8 @@ func processLine(line string, platform platform) error {
|
|||||||
// There is no corresponding button in the Web standard gamepad layout.
|
// There is no corresponding button in the Web standard gamepad layout.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gamepadNames[id] = tokens[1]
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,6 +381,13 @@ type GamepadState interface {
|
|||||||
Hat(index int) int
|
Hat(index int) int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Name(id string) string {
|
||||||
|
mappingsM.RLock()
|
||||||
|
defer mappingsM.RUnlock()
|
||||||
|
|
||||||
|
return gamepadNames[id]
|
||||||
|
}
|
||||||
|
|
||||||
func AxisValue(id string, axis driver.StandardGamepadAxis, state GamepadState) float64 {
|
func AxisValue(id string, axis driver.StandardGamepadAxis, state GamepadState) float64 {
|
||||||
mappingsM.RLock()
|
mappingsM.RLock()
|
||||||
defer mappingsM.RUnlock()
|
defer mappingsM.RUnlock()
|
||||||
|
@ -119,6 +119,9 @@ func (i *Input) GamepadName(id driver.GamepadID) string {
|
|||||||
if len(i.gamepads) <= int(id) {
|
if len(i.gamepads) <= int(id) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
if name := gamepaddb.Name(i.gamepads[id].guid); name != "" {
|
||||||
|
return name
|
||||||
|
}
|
||||||
return i.gamepads[id].name
|
return i.gamepads[id].name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +67,9 @@ func (i *Input) GamepadName(id driver.GamepadID) string {
|
|||||||
if g.ID != id {
|
if g.ID != id {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if name := gamepaddb.Name(g.SDLID); name != "" {
|
||||||
|
return name
|
||||||
|
}
|
||||||
return g.Name
|
return g.Name
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
|
Loading…
Reference in New Issue
Block a user