Skip to content

Commit 3141002

Browse files
committed
Add regex rule for replacing MovableMan:RemoveActor() with .ToDelete = true
Fix .format crash because of unescaped braces in all_lines
1 parent 132040c commit 3141002

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Python/regex_rules.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def regex_replace(all_lines):
2424
all_lines = replace_using_match(all_lines, "ModuleName = (.*) Tech\n", "ModuleName = {}\n\tIsFaction = 1\n")
2525
all_lines = replace_using_match(all_lines, "FundsOfTeam(.*) =", "Team{}Funds =")
2626
all_lines = replace_using_match(all_lines, "[bB]ase\.rte(.*?)\.wav", "Base.rte{}.flac")
27+
all_lines = replace_using_match(all_lines, r"MovableMan:RemoveActor\((.*?)\)", "{}.ToDelete = true")
2728

2829
all_lines = special_replace_using_matches(all_lines, regex_replace_particle,
2930
"ParticleNumberToAdd = (.*)" \
@@ -55,16 +56,18 @@ def replace_without_using_match(all_lines, pattern, replacement):
5556
def replace_using_match(all_lines, pattern, replacement):
5657
matches = re.findall(pattern, all_lines)
5758
if len(matches) > 0:
58-
return re.sub(pattern, replacement, all_lines).format(*matches)
59+
escaped_all_lines = all_lines.replace("{", "{{").replace("}", "}}")
60+
return re.sub(pattern, replacement, escaped_all_lines).format(*matches)
5961
return all_lines
6062

6163

6264
def special_replace_using_matches(all_lines, fn, pattern, replacement, dotall):
6365
matches = re.findall(pattern, all_lines, flags=re.DOTALL if dotall else 0)
6466
# print(matches)
6567
if len(matches) > 0:
68+
escaped_all_lines = all_lines.replace("{", "{{").replace("}", "}}")
6669
new = fn(all_lines, pattern, replacement, matches)
67-
return re.sub(pattern, replacement, all_lines, flags=re.DOTALL if dotall else 0).format(*new)
70+
return re.sub(pattern, replacement, escaped_all_lines, flags=re.DOTALL if dotall else 0).format(*new)
6871
return all_lines
6972

7073

0 commit comments

Comments
 (0)