Skip to content

Commit

Permalink
Merge pull request #247 from Toufool/start-also-resets
Browse files Browse the repository at this point in the history
Option for start command to also reset
  • Loading branch information
Avasam authored Jul 9, 2023
2 parents 98f2b60 + f2b674a commit 27e3aec
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 12 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ If this option is enabled, when the last split meets the threshold and splits, A
If this option is disabled, when the last split meets the threshold and splits, AutoSplit will stop running comparisons.
This option does not loop single, specific images. See the Custom Split Image Settings section above for this feature.

#### Start also Resets

If this option is enabled, a "Start" command (ie: from the Start Image) will also send the "Reset" command. This is useful if you want to automatically restart your timer using the Start Image. Since AutoSplit won't be running and won't be checking for the Reset Image.

Having the reset image check be active at all time would be a better, more organic solution in the future. But that is dependent on migrating to an observer pattern (<https://github.com/Toufool/AutoSplit/issues/219>) and being able to reload all images.

#### Enable auto Reset Image

This option is mainly meant to be toggled with the `Toggle auto Reset Image` hotkey. You can enable it to temporarily disable the Reset Image if you make a mistake in your run that would cause the Reset Image to trigger. Like exiting back to the game's menu (aka Save&Quit).
Expand Down
34 changes: 27 additions & 7 deletions res/settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<x>0</x>
<y>0</y>
<width>285</width>
<height>274</height>
<height>294</height>
</rect>
</property>
<property name="minimumSize">
Expand All @@ -20,7 +20,7 @@
<property name="maximumSize">
<size>
<width>310</width>
<height>290</height>
<height>294</height>
</size>
</property>
<property name="font">
Expand All @@ -41,7 +41,7 @@
<x>-3</x>
<y>-3</y>
<width>291</width>
<height>281</height>
<height>301</height>
</rect>
</property>
<property name="currentIndex">
Expand Down Expand Up @@ -551,7 +551,7 @@ reset image</string>
<property name="geometry">
<rect>
<x>144</x>
<y>205</y>
<y>220</y>
<width>71</width>
<height>31</height>
</rect>
Expand Down Expand Up @@ -599,7 +599,7 @@ reset image</string>
<property name="geometry">
<rect>
<x>10</x>
<y>153</y>
<y>170</y>
<width>261</width>
<height>24</height>
</rect>
Expand Down Expand Up @@ -691,9 +691,9 @@ It is highly recommended to NOT use pHash if you use masked images, or it'll be
<property name="geometry">
<rect>
<x>10</x>
<y>180</y>
<y>200</y>
<width>261</width>
<height>71</height>
<height>61</height>
</rect>
</property>
<property name="font">
Expand Down Expand Up @@ -801,6 +801,25 @@ It is highly recommended to NOT use pHash if you use masked images, or it'll be
<string>Default Delay Time (ms):</string>
</property>
</widget>
<widget class="QCheckBox" name="start_also_resets_checkbox">
<property name="geometry">
<rect>
<x>10</x>
<y>150</y>
<width>261</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>Start also Resets</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="tristate">
<bool>false</bool>
</property>
</widget>
<zorder>custom_image_settings_info_label</zorder>
<zorder>default_delay_time_spinbox</zorder>
<zorder>enable_auto_reset_image_checkbox</zorder>
Expand All @@ -813,6 +832,7 @@ It is highly recommended to NOT use pHash if you use masked images, or it'll be
<zorder>default_pause_time_label</zorder>
<zorder>default_delay_time_label</zorder>
<zorder>readme_link_button</zorder>
<zorder>start_also_resets_checkbox</zorder>
</widget>
</widget>
</widget>
Expand Down
13 changes: 11 additions & 2 deletions src/hotkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,18 @@ def after_setting_hotkey(autosplit: AutoSplit):


def send_command(autosplit: AutoSplit, command: Commands):
# Note: Rather than having the start image able to also reset the timer,
# having the reset image check be active at all time would be a better, more organic solution,
# but that is dependent on migrating to an observer pattern (#219) and being able to reload all images.
if autosplit.is_auto_controlled:
if command == "start" and autosplit.settings_dict["start_also_resets"]:
print("reset", flush=True)
print(command, flush=True)
elif command in {"split", "start"}:
elif command == "start":
if autosplit.settings_dict["start_also_resets"]:
_send_hotkey(autosplit.settings_dict["reset_hotkey"])
_send_hotkey(autosplit.settings_dict["split_hotkey"])
elif command == "split":
_send_hotkey(autosplit.settings_dict["split_hotkey"])
elif command == "pause":
_send_hotkey(autosplit.settings_dict["pause_hotkey"])
Expand All @@ -64,7 +73,7 @@ def send_command(autosplit: AutoSplit, command: Commands):
_send_hotkey(autosplit.settings_dict["undo_split_hotkey"])

else:
raise KeyError(f"{command!r} is not a valid LiveSplit.AutoSplitIntegration command")
raise KeyError(f"{command!r} is not a valid command")


def _unhook(hotkey_callback: Callable[[], None] | None):
Expand Down
7 changes: 6 additions & 1 deletion src/menu_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def hotkey_connect(hotkey: Hotkey):
self.default_delay_time_spinbox.setValue(self.autosplit.settings_dict["default_delay_time"])
self.default_pause_time_spinbox.setValue(self.autosplit.settings_dict["default_pause_time"])
self.loop_splits_checkbox.setChecked(self.autosplit.settings_dict["loop_splits"])
self.start_also_resets_checkbox.setChecked(self.autosplit.settings_dict["start_also_resets"])
self.enable_auto_reset_image_checkbox.setChecked(self.autosplit.settings_dict["enable_auto_reset"])
# endregion
# region Binding
Expand Down Expand Up @@ -350,6 +351,9 @@ def hotkey_connect(hotkey: Hotkey):
self.loop_splits_checkbox.stateChanged.connect(
lambda: self.__set_value("loop_splits", self.loop_splits_checkbox.isChecked()),
)
self.start_also_resets_checkbox.stateChanged.connect(
lambda: self.__set_value("start_also_resets", self.start_also_resets_checkbox.isChecked()),
)
self.enable_auto_reset_image_checkbox.stateChanged.connect(
lambda: self.__set_value("enable_auto_reset", self.enable_auto_reset_image_checkbox.isChecked()),
)
Expand All @@ -375,7 +379,6 @@ def get_default_settings_from_ui(autosplit: AutoSplit):
"toggle_auto_reset_image_hotkey": default_settings_dialog.toggle_auto_reset_image_input.text(),
"fps_limit": default_settings_dialog.fps_limit_spinbox.value(),
"live_capture_region": default_settings_dialog.live_capture_region_checkbox.isChecked(),
"enable_auto_reset": default_settings_dialog.enable_auto_reset_image_checkbox.isChecked(),
"capture_method": CAPTURE_METHODS.get_method_by_index(
default_settings_dialog.capture_method_combobox.currentIndex(),
),
Expand All @@ -386,6 +389,8 @@ def get_default_settings_from_ui(autosplit: AutoSplit):
"default_delay_time": default_settings_dialog.default_delay_time_spinbox.value(),
"default_pause_time": default_settings_dialog.default_pause_time_spinbox.value(),
"loop_splits": default_settings_dialog.loop_splits_checkbox.isChecked(),
"start_also_resets": default_settings_dialog.start_also_resets_checkbox.isChecked(),
"enable_auto_reset": default_settings_dialog.enable_auto_reset_image_checkbox.isChecked(),
"split_image_directory": autosplit.split_image_folder_input.text(),
"screenshot_directory": default_settings_dialog.screenshot_directory_input.text(),
"open_screenshot": default_settings_dialog.open_screenshot_checkbox.isChecked(),
Expand Down
6 changes: 4 additions & 2 deletions src/user_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class UserProfileDict(TypedDict):
toggle_auto_reset_image_hotkey: str
fps_limit: int
live_capture_region: bool
enable_auto_reset: bool
capture_method: str | CaptureMethodEnum
capture_device_id: int
capture_device_name: str
Expand All @@ -35,6 +34,8 @@ class UserProfileDict(TypedDict):
default_delay_time: int
default_pause_time: float
loop_splits: bool
start_also_resets: bool
enable_auto_reset: bool
split_image_directory: str
screenshot_directory: str
open_screenshot: bool
Expand All @@ -52,7 +53,6 @@ class UserProfileDict(TypedDict):
toggle_auto_reset_image_hotkey="",
fps_limit=60,
live_capture_region=True,
enable_auto_reset=True,
capture_method=CAPTURE_METHODS.get_method_by_index(0),
capture_device_id=0,
capture_device_name="",
Expand All @@ -61,6 +61,8 @@ class UserProfileDict(TypedDict):
default_delay_time=0,
default_pause_time=10,
loop_splits=False,
start_also_resets=False,
enable_auto_reset=True,
split_image_directory="",
screenshot_directory="",
open_screenshot=True,
Expand Down

0 comments on commit 27e3aec

Please sign in to comment.