Skip to content

Commit dc43352

Browse files
committed
augh... MORE tests???'
1 parent 6e8a7c9 commit dc43352

File tree

2 files changed

+66
-40
lines changed

2 files changed

+66
-40
lines changed

.github/test.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"HELL_KEEP": "Ultimate Doom///E3: Inferno///E3M1: Hell Keep",
3+
"WARRENS": "Ultimate Doom///E3: Inferno///E3M9: Warrens",
4+
"struct": {
5+
"Ultimate Doom": {
6+
"E3: Inferno": {
7+
"E3M1: Hell Keep": {
8+
"screenshots": [
9+
"https://doomwiki.org/w/images/5/5f/E3m1_shotgun.PNG"
10+
],
11+
"secrets": 1
12+
},
13+
"E3M9: Warrens": {
14+
"screenshots": [
15+
"https://doomwiki.org/w/images/a/a0/E3m9_arena.PNG"
16+
],
17+
"secrets": 1
18+
}
19+
}
20+
}
21+
}
22+
}

main.py

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def send_dialog(dtype: str, title: str, message: str, wraplength: int = 400, roo
156156
__send_responsive_dialog(dtype, title, message, wraplength, kw.get('overwrite_font', SUBTITLE), root_of)
157157

158158
except FileNotFoundError as e:
159-
return handle_error(10, f"Invalid icon. A valid icon bust be the name of an image - without extension - that is inside:\nassets/icons/universal\n\n{e}")
159+
return handle_error(10, f"Invalid icon. A valid icon must be the name of an image - without extension - that is inside:\nassets/icons/universal\n\n{e}")
160160

161161
except __CloseDialogError as e:
162162
return handle_error(12, f"Failed to close dialog by left/right clicking.\n{e}")
@@ -245,11 +245,11 @@ def resize_image(image: Image.Image, wanted_width: int, width_is_height: bool =
245245
new_height = None
246246

247247
match aspect_ratio:
248-
case '1:1':
248+
case '1:1' | '1:1 (Square)':
249249
new_width = nl(new_width, wanted_width)
250250
new_height = nl(new_height, wanted_width)
251251

252-
case "16:9":
252+
case "16:9" | '16:9 (Landscape)':
253253
if new_width is None:
254254
new_width = int(new_height * (16 / 9))
255255

@@ -570,6 +570,11 @@ def setup_play_screen():
570570
GEN_SF = 0
571571
POINTS = 0
572572

573+
selected_game.set(list(CUR_DB.structure.keys())[0])
574+
selected_episode.set(list(CUR_DB.structure[selected_game.get()].keys())[0])
575+
selected_map.set(list(CUR_DB.structure[selected_game.get()][selected_episode.get()].keys())[0])
576+
selected_secrets.set(0)
577+
573578
PLAY_ITEMS.headframe = ttk.Frame(PLAY_ITEMS)
574579
PLAY_ITEMS.heading = ttk.Label(PLAY_ITEMS.headframe, text='Play', font=HEADING1, justify='left')
575580
PLAY_ITEMS.f0 = ImportantFrame(master=PLAY_ITEMS.headframe)
@@ -683,6 +688,8 @@ def open_database_editor(master: tk.Toplevel, copy: Any) -> None:
683688
def run_button(action: int, **kw) -> None | int | Database | bool:
684689
match action:
685690
case 0:
691+
DATABASES[chosen_db_index.get()].obtain()
692+
DATABASES[chosen_db_index.get()].verify()
686693
DATABASES[chosen_db_index.get()].use()
687694
copy.databases = [i.source for i in DATABASES]
688695

@@ -698,40 +705,28 @@ def run_button(action: int, **kw) -> None | int | Database | bool:
698705
return
699706

700707
case 1:
701-
chosen_db_index.set(chosen_db_index.get() - 1)
702-
703-
try:
704-
chosen_db.set(DATABASES[chosen_db_index.get()].source[:90] if len(DATABASES[chosen_db_index.get()].source) > 90 else DATABASES[chosen_db_index.get()].source)
705-
706-
except IndexError:
707-
chosen_db_index.set(chosen_db_index.get() + 1)
708-
return
709-
710-
down.configure(state=tk.ACTIVE)
711-
712-
if chosen_db.get() == DATABASES[0].source:
713-
up.configure(state=tk.DISABLED)
714-
return
715-
708+
print('no longer available')
709+
716710
case 2:
717711
chosen_db_index.set(chosen_db_index.get() + 1)
718712

719713
try:
720714
chosen_db.set(DATABASES[chosen_db_index.get()].source[:90] if len(DATABASES[chosen_db_index.get()].source) > 90 else DATABASES[chosen_db_index.get()].source)
721715

722716
except IndexError:
723-
chosen_db_index.set(chosen_db_index.get() - 1)
724-
return
717+
chosen_db_index.set(0)
718+
chosen_db.set(DATABASES[chosen_db_index.get()].source[:90] if len(DATABASES[chosen_db_index.get()].source) > 90 else DATABASES[chosen_db_index.get()].source)
725719

726-
up.configure(state=tk.ACTIVE)
727-
728-
if chosen_db.get() == DATABASES[-1].source:
729-
down.configure(state=tk.DISABLED)
730-
return
720+
return
731721

732722
case 3:
733-
return DATABASES[chosen_db_index.get()].remove()
723+
DATABASES[chosen_db_index.get()].remove()
724+
725+
chosen_db_index.set(0)
726+
chosen_db.set(DATABASES[chosen_db_index.get()].source[:90] if len(DATABASES[chosen_db_index.get()].source) > 90 else DATABASES[chosen_db_index.get()].source)
734727

728+
return
729+
735730
case 4:
736731
input_text: str = add_db_entry.get()
737732

@@ -745,6 +740,7 @@ def run_button(action: int, **kw) -> None | int | Database | bool:
745740
return handle_error(54, "This database cannot be used by DoomMapGuesser. Please refer to the previously showed error.")
746741

747742
del test_var
743+
add_db_entry.delete(0, tk.END)
748744

749745
return add_database(input_text)
750746

@@ -791,14 +787,12 @@ def run_button(action: int, **kw) -> None | int | Database | bool:
791787
db_picker = ttk.Button(f_existing, textvariable=chosen_db, width=120, command=lambda:
792788
simple_webbrowser.website(chosen_db.get()))
793789

794-
up = ttk.Button(f_existing, text='↑', command=lambda:
795-
run_button(1))
796790
down = ttk.Button(f_existing, text='↓', command=lambda:
797791
run_button(2))
798792
remove = ttk.Button(f_existing, text='X', command=lambda:
799793
run_button(3))
800794

801-
add_db_entry = ttk.Entry(f_controls)
795+
add_db_entry = ttk.Entry(f_controls, font=SUBTITLE)
802796
add_db_button = ttk.Button(f_controls, text='+', command=lambda: # [i] if the user doesn't hit enter they could always use the button, right?
803797
run_button(4))
804798
cancel_add_db = ttk.Button(f_controls, text='X', command=lambda:
@@ -811,17 +805,16 @@ def run_button(action: int, **kw) -> None | int | Database | bool:
811805
cancel = ttk.Button(database_win, text='Cancel', command=lambda:
812806
run_button(7))
813807

814-
warning_label_1 = ttk.Label(database_win, text='Sorting databases can only be done by editing the actual JSON file. This interface is intended for users that lack programming skills.', font=LIGHT_TEXT, wraplength=400)
815-
warning_label_2 = ttk.Label(database_win, text='Databases should be raw JSON. An example is the default database. It\'s highly recommended to also host it in a safe way that promotes easy access from scripts, such as GitHub.', font=LIGHT_TEXT, wraplength=400)
808+
warning_label_1 = ttk.Label(database_win, text='Sorting databases can only be done by editing the actual JSON file. This interface is intended for users that lack programming skills.', font=LIGHT_TEXT, wraplength=400, justify='center')
809+
warning_label_2 = ttk.Label(database_win, text='Databases should be raw JSON. An example is the default database. It\'s highly recommended to also host it in a safe way that promotes easy access from scripts, such as GitHub.', font=LIGHT_TEXT, wraplength=400, justify='center')
816810

817811
title.pack(padx=5 // int(copy.small_fonts + 1), pady=5 // int(copy.small_fonts + 1), ipadx=5 // int(copy.small_fonts + 1), ipady=5 // int(copy.small_fonts + 1))
818812

819813
existing.pack(padx=5 // int(copy.small_fonts + 1), pady=5 // int(copy.small_fonts + 1), ipadx=5 // int(copy.small_fonts + 1), ipady=5 // int(copy.small_fonts + 1))
820814

821815
db_picker.grid(column=0, row=0, padx=5 // int(copy.small_fonts + 1), pady=5 // int(copy.small_fonts + 1), ipadx=5 // int(copy.small_fonts + 1), ipady=5 // int(copy.small_fonts + 1))
822-
up.grid(column=1, row=0, padx=5 // int(copy.small_fonts + 1), pady=5 // int(copy.small_fonts + 1), ipadx=5 // int(copy.small_fonts + 1), ipady=5 // int(copy.small_fonts + 1))
823-
down.grid(column=2, row=0, padx=5 // int(copy.small_fonts + 1), pady=5 // int(copy.small_fonts + 1), ipadx=5 // int(copy.small_fonts + 1), ipady=5 // int(copy.small_fonts + 1))
824-
remove.grid(column=3, row=0, padx=5 // int(copy.small_fonts + 1), pady=5 // int(copy.small_fonts + 1), ipadx=5 // int(copy.small_fonts + 1), ipady=5 // int(copy.small_fonts + 1))
816+
down.grid(column=1, row=0, padx=5 // int(copy.small_fonts + 1), pady=5 // int(copy.small_fonts + 1), ipadx=5 // int(copy.small_fonts + 1), ipady=5 // int(copy.small_fonts + 1))
817+
remove.grid(column=2, row=0, padx=5 // int(copy.small_fonts + 1), pady=5 // int(copy.small_fonts + 1), ipadx=5 // int(copy.small_fonts + 1), ipady=5 // int(copy.small_fonts + 1))
825818

826819
f_existing.pack(padx=5 // int(copy.small_fonts + 1), pady=5 // int(copy.small_fonts + 1), ipadx=5 // int(copy.small_fonts + 1), ipady=5 // int(copy.small_fonts + 1))
827820

@@ -865,11 +858,19 @@ def run_button(action: int):
865858
cur_settings.zoom_boost = float(zoom_boost.get()[:-1])
866859
cur_settings.check_for_updates_on_startup = bool(updates_startup.get())
867860
cur_settings.small_fonts = bool(smol_fonts_var.get())
861+
862+
try:
863+
cur_settings.image_width = int(wanted_width_entry.get())
864+
865+
except TypeError:
866+
return handle_error(55, "Bad Image Width.\nThe image width must always be an integer, even if when resized becomes a float.")
868867

869868
cur_settings.save_settings()
870869
settings_win.destroy()
870+
871871
for child in list(PLAY_ITEMS.children.values()):
872872
child.destroy()
873+
873874
play_butt.configure(state=tk.ACTIVE)
874875
root.focus_force()
875876
return
@@ -934,7 +935,7 @@ def run_button(action: int):
934935
ratio_picker = ttk.OptionMenu(f_inner_image, chosen_ratio, cur_settings.image_ratio, 'Autodetect', "1:1 (Square)", "16:9 (Landscape)")
935936

936937
wanted_width_label = ttk.Label(f_inner_image, text='Desired Width: ')
937-
wanted_width_entry = ttk.Entry(f_inner_image)
938+
wanted_width_entry = ttk.Entry(f_inner_image, font=SUBTITLE)
938939
wanted_width_entry.insert(0, str(cur_settings.image_width))
939940

940941
reverse_width_height = ttk.Checkbutton(f_image, variable=width_is_height, text='Use the value above as the desired height')
@@ -1099,7 +1100,7 @@ def add(self, **kw) -> None:
10991100
DATABASES[self._INDEX] = self
11001101

11011102
else:
1102-
if kw.get('index', -2) == -2:
1103+
if kw.get('index', None) is None:
11031104
DATABASES.append(self)
11041105

11051106
else:
@@ -1167,6 +1168,10 @@ def verify(self) -> int:
11671168
self._DB = {}
11681169
return handle_error(19, "The database structure is not correct. WARRENS and HELL_KEEP require each other, so the user might leave both undefined or define both, but cannot define only one of them.")
11691170

1171+
if w is not None and hk is not None:
1172+
if w == hk:
1173+
return handle_error(19, "The database structure is not correct. WARRENS and HELL_KEEP must not point to the same map.")
1174+
11701175
# [!?] Rule 2: overall structure should be correct
11711176
if self._DB.get('struct', None) is None:
11721177
self._DB = {}
@@ -1213,7 +1218,7 @@ def verify(self) -> int:
12131218
return handle_error(25, "An integer between 0 and 99, both ends included, must be the match for the key 'secrets'.")
12141219

12151220
# [!?] Rule 3: WARRENS and HELL_KEEP are pointing to valid maps
1216-
if w is None or hk is None:
1221+
if w is not None and hk is not None:
12171222
w_list = w.split('///')
12181223
hk_list = hk.split('///')
12191224

@@ -1432,8 +1437,8 @@ def __setitem__(self, item, value) -> None:
14321437

14331438
def add_database(source: str, *_, index: int | None = None) -> Database | bool:
14341439
new_database = Database(source=source)
1435-
new_database.get()
1436-
1440+
new_database.obtain()
1441+
14371442
if new_database.database is None:
14381443
return False
14391444

@@ -1501,7 +1506,6 @@ def add_database(source: str, *_, index: int | None = None) -> Database | bool:
15011506
style.configure('Important.TFrame', background='#f17b7b' if settings.theme == 'dark' else "#5a0606")
15021507
style.configure('Important.TLabel', font=BOLD_TEXT, foreground='#000000' if settings.theme == 'dark' else "#ffffff", background='#f17b7b' if settings.theme == 'dark' else "#5a0606")
15031508
style.configure('TEntry', font=SUBTITLE, background='#9c9c9c' if settings.theme == 'dark' else "#0e0e0e", foreground='#ffffff' if settings.theme == 'dark' else '#000000')
1504-
style.configure('TOptionMenu', font=SUBTITLE)
15051509
style.configure('TCheckbutton', font=BOLD_TEXT)
15061510

15071511
settings.save_settings()

0 commit comments

Comments
 (0)