wmllint: automatically remove {SOUND:SLOW} and {SOUND:POISON} lines

Part of point 5 of issue #6403
This commit is contained in:
Elvish_Hunter 2022-05-17 23:57:08 +02:00
parent 77d5c6cf47
commit f7859ad104
2 changed files with 19 additions and 5 deletions

View file

@ -14,6 +14,7 @@
### User interface
### WML Engine
### Miscellaneous and Bug Fixes
* wmllint automatically removes the obsolete lines `{SOUND:SLOW}` and `{SOUND:POISON}`
## Version 1.17.4
### Campaigns
* Sceptre of Fire

View file

@ -223,6 +223,13 @@ aliaschanges = (
("Vi", "Vt"),
)
# Deprecated lines that ought to be removed globally. Suppressed by noconvert.
obsolete_lines = (
"{MAGENTA_IS_THE_TEAM_COLOR}",
"{SOUND:SLOW}",
"{SOUND:POISON}",
)
# Global changes meant to be done on all lines. Suppressed by noconvert.
linechanges = (
("canrecruit=1", "canrecruit=yes"),
@ -2947,13 +2954,19 @@ def hack_syntax(filename, lines):
in_side_one_tag = False
side_one_tag_needs_side_one = True
break
# handle removal of {MAGENTA_IS_THE_TEAM_COLOR}
# handle removal of obsolete lines without replacement
# obsolete_lines contains normal strings, so re.escape is needed to embed them into this regex
obsolete_re = re.compile(r"(\s*)(" + "|".join([re.escape(l) for l in obsolete_lines]) + r")(.*)")
for i, line in enumerate(lines):
if "no-syntax-rewrite" in line:
break
m = re.match(r"(\s*)\{MAGENTA_IS_THE_TEAM_COLOR\}(.*)", line)
if "wmllint: noconvert" in line:
continue
m = obsolete_re.match(line)
if m:
new_line = m.group(1) + m.group(2).lstrip()
# match group 1 is the indentation
# match group 3 contains everything after the removed part (like comments)
new_line = m.group(1) + m.group(3).lstrip()
if new_line.isspace():
# only empty spaces, make the line blank
# don't remove the line to not alter the other for cycles
@ -2961,8 +2974,8 @@ def hack_syntax(filename, lines):
else:
# keep indentation and comments
lines[i] = new_line + "\n"
print('"{}", line {}: removed MAGENTA_IS_THE_TEAM_COLOR'.format(filename,
i+1))
# match group 2 contains the removed part
print('"{}", line {}: removed {}'.format(filename, i+1, m.group(2)))
# handle deprecation of [unit] placement=map_overwrite/map_passable/leader_passable
in_unit = False
for i, line in enumerate(lines):