diff --git a/joystick_diagrams/input/profile.py b/joystick_diagrams/input/profile.py index 55aaa09..e5af49b 100644 --- a/joystick_diagrams/input/profile.py +++ b/joystick_diagrams/input/profile.py @@ -1,6 +1,7 @@ import logging from copy import deepcopy +from joystick_diagrams.input.button import Button from joystick_diagrams.input.device import Device_ _logger = logging.getLogger("__name__") @@ -49,20 +50,21 @@ def merge_profiles(self, profile: "Profile_"): else: # If the device exists in the current profile, merge inputs existing_device = src_profile.devices[guid] - for input_id, input_ in device.inputs.items(): - if input_id not in existing_device.inputs: - # If the input is not in the existing device, deepcopy the input - existing_device.inputs[input_id] = deepcopy(input_) - else: - # If the input exists, merge modifiers - existing_input = existing_device.inputs[input_id] - for modifier in input_.modifiers: - existing_modifier = existing_input._check_existing_modifier(modifier.modifiers) - if existing_modifier is None: - existing_input.modifiers.append(deepcopy(modifier)) - else: - # If the modifier exists, update the command with the supplied profile value - existing_modifier.command = modifier.command + for input_type, inputs in device.inputs.items(): + for input_key, input_ in inputs.items(): + if input_key not in existing_device.inputs[input_type]: + # If the input is not in the existing device, deepcopy the input + existing_device.inputs[input_type][input_key] = deepcopy(input_) + else: + # If the input exists, merge modifiers + existing_input = existing_device.inputs[input_type][input_key] + for modifier in input_.modifiers: + existing_modifier = existing_input._check_existing_modifier(modifier.modifiers) + if existing_modifier is None: + existing_input.modifiers.append(deepcopy(modifier)) + else: + # If the modifier exists, update the command with the supplied profile value + existing_modifier.command = modifier.command return src_profile @@ -71,24 +73,16 @@ def merge_profiles(self, profile: "Profile_"): profile1 = Profile_("Profile1") dev1 = profile1.add_device("dev_1", "dev_1") - dev2 = profile1.add_device("dev_2", "dev_2") + dev1.create_input(Button(1), "shoot") - dev1.create_input("input1", "shoot") - dev2.create_input("input2", "fly") - - dev1.add_modifier_to_input("input1", {"ctrl"}, "bang") - dev1.add_modifier_to_input("input1", {"alt"}, "bang again") + dev1.add_modifier_to_input(Button(1), {"ctrl"}, "bang") + dev1.add_modifier_to_input(Button(1), {"alt"}, "bang again") profile2 = Profile_("Profile2") dev3 = profile2.add_device("dev_1", "dev_1") - dev4 = profile2.add_device("dev_2", "dev_2") - - dev3.create_input("input1", "potato") - - dev3.add_modifier_to_input("input1", {"ctrl"}, "hello") - dev1.add_modifier_to_input("input1", {"ctrl", "alt", "space"}, "bang again again") - - dev4.create_input("input4", "another") + dev3.create_input(Button(3), "potato") + dev3.add_modifier_to_input(Button(1), {"ctrl"}, "hello") - profile1.merge_profiles(profile2) + data = profile1.merge_profiles(profile2) + print(data)