Skip to content

Commit a4e74b0

Browse files
authored
Merge pull request #3362 from dankcushions/buttonlabels
Use Libretro's RetroArch joypad autoconfig presets to generate button labels
2 parents 294db24 + d6a78a2 commit a4e74b0

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

scriptmodules/emulators/retroarch.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,15 @@ function update_overlays_retroarch() {
9191
local dir="$configdir/all/retroarch/overlay"
9292
# remove if not a git repository for fresh checkout
9393
[[ ! -d "$dir/.git" ]] && rm -rf "$dir"
94-
gitPullOrClone "$configdir/all/retroarch/overlay" https://github.com/libretro/common-overlays.git
94+
gitPullOrClone "$dir" https://github.com/libretro/common-overlays.git
9595
chown -R $user:$user "$dir"
9696
}
9797

98+
function update_joypad_autoconfigs_retroarch() {
99+
gitPullOrClone "$md_build/autoconfigs" https://github.com/libretro/retroarch-joypad-autoconfig.git
100+
cp -a "$md_build/autoconfigs/." "$md_inst/autoconfig-presets/"
101+
}
102+
98103
function update_assets_retroarch() {
99104
local dir="$configdir/all/retroarch/assets"
100105
# remove if not a git repository for fresh checkout
@@ -141,6 +146,9 @@ function configure_retroarch() {
141146
# install minimal assets
142147
install_minimal_assets_retroarch
143148

149+
# install joypad autoconfig presets
150+
update_joypad_autoconfigs_retroarch
151+
144152
local config="$(mktemp)"
145153

146154
cp "$md_inst/retroarch.cfg" "$config"

scriptmodules/supplementary/emulationstation/configscripts/retroarch.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ function map_retroarch_joystick() {
239239
local value
240240
local type
241241
declare -A hat_map=([1]="up" [2]="right" [4]="down" [8]="left")
242+
iniGet "input_driver"
243+
local input_driver="$ini_value"
244+
local autoconfig_preset=$(grep -rwl "$rootdir/emulators/retroarch/autoconfig-presets/$input_driver" -e "$DEVICE_NAME" | head -1)
242245
for key in "${keys[@]}"; do
243246
case "$input_type" in
244247
hat)
@@ -260,8 +263,7 @@ function map_retroarch_joystick() {
260263
value="$input_id"
261264

262265
# workaround for mismatched controller mappings
263-
iniGet "input_driver"
264-
if [[ "$ini_value" == "udev" ]]; then
266+
if [[ "$input_driver" == "udev" ]]; then
265267
case "$DEVICE_NAME" in
266268
"8Bitdo FC30"*|"8Bitdo NES30"*|"8Bitdo SFC30"*|"8Bitdo SNES30"*|"8Bitdo Zero"*)
267269
if [[ "$_atebitdo_hack" -eq 1 ]]; then
@@ -277,6 +279,16 @@ function map_retroarch_joystick() {
277279
fi
278280
key+="_$type"
279281
iniSet "$key" "$value"
282+
283+
# set button labels from autoconfig preset (if available), when binding matches the preset
284+
if [[ -f "$autoconfig_preset" ]]; then
285+
iniGet "$key" "$autoconfig_preset"
286+
if [[ "$ini_value" == "$value" ]]; then
287+
key+="_label"
288+
iniGet "$key" "$autoconfig_preset"
289+
[[ -n "$ini_value" ]] && iniSet "$key" "$ini_value"
290+
fi
291+
fi
280292
done
281293
}
282294

0 commit comments

Comments
 (0)