forked from Gafgharion/Initiative-Tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_monster_window.py
389 lines (340 loc) · 14.8 KB
/
add_monster_window.py
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
import tkinter as tk
import customtkinter
from statblock_scraper import get_statblock
import asyncio
class MonsterWindow(customtkinter.CTk):
def __init__(self, parent, callback):
super().__init__()
self.skills = {}
self.title("Add Monster")
self.monster_frame = customtkinter.CTkFrame(
self, width=400, height=200, corner_radius=0
)
self.monster_frame.grid(row=0, column=0, sticky="nsew", padx=30, pady=10)
self.monster_name_entry = customtkinter.CTkEntry(
self.monster_frame, placeholder_text="Monster Name"
)
self.monster_name_entry.grid(row=1, column=0, sticky="nsew", padx=30, pady=10)
self.monster_name_entry.bind("<KeyRelease>", self.show_import_button)
self.monster_name_entry.bind("<Return>", self.on_enter)
self.after(100, self.monster_name_entry.focus_force)
# Import button (initially hidden)
self.import_button = customtkinter.CTkButton(
self.monster_frame, text="Import Monster", command=self.import_monster
)
self.import_button.grid(row=1, column=1, sticky="nsew", padx=10, pady=10)
self.import_button.grid_remove() # Initially hide the button
self.initiative_modifier_entry = customtkinter.CTkEntry(
self.monster_frame, placeholder_text="Initiative"
)
self.initiative_modifier_entry.grid(
row=2, column=0, sticky="nsew", padx=30, pady=10
)
self.num_monsters_entry = customtkinter.CTkEntry(
self.monster_frame,
placeholder_text="How many?",
)
self.num_monsters_entry.grid(row=3, column=0, sticky="nsew", padx=30, pady=10)
self.num_monsters_entry.bind("<Return>", self.on_enter_with_filled_form)
self.average_health_entry = customtkinter.CTkEntry(
self.monster_frame,
placeholder_text="Average Health",
)
self.average_health_entry.grid(row=4, column=0, sticky="nsew", padx=30, pady=10)
self.armor_class_entry = customtkinter.CTkEntry(
self.monster_frame,
placeholder_text="Armor Class",
)
self.armor_class_entry.grid(row=5, column=0, sticky="nsew", padx=30, pady=10)
self.speed_entry = customtkinter.CTkEntry(
self.monster_frame, placeholder_text="Speed"
)
self.speed_entry.grid(row=6, column=0, sticky="nsew", padx=30, pady=10)
self.resistances_entry = customtkinter.CTkEntry(
self.monster_frame, placeholder_text="Resistances"
)
self.resistances_entry.grid(row=7, column=0, sticky="nsew", padx=30, pady=10)
self.damage_immunities_entry = customtkinter.CTkEntry(
self.monster_frame, placeholder_text="Damage Immunities"
)
self.damage_immunities_entry.grid(
row=8, column=0, sticky="nsew", padx=30, pady=10
)
self.damage_vulnerabilities_entry = customtkinter.CTkEntry(
self.monster_frame, placeholder_text="Damage Vulnerabilities"
)
self.damage_vulnerabilities_entry.grid(
row=9, column=0, sticky="nsew", padx=30, pady=10
)
self.condition_immunities_entry = customtkinter.CTkEntry(
self.monster_frame, placeholder_text="Condition Immunities"
)
self.condition_immunities_entry.grid(
row=10, column=0, sticky="nsew", padx=30, pady=10
)
self.monstertyp_auswahl_frame = customtkinter.CTkFrame(self)
self.monstertyp_auswahl_frame.grid(
row=0, column=1, sticky="nsew", padx=30, pady=10
)
self.type_var = tk.StringVar()
self.monstertyp_auswahl_frame_label = customtkinter.CTkLabel(
master=self.monstertyp_auswahl_frame, text="Choose the monster type:"
)
self.monstertyp_auswahl_frame_label.grid(
row=0, column=0, sticky="nsew", padx=30, pady=10
)
self.humanoid_button = customtkinter.CTkRadioButton(
master=self.monstertyp_auswahl_frame,
text="Humanoid",
variable=self.type_var,
value="humanoid",
)
self.humanoid_button.grid(row=1, column=0, sticky="nsew", padx=30, pady=10)
self.tier_button = customtkinter.CTkRadioButton(
master=self.monstertyp_auswahl_frame,
text="Tier",
variable=self.type_var,
value="beast",
)
self.tier_button.grid(row=2, column=0, sticky="nsew", padx=30, pady=10)
self.untot_button = customtkinter.CTkRadioButton(
master=self.monstertyp_auswahl_frame,
text="Untot",
variable=self.type_var,
value="undead",
)
self.untot_button.grid(row=3, column=0, sticky="nsew", padx=30, pady=10)
self.maschine_button = customtkinter.CTkRadioButton(
master=self.monstertyp_auswahl_frame,
text="Maschine",
variable=self.type_var,
value="construct",
)
self.maschine_button.grid(row=4, column=0, sticky="nsew", padx=30, pady=10)
self.schleim_button = customtkinter.CTkRadioButton(
master=self.monstertyp_auswahl_frame,
text="Schleim",
variable=self.type_var,
value="ooze",
)
self.schleim_button.grid(row=5, column=0, sticky="nsew", padx=30, pady=10)
self.celestial_button = customtkinter.CTkRadioButton(
master=self.monstertyp_auswahl_frame,
text="Celestial",
variable=self.type_var,
value="celestial",
)
self.celestial_button.grid(row=6, column=0, sticky="nsew", padx=30, pady=10)
self.drache_button = customtkinter.CTkRadioButton(
master=self.monstertyp_auswahl_frame,
text="Drache",
variable=self.type_var,
value="dragon",
)
self.drache_button.grid(row=7, column=0, sticky="nsew", padx=30, pady=10)
self.element_button = customtkinter.CTkRadioButton(
master=self.monstertyp_auswahl_frame,
text="Elementar",
variable=self.type_var,
value="elemental",
)
self.element_button.grid(row=8, column=0, sticky="nsew", padx=30, pady=10)
self.aberration_button = customtkinter.CTkRadioButton(
master=self.monstertyp_auswahl_frame,
text="Aberration",
variable=self.type_var,
value="aberration",
)
self.aberration_button.grid(row=9, column=0, sticky="nsew", padx=30, pady=10)
self.fey_button = customtkinter.CTkRadioButton(
master=self.monstertyp_auswahl_frame,
text="Fee",
variable=self.type_var,
value="fey",
)
self.fey_button.grid(row=10, column=0, sticky="nsew", padx=30, pady=10)
self.fiend_button = customtkinter.CTkRadioButton(
master=self.monstertyp_auswahl_frame,
text="Fiend",
variable=self.type_var,
value="fiend",
)
self.fiend_button.grid(row=1, column=1, sticky="nsew", padx=30, pady=10)
self.giant_button = customtkinter.CTkRadioButton(
master=self.monstertyp_auswahl_frame,
text="Riese",
variable=self.type_var,
value="giant",
)
self.giant_button.grid(row=2, column=1, sticky="nsew", padx=30, pady=10)
self.monstrosity_button = customtkinter.CTkRadioButton(
master=self.monstertyp_auswahl_frame,
text="Monstrosität",
variable=self.type_var,
value="monstrosity",
)
self.monstrosity_button.grid(row=3, column=1, sticky="nsew", padx=30, pady=10)
self.plant_button = customtkinter.CTkRadioButton(
master=self.monstertyp_auswahl_frame,
text="Pflanze",
variable=self.type_var,
value="plant",
)
self.plant_button.grid(row=4, column=1, sticky="nsew", padx=30, pady=10)
# create Submit button frame
self.submit_button_frame = customtkinter.CTkFrame(self)
self.submit_button_frame.grid(
row=1, column=0, sticky="nsew", padx=30, pady=10, columnspan=3
)
self.submit_button_frame.grid_rowconfigure(2, weight=1)
self.submit_button = customtkinter.CTkButton(
master=self.submit_button_frame, text="Submit", command=self.submit
)
self.submit_button.grid(row=0, column=0, padx=30, pady=10)
# TODO: rausfinden wie man in einer FUnktion variablen generierne, die in self zur Verfügung stehen, EIngabefeld für Spieler mit Typ und default = HUmanoid,
self.callback = callback
"""this method defines the behaviour of the submit button which is used in the MonsterWIndow class. It reads out the values in the EntryWidgets, the radiobutton which was ticked and passes the values to the add_monster Method"""
def show_import_button(self, *args):
# Get the current text from the monster name entry
monster_name = self.monster_name_entry.get()
# Show the Import button only if the monster name entry is not empty
if monster_name:
self.import_button.grid() # Make the button visible
self.import_button.configure(
text=f"Import {monster_name}"
) # Update button text
else:
self.import_button.grid_remove() # Hide the button if the entry is cleared
self.import_button.configure(text="Import Monster") # Reset button text
def import_monster(self):
monster_name = self.monster_name_entry.get()
monster_statblock = asyncio.run(get_statblock(monster_name))
print(monster_statblock)
possible_types = [
"aberration",
"humanoid",
"beast",
"undead",
"construct",
"ooze",
"celestial",
"dragon",
"elemental",
"fey",
"fiend",
"giant",
"monstrosity",
"plant",
]
if monster_statblock:
dex_score_string = monster_statblock.get("ability_scores", {}).get(
"DEX", "0 (0)"
)
dex_modifier = dex_score_string.split("(")[-1].strip(")")
self.initiative_modifier_entry.delete(0, tk.END)
self.initiative_modifier_entry.insert(0, dex_modifier)
hit_points = monster_statblock.get("important_info", {}).get(
"Hit Points", "0 (0)"
)
average_health = hit_points.split("(")[-1].strip(")")
self.average_health_entry.delete(0, tk.END)
self.average_health_entry.insert(0, average_health)
armor_class = monster_statblock.get("important_info", {}).get(
"Armor Class", "0"
)
speed = monster_statblock.get("important_info", {}).get("Speed", "0")
self.armor_class_entry.delete(0, tk.END)
self.armor_class_entry.insert(0, armor_class)
self.speed_entry.delete(0, tk.END)
self.speed_entry.insert(0, speed)
# Set new fields with default values for None
self.resistances_entry.delete(0, tk.END)
self.resistances_entry.insert(
0,
monster_statblock.get("important_info", {}).get(
"Damage Resistances", "None"
),
)
self.damage_immunities_entry.delete(0, tk.END)
self.damage_immunities_entry.insert(
0,
monster_statblock.get("important_info", {}).get(
"Damage Immunities", "None"
),
)
self.damage_vulnerabilities_entry.delete(0, tk.END)
self.damage_vulnerabilities_entry.insert(
0,
monster_statblock.get("important_info", {}).get(
"Damage Vulnerabilities", "None"
),
)
self.condition_immunities_entry.delete(0, tk.END)
self.condition_immunities_entry.insert(
0,
monster_statblock.get("important_info", {}).get(
"Condition Immunities", "None"
),
)
split_monster_type = (
monster_statblock.get("creature_type").replace(",", " ").split()
)
found_types = [
word for word in split_monster_type if word in possible_types
]
if found_types:
self.type_var.set(found_types[0])
skills_string = monster_statblock.get("important_info", {}).get(
"Skills", "None"
)
if skills_string != "None":
# Split the string by commas to separate each skill
skills_list = skills_string.split(", ")
# Iterate over the list to populate the dictionary
for skill in skills_list:
# Split each skill into its name and value
name, value = skill.split(" ")
# Add to the dictionary
self.skills[name] = value
self.after(100, self.num_monsters_entry.focus_force)
def on_enter(self, event):
if self.monster_name_entry.get():
self.import_monster()
def on_enter_with_filled_form(self, event):
# Check if all necessary fields are filled
if (
self.monster_name_entry.get()
and self.initiative_modifier_entry.get()
and self.num_monsters_entry.get()
and self.average_health_entry.get()
and self.type_var.get()
):
self.submit()
def submit(self):
monster_name = self.monster_name_entry.get()
initiative_modifier = int(self.initiative_modifier_entry.get())
num_monsters = int(self.num_monsters_entry.get())
average_health = self.average_health_entry.get()
monster_type = self.type_var.get()
armor_class = self.armor_class_entry.get() or None
speed = self.speed_entry.get() or None
resistances = self.resistances_entry.get() or None
damage_immunities = self.damage_immunities_entry.get() or None
damage_vulnerabilities = self.damage_vulnerabilities_entry.get() or None
condition_immunities = self.condition_immunities_entry.get() or None
monster_skills = self.skills or None
self.callback(
monster_name,
initiative_modifier,
num_monsters,
average_health,
monster_type,
armor_class,
speed,
resistances,
damage_immunities,
damage_vulnerabilities,
condition_immunities,
monster_skills,
)
self.destroy()