-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsmb3-foundry.py
executable file
·129 lines (89 loc) · 3.6 KB
/
smb3-foundry.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
#!/usr/bin/env python3
import logging
import os
import pathlib
import sys
import traceback
import warnings
from PySide6.QtWidgets import QApplication, QMessageBox
from foundry import auto_save_rom_path, github_issue_link
from foundry.game.File import ROM
from foundry.gui.dialogs.AutoSaveDialog import AutoSaveDialog
LOAD_LEVEL = "--load-level"
LOAD_M3L = "--load-m3l"
CHECK_AUTO_SAVE = "--dont-check-auto-save"
# compatibility for dark mode
warnings.warning = warnings.warn
logger = logging.getLogger(__name__)
# change into the tmp directory pyinstaller uses for the data
if hasattr(sys, "_MEIPASS"):
logger.info(f"Changing current dir to {getattr(sys, '_MEIPASS')}")
os.chdir(getattr(sys, "_MEIPASS"))
from foundry.gui.FoundryMainWindow import FoundryMainWindow # noqa
app = None
def main(path_to_rom, check_auto_save=True, level_data_tuple=(), m3l_path=""):
global app
app = QApplication()
if check_auto_save and auto_save_rom_path.exists():
result = AutoSaveDialog().exec()
if result == QMessageBox.DialogCode.Accepted:
path_to_rom = auto_save_rom_path
QMessageBox.information(
None, "Auto Save recovered", "Don't forget to save the loaded ROM under a new name!"
)
main_window = FoundryMainWindow(path_to_rom, m3l_path)
main_window.on_open_rom(path_to_rom)
if ROM.is_loaded():
if m3l_path:
main_window.load_m3l(m3l_path)
elif level_data_tuple:
main_window.update_level("", *level_data_tuple)
elif not main_window.open_level_selector(None):
main_window.on_new_level(dont_check=True)
main_window.enable_disable_gui_elements()
app.exec()
if __name__ == "__main__":
should_check_auto_save = True
path = ""
m3l_path = ""
level_data_tuple = tuple()
args = sys.argv[1:]
try:
while args:
arg = args.pop(0)
if arg == CHECK_AUTO_SAVE:
should_check_auto_save = False
elif arg == LOAD_M3L:
if not args:
raise ValueError("Did not provide a file path after --load-m3l")
m3l_path = args.pop(0)
if not pathlib.Path(m3l_path).exists():
raise ValueError(f"M3L path '{m3l_path}' does not exist.")
elif arg == LOAD_LEVEL:
if len(args) < 3:
raise ValueError("Needs level address, enemy address and object set number to load a level.")
try:
level_address = int(args.pop(0), 16)
enemy_address = int(args.pop(0), 16)
object_set_number = int(args.pop(0), 16)
except ValueError:
raise ValueError("Level address, enemy address and object set number must be hex integers.")
level_data_tuple = (level_address, enemy_address, object_set_number)
elif pathlib.Path(arg).exists():
path = arg
else:
raise ValueError(f"Unknown command line argument '{arg}'")
print(f"{path=}, {should_check_auto_save=}, {m3l_path=}")
main(path, should_check_auto_save, level_data_tuple, m3l_path)
except Exception as e:
if app is None:
app = QApplication()
box = QMessageBox()
box.setWindowTitle("Crash report")
box.setText(
f"An unexpected error occurred! Please contact the developers at {github_issue_link} "
f"with the error below:\n\n{e}\n\n{traceback.format_exc()}"
)
box.exec()
app.exec()
raise