From 7b2df2239daaf123bbc9805d281a24902c993afc Mon Sep 17 00:00:00 2001 From: Sumwatt <172867164+Sumwatt0@users.noreply.github.com> Date: Thu, 8 Aug 2024 03:55:20 -0400 Subject: [PATCH 1/5] Cleaned Tabs Code In Camp Selection --- scripts/screens/MakeClanScreen.py | 32 ++++++------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/scripts/screens/MakeClanScreen.py b/scripts/screens/MakeClanScreen.py index 6d48486b38..75bfb5e6df 100644 --- a/scripts/screens/MakeClanScreen.py +++ b/scripts/screens/MakeClanScreen.py @@ -892,32 +892,12 @@ def refresh_selected_camp(self): manager=MANAGER, ) - - if self.selected_camp_tab == 1: - self.tabs["tab1"].disable() - self.tabs["tab2"].enable() - self.tabs["tab3"].enable() - self.tabs["tab4"].enable() - elif self.selected_camp_tab == 2: - self.tabs["tab1"].enable() - self.tabs["tab2"].disable() - self.tabs["tab3"].enable() - self.tabs["tab4"].enable() - elif self.selected_camp_tab == 3: - self.tabs["tab1"].enable() - self.tabs["tab2"].enable() - self.tabs["tab3"].disable() - self.tabs["tab4"].enable() - elif self.selected_camp_tab == 4: - self.tabs["tab1"].enable() - self.tabs["tab2"].enable() - self.tabs["tab3"].enable() - self.tabs["tab4"].disable() - else: - self.tabs["tab1"].enable() - self.tabs["tab2"].enable() - self.tabs["tab3"].enable() - self.tabs["tab4"].enable() + # Disables the selected camp tab, enables others. + for i in range(1, 5): + if i == self.selected_camp_tab: + self.tabs["tab"+str(i)].disable() + else: + self.tabs["tab"+str(i)].enable() # I have to do this for proper layering. if "camp_art" in self.elements: From faa383776eb4e9a3f2305b6ecbb31d7aae2e12c7 Mon Sep 17 00:00:00 2001 From: Sumwatt <172867164+Sumwatt0@users.noreply.github.com> Date: Thu, 8 Aug 2024 16:59:59 -0400 Subject: [PATCH 2/5] Simplified Tab Code in MakeClanScreen Loops throught the tabs instead of checking each one manually. --- scripts/screens/MakeClanScreen.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/scripts/screens/MakeClanScreen.py b/scripts/screens/MakeClanScreen.py index 362e0f86d6..260a0eb6ba 100644 --- a/scripts/screens/MakeClanScreen.py +++ b/scripts/screens/MakeClanScreen.py @@ -1,4 +1,5 @@ from random import choice, randrange +from enum import Enum from re import sub import pygame @@ -451,17 +452,6 @@ def handle_choose_background_event(self, event): self.biome_selected = "Beach" self.selected_camp_tab = 1 self.refresh_text_and_buttons() - elif event.ui_element == self.tabs["tab1"]: - self.selected_camp_tab = 1 - self.refresh_selected_camp() - elif event.ui_element == self.tabs["tab2"]: - self.selected_camp_tab = 2 - self.refresh_selected_camp() - elif event.ui_element == self.tabs["tab3"]: - self.selected_camp_tab = 3 - self.refresh_selected_camp() - elif event.ui_element == self.tabs["tab4"]: - self.selected_camp_tab = 4 self.refresh_selected_camp() elif event.ui_element == self.tabs["newleaf_tab"]: self.selected_season = "Newleaf" @@ -486,6 +476,12 @@ def handle_choose_background_event(self, event): self.refresh_text_and_buttons() elif event.ui_element == self.elements["next_step"]: self.open_choose_symbol() + else: + for i in range(1, 5): + if event.ui_element == self.tabs["tab"+str(i)]: + self.selected_camp_tab = i + self.refresh_selected_camp() + break def handle_choose_background_key(self, event): if event.key == pygame.K_RIGHT: From 015efc8c7232c647cf60da0b55b20faf85d36452 Mon Sep 17 00:00:00 2001 From: Sumwatt <172867164+Sumwatt0@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:04:53 -0400 Subject: [PATCH 3/5] Added Comment --- scripts/screens/MakeClanScreen.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/screens/MakeClanScreen.py b/scripts/screens/MakeClanScreen.py index 260a0eb6ba..eb46289943 100644 --- a/scripts/screens/MakeClanScreen.py +++ b/scripts/screens/MakeClanScreen.py @@ -477,6 +477,7 @@ def handle_choose_background_event(self, event): elif event.ui_element == self.elements["next_step"]: self.open_choose_symbol() else: + # Runs through all of the tabs to select the one that matches. for i in range(1, 5): if event.ui_element == self.tabs["tab"+str(i)]: self.selected_camp_tab = i From 15573a2e63171776b95486269b567660c9fd52a1 Mon Sep 17 00:00:00 2001 From: Sumwatt <172867164+Sumwatt0@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:21:34 -0400 Subject: [PATCH 4/5] Oops forgot to delete that. Deleted a line that should've been deleted last commit. --- scripts/screens/MakeClanScreen.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/screens/MakeClanScreen.py b/scripts/screens/MakeClanScreen.py index eb46289943..d92f45e69e 100644 --- a/scripts/screens/MakeClanScreen.py +++ b/scripts/screens/MakeClanScreen.py @@ -452,7 +452,6 @@ def handle_choose_background_event(self, event): self.biome_selected = "Beach" self.selected_camp_tab = 1 self.refresh_text_and_buttons() - self.refresh_selected_camp() elif event.ui_element == self.tabs["newleaf_tab"]: self.selected_season = "Newleaf" self.refresh_text_and_buttons() From 28066315603ea5601f8d934d7b85636985ef1a1d Mon Sep 17 00:00:00 2001 From: Sumwatt <172867164+Sumwatt0@users.noreply.github.com> Date: Sun, 11 Aug 2024 23:01:54 -0400 Subject: [PATCH 5/5] Trying something Ill fix the other stuff later but im saving these changes for now. Just trying to make the BIOME an enum. --- scripts/clan.py | 5 +- scripts/enums.py | 13 +++++ scripts/screens/MakeClanScreen.py | 84 ++++++++++++++----------------- tests/test_thoughts.py | 11 ++-- 4 files changed, 59 insertions(+), 54 deletions(-) create mode 100644 scripts/enums.py diff --git a/scripts/clan.py b/scripts/clan.py index 05775f082f..ab5b1dab2e 100644 --- a/scripts/clan.py +++ b/scripts/clan.py @@ -20,6 +20,7 @@ from scripts.cat.history import History from scripts.cat.names import names from scripts.cat.sprites import sprites +from scripts.enums import BIOME, SEASON from scripts.clan_resources.freshkill import FreshkillPile, Nutrition from scripts.events_module.generate_events import OngoingEvent from scripts.game_structure.game_essentials import game @@ -39,7 +40,7 @@ class Clan: """ - BIOME_TYPES = ["Forest", "Plains", "Mountainous", "Beach"] + BIOME_TYPES = list(BIOME) CAT_TYPES = [ "newborn", @@ -93,7 +94,7 @@ def __init__( leader=None, deputy=None, medicine_cat=None, - biome="Forest", + biome=BIOME.FOREST, camp_bg=None, symbol=None, game_mode="classic", diff --git a/scripts/enums.py b/scripts/enums.py new file mode 100644 index 0000000000..d46a91a2d9 --- /dev/null +++ b/scripts/enums.py @@ -0,0 +1,13 @@ +from enum import Enum + +class BIOME(Enum): + FOREST = 0 + MOUNTAINOUS = 1 + PLAINS = 2 + BEACH = 3 + +class SEASON(Enum): + NEWLEAF = 0 + GREENLEAF = 1 + LEAFFALL = 2 + LEAFBARE = 3 diff --git a/scripts/screens/MakeClanScreen.py b/scripts/screens/MakeClanScreen.py index d92f45e69e..fa1e209053 100644 --- a/scripts/screens/MakeClanScreen.py +++ b/scripts/screens/MakeClanScreen.py @@ -5,6 +5,7 @@ import pygame import pygame_gui +from scripts.enums import BIOME, SEASON from scripts.utility import get_text_box_theme, scale from scripts.clan import Clan from scripts.cat.cats import create_example_cats, create_cat, Cat @@ -25,7 +26,6 @@ from ..cat.sprites import sprites from ..game_structure.windows import SymbolFilterWindow - class MakeClanScreen(Screens): # UI images clan_frame_img = pygame.transform.scale( @@ -437,19 +437,19 @@ def handle_choose_background_event(self, event): if event.ui_element == self.elements["previous_step"]: self.open_choose_members() elif event.ui_element == self.elements["forest_biome"]: - self.biome_selected = "Forest" + self.biome_selected = BIOME.FOREST self.selected_camp_tab = 1 self.refresh_text_and_buttons() elif event.ui_element == self.elements["mountain_biome"]: - self.biome_selected = "Mountainous" + self.biome_selected = BIOME.MOUNTAINOUS self.selected_camp_tab = 1 self.refresh_text_and_buttons() elif event.ui_element == self.elements["plains_biome"]: - self.biome_selected = "Plains" + self.biome_selected = BIOME.PLAINS self.selected_camp_tab = 1 self.refresh_text_and_buttons() elif event.ui_element == self.elements["beach_biome"]: - self.biome_selected = "Beach" + self.biome_selected = BIOME.BEACH self.selected_camp_tab = 1 self.refresh_text_and_buttons() elif event.ui_element == self.tabs["newleaf_tab"]: @@ -467,7 +467,7 @@ def handle_choose_background_event(self, event): elif event.ui_element == self.elements["random_background"]: # Select a random biome and background self.biome_selected = self.random_biome_selection() - if self.biome_selected in ['Forest', "Mountainous"]: + if self.biome_selected in [BIOME.FOREST, BIOME.MOUNTAINOUS]: self.selected_camp_tab = randrange(1, 5) else: self.selected_camp_tab = randrange(1, 4) @@ -486,24 +486,28 @@ def handle_choose_background_event(self, event): def handle_choose_background_key(self, event): if event.key == pygame.K_RIGHT: if self.biome_selected is None: - self.biome_selected = "Forest" - elif self.biome_selected == "Forest": - self.biome_selected = "Mountainous" - elif self.biome_selected == "Mountainous": - self.biome_selected = "Plains" - elif self.biome_selected == "Plains": - self.biome_selected = "Beach" + self.biome_selected = list(BIOME)[0] + else: + for i in range(len(list(BIOME))): + if self.biome_selected is list(BIOME)[i]: + if i == len(list(BIOME)): + self.biome_selected = list(BIOME)[0] + break + self.biome_selected = list(BIOME)[i+1] + break self.selected_camp_tab = 1 self.refresh_text_and_buttons() elif event.key == pygame.K_LEFT: if self.biome_selected is None: - self.biome_selected = "Beach" - elif self.biome_selected == "Beach": - self.biome_selected = "Plains" - elif self.biome_selected == "Plains": - self.biome_selected = "Mountainous" - elif self.biome_selected == "Mountainous": - self.biome_selected = "Forest" + self.biome_selected = list(BIOME)[len(list(BIOME))] + else: + for i in range(len(list(BIOME))): + if self.biome_selected is list(BIOME)[i]: + if i == 0: + self.biome_selected = list(BIOME)[len(list(BIOME))] + break + self.biome_selected = list(BIOME)[i-1] + break self.selected_camp_tab = 1 self.refresh_text_and_buttons() elif event.key == pygame.K_UP and self.biome_selected is not None: @@ -730,27 +734,13 @@ def refresh_text_and_buttons(self): elif self.sub_screen == "choose camp": # Enable/disable biome buttons - if self.biome_selected == "Forest": - self.elements["forest_biome"].disable() - self.elements["mountain_biome"].enable() - self.elements["plains_biome"].enable() - self.elements["beach_biome"].enable() - elif self.biome_selected == "Mountainous": - self.elements["forest_biome"].enable() - self.elements["mountain_biome"].disable() - self.elements["plains_biome"].enable() - self.elements["beach_biome"].enable() - elif self.biome_selected == "Plains": - self.elements["forest_biome"].enable() - self.elements["mountain_biome"].enable() - self.elements["plains_biome"].disable() - self.elements["beach_biome"].enable() - elif self.biome_selected == "Beach": - self.elements["forest_biome"].enable() - self.elements["mountain_biome"].enable() - self.elements["plains_biome"].enable() - self.elements["beach_biome"].disable() - + biomes = ["forest_biome", "mountain_biome", "plains_biome", "beach_biome"] # The possible biomes + for i in range(len(list(BIOME))): + if self.biome_selected is list(BIOME)[i]: + self.elements[biomes[i]].disable() + else: + self.elements[biomes[i]].enable() + if self.selected_season == "Newleaf": self.tabs["newleaf_tab"].disable() self.tabs["greenleaf_tab"].enable() @@ -799,7 +789,7 @@ def refresh_selected_camp(self): self.tabs["tab3"].kill() self.tabs["tab4"].kill() - if self.biome_selected == "Forest": + if self.biome_selected is BIOME.FOREST: self.tabs["tab1"] = UIImageButton( scale(pygame.Rect((190, 360), (308, 60))), "", @@ -824,7 +814,7 @@ def refresh_selected_camp(self): object_id="#lakeside_tab", manager=MANAGER, ) - elif self.biome_selected == "Mountainous": + elif self.biome_selected is BIOME.MOUNTAINOUS: self.tabs["tab1"] = UIImageButton( scale(pygame.Rect((222, 360), (308, 60))), "", @@ -849,7 +839,7 @@ def refresh_selected_camp(self): object_id="#ruins_tab", manager=MANAGER ) - elif self.biome_selected == "Plains": + elif self.biome_selected is BIOME.PLAINS: self.tabs["tab1"] = UIImageButton( scale(pygame.Rect((128, 360), (308, 60))), "", @@ -868,7 +858,7 @@ def refresh_selected_camp(self): object_id="#wasteland_tab", manager=MANAGER, ) - elif self.biome_selected == "Beach": + elif self.biome_selected is BIOME.BEACH: self.tabs["tab1"] = UIImageButton( scale(pygame.Rect((152, 360), (308, 60))), "", @@ -1120,7 +1110,7 @@ def random_clan_name(self): def random_biome_selection(self): # Select a random biome and background old_biome = self.biome_selected - possible_biomes = ['Forest', 'Mountainous', 'Plains', 'Beach'] + possible_biomes = list(BIOME) # ensuring that the new random camp will not be the same one if old_biome is not None: possible_biomes.remove(old_biome) @@ -1938,7 +1928,7 @@ def get_camp_art_path(self, campnum): if game.settings["dark mode"]: light_dark = "dark" - biome = self.biome_selected.lower() + biome = self.biome_selected.name.lower() if campnum: return f"{camp_bg_base_dir}/{biome}/{start_leave}_camp{campnum}_{light_dark}.png" diff --git a/tests/test_thoughts.py b/tests/test_thoughts.py index b24cde2c8d..dd9aa0da94 100644 --- a/tests/test_thoughts.py +++ b/tests/test_thoughts.py @@ -3,6 +3,7 @@ from scripts.cat.cats import Cat from scripts.cat.thoughts import Thoughts +from scripts.enums import BIOME, SEASON os.environ["SDL_VIDEODRIVER"] = "dummy" os.environ["SDL_AUDIODRIVER"] = "dummy" @@ -12,7 +13,7 @@ class TestNotWorkingThoughts(unittest.TestCase): def setUp(self): self.main = Cat(status="warrior") self.other = Cat(status="warrior") - self.biome = "Forest" + self.biome = BIOME.FOREST self.season = "Newleaf" self.camp = "camp2" @@ -77,7 +78,7 @@ def test_medicine_thought(self): medicine.status = "medicine cat" warrior.status = "warrior" medicine.trait = "bold" - biome = "Forest" + biome = BIOME.FOREST season = "Newleaf" camp = "camp2" @@ -92,7 +93,7 @@ def test_exiled_thoughts(self): cat = Cat(status="exiled", moons=40) cat.exiled = True cat.outside = True - biome = "Forest" + biome = BIOME.FOREST season = "Newleaf" camp = "camp2" @@ -103,7 +104,7 @@ def test_lost_thoughts(self): # given cat = Cat(status="warrior", moons=40) cat.outside = True - biome = "Forest" + biome = BIOME.FOREST season = "Newleaf" camp = "camp2" @@ -117,7 +118,7 @@ def test_family_thought_young_children(self): # given parent = Cat(moons=40) kit = Cat(parent1=parent.ID, moons=4) - biome = "Forest" + biome = BIOME.FOREST season = "Newleaf" camp = "camp2"