eranheres / ultra_type

0 stars 0 forks source link

sweep: add options in settings submenu to toggle click sound #45

Closed eranheres closed 11 months ago

eranheres commented 11 months ago

choosing the option will toggle on/off the sound. this settings will be save to the settings the following files are relevant: controller.py view.py clicker.py model.py

Checklist - [X] Modify `ultra_type/controller.py` ✓ https://github.com/eranheres/ultra_type/commit/2651e51b6f102c1c58dad7365116a86d0b929c10 [Edit](https://github.com/eranheres/ultra_type/edit/sweep/toggle-click-sound/ultra_type/controller.py) - [X] Running GitHub Actions for `ultra_type/controller.py` ✓ [Edit](https://github.com/eranheres/ultra_type/edit/sweep/toggle-click-sound/ultra_type/controller.py) - [X] Modify `ultra_type/view.py` ✓ https://github.com/eranheres/ultra_type/commit/0878d5dc5a41f0c80994b0386d2e7e19b4eb28bf [Edit](https://github.com/eranheres/ultra_type/edit/sweep/toggle-click-sound/ultra_type/view.py) - [X] Running GitHub Actions for `ultra_type/view.py` ✓ [Edit](https://github.com/eranheres/ultra_type/edit/sweep/toggle-click-sound/ultra_type/view.py) - [X] Modify `ultra_type/clicker.py` ✓ https://github.com/eranheres/ultra_type/commit/58ed5ed17d67770eb55897bed508d5e656374dac [Edit](https://github.com/eranheres/ultra_type/edit/sweep/toggle-click-sound/ultra_type/clicker.py) - [X] Running GitHub Actions for `ultra_type/clicker.py` ✓ [Edit](https://github.com/eranheres/ultra_type/edit/sweep/toggle-click-sound/ultra_type/clicker.py) - [X] Modify `ultra_type/model.py` ✓ https://github.com/eranheres/ultra_type/commit/7ea47fc5f08c6d8e8db1cfe668fec1c528bc54e2 [Edit](https://github.com/eranheres/ultra_type/edit/sweep/toggle-click-sound/ultra_type/model.py) - [X] Running GitHub Actions for `ultra_type/model.py` ✓ [Edit](https://github.com/eranheres/ultra_type/edit/sweep/toggle-click-sound/ultra_type/model.py) ![Flowchart](https://raw.githubusercontent.com/eranheres/ultra_type/sweep/assets/4461f1a1d94b0998092b85a5795bbc69484ffa3f24d4ec25c7d7e4f7c3c31e47_45_flowchart.svg)
sweep-mine[bot] commented 11 months ago

Here's the PR! https://github.com/eranheres/ultra_type/pull/46. See Sweep's process at dashboard.

💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: f23c35a9eb)

Actions (click)

Sandbox Execution ✓

Here are the sandbox execution logs prior to making any changes:

Sandbox logs for 11f850a
Checking ultra_type/controller.py for syntax errors... ✅ ultra_type/controller.py has no syntax errors! 1/1 ✓
Checking ultra_type/controller.py for syntax errors...
✅ ultra_type/controller.py has no syntax errors!

Sandbox passed on the latest main, so sandbox checks will be enabled for this issue.


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/eranheres/ultra_type/blob/11f850afd5c3f6b7bb8361e0dc24ac2d724459b9/ultra_type/controller.py#L72-L98 https://github.com/eranheres/ultra_type/blob/11f850afd5c3f6b7bb8361e0dc24ac2d724459b9/ultra_type/clicker.py#L1-L23 https://github.com/eranheres/ultra_type/blob/11f850afd5c3f6b7bb8361e0dc24ac2d724459b9/ultra_type/model.py#L50-L70 https://github.com/eranheres/ultra_type/blob/11f850afd5c3f6b7bb8361e0dc24ac2d724459b9/ultra_type/view.py#L1-L46

Step 2: ⌨️ Coding

--- 
+++ 
@@ -84,6 +84,8 @@
             self._change_lang()
         elif action == '2':
             self._change_practice()
+        elif action == '3':
+            self.model.toggle_click_sound()

 if __name__ == '__main__':
     model = Model()

Ran GitHub Actions for 2651e51b6f102c1c58dad7365116a86d0b929c10:

--- 
+++ 
@@ -48,7 +48,8 @@
         header = "Settings Menu"
         return self._display_menu(header=header, options=[
             "Change language",
-            "Change practice"])
+            "Change practice",
+            "Toggle click sound"])

     def show_language_menu(self):
         return self._display_menu(header="Choose language:", options=[

Ran GitHub Actions for 0878d5dc5a41f0c80994b0386d2e7e19b4eb28bf:

--- 
+++ 
@@ -5,6 +5,7 @@
 class Clicker:

     def __init__(self):
+        self.sound_enabled = True # Store state of the click sound
         # Initialize Pygame Mixer
         try:
             pygame.mixer.init()
@@ -18,7 +19,11 @@
             return
         try:
             self._click_sound.set_volume(random.random() * 0.5 + 0.5)
-            #self._click_sound.play()
+            if self.sound_enabled: # Check if sound is enabled before playing
+                self._click_sound.play()
         except Exception as e:
             print(f"Error playing sound: {e}")

+    def toggle_sound(self):
+        self.sound_enabled = not self.sound_enabled # Toggle the state of the click sound
+

Ran GitHub Actions for 58ed5ed17d67770eb55897bed508d5e656374dac:

--- 
+++ 
@@ -1,6 +1,7 @@
 from ultra_type.database import Database
 from ultra_type.languages.language import Language
 from ultra_type.statistics import Statistics
+from ultra_type.clicker import Clicker
 import datetime
 import importlib

@@ -8,6 +9,8 @@

     def __init__(self):
         self.database = Database(db_name="ultra_type.db", stats_fields=Statistics.FIELD_STRACTURE)
+        self.clicker = Clicker()
+        self.click_sound_enabled = self.clicker.sound_enabled
         self.load_setting()

     @property
@@ -23,9 +26,21 @@
         self._language = lang
         self._statistics = Statistics(self.database.load_stats(self.language.name))

+    def toggle_click_sound(self):
+        self.clicker.toggle_sound()
+        self.click_sound_enabled = self.clicker.sound_enabled
+
     @property
     def practice(self):
         return self._practice
+
+    @property
+    def click_sound_enabled(self):
+        return self._click_sound_enabled
+
+    @click_sound_enabled.setter
+    def click_sound_enabled(self, value: bool):
+        self._click_sound_enabled = value

     @practice.setter
     def practice(self, practice):
@@ -55,6 +70,7 @@
             "practice": self.practice.__class__.__name__,
             "practice_attributes": attr
         }
+        settings['click_sound_enabled'] = self.click_sound_enabled
         self.database.save_settings(settings)

     def load_setting(self):
@@ -67,5 +83,6 @@
         self.language = getattr(module, settings["language"])()
         module = importlib.import_module("ultra_type.practices.practice")
         self.practice = getattr(module, settings["practice"])()
+        self.click_sound_enabled = settings.get('click_sound_enabled', True)
         if "practice_attributes" in settings:
             self.practice.attributes = settings["practice_attributes"]

Ran GitHub Actions for 7ea47fc5f08c6d8e8db1cfe668fec1c528bc54e2:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/toggle-click-sound.


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord