update the code which parses controller inputs

This commit is contained in:
otavepto 2024-02-17 10:15:25 +02:00
parent 210c86c1a3
commit c1d1779624
3 changed files with 51 additions and 34 deletions

View File

@ -1,5 +1,6 @@
* generate_emu_config: allow setting the steam id of apps/games owners from an external file `top_owners_ids.txt` beside the script, suggested by **[M4RCK5]** * generate_emu_config: allow setting the steam id of apps/games owners from an external file `top_owners_ids.txt` beside the script, suggested by **[M4RCK5]**
* generate_emu_config: support the new format for `supported_languages` * generate_emu_config: support the new format for `supported_languages`
* generate_emu_config: update the code which parses controller inputs
* generate_emu_config: always use the directory of the script for: the data `backup` folder, the `login_temp` folder, the `my_login.txt` file * generate_emu_config: always use the directory of the script for: the data `backup` folder, the `login_temp` folder, the `my_login.txt` file
--- ---

View File

@ -19,8 +19,8 @@ keymap_digital = {
"right_bumper": "RBUMPER", "right_bumper": "RBUMPER",
"button_back_left": "A", "button_back_left": "A",
"button_back_right": "X", "button_back_right": "X",
"": "", "button_back_left_upper": "B",
"": "", "button_back_right_upper": "Y",
"": "", "": "",
"": "", "": "",
"": "", "": "",
@ -33,19 +33,31 @@ def add_input_bindings(group, bindings, force_binding=None, keymap=keymap_digita
for fp in group["inputs"][i][act]: for fp in group["inputs"][i][act]:
for bd in group["inputs"][i][act][fp]: for bd in group["inputs"][i][act][fp]:
for bbd in group["inputs"][i][act][fp][bd]: for bbd in group["inputs"][i][act][fp][bd]:
if bbd == 'binding': if bbd.lower() == 'binding':
x = group["inputs"][i][act][fp][bd].get_all_for(bbd) x = group["inputs"][i][act][fp][bd].get_all_for(bbd)
for ss in x: for ss in x:
st = ss.split() st = ss.split()
if st[0] == 'game_action': supported_binding = False
if st[0].lower() == 'game_action':
supported_binding = True
if st[2][-1] == ",": if st[2][-1] == ",":
action_name = st[2][:-1] action_name = st[2][:-1]
else: else:
action_name = st[2][:] action_name = st[2][:]
elif st[0].lower() == 'xinput_button':
supported_binding = True
if st[1][-1] == ",":
action_name = st[1][:-1]
else:
action_name = st[1][:]
if supported_binding:
if force_binding is None: if force_binding is None:
binding = keymap[i.lower()] binding = keymap.get(i.lower(), None)
else: else:
binding = force_binding binding = force_binding
if binding:
if action_name in bindings: if action_name in bindings:
if binding not in bindings[action_name]: if binding not in bindings[action_name]:
bindings[action_name].append(binding) bindings[action_name].append(binding)
@ -74,29 +86,29 @@ def generate_controller_config(controller_vdf, config_dir):
all_bindings = {} all_bindings = {}
for p in presets: for p in presets:
name = p["name"] name = p["name"]
if name not in action_list: if (name not in action_list) and name.lower() != 'default':
continue continue
group_bindings = p["group_source_bindings"] group_bindings = p["group_source_bindings"]
bindings = {} bindings = {}
for number in group_bindings: for number in group_bindings:
s = group_bindings[number].split() s = group_bindings[number].split()
if s[1] != "active": if s[1].lower() != "active":
continue continue
#print(s) #print(s)
if s[0] in ["switch", "button_diamond", "dpad"]: if s[0].lower() in ["switch", "button_diamond", "dpad"]:
group = groups_byid[number] group = groups_byid[number]
#print(group) #print(group)
bindings = add_input_bindings(group, bindings) bindings = add_input_bindings(group, bindings)
if s[0] in ["left_trigger", "right_trigger"]: if s[0].lower() in ["left_trigger", "right_trigger"]:
group = groups_byid[number] group = groups_byid[number]
if group["mode"] == "trigger": if group["mode"].lower() == "trigger":
for g in group: for g in group:
if g == "gameactions": if g.lower() == "gameactions":
#print(group) #print(group)
action_name = group["gameactions"][name] action_name = group["gameactions"][name]
if s[0] == "left_trigger": if s[0].lower() == "left_trigger":
binding = "LTRIGGER" binding = "LTRIGGER"
else: else:
binding = "RTRIGGER" binding = "RTRIGGER"
@ -105,8 +117,8 @@ def generate_controller_config(controller_vdf, config_dir):
bindings[action_name].insert(0, binding) bindings[action_name].insert(0, binding)
else: else:
bindings[action_name] = [binding + "=trigger"] bindings[action_name] = [binding + "=trigger"]
if g == "inputs": if g.lower() == "inputs":
if s[0] == "left_trigger": if s[0].lower() == "left_trigger":
binding = "DLTRIGGER" binding = "DLTRIGGER"
else: else:
binding = "DRTRIGGER" binding = "DRTRIGGER"
@ -114,18 +126,19 @@ def generate_controller_config(controller_vdf, config_dir):
else: else:
print("unhandled trigger mode", group["mode"]) print("unhandled trigger mode", group["mode"])
if s[0] in ["joystick", "right_joystick", "dpad"]:
if s[0].lower() in ["joystick", "right_joystick", "dpad"]:
group = groups_byid[number] group = groups_byid[number]
if group["mode"] == "joystick_move": if group["mode"].lower() == "joystick_move":
for g in group: for g in group:
if g == "gameactions": if g.lower() == "gameactions":
#print(group) #print(group)
action_name = group["gameactions"][name] action_name = group["gameactions"][name]
if s[0] == "joystick": if s[0].lower() == "joystick":
binding = "LJOY" binding = "LJOY"
elif s[0] == "right_joystick": elif s[0].lower() == "right_joystick":
binding = "RJOY" binding = "RJOY"
elif s[0] == "dpad": elif s[0].lower() == "dpad":
binding = "DPAD" binding = "DPAD"
else: else:
print("could not handle", s[0]) print("could not handle", s[0])
@ -134,22 +147,22 @@ def generate_controller_config(controller_vdf, config_dir):
bindings[action_name].insert(0, binding) bindings[action_name].insert(0, binding)
else: else:
bindings[action_name] = [binding + "=joystick_move"] bindings[action_name] = [binding + "=joystick_move"]
if g == "inputs": if g.lower() == "inputs":
if s[0] == "joystick": if s[0].lower() == "joystick":
binding = "LSTICK" binding = "LSTICK"
else: else:
binding = "RSTICK" binding = "RSTICK"
bindings = add_input_bindings(group, bindings, binding) bindings = add_input_bindings(group, bindings, binding)
elif group["mode"] == "dpad": elif group["mode"].lower() == "dpad":
if s[0] == "joystick": if s[0].lower() == "joystick":
binding_map = {"dpad_north":"DLJOYUP", "dpad_south": "DLJOYDOWN", "dpad_west": "DLJOYLEFT", "dpad_east": "DLJOYRIGHT", "click": "LSTICK"} binding_map = {"dpad_north":"DLJOYUP", "dpad_south": "DLJOYDOWN", "dpad_west": "DLJOYLEFT", "dpad_east": "DLJOYRIGHT", "click": "LSTICK"}
bindings = add_input_bindings(group, bindings, keymap=binding_map) bindings = add_input_bindings(group, bindings, keymap=binding_map)
elif s[0] == "right_joystick": elif s[0].lower() == "right_joystick":
binding_map = {"dpad_north":"DRJOYUP", "dpad_south": "DRJOYDOWN", "dpad_west": "DRJOYLEFT", "dpad_east": "DRJOYRIGHT", "click": "RSTICK"} binding_map = {"dpad_north":"DRJOYUP", "dpad_south": "DRJOYDOWN", "dpad_west": "DRJOYLEFT", "dpad_east": "DRJOYRIGHT", "click": "RSTICK"}
bindings = add_input_bindings(group, bindings, keymap=binding_map) bindings = add_input_bindings(group, bindings, keymap=binding_map)
else: else:
if s[0] != "dpad": if s[0].lower() != "dpad":
print("no pad", s[0]) print("no pad", s[0])
else: else:
print("unhandled joy mode", group["mode"]) print("unhandled joy mode", group["mode"])

View File

@ -787,6 +787,7 @@ def main():
if "config" in game_info: if "config" in game_info:
if "steamcontrollerconfigdetails" in game_info["config"]: if "steamcontrollerconfigdetails" in game_info["config"]:
controller_details = game_info["config"]["steamcontrollerconfigdetails"] controller_details = game_info["config"]["steamcontrollerconfigdetails"]
print('downloading controller vdf files')
for id in controller_details: for id in controller_details:
details = controller_details[id] details = controller_details[id]
controller_type = "" controller_type = ""
@ -795,10 +796,12 @@ def main():
controller_type = details["controller_type"] controller_type = details["controller_type"]
if "enabled_branches" in details: if "enabled_branches" in details:
enabled_branches = details["enabled_branches"] enabled_branches = details["enabled_branches"]
print(id, controller_type) print(f'downloading controller data, file id = {id}, controller type = {controller_type}')
out_vdf = download_published_file(client, int(id), os.path.join(backup_dir, controller_type + str(id)))
out_vdf = download_published_file(client, int(id), os.path.join(backup_dir, f'{controller_type}-{str(id)}'))
if out_vdf is not None and not config_generated: if out_vdf is not None and not config_generated:
if (controller_type in ["controller_xbox360", "controller_xboxone"] and (("default" in enabled_branches) or ("public" in enabled_branches))): if (controller_type in ["controller_xbox360", "controller_xboxone", "controller_steamcontroller_gordon"] and (("default" in enabled_branches) or ("public" in enabled_branches))):
print(f'controller type is supported')
parse_controller_vdf.generate_controller_config(out_vdf.decode('utf-8'), os.path.join(emu_settings_dir, "controller")) parse_controller_vdf.generate_controller_config(out_vdf.decode('utf-8'), os.path.join(emu_settings_dir, "controller"))
config_generated = True config_generated = True
if "steamcontrollertouchconfigdetails" in game_info["config"]: if "steamcontrollertouchconfigdetails" in game_info["config"]: