Skip to content

Commit 0cafc06

Browse files
committed
Fix warnings.py
1 parent ff78265 commit 0cafc06

File tree

1 file changed

+9
-41
lines changed

1 file changed

+9
-41
lines changed

Python/warnings.py

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,14 @@
66
from Python import convert
77

88

9-
warning_rules = {} # A global that's initialized in load_conversion_and_warning_rules()
10-
11-
129
MANUAL_REPLACEMENT_TITLE_SEPARATOR = "=" * 50
13-
mods_warnings = None # A global list set in init_mods_warnings()
14-
15-
def init_mods_warnings():
16-
global mods_warnings
17-
mods_warnings = [
18-
"\n".join(
19-
(MANUAL_REPLACEMENT_TITLE_SEPARATOR, "LINES REQUIRING MANUAL REPLACEMENT", MANUAL_REPLACEMENT_TITLE_SEPARATOR)
20-
)
21-
]
2210

11+
mods_warnings = []
2312

2413
FRESH_CONVERSION_RULES_REMINDER = "You can get a fresh Conversion Rules folder by redownloading the Legacy Mod Converter from its GitHub repository with the below button."
2514

2615

16+
warning_rules = {}
2717
def load_conversion_and_warning_rules():
2818
try:
2919
for folder_path, subfolders, subfiles in os.walk("Conversion Rules"):
@@ -51,51 +41,29 @@ def check_github_button_clicked_and_exit(clicked_github_button):
5141
sys.exit()
5242

5343

54-
mod_warnings = None # A global list set in clear_mod_warnings()
55-
def clear_mod_warnings():
56-
global mod_warnings
57-
mod_warnings = []
58-
59-
6044
def append_mod_replacement_warnings(line, file_path, line_number):
6145
for old_str, new_str in warning_rules.items():
6246
if old_str in line:
63-
append_mod_replacement_warning(file_path, line_number, old_str, new_str)
64-
65-
66-
def append_mod_replacement_warning(file_path, line_number, old_str, new_str):
67-
append_mod_warning(file_path, line_number, f"Replace '{old_str}' with", f"'{new_str}'")
47+
append_mod_warning(file_path, line_number, f"\"{old_str}\"", new_str)
6848

6949

7050
def append_mod_warning(file_path, line_number, error, error_subject):
71-
global mod_warnings
51+
global mods_warnings
7252
warning = f"\nLine {line_number} at {file_path}\n\t{error}: {error_subject}"
73-
mod_warnings.append(warning)
74-
75-
76-
def prepend_mod_title(mod_name):
77-
title = "\n" + "\n".join(
78-
(cfg.WARNINGS_MOD_NAME_SEPARATOR, f"\t{mod_name}", cfg.WARNINGS_MOD_NAME_SEPARATOR)
79-
)
80-
mod_warnings.insert(0, title)
81-
82-
83-
def push_mod_warnings():
84-
global mod_warnings
85-
mods_warnings.extend(mod_warnings)
53+
mods_warnings.append(warning)
8654

8755

8856
def show_popup_if_necessary():
89-
if len(mods_warnings) > 1: # mods_warnings is initialized with a first line, so mods_warnings starts with a len of 1.
57+
if len(mods_warnings) > 0:
9058
warnings_popup()
9159

9260

9361
def warnings_popup():
94-
message = "\n".join(mods_warnings)
62+
message = f"{MANUAL_REPLACEMENT_TITLE_SEPARATOR}\nLINES REQUIRING MANUAL REPLACEMENT\n{MANUAL_REPLACEMENT_TITLE_SEPARATOR}\n" + "\n".join(mods_warnings)
9563

9664
w = max(
9765
30,
98-
len(get_longest_line_length(message)) + 1 # TODO: Add a comment here on why + 1 is necessary.
66+
len(get_longest_line(message)) # Can't divide by two or anything because the line wrapping will cause the height of the window to be wrong, making user have to scroll.
9967
)
10068
h = min(
10169
50,
@@ -111,5 +79,5 @@ def warnings_popup():
11179
)
11280

11381

114-
def get_longest_line_length(message):
82+
def get_longest_line(message):
11583
return max(message.split("\n"), key=len)

0 commit comments

Comments
 (0)