1010 from ...Emulator import Emulator
1111
1212
13+ def _build_long_config_name (name , buttons , axes , hats ):
14+ # e.g.: "Xbox Wireless Controller", 11, 6, 1 → "xbox_wireless_controller_11_6_1_0_linux"
15+ name = name .split ('#' )[0 ].lower ().strip ()
16+ for c in name :
17+ if not c .isalnum () and c != '_' :
18+ name = name .replace (c , '_' )
19+ # collapse consecutive underscores
20+ while '__' in name :
21+ name = name .replace ('__' , '_' )
22+ name = name .strip ('_' )
23+ return f"{ name } _{ buttons } _{ axes } _{ hats } _0_linux"
24+
1325# Create the controller configuration file
1426def generateControllerConfig (system : Emulator , playersControllers : Controllers ) -> None :
1527
@@ -36,37 +48,46 @@ def generateControllerConfig(system: Emulator, playersControllers: Controllers)
3648 mkdir_if_not_exists (confDirectory )
3749
3850 for pad in playersControllers :
39- configFileName = confDirectory / f"{ pad .guid } _linux.conf"
40- f = configFileName .open ("w" )
41-
42- # fs-uae-controller
43- f .write ("[fs-uae-controller]\n " )
44- f .write (f"name = { pad .real_name } \n " )
45- f .write ("platform = linux\n " )
46- f .write ("\n " )
47-
48- # events
49- f .write ("[default]\n " )
50- f .write ("include = universal_gamepad\n " )
51+ # Build mapping lines to reuse for both config files
52+ mapping_lines = []
5153
5254 for x in pad .inputs :
5355 input = pad .inputs [x ]
5456 #f.write(f"# undefined key: name={input.name}, type={input.type}, id={input.id}, value={input.value}\n")
5557
5658 if input .name in fsuaeMapping :
5759 if input .type == "button" :
58- f . write (f"button_{ input .id } = { fsuaeMapping [input .name ]} \n " )
60+ mapping_lines . append (f"button_{ input .id } = { fsuaeMapping [input .name ]} \n " )
5961 elif input .type == "hat" :
6062 if input .value in fsuaeHatMapping :
61- f . write (f"hat_{ input .id } _{ fsuaeHatMapping [input .value ]} = { fsuaeMapping [input .name ]} \n " )
63+ mapping_lines . append (f"hat_{ input .id } _{ fsuaeHatMapping [input .value ]} = { fsuaeMapping [input .name ]} \n " )
6264 elif input .type == "axis" :
6365 if input .value == "1" :
6466 axis_valstr = "pos"
6567 revaxis_valstr = "neg"
6668 else :
6769 axis_valstr = "neg"
6870 revaxis_valstr = "pos"
69- f . write (f"axis_{ input .id } _{ axis_valstr } = { fsuaeMapping [input .name ]} \n " )
71+ mapping_lines . append (f"axis_{ input .id } _{ axis_valstr } = { fsuaeMapping [input .name ]} \n " )
7072 if input .name in fsuaeReverseAxisMapping and fsuaeReverseAxisMapping [input .name ] in fsuaeMapping :
71- f .write (f"axis_{ input .id } _{ revaxis_valstr } = { fsuaeMapping [fsuaeReverseAxisMapping [input .name ]]} \n " )
72- f .close ()
73+ mapping_lines .append (f"axis_{ input .id } _{ revaxis_valstr } = { fsuaeMapping [fsuaeReverseAxisMapping [input .name ]]} \n " )
74+
75+ # Write config for both GUID lookup (joystick config) and long-name lookup (menu config)
76+ long_name = _build_long_config_name (pad .real_name , pad .button_count , pad .axis_count , pad .hat_count )
77+ for config_name in [pad .guid .lower (), long_name ]:
78+ configFileName = confDirectory / f"{ config_name } .conf"
79+ f = configFileName .open ("w" )
80+
81+ # fs-uae-controller
82+ f .write ("[fs-uae-controller]\n " )
83+ f .write (f"name = { pad .real_name } \n " )
84+ f .write ("platform = linux\n " )
85+ f .write ("\n " )
86+
87+ # events
88+ f .write ("[default]\n " )
89+ f .write ("include = universal_gamepad\n " )
90+
91+ for line in mapping_lines :
92+ f .write (line )
93+ f .close ()
0 commit comments