From c9a36a60bed806321c70a10b38deda039b513f8a Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Mon, 17 Jun 2024 17:31:19 +0200 Subject: [PATCH] feat(#275): Refactored roadmap make StationObject decend from se.Text --- pokete_classes/color.py | 33 +++-- pokete_classes/roadmap.py | 125 ++++++----------- pokete_data/__init__.py | 2 +- pokete_data/mapstations.py | 275 +++++++++++++------------------------ 4 files changed, 155 insertions(+), 280 deletions(-) diff --git a/pokete_classes/color.py b/pokete_classes/color.py index 23707ea9..3a8f8ef0 100644 --- a/pokete_classes/color.py +++ b/pokete_classes/color.py @@ -1,6 +1,7 @@ """Contains the color class""" from os import environ + class Color: """Color class that provides all needed escape codes""" reset = "\033[0m" @@ -16,23 +17,21 @@ class Color: cyan = "\033[1;36m" lightgrey = "\033[37m" white = "\033[1;37m" - - #extended color palette - brown="\033[38;5;88m" - lakeblue="\033[38;5;33m" - mediumgray="\033[38;5;238m" - brightyellow="\033[38;5;155m" - deepgreen="\033[38;5;35m" - lightgray="\033[38;5;246m" - brightgreen="\033[38;5;46m" - darkgreen="\033[38;5;29m" - gold="\033[38;5;94m" - cavegray="\033[38;5;236m" - - if environ["TERM"] == "linux": #this fixes some colors on TTY - gold="\033[38;5;9m" - cavegray="\033[38;5;7m" - + + # extended color palette + brown = "\033[38;5;88m" + lakeblue = "\033[38;5;33m" + mediumgrey = "\033[38;5;238m" + brightyellow = "\033[38;5;155m" + deepgreen = "\033[38;5;35m" + brightgreen = "\033[38;5;46m" + darkgreen = "\033[38;5;29m" + gold = "\033[38;5;94m" + cavegrey = "\033[38;5;236m" + + if environ["TERM"] == "linux": # this fixes some colors on TTY + gold = "\033[38;5;9m" + cavegrey = "\033[38;5;7m" if __name__ == "__main__": diff --git a/pokete_classes/roadmap.py b/pokete_classes/roadmap.py index 1885692f..a90cc96a 100644 --- a/pokete_classes/roadmap.py +++ b/pokete_classes/roadmap.py @@ -1,7 +1,4 @@ """Contains all classes relevant to show the roadmap""" - -import time -import random import scrap_engine as se import pokete_data as p_data @@ -23,56 +20,15 @@ def __init__(self, _map): super().__init__(text) -"""A little hackaround""" - - -class StationObject(se.Box): - - def __init__(self, text, width, height, ob_class=se.Object): - super().__init__(height, width) - self.ob_class = ob_class - self.text = text - self.ob_args = {} - self.__create() - #TODO: if self.desc == "_LAKE" animate water - - def __create(self): - for ry in range(self.height): - for rx in range(self.width): - if len(self.text) == 1: - r = 0 - else: - r = ry * self.width + rx - self.add_ob( - self.ob_class(self.text[r], "float", - arg_proto=self.ob_args), rx, ry - ) - - def recolor(self, color): - r = 0 - for obj in self.obs: - obj.rechar(color + self.text[r] + Color.reset) - if len(self.text) != 1: - r += 1 - - def animate_water(self): - # bruh i think this could be done better - water_colors = [ - "\033[38;5;38m", - "\033[38;5;75m", - "\033[38;5;39m", - "\033[38;5;74m", - ] - while True: - r = 0 - for obj in self.obs: - obj.rechar( - water_colors[random.randint(0, len(water_colors) - 1)] - + self.text[r] - + Color.reset - ) - r += 1 - time.sleep(0.7) +class StationObject(se.Text): + + def __init__(self, text, color): + super().__init__(text, esccode=color, state="float") + + +class Decoration(StationObject): + def __init__(self, text, color=""): + super().__init__(text, getattr(Color, color, Color.lightgrey)) class Station(StationObject): @@ -81,10 +37,7 @@ class Station(StationObject): roadmap: RoadMap object associate: Main PlayMap name the station belongs to additionals: List of PlayMap names the station also belongs to - width: The Station's width - height: The Station's height desc: The associated description - char: Displayed char {w,a,s,d}_next: The next Station's name in a certain direction""" choosen = None @@ -95,11 +48,9 @@ def __init__( roadmap, associate, additionals, - width, - height, desc, + text, color="", - text="#", w_next="", a_next="", s_next="", @@ -107,14 +58,13 @@ def __init__( ): self.desc = desc self.roadmap = roadmap - self.org_char = text - self.associates = [associate] + [obmp.ob_maps[i] for i in additionals] self.color = getattr(Color, color, "\033[1;37m") + self.base_color = self.color + self.base_text = text + self.associates = [associate] + [obmp.ob_maps[i] for i in additionals] if self.associates[0]: self.name = self.associates[0].pretty_name - super().__init__(text, width, height) - self.recolor(self.color) - #self.hide_if_visited() + super().__init__(text, self.color) self.w_next = w_next self.a_next = a_next self.s_next = s_next @@ -132,10 +82,10 @@ def unchoose(self): self.un_blink() def blink(self): - self.recolor(Color.red + Color.thicc) + self.rechar(self.text, Color.red + Color.thicc) def un_blink(self): - self.recolor(self.color) + self.rechar(self.text, self.color) def next(self, inp: ActionList): """Chooses the next station in a certain direction @@ -163,25 +113,21 @@ def is_city(self): """Returns if the station is a city""" return "pokecenter" in p_data.map_data[self.associates[0].name][ "hard_obs"] - - def is_cave(self): - #returns if the station is in a cave - if self.text[0] == "█": return True - return False def hide_if_visited(self, choose=False): - if self.associates[0] is not None: - if choose: - if self.is_city() and self.has_been_visited(): - self.recolor(Color.green + Color.thicc) - elif not self.is_cave(): - self.recolor(Color.white) + self.text = self.base_text + if not self.has_been_visited(): + self.color = Color.white + for ch in ["A", "P", "$", "C", "#"]: + self.text = self.text.replace(ch, " ") + elif choose: + if self.is_city(): + self.color = self.base_color else: - self.recolor(self.color) - if not self.has_been_visited(): - features = ["A", "P", "$", "C", "⌂", "#"] - for ch in features: - self.text = self.text.replace(ch, " ") + self.color = Color.white + else: + self.color = self.base_color + self.rechar(self.text, self.color) class RoadMap: @@ -195,10 +141,23 @@ def __init__(self, fig): 17, 61, "Roadmap", f"{Action.CANCEL.mapping}:close", overview=mvp.movemap ) + self.rose = se.Text(""" N + ▲ +W ◀ ▶ E + ▼ + S""", state="float") + self.legend = se.Text("""│ Legend: +│ P-Pokecenter +│ $-Shop +│ C-PoketeCare +│ A-Arena +└──────────────""", state="float") self.info_label = se.Text("", state="float") self.box.add_ob(self.info_label, self.box.width - 2, 0) + self.box.add_ob(self.rose, 53, 11) + self.box.add_ob(self.legend, 45, 1) for sta, _dict in p_data.decorations.items(): - obj = Station(self, None, **_dict["gen"]) + obj = Decoration(**_dict["gen"]) self.box.add_ob(obj, **_dict["add"]) setattr(self, sta, obj) diff --git a/pokete_data/__init__.py b/pokete_data/__init__.py index da726d53..e77f9983 100644 --- a/pokete_data/__init__.py +++ b/pokete_data/__init__.py @@ -93,7 +93,7 @@ def validate(): "soft_ob": ["x", "y", "txt"], "dor": ["x", "y", "args"], "ball": ["x", "y"], - "gen": ["additionals", "width", "height", "desc"], + "gen": ["additionals", "text", "desc"], "add": ["x", "y"], "poke_ico": ["txt", "esc"], "trainer": ["pokes", "args"] diff --git a/pokete_data/mapstations.py b/pokete_data/mapstations.py index b0d3d533..4a87921d 100644 --- a/pokete_data/mapstations.py +++ b/pokete_data/mapstations.py @@ -2,11 +2,11 @@ "playmap_1": { "gen": { "additionals": ["intromap"], - "width": 4, - "height": 3, "desc": "A small town.", "d_next": "playmap_51", - "text": """ *P#├─── # #""", + "text": """ *P# +├─── + # #""", "color": "brightgreen" }, "add": { @@ -17,14 +17,13 @@ "playmap_51": { "gen": { "additionals": [], - "width": 3, - "height": 2, "desc": "Some small patches of grass surrounded by forrest, near " "Nice Town.", "a_next": "playmap_1", "w_next": "cave_1", - "text": r"""└─┐──┘""", + "text": r"""└─┐ +──┘""", "color": "darkgreen" }, "add": { @@ -35,13 +34,13 @@ "cave_1": { "gen": { "additionals": [], - "width": 1, - "height": 3, "desc": "A dark cave full of batos.", "s_next": "playmap_51", "d_next": "playmap_2", - "text": """███""", - "color": "cavegray" + "text": """█ +█ +█""", + "color": "cavegrey" }, "add": { "x": 7, @@ -51,8 +50,6 @@ "playmap_2": { "gen": { "additionals": [], - "width": 4, - "height": 1, "desc": "Part of light areas near Sunny Dale.", "a_next": "cave_1", "d_next": "playmap_3", @@ -67,13 +64,13 @@ "playmap_3": { "gen": { "additionals": ["playmap_49"], - "width": 3, - "height": 3, "desc": "A small sunny village.", "a_next": "playmap_2", "w_next": "playmap_4", "s_next": "playmap_6", - "text": """P│$─┤ #│#""", + "text": """P│$ +─┤ +#│#""", "color": "brightgreen" }, "add": { @@ -84,12 +81,12 @@ "playmap_4": { "gen": { "additionals": ["playmap_5"], - "width": 1, - "height": 3, "desc": "The shores of the great Sunnydale lake.", "s_next": "playmap_3", "d_next": "playmap_28", - "text": """├││""", + "text": """├ +│ +│""", "color": "darkgreen" }, "add": { @@ -100,14 +97,14 @@ "playmap_6": { "gen": { "additionals": [], - "width": 3, - "height": 3, "desc": "The woodland edge at the foot of a great mountain full of \ caves.", "w_next": "playmap_3", "a_next": "playmap_7", "d_next": "playmap_8", - "text": """│ │ ┴──""", + "text": """│ +│ +┴──""", "color": "deepgreen" }, "add": { @@ -118,12 +115,10 @@ "playmap_7": { "gen": { "additionals": [], - "width": 2, - "height": 1, "desc": "A dark and mysterious cave.", "d_next": "playmap_6", "text": """██""", - "color": "cavegray" + "color": "cavegrey" }, "add": { "x": 11, @@ -133,13 +128,12 @@ "playmap_8": { "gen": { "additionals": ["playmap_10", "playmap_9"], - "width": 3, - "height": 2, "desc": "An abandoned fisher village.", "a_next": "playmap_6", "s_next": "playmap_11", "d_next": "playmap_12", - "text": """# ─┬─""", + "text": """# +─┬─""", "color": "brightyellow" }, "add": { @@ -150,8 +144,6 @@ "playmap_11": { "gen": { "additionals": [], - "width": 1, - "height": 1, "desc": "The shore of a lake near an olf fisher village.", "w_next": "playmap_8", "text": """│""", @@ -165,12 +157,11 @@ "playmap_12": { "gen": { "additionals": [], - "width": 2, - "height": 2, "desc": "A dense forest near Deepens forest.", "a_next": "playmap_8", "w_next": "playmap_13", - "text": """ │─┘""", + "text": """ │ +─┘""", "color": "brown" }, "add": { @@ -181,13 +172,14 @@ "playmap_13": { "gen": { "additionals": ["playmap_14", "playmap_20"], - "width": 3, - "height": 3, - "desc": "Deepens forest, a big town in the middle of the deepest \ -forest, populated by thousands of people and cultural center of the region.", + "desc": "Deepens forest, a big town in the middle of the deepest " + "forest, populated by thousands of people and cultural " + "center of the region.", "s_next": "playmap_12", "w_next": "playmap_15", - "text": """#│A │ P│$""", + "text": """#│A + │ +P│$""", "color": "gold" }, "add": { @@ -198,8 +190,6 @@ "playmap_15": { "gen": { "additionals": [], - "width": 3, - "height": 1, "desc": "A small clearing near Deepens forest.", "s_next": "playmap_13", "d_next": "playmap_16", @@ -214,8 +204,6 @@ "playmap_16": { "gen": { "additionals": ["playmap_17"], - "width": 3, - "height": 1, "desc": "A small 'village', that's not even worth talking about.", "a_next": "playmap_15", "d_next": "playmap_18", @@ -230,8 +218,6 @@ "playmap_18": { "gen": { "additionals": [], - "width": 3, - "height": 1, "desc": "A small see at the foot of the Big mountain.", "a_next": "playmap_16", "w_next": "playmap_19", @@ -246,13 +232,12 @@ "playmap_19": { "gen": { "additionals": [], - "width": 1, - "height": 2, "desc": "A dark and big cave in the Big mountain.", "s_next": "playmap_18", "w_next": "playmap_21", - "text": """██""", - "color": "cavegray" + "text": """█ +█""", + "color": "cavegrey" }, "add": { "x": 28, @@ -264,16 +249,16 @@ "additionals": ["playmap_22", "playmap_23", "playmap_24", "playmap_25", "playmap_26", "playmap_27", "playmap_29", "playmap_50"], - "width": 4, - "height": 3, - "desc": "The great Rock-ville is the biggest city in the region \ -around the Big mountain. With the Rocky hotel it's also a tourist \ -hotspot.", + "desc": "The great Rock-ville is the biggest city in the region " + "around the Big mountain. With the Rocky hotel it's " + "also a tourist hotspot.", "s_next": "playmap_19", "d_next": "playmap_33", "w_next": "playmap_40", - "text": """P│ #┌┴──│#C """, - "color": "lightgray" + "text": """P│ # +┌┴── +│#C """, + "color": "lightgrey" }, "add": { "x": 28, @@ -283,8 +268,6 @@ "playmap_40": { "gen": { "additionals": [], - "width": 1, - "height": 1, "desc": "A Great beach, with great weather, always.", "s_next": "playmap_21", "text": """│""", @@ -298,12 +281,11 @@ "playmap_28": { "gen": { "additionals": [], - "width": 5, - "height": 2, "desc": "A foggy place full of ghosts and plants.", "a_next": "playmap_4", "d_next": "playmap_30", - "text": """ ┌────┘ """, + "text": """ ┌── +──┘""", "color": "brightgreen" }, "add": { @@ -314,13 +296,13 @@ "playmap_30": { "gen": { "additionals": ["playmap_31", "playmap_32"], - "width": 4, - "height": 3, - "desc": "With its plant Poketes, Flowy Town may be the greenest \ -spot in the Pokete world and with the great git-tree it may also be one \ -of the most spectacular.", + "desc": "With its plant Poketes, Flowy Town may be the greenest " + "spot in the Pokete world and with the great git-tree it " + "may also be one of the most spectacular.", "a_next": "playmap_28", - "text": """A$P ───┤# # """, + "text": """A$P +───┤ +# # """, "color": "deepgreen" }, "add": { @@ -331,8 +313,6 @@ "playmap_33": { "gen": { "additionals": ["playmap_34"], - "width": 2, - "height": 1, "desc": "Part of the great agracultural landscape near Agrawos.", "a_next": "playmap_21", "d_next": "playmap_35", @@ -347,12 +327,12 @@ "playmap_35": { "gen": { "additionals": ["playmap_36", "playmap_37", "playmap_38"], - "width": 3, - "height": 3, "desc": "Part of the great agracultural landscape near Agrawos.", "a_next": "playmap_33", "s_next": "playmap_39", - "text": """──┐┌─┘└─┐""", + "text": """──┐ +┌─┘ +└─┐""", "color": "brightyellow" }, "add": { @@ -365,8 +345,6 @@ "additionals": ["playmap_41", "playmap_42", "playmap_43", "playmap_44", "playmap_45", "playmap_46", "playmap_47", "playmap_48"], - "width": 4, - "height": 4, "desc": "The great city of Agrawos, agricultural and cultural " "center of the whole region. It's famous for its great " "Pokete-Arena and its master trainer. Check out the " @@ -374,7 +352,10 @@ "juiciest and most delicious Mowcow-burgers, cut from the " "happiest and most delicious Mowcows anywhere to find!", "w_next": "playmap_35", - "text": """ #│# P│A├─┘# $ #""", + "text": """ #│# + P│A +├─┘# + $ #""", "color": "yellow" }, "add": { @@ -382,95 +363,84 @@ "y": 7 } }, - - - + } -decorations={ +decorations = { "cave3": { "gen": { - "additionals": [], - "width": 5, - "height": 3, - "desc": "", - "text": """██ ████ ███""", - "color": "mediumgray" + "text": """██ +████ + ███""", + "color": "mediumgrey" }, "add": { "x": 8, "y": 10 } }, - + "cave2": { "gen": { - "additionals": [], - "width": 4, - "height": 3, - "desc": "", - "text": """█ ███ ███""", - "color": "mediumgray" + "text": """█ +███ + ███""", + "color": "mediumgrey" }, "add": { "x": 10, "y": 13 } }, - + "cave1": { "gen": { - "additionals": [], - "width": 6, - "height": 4, - "desc": "", - "text": """ ████████████ █""", - "color": "mediumgray" + "text": """ +██████ +██████ + █""", + "color": "mediumgrey" }, "add": { "x": 1, "y": 8 } }, - + "cave4-1": { "gen": { - "additionals": [], - "width": 4, - "height": 2, - "desc": "", - "text": """████████""", - "color": "mediumgray" + "text": """████ +████""", + "color": "mediumgrey" }, "add": { "x": 23, "y": 1 } }, - + "cave4": { "gen": { - "additionals": [], - "width": 5, - "height": 5, - "desc": "", - "text": """ ███ ███ ███ ███ ██""", - "color": "mediumgray" + "text": """ ███ + ███ + ███ + ███ + ██""", + "color": "mediumgrey" }, "add": { "x": 23, "y": 3 } }, - + "cave5": { "gen": { - "additionals": [], - "width": 5, - "height": 4, - "desc": "", - "text": """ ███████████ ██ """, - "color": "mediumgray" + "text": """ ██ +█████ +████ + ██ """, + "color": "mediumgrey" }, "add": { "x": 29, @@ -479,10 +449,6 @@ }, "mountainsee": { "gen": { - "additionals": [], - "width": 1, - "height": 1, - "desc": "_LAKE", "text": """█""", "color": "lakeblue" }, @@ -491,28 +457,22 @@ "y": 8 } }, - + "cave7": { "gen": { - "additionals": [], - "width": 6, - "height": 3, - "desc": "", - "text": """ ████ ████ ███ """, - "color": "mediumgray" + "text": """ ████ + ████ + ███ """, + "color": "mediumgrey" }, "add": { "x": 31, "y": 1 } }, - + "rockybeach": { "gen": { - "additionals": [], - "width": 5, - "height": 1, - "desc": "_LAKE", "text": """█████""", "color": "lakeblue" }, @@ -521,42 +481,19 @@ "y": 1 } }, - - + "cave6": { "gen": { - "additionals": [], - "width": 2, - "height": 1, - "desc": "", "text": """██""", - "color": "cavegray" + "color": "cavegrey" }, "add": { "x": 32, "y": 4 } }, - - "rose": { - "gen": { - "additionals": [], - "width": 7, - "height": 5, - "desc": "", - "text": """ N ▲ W ◀ ▶ E ▼ S """ - }, - "add": { - "x": 53, - "y": 11 - } - }, "sunnylake": { "gen": { - "additionals": [], - "width": 3, - "height": 1, - "desc": "_LAKE", "text": """███""", "color": "lakeblue" }, @@ -565,13 +502,8 @@ "y": 4 } }, - "fisherlake": { "gen": { - "additionals": [], - "width": 6, - "height": 1, - "desc": "_LAKE", "text": """ ████ """, "color": "lakeblue" }, @@ -580,21 +512,6 @@ "y": 15 } }, - - "Legend": { - "gen": { - "additionals": [], - "width": 15, - "height": 6, - "desc": "", - "text": """│ Legend: │ P-Pokecenter │ $-Shop │ C-PoketeCare │ A-Arena └──────────────""" - #! - avaiable quests - }, - "add": { - "x": 45, - "y": 1 - } - }, } if __name__ == "__main__":