Skip to content

Commit

Permalink
Merge pull request #276 from JanekKermit/275-improve-roadmap
Browse files Browse the repository at this point in the history
275 improve roadmap
  • Loading branch information
lxgr-linux authored Jun 17, 2024
2 parents fc28e8a + c9a36a6 commit 2c89867
Show file tree
Hide file tree
Showing 5 changed files with 443 additions and 174 deletions.
4 changes: 2 additions & 2 deletions pokete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,)],
Expand Down
22 changes: 19 additions & 3 deletions pokete_classes/color.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Contains the color class"""
from os import environ


class Color:
Expand All @@ -7,16 +8,31 @@ 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"
cyan = "\033[1;36m"
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")
191 changes: 134 additions & 57 deletions pokete_classes/roadmap.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"""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
from .hotkeys import ACTION_DIRECTIONS, Action, ActionList, get_action
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


Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -133,50 +180,67 @@ 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()
if action.triggers(*ACTION_DIRECTIONS):
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
Expand All @@ -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")
2 changes: 1 addition & 1 deletion pokete_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Loading

0 comments on commit 2c89867

Please sign in to comment.