From d6362455b2e6b98a5fbd0015bca62f9c7a0a990d Mon Sep 17 00:00:00 2001 From: Shute052 Date: Tue, 20 Feb 2024 04:09:36 +0800 Subject: [PATCH] Release the pressed clashed `ActionData` --- src/clashing_inputs.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/clashing_inputs.rs b/src/clashing_inputs.rs index e9255c7a..740a384a 100644 --- a/src/clashing_inputs.rs +++ b/src/clashing_inputs.rs @@ -92,9 +92,19 @@ impl InputMap { clash_strategy: ClashStrategy, ) { for clash in self.get_clashes(action_data, input_streams) { - // Reset the action in the pair that was overruled, if any if let Some(culled_action) = resolve_clash(&clash, clash_strategy, input_streams) { - action_data.insert(culled_action, ActionData::default()); + let culled_action_data = action_data + .raw_entry_mut() + .from_key(&culled_action) + .or_insert_with(|| (culled_action.clone(), ActionData::default())) + .1; + if culled_action_data.state.pressed() { + // Reset the pressed action in the pair that was overruled, if any + culled_action_data.state.release(); + } else { + // Remove the released action in the pair that was overruled, if any + action_data.remove(&culled_action); + } } } }