From 31783cc10f28baee7c6f0cd06cce9b032296b8a0 Mon Sep 17 00:00:00 2001
From: CrispyPin <crispin@tasa.se>
Date: Sun, 13 Apr 2025 22:34:42 +0200
Subject: [PATCH] fix stop sim binding not working when bound to the same thing
 as start

---
 CHANGELOG.md  |  1 +
 src/editor.rs | 21 ++++++++++++---------
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 58f2ef8..651c1b8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ Game store page: https://crispypin.itch.io/marble-machinations
 - click to collapse chapters in level list
 - input bindings for eraser (X), selection (B), blueprint list (Ctrl B), no tool (no default binding)
 ### fixed
+- when start and stop are bound to the same thing (as by default), only start works
 - When two input bindings had the same trigger but one has a strict subset of the others modifiers, both would activate when the one with more modifiers was pressed. For example (Ctrl+S -> Save) would also trigger (S -> Wire Tool). Now, Shift+S will still trigger Wire Tool, unless Shift+S (or eg. Shift+Ctrl+S) is bound to something else.
 
 ## v0.3.1 - 2025-04-05
diff --git a/src/editor.rs b/src/editor.rs
index 47537d6..f8fa6a1 100644
--- a/src/editor.rs
+++ b/src/editor.rs
@@ -478,22 +478,25 @@ impl Editor {
 		if globals.is_pressed(ActionId::StepSim) {
 			self.step_pressed()
 		}
-		if globals.is_pressed(ActionId::StartSim) {
-			match self.sim_state {
-				SimState::Editing => {
+		match self.sim_state {
+			SimState::Editing => {
+				if globals.is_pressed(ActionId::StartSim) {
 					self.init_sim();
 					self.sim_state = SimState::Running;
 				}
-				SimState::Stepping => self.sim_state = SimState::Running,
-				SimState::Running => (),
 			}
-		} else if globals.is_pressed(ActionId::StopSim) {
-			match self.sim_state {
-				SimState::Running | SimState::Stepping => {
+			SimState::Stepping => {
+				if globals.is_pressed(ActionId::StartSim) {
+					self.sim_state = SimState::Running
+				} else if globals.is_pressed(ActionId::StopSim) {
 					self.sim_state = SimState::Editing;
 					self.popup = Popup::None;
 				}
-				SimState::Editing => (),
+			}
+			SimState::Running => {
+				if globals.is_pressed(ActionId::StopSim) {
+					self.sim_state = SimState::Editing;
+				}
 			}
 		}