Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/idbrii/love-gamepadguesser
Guess what a gamepad should look like and provide a default set of art that matches the input gamepad.
https://github.com/idbrii/love-gamepadguesser
Last synced: 3 days ago
JSON representation
Guess what a gamepad should look like and provide a default set of art that matches the input gamepad.
- Host: GitHub
- URL: https://github.com/idbrii/love-gamepadguesser
- Owner: idbrii
- License: mit
- Created: 2022-01-03T02:01:47.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-11T08:28:30.000Z (almost 3 years ago)
- Last Synced: 2024-08-02T06:17:41.133Z (3 months ago)
- Language: Lua
- Homepage:
- Size: 2.33 MB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-love2d - GamepadGuesser - Get the right button icons for gamepads; load updated gamepad db. (Input)
README
[![Requires love2d 11.3+
](https://img.shields.io/badge/L%F6ve-11.3%2B-pink.svg)](https://love2d.org/) [![Lint status
](https://github.com/idbrii/love-gamepadguesser/actions/workflows/luacheck.yml/badge.svg?branch=main)
](https://github.com/idbrii/love-gamepadguesser/actions?query=branch%3Amain)# GamepadGuesser
Guesses what a gamepad should look like and provides a default set of art that
matches the input gamepad.*Not an input mapping library. If you want to define input bindings, I
recommend [baton](https://github.com/tesselode/baton).*Simplify showing gamepad icons with gamepadguesser. It loads the extensive
[SDL_GameControllerDB](https://github.com/gabomdq/SDL_GameControllerDB) for
better gamepad support, maps joysticks to appearance (console-specific buttons
like Xbox, Nintendo, ...), and builds images on demand for each GamepadButton
and GamepadAxis.You can start displaying the correct image for your buttons in only a few lines
of code:```lua
local gamepadguesser = require "gamepadguesser"local joy = gamepadguesser.createJoystickData("gamepadguesser")
function love.gamepadpressed(joystick, button)
gamepad = joystick
btn = button
endfunction love.draw()
if btn then
love.graphics.draw(joy:getImage(gamepad, btn), 0, 0)
end
end
```GamepadGuesser caches each image it creates, so you can call getImage in draw
without worrying about garbage.See main.lua for a more extensive example.
## Disabling Autodetection
Autodetection may be imperfect, so you can set an override to force a specific
console visual:
```
joy:overrideConsole(joystick, "nintendo")
```
You can use `gamepadguesser.CONSOLES` to provide a list of options in your
settings menu (also include an "auto" option that passes `nil` to
overrideConsole.## Low-level operation
You can also use gamepadguesser with your own art. The easiest way is to modify
the art in gamepadguesser/assets/images/ to ensure the correct file names.You can also get the name of the console associated with the joystick ("xbox",
"playstation", "nintendo"):```lua
function love.gamepadpressed(joystick, button)
text = gamepadguesser.joystickToConsole(joystick)
endfunction love.draw()
love.graphics.printf(text or "", 0, 0, 100)
end
```Calling `gamepadguesser` functions directly doesn't automatically load
SDL_GameControllerDB. You can call
`gamepadguesser.loadMappings(path_to_gamepadguesser)` to load them yourself.## Caveats
lovejs returns `nil` for `getGamepadMappingString()` and `getName()` produces
generic names, so all gamepads appear to be xbox gamepads in web builds.Requires love2d 11.3+ because getting gamepad names depends on
[getGamepadMappingString](https://love2d.org/wiki/Joystick:getGamepadMappingString).## License
* gamepadguesser - idbrii - MIT
* [SDL_GameControllerDB](https://github.com/gabomdq/SDL_GameControllerDB) - Sam Lantinga - [SDL License](https://github.com/gabomdq/SDL_GameControllerDB/blob/master/LICENSE)
* [gamepad art in assets/images/](https://thoseawesomeguys.com/prompts/) - Nicolae (Xelu) Berbece - [CC0](https://creativecommons.org/share-your-work/public-domain/cc0/)