SDL_GameControllerDB/README.md

125 lines
5.6 KiB
Markdown
Raw Normal View History

2017-10-14 19:08:21 -04:00
# SDL_GameControllerDB
2013-11-27 17:20:34 -03:00
2017-11-23 13:39:30 -03:00
[![Build Status](https://travis-ci.org/gabomdq/SDL_GameControllerDB.svg?branch=master)](https://travis-ci.org/gabomdq/SDL_GameControllerDB)
2013-11-27 17:20:34 -03:00
2014-01-10 15:15:57 -03:00
A community source database of game controller mappings to be used with SDL2 Game Controller functionality.
2013-11-27 17:20:34 -03:00
2017-11-23 13:39:30 -03:00
## SDL Variants
2017-12-17 16:27:38 -05:00
### gamecontrollerdb.txt
For games or engines using the SDL >= 2.0.6 format. This is the most recent version.
2017-12-17 15:50:06 -05:00
2017-12-17 16:27:38 -05:00
### gamecontrollerdb_205.txt
For games or engines using the SDL >= 2.0.5 format. There are no range or inversion modifiers (+,-,~).
2017-11-05 13:55:14 -05:00
2017-12-17 16:27:38 -05:00
### gamecontrollerdb_204.txt
2017-11-23 14:10:28 -03:00
For games or engines using the SDL 2.0.4 format. GUIDs are different depending on the platform. Note that SDL > 2.0.4 can still read this format.
2017-10-14 19:08:21 -04:00
2017-11-05 14:13:39 -05:00
## Create New Mappings
A mapping looks like this :
```
030000004c050000c405000000010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Mac OS X,
```
2017-11-05 14:14:06 -05:00
It is comprised of a controller GUID (`030000004c050000c405000000010000`), a name (`PS4 Controller`), button / axis mappings (`leftshoulder:b4`) and a platform (`platform:Mac OS X`).
2017-11-05 14:13:39 -05:00
2018-01-12 14:50:10 -05:00
## Naming Convention
- If the controller has a unique name, use that (ex. XBox Controller, XBox One Controller).
- If the controller doesn't have a unique name, or when in doubt, use brand + model (ex. ACME GA09, 8Bitdo NES30 Pro).
- You can add `Wireless` for controllers with such an option. (ex. XBox Wireless Controller).
## Mapping Tools
2017-11-23 14:10:28 -03:00
There are a few different tools that let you create mappings.
2017-11-05 14:13:39 -05:00
2018-03-27 23:36:55 -04:00
### [SDL2 Gamepad Tool](http://www.generalarcade.com/gamepadtool/)
2018-04-14 12:05:22 -04:00
Third party cross-platform tool with GUI (Windows, macOS and Linux). Likely the easiest tool to use.
2018-03-27 23:36:55 -04:00
2017-11-23 14:10:28 -03:00
### [SDL2 ControllerMap](https://www.libsdl.org/download-2.0.php)
The controllermap utility provided with SDL2 is the official tool to create these mappings, it runs on all the platforms SDL runs (Windows, Mac, Linux, iOS, Android, etc).
2017-10-14 19:08:21 -04:00
2017-11-05 14:13:39 -05:00
### [Steam](http://store.steampowered.com)
2017-10-14 19:08:21 -04:00
In Steam's Big Picture mode, configure your joystick. Then look in `[steam_installation_directory]/config/config.vdf` in your Steam installation directory for the `SDL_GamepadBind` entry. It is one of the last entries, it will look something like this.
2013-11-27 17:20:34 -03:00
```
2017-10-14 19:08:21 -04:00
"SDL_GamepadBind" "030000004c050000c405000000010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,"
2013-11-27 17:20:34 -03:00
```
2018-10-05 13:44:21 -04:00
Unfortunately, **Steam does not output the platform field**, so you will need to add it manually. At the end of the generated entry, add `platform:Windows,` or `platform:Mac OS X,` or `platform:Linux,` (with the trailing comma).
2018-01-20 14:38:37 -05:00
## Standard Mappings
Some controllers are a little tricky to figure out. Here are the recommended mappings.
![mapping standard](data/mapping_guide.png)
# Usage
2017-11-05 14:13:39 -05:00
Download gamecontrollerdb.txt, place it in your app's directory and load it.
2013-11-27 17:20:34 -03:00
2017-11-05 14:13:39 -05:00
For example :
2017-10-14 19:08:21 -04:00
```
2017-12-17 16:27:38 -05:00
SDL_GameControllerAddMappingsFromFile("gamecontrollerdb.txt");
2017-10-14 19:08:21 -04:00
```
2018-10-05 13:44:21 -04:00
## Upstream SDL Mappings
This project includes all mappings from the latest SDL_gamecontrollerdb.h. The community db adds a superset of mappings to the official ones, it does not modify them in any way.
If you ever wish to modify one of these mappings, you will need to send a PR directly to the SDL project. The changes will get pulled in the community db when a new SDL release occurs.
2017-10-14 19:08:21 -04:00
# For Contributors
2017-11-05 14:13:39 -05:00
## Check Your Mappings
2017-12-17 15:50:06 -05:00
The currently active version is gamecontrollerdb.txt. If your mappings work on older SDL versions, you can add them to the appropriate files.
2018-01-08 17:30:11 -05:00
Before submitting a new Pull Request, please run the `check.py` tool to make sure everything is in order.
2018-01-08 21:59:07 -05:00
Run it with:
```
2017-12-17 15:50:06 -05:00
python check.py gamecontrollerdb.txt
```
2018-01-09 11:57:53 -05:00
Once no issues are detected, run the script with the `--format` option to sort the database in the appropriate format.
2018-01-08 21:59:07 -05:00
```
python check.py --format gamecontrollerdb.txt
```
2018-01-09 11:57:53 -05:00
You may now send a Pull Request. Tests are automatically run on Pull Requests, so you'll easily see if there is an issue.
2017-10-14 19:08:21 -04:00
2018-01-20 19:39:32 -05:00
### Unit Tests
2018-01-08 21:59:07 -05:00
- GUID is correct length and is hexadecimal.
2018-01-20 19:39:32 -05:00
- GUID is in 2.0.5+ format.
2018-01-08 21:59:07 -05:00
- Platform is present and supported.
- Inversion and range modifiers are applied to axis fields.
- No duplicate mappings.
- No duplicate keys.
- Buttons conform to supported values.
2018-06-10 12:23:59 -04:00
- Hats aren't 0 or diagonals.
2018-01-20 19:39:32 -05:00
- No upstream official mappings are modified.
- All mappings end with a comma.
2018-01-08 21:59:07 -05:00
### Formatting
- The database is sorted by platform, then by name.
- Individual mapping keys are sorted alphabetically.
- Names are parsed for extraneous spaces.
2017-10-14 19:08:21 -04:00
### Options
```
2018-01-09 14:06:28 -05:00
usage: check.py [-h] [--format] [--convert_guids] [--add_missing_platform]
2018-01-09 16:33:42 -05:00
[--import_header sdl_header]
2018-01-09 14:06:28 -05:00
input_file
2017-10-14 19:08:21 -04:00
positional arguments:
2018-01-09 14:06:28 -05:00
input_file database file to check, ex. gamecontrollerdb.txt
2017-10-14 19:08:21 -04:00
optional arguments:
2018-01-09 14:06:28 -05:00
-h, --help show this help message and exit
--format sorts, formats and removes duplicates
--convert_guids convert Windows and macOS GUIDs to the newer SDL 2.0.5
2018-01-09 16:33:42 -05:00
format
2018-01-09 14:06:28 -05:00
--add_missing_platform
adds a platform field if it is missing on Windows and
2018-01-09 16:33:42 -05:00
Mac OS X 2.0.4 entries
--import_header sdl_header
imports and overrides mappings using
SDL_gamecontrollerdb.h
2017-10-14 19:08:21 -04:00
```
2018-08-18 13:35:58 -04:00
## Resources
2013-11-27 17:20:34 -03:00
* [SDL2](http://www.libsdl.org)
* [SDL_GameControllerAddMappingsFromFile](http://wiki.libsdl.org/SDL_GameControllerAddMappingsFromFile)