diff --git a/pokete.py b/pokete.py index 1102c6e3..c6c8725c 100755 --- a/pokete.py +++ b/pokete.py @@ -983,7 +983,7 @@ def teleport(poke): """Teleports the player to another towns pokecenter ARGS: poke: The Poke shown in the animation""" - if (obj := roadmap(mvp.movemap, choose=True)) is None: + if (obj := roadmap(mvp.movemap, None, choose=True)) is None: return if settings("animations").val: animations.transition(mvp.movemap, poke) @@ -1092,7 +1092,7 @@ def _game(_map): pevm = PeriodicEventManager(_map) inp_dict = { Action.DECK: [deck.deck, (mvp.movemap, 6, "Your deck")], - Action.MAP: [roadmap, (mvp.movemap,)], + Action.MAP: [roadmap, (mvp.movemap, pevm)], Action.INVENTORY: [inv, ()], Action.POKEDEX: [pokete_dex, ()], Action.CLOCK: [timer.clock, (mvp.movemap,)], diff --git a/pokete_classes/color.py b/pokete_classes/color.py index 87cd1ab2..3a8f8ef0 100644 --- a/pokete_classes/color.py +++ b/pokete_classes/color.py @@ -1,4 +1,5 @@ """Contains the color class""" +from os import environ class Color: @@ -7,9 +8,9 @@ class Color: thicc = "\033[1m" underlined = "\033[4m" grey = "\033[1;30m" - red = "\033[31m" - green = "\033[32m" - yellow = "\033[33m" + red = "\033[38;5;196m" + green = "\033[38;5;70m" + yellow = "\033[38;5;226m" lightblue = "\033[1;34m" blue = "\033[34m" purple = "\033[1;35m" @@ -17,6 +18,21 @@ class Color: lightgrey = "\033[37m" white = "\033[1;37m" + # 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__": print("\033[31;1mDo not execute this!\033[0m") diff --git a/pokete_classes/roadmap.py b/pokete_classes/roadmap.py index 7c9531e0..a90cc96a 100644 --- a/pokete_classes/roadmap.py +++ b/pokete_classes/roadmap.py @@ -1,6 +1,6 @@ """Contains all classes relevant to show the roadmap""" - import scrap_engine as se + import pokete_data as p_data import pokete_classes.ob_maps as obmp from pokete_general_use_fns import liner @@ -8,7 +8,6 @@ from .loops import std_loop, easy_exit_loop from .color import Color from .ui_elements import Box, InfoBox -from .tss import tss from . import movemap as mvp @@ -21,29 +20,51 @@ def __init__(self, _map): super().__init__(text) -class Station(se.Square): +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): """Selectable station for Roadmap ARGS: 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 obs = [] - def __init__(self, roadmap, associate, additionals, width, height, desc, - char="#", w_next="", a_next="", s_next="", d_next=""): + def __init__( + self, + roadmap, + associate, + additionals, + desc, + text, + color="", + w_next="", + a_next="", + s_next="", + d_next="", + ): self.desc = desc self.roadmap = roadmap - self.org_char = char + 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] - self.color = "" - self.name = self.associates[0].pretty_name - super().__init__(char, width, height, state="float") + if self.associates[0]: + self.name = self.associates[0].pretty_name + super().__init__(text, self.color) self.w_next = w_next self.a_next = a_next self.s_next = s_next @@ -52,15 +73,19 @@ def __init__(self, roadmap, associate, additionals, width, height, desc, def choose(self): """Chooses and hightlights the station""" - self.rechar(Color.red + Color.thicc + self.org_char + Color.reset) Station.choosen = self self.roadmap.rechar_info( - self.name if self.has_been_visited() else "???" - ) + self.name if self.has_been_visited() else "???") def unchoose(self): """Unchooses the station""" - self.rechar(self.color + self.org_char + Color.reset) + self.un_blink() + + def blink(self): + self.rechar(self.text, Color.red + Color.thicc) + + def un_blink(self): + self.rechar(self.text, self.color) def next(self, inp: ActionList): """Chooses the next station in a certain direction @@ -71,10 +96,10 @@ def next(self, inp: ActionList): inp = action break inp = { - Action.UP: 'w', - Action.DOWN: 's', - Action.LEFT: 'a', - Action.RIGHT: 'd', + Action.UP: "w", + Action.DOWN: "s", + Action.LEFT: "a", + Action.RIGHT: "d", }[inp] if (n_e := getattr(self, inp + "_next")) != "": self.unchoose() @@ -86,18 +111,23 @@ def has_been_visited(self): def is_city(self): """Returns if the station is a city""" - return "pokecenter" \ - in p_data.map_data[self.associates[0].name]["hard_obs"] + return "pokecenter" in p_data.map_data[self.associates[0].name][ + "hard_obs"] - def set_color(self, choose=False): - """Marks a station as visited - ARGS: - choose: Bool whether or not this done when choosing a city""" - if self.has_been_visited() and (self.is_city() if choose else True): - self.color = Color.yellow + def hide_if_visited(self, choose=False): + 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.color = Color.white else: - self.color = "" - self.unchoose() + self.color = self.base_color + self.rechar(self.text, self.color) class RoadMap: @@ -108,15 +138,32 @@ class RoadMap: def __init__(self, fig): self.fig = fig self.box = Box( - 11, 40, "Roadmap", - f"{Action.CANCEL.mapping}:close", + 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 = Decoration(**_dict["gen"]) + self.box.add_ob(obj, **_dict["add"]) + setattr(self, sta, obj) + for sta, _dict in p_data.stations.items(): - obj = Station(self, obmp.ob_maps[sta], **_dict['gen']) - self.box.add_ob(obj, **_dict['add']) + obj = Station(self, obmp.ob_maps[sta], **_dict["gen"]) + self.box.add_ob(obj, **_dict["add"]) setattr(self, sta, obj) @property @@ -133,19 +180,25 @@ def rechar_info(self, name): self.info_label.rechar(name) self.box.add_ob(self.info_label, self.box.width - 2 - len(name), 0) - def __call__(self, _map, choose=False): + def __call__(self, _map: se.Submap, pevm, choose=False): """Shows the roadmap ARGS: _map: se.Map this is shown on choose: Bool whether or not this is done to choose a city""" for i in Station.obs: - i.set_color(choose) - [i for i in Station.obs - if (self.fig.map - if self.fig.map not in [obmp.ob_maps[i] for i in - ("shopmap", "centermap")] - else self.fig.oldmap) - in i.associates][0].choose() + i.hide_if_visited(choose) + [ + i + for i in Station.obs + if ( + self.fig.map + if self.fig.map + not in [obmp.ob_maps[i] for i in ("shopmap", "centermap")] + else self.fig.oldmap + ) + in i.associates + ][0].choose() + blinker = Blinker() with self.box.center_add(_map): while True: action = get_action() @@ -153,30 +206,41 @@ def __call__(self, _map, choose=False): self.sta.next(action) elif action.triggers(Action.MAP, Action.CANCEL): break - elif (action.triggers(Action.ACCEPT) and choose - and self.sta.has_been_visited() - and self.sta.is_city()): + elif ( + action.triggers(Action.ACCEPT) + and choose + and self.sta.has_been_visited() + and self.sta.is_city() + ): return self.sta.associates[0] - elif (action.triggers(Action.ACCEPT) and not choose - and self.sta.has_been_visited()): - p_list = ", ".join(set(p_data.pokes[j]["name"] - for i in self.sta.associates - for j in - i.poke_args.get("pokes", []) - + i.w_poke_args.get("pokes", []))) + elif ( + action.triggers(Action.ACCEPT) + and not choose + and self.sta.has_been_visited() + ): + p_list = ", ".join( + set( + p_data.pokes[j]["name"] + for i in self.sta.associates + for j in i.poke_args.get("pokes", []) + + i.w_poke_args.get("pokes", []) + ) + ) with InfoBox( liner( self.sta.desc + "\n\n Here you can find: " + (p_list if p_list != "" else "Nothing"), - 30 + 30, ), self.sta.name, - _map=_map, overview=self.box + _map=_map, + overview=self.box, ) as box: easy_exit_loop(box=box) - std_loop(box=self.box) - _map.show() + std_loop(box=self.box, pevm=pevm) + blinker(self.sta) + _map.full_show() self.sta.unchoose() @staticmethod @@ -185,12 +249,25 @@ def check_maps(): all_road_maps = ["centermap", "shopmap"] for i, _dict in p_data.stations.items(): all_road_maps.append(i) - all_road_maps += _dict['gen']['additionals'] + all_road_maps += _dict["gen"]["additionals"] for _, _map in obmp.ob_maps.items(): if _map.name not in all_road_maps: raise RoadMapException(_map) +class Blinker: + def __init__(self): + self.idx = 0 + + def __call__(self, station: Station): + self.idx += 1 + if self.idx == 10: + station.blink() + if self.idx == 20: + station.un_blink() + self.idx = 0 + + if __name__ == "__main__": print("\033[31;1mDo not execute this!\033[0m") 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 eef94cb6..4a87921d 100644 --- a/pokete_data/mapstations.py +++ b/pokete_data/mapstations.py @@ -2,229 +2,246 @@ "playmap_1": { "gen": { "additionals": ["intromap"], - "width": 2, - "height": 1, "desc": "A small town.", - "d_next": "playmap_51" + "d_next": "playmap_51", + "text": """ *P# +├─── + # #""", + "color": "brightgreen" }, "add": { - "x": 4, - "y": 7 + "x": 3, + "y": 12 } }, "playmap_51": { "gen": { "additionals": [], - "width": 1, - "height": 1, "desc": "Some small patches of grass surrounded by forrest, near " "Nice Town.", "a_next": "playmap_1", - "w_next": "cave_1" + "w_next": "cave_1", + "text": r"""└─┐ +──┘""", + "color": "darkgreen" }, "add": { - "x": 6, - "y": 7 + "x": 7, + "y": 12 } }, "cave_1": { "gen": { "additionals": [], - "width": 1, - "height": 2, "desc": "A dark cave full of batos.", "s_next": "playmap_51", "d_next": "playmap_2", + "text": """█ +█ +█""", + "color": "cavegrey" }, "add": { - "x": 6, - "y": 5 + "x": 7, + "y": 9 } }, "playmap_2": { "gen": { "additionals": [], - "width": 2, - "height": 1, "desc": "Part of light areas near Sunny Dale.", "a_next": "cave_1", "d_next": "playmap_3", + "text": """────""", + "color": "darkgreen" }, "add": { - "x": 7, - "y": 5 + "x": 8, + "y": 9 } }, "playmap_3": { "gen": { "additionals": ["playmap_49"], - "width": 2, - "height": 1, "desc": "A small sunny village.", "a_next": "playmap_2", "w_next": "playmap_4", "s_next": "playmap_6", + "text": """P│$ +─┤ +#│#""", + "color": "brightgreen" }, "add": { - "x": 9, - "y": 5 + "x": 12, + "y": 8 } }, "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" + "d_next": "playmap_28", + "text": """├ +│ +│""", + "color": "darkgreen" }, "add": { - "x": 10, - "y": 2 + "x": 13, + "y": 5 } }, "playmap_6": { "gen": { "additionals": [], - "width": 1, - "height": 2, "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": """│ +│ +┴──""", + "color": "deepgreen" }, "add": { - "x": 10, - "y": 6 + "x": 13, + "y": 11 } }, "playmap_7": { "gen": { "additionals": [], - "width": 1, - "height": 1, "desc": "A dark and mysterious cave.", "d_next": "playmap_6", + "text": """██""", + "color": "cavegrey" }, "add": { - "x": 9, - "y": 7 + "x": 11, + "y": 13 } }, "playmap_8": { "gen": { "additionals": ["playmap_10", "playmap_9"], - "width": 2, - "height": 1, "desc": "An abandoned fisher village.", "a_next": "playmap_6", "s_next": "playmap_11", "d_next": "playmap_12", + "text": """# +─┬─""", + "color": "brightyellow" }, "add": { - "x": 11, - "y": 7 + "x": 16, + "y": 12 } }, "playmap_11": { "gen": { "additionals": [], - "width": 1, - "height": 1, "desc": "The shore of a lake near an olf fisher village.", "w_next": "playmap_8", + "text": """│""", + "color": "yellow" }, "add": { - "x": 11, - "y": 8 + "x": 17, + "y": 14 } }, "playmap_12": { "gen": { - "width": 2, "additionals": [], - "height": 1, "desc": "A dense forest near Deepens forest.", "a_next": "playmap_8", "w_next": "playmap_13", + "text": """ │ +─┘""", + "color": "brown" }, "add": { - "x": 13, - "y": 7 + "x": 19, + "y": 12 } }, "playmap_13": { "gen": { "additionals": ["playmap_14", "playmap_20"], - "width": 1, - "height": 2, - "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│$""", + "color": "gold" }, "add": { - "x": 14, - "y": 5 + "x": 19, + "y": 9 } }, "playmap_15": { "gen": { "additionals": [], - "width": 2, - "height": 1, "desc": "A small clearing near Deepens forest.", "s_next": "playmap_13", "d_next": "playmap_16", + "text": """┌──""", + "color": "brown" }, "add": { - "x": 14, - "y": 4 + "x": 20, + "y": 8 } }, "playmap_16": { "gen": { "additionals": ["playmap_17"], - "width": 1, - "height": 1, "desc": "A small 'village', that's not even worth talking about.", "a_next": "playmap_15", "d_next": "playmap_18", + "text": """───""", + "color": "brightyellow" }, "add": { - "x": 16, - "y": 4 + "x": 23, + "y": 8 } }, "playmap_18": { "gen": { "additionals": [], - "width": 2, - "height": 1, "desc": "A small see at the foot of the Big mountain.", "a_next": "playmap_16", "w_next": "playmap_19", + "text": """──┘""", + "color": "darkgreen" }, "add": { - "x": 17, - "y": 4 + "x": 26, + "y": 8 } }, "playmap_19": { "gen": { "additionals": [], - "width": 1, - "height": 1, "desc": "A dark and big cave in the Big mountain.", "s_next": "playmap_18", "w_next": "playmap_21", + "text": """█ +█""", + "color": "cavegrey" }, "add": { - "x": 18, - "y": 3 + "x": 28, + "y": 6 } }, "playmap_21": { @@ -232,88 +249,95 @@ "additionals": ["playmap_22", "playmap_23", "playmap_24", "playmap_25", "playmap_26", "playmap_27", "playmap_29", "playmap_50"], - "width": 3, - "height": 1, - "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" + "w_next": "playmap_40", + "text": """P│ # +┌┴── +│#C """, + "color": "lightgrey" }, "add": { - "x": 18, + "x": 28, + "y": 3 + } + }, + "playmap_40": { + "gen": { + "additionals": [], + "desc": "A Great beach, with great weather, always.", + "s_next": "playmap_21", + "text": """│""", + "color": "yellow" + }, + "add": { + "x": 29, "y": 2 } }, "playmap_28": { "gen": { "additionals": [], - "width": 2, - "height": 1, "desc": "A foggy place full of ghosts and plants.", "a_next": "playmap_4", "d_next": "playmap_30", + "text": """ ┌── +──┘""", + "color": "brightgreen" }, "add": { - "x": 11, - "y": 3 + "x": 14, + "y": 4 } }, "playmap_30": { "gen": { "additionals": ["playmap_31", "playmap_32"], - "width": 1, - "height": 1, - "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 +───┤ +# # """, + "color": "deepgreen" }, "add": { - "x": 13, + "x": 19, "y": 3 } }, "playmap_33": { "gen": { "additionals": ["playmap_34"], - "width": 1, - "height": 1, "desc": "Part of the great agracultural landscape near Agrawos.", "a_next": "playmap_21", "d_next": "playmap_35", + "text": """──""", + "color": "yellow" }, "add": { - "x": 21, - "y": 2 + "x": 34, + "y": 4 } }, "playmap_35": { "gen": { "additionals": ["playmap_36", "playmap_37", "playmap_38"], - "width": 1, - "height": 2, "desc": "Part of the great agracultural landscape near Agrawos.", "a_next": "playmap_33", "s_next": "playmap_39", + "text": """──┐ +┌─┘ +└─┐""", + "color": "brightyellow" }, "add": { - "x": 22, - "y": 2 - } - }, - "playmap_40": { - "gen": { - "additionals": [], - "width": 2, - "height": 1, - "desc": "A Great beach, with great weather, always.", - "s_next": "playmap_21", - }, - "add": { - "x": 18, - "y": 1 + "x": 36, + "y": 4 } }, "playmap_39": { @@ -321,8 +345,6 @@ "additionals": ["playmap_41", "playmap_42", "playmap_43", "playmap_44", "playmap_45", "playmap_46", "playmap_47", "playmap_48"], - "width": 2, - "height": 2, "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 " @@ -330,13 +352,167 @@ "juiciest and most delicious Mowcow-burgers, cut from the " "happiest and most delicious Mowcows anywhere to find!", "w_next": "playmap_35", + "text": """ #│# + P│A +├─┘# + $ #""", + "color": "yellow" + }, + "add": { + "x": 36, + "y": 7 + } + }, + +} + +decorations = { + "cave3": { + "gen": { + "text": """██ +████ + ███""", + "color": "mediumgrey" + }, + "add": { + "x": 8, + "y": 10 + } + }, + + "cave2": { + "gen": { + "text": """█ +███ + ███""", + "color": "mediumgrey" + }, + "add": { + "x": 10, + "y": 13 + } + }, + + "cave1": { + "gen": { + "text": """ +██████ +██████ + █""", + "color": "mediumgrey" + }, + "add": { + "x": 1, + "y": 8 + } + }, + + "cave4-1": { + "gen": { + "text": """████ +████""", + "color": "mediumgrey" + }, + "add": { + "x": 23, + "y": 1 + } + }, + + "cave4": { + "gen": { + "text": """ ███ + ███ + ███ + ███ + ██""", + "color": "mediumgrey" }, "add": { - "x": 21, + "x": 23, + "y": 3 + } + }, + + "cave5": { + "gen": { + "text": """ ██ +█████ +████ + ██ """, + "color": "mediumgrey" + }, + "add": { + "x": 29, + "y": 5 + } + }, + "mountainsee": { + "gen": { + "text": """█""", + "color": "lakeblue" + }, + "add": { + "x": 29, + "y": 8 + } + }, + + "cave7": { + "gen": { + "text": """ ████ + ████ + ███ """, + "color": "mediumgrey" + }, + "add": { + "x": 31, + "y": 1 + } + }, + + "rockybeach": { + "gen": { + "text": """█████""", + "color": "lakeblue" + }, + "add": { + "x": 27, + "y": 1 + } + }, + + "cave6": { + "gen": { + "text": """██""", + "color": "cavegrey" + }, + "add": { + "x": 32, + "y": 4 + } + }, + "sunnylake": { + "gen": { + "text": """███""", + "color": "lakeblue" + }, + "add": { + "x": 12, "y": 4 } }, + "fisherlake": { + "gen": { + "text": """ ████ """, + "color": "lakeblue" + }, + "add": { + "x": 14, + "y": 15 + } + }, } if __name__ == "__main__": - print("\033[31;1mDo not execute this!\033[0m") + print("\033[31;1mDo not execute this!\033[0;1m")