-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.py
More file actions
146 lines (124 loc) · 4.79 KB
/
ui.py
File metadata and controls
146 lines (124 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
from rich.console import Console
from rich.panel import Panel
from rich.text import Text
import classes
console = Console(width=40)
def print_panel(content: Text, title: str, color: str = "green"):
"""
A general-purpose function to print a rich Panel.
It takes the content, title, and border color.
"""
console.print(
Panel(
content,
title=f"--- {title} ---",
title_align="left",
border_style=color,
padding=(1, 2)
)
)
def show_hero_profile(hero: classes.Hero):
"""
Gathers hero-specific data and passes it to print_panel.
"""
profile_text = Text.assemble(
("Name: ", "dim"), (f"{hero.name}\n",
"bold white"),
("Class: ", "dim"), (f"{hero.proff}\n",
"bold white"),
("Level: ", "dim"), (f"{hero.lvl} (XP: {hero.xp}/{hero.lvlNxt})\n",
"white"),
("Gold: ", "dim"), (f"{hero.gold}\n",
"bold yellow"),
("\n",), # Space
("HP: ", "dim"), (f"{hero.sStats['Health']} / {hero.hpMax}\n",
"bold red"),
("Attack: ", "dim"), (f"{hero.atk}\n", "bold"),
("Defence: ", "dim"), (f"{hero.dfn}\n", "bold"),
("Speed: ", "dim"), (f"{hero.speed}\n", "bold"),
("Evasion: ", "dim"), (f"{hero.evasion}%\n", "bold"),
("\n",), # Space
("Weapon: ", "dim"), (f"{hero.equipment['weapon']}\n", "cyan"),
("Armour: ", "dim"), (f"{hero.equipment['armour']}\n", "cyan"),
("Accessory: ", "dim"), (f"{hero.equipment['accessory']}\n", "cyan")
)
title = f"{hero.name}'s Profile"
print_panel(profile_text, title, color="green")
def show_enemy_stats(enemy: classes.Enemy):
"""
Gathers enemy-specific data and passes it to print_panel.
"""
stats_text = Text.assemble(
("Level: ", "dim"), (f"{enemy.lvl}\n", "white"),
("HP: ", "dim"), (f"{enemy.sStats['Health']}\n", "bold red"),
("Attack: ", "dim"), (f"{enemy.atk}\n", "bold"),
("Defence: ", "dim"), (f"{enemy.dfn}\n", "bold"),
("Speed: ", "dim"), (f"{enemy.sStats['Speed']}\n", "bold"),
("Evasion: ", "dim"), (f"{enemy.sStats['Evasion']}%\n", "bold"),
("\n",), # Space
("XP Reward: ", "dim"), (f"{enemy.xpG}\n", "white"),
("Gold Drop: ", "dim"), (f"0 - {enemy.goldG}\n", "yellow")
)
stats_text.append("\n",) # Space
stats_text.append("Potential Loot:\n", "bold")
if not enemy.loot:
stats_text.append(" (None)\n", "dim")
else:
for item in enemy.loot:
stats_text.append(f" - {item.name}\n", "white")
title = f"{enemy.name} Stats"
print_panel(stats_text, title, color="red")
def show_item_stats(item: classes.Item):
"""
Gathers item-specific data and passes it to print_panel.
"""
stats_text = Text("")
if item.hp:
stats_text.append(f" HP: {item.hp}\n", style="red")
if item.atk != [0, 0]:
stats_text.append(f" ATK: {item.atk}\n", style="white")
if item.dfn:
stats_text.append(f" DEF: {item.dfn}\n", style="white")
if item.spd:
stats_text.append(f" SPD: {item.spd}\n", style="white")
if item.eva:
stats_text.append(f" EVA: {item.eva}%\n", style="white")
if not stats_text:
stats_text = Text(" (No Stats)\n", style="dim")
full_text = Text.assemble(
("Type: ", "dim"), (f"{item.type.capitalize()}\n", "bold white"),
("Value: ", "dim"), (f"{item.value} Gold\n", "yellow"),
("\n",),
("Stats:\n", "dim"),
stats_text
)
print_panel(full_text, title=item.name, color="blue")
def show_inventory(hero: classes.Hero):
"""
Displays the hero's gold and a list of "treasure" items in their satchel.
It ignores weapons, armor, and accessories.
"""
content_text = Text.assemble(
("Gold: ", "dim"), (f"{hero.gold}\n\n", "bold yellow"),
("Treasures:\n", "bold")
)
# Filter the inventory to get *only* treasures
treasure_items = [item for item in hero.inventory if
item.type == "Treasure"]
# Add treasures to the Text object
if not treasure_items:
content_text.append(" (Empty)\n", style="dim")
else:
for item in treasure_items:
content_text.append(f" - {item.name} ", style="white")
content_text.append(f"(Value: {item.value}g)\n",
style="dim yellow")
console.print(
Panel(
content_text,
title=f"--- {hero.name}'s Satchel ---",
title_align="left",
border_style="yellow",
padding=(1, 2)
)
)