Skip to content

Commit

Permalink
Bug Fix for #84
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexeh committed Sep 8, 2024
1 parent f1bdd1c commit ffb7210
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 9 additions & 0 deletions joystick_diagrams/input/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,30 @@ def merge_profiles(self, profile: "Profile_"):
src_profile = deepcopy(self)

for guid, device in profile.devices.items():
_logger.debug(f"Handling {guid=} and {device=}")
if guid not in src_profile.devices:
# If the device is not in the current profile, deepcopy the entire device
_logger.debug(f"Device {guid=} not found so adding whole device")
src_profile.devices[guid] = deepcopy(device)
else:
# If the device exists in the current profile, merge inputs
existing_device = src_profile.devices[guid]
_logger.debug(f"Existing device is {existing_device=}")
for input_type, inputs in device.inputs.items():
_logger.debug(f"Processing {input_type} and {inputs=}")
for input_key, input_ in inputs.items():
_logger.debug(f"Processing {input_key} and {input_=}")
if input_key not in existing_device.inputs[input_type]:
_logger.debug(
f"Input key not found, so adding whole key {input_key=}"
)
# 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
_logger.debug(f"Input key exists {input_key=}")
existing_input = existing_device.inputs[input_type][
input_key
]
Expand Down
8 changes: 6 additions & 2 deletions joystick_diagrams/profile_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ def get_parents_for_profile(self):
_wrapper = [
x for x in _state.profile_wrappers if x.profile_key == parent_key
]
_logger.debug(f"Profiles fond {_wrapper}")
_logger.debug(f"Profiles found {_wrapper}")
if _wrapper:
_logger.debug(f"Appending profile to parents {_wrapper}")
self.parents.append(_wrapper[0])

def update_parents_for_profile(self, parents: list["ProfileWrapper"]):
Expand All @@ -70,9 +71,12 @@ def inherit_parents_into_profile(self):
_parents = self.parents # Reverse list to flip obj >> parent
_parents.reverse()

_logger.debug(f"Parents are {_parents}")

merged_profiles = deepcopy(self.original_profile)

for parent in _parents[:1]:
for parent in _parents:
_logger.debug(f"Processing {parent=}")
obj = deepcopy(parent.original_profile)
merged_profiles = merged_profiles.merge_profiles(obj)

Expand Down

0 comments on commit ffb7210

Please sign in to comment.