move upconversion of ancient abilities ahead of lifting [frame] to fix problem of weapon specials appearing after [frame] sequence
After my last change, I noticed a puzzling failure by wmllint to convert a weapon special. This special was among some attributes that followed the [frame] sequence. It seems that Python does not wait for the earlier code block to complete before running the new one, and those lines aren't passed through the new block because they've been deleted and stashed in 'postframe'. When they're spewed back out, the new block has already passed those lines by. I was relieved to find that this was not an issue introduced by my change, but an existing one. When I ran the original wmllint on the file, I found that the special= line got deleted, without being replaced by the [special] tags and macro. The latter is supposed to appear when wmllint hits the [/attack] tag, but never triggers because [/attack] has been changed to [/attack_anim]. Moving this code block up, so that abilities and specials are transformed before the [frame] lift (and 'postframe' stash), appeared to fix the problem. Hopefully, it won't cause a new on to show up.
This commit is contained in:
parent
29c9931c05
commit
4bfcb7fe66
1 changed files with 65 additions and 65 deletions
|
@ -1312,6 +1312,71 @@ def hack_syntax(filename, lines):
|
|||
modcount += 1
|
||||
elif converting and "[/animation]" in lines[i]:
|
||||
lines[i] = lines[i].replace("animation", "attack_anim")
|
||||
# Upconvert ancient ability declarations from 1.x
|
||||
level = None
|
||||
abilities = []
|
||||
specials = []
|
||||
lastability = None
|
||||
lastspecial = None
|
||||
for i in range(len(lines)):
|
||||
if "no-syntax-rewrite" in lines[i]:
|
||||
break
|
||||
if "[unit]" in lines[i]:
|
||||
abilities = []
|
||||
if "[attack]" in lines[i]:
|
||||
specials = []
|
||||
elif "[/attack]" in lines[i]:
|
||||
if specials:
|
||||
if verbose:
|
||||
print "Lifting obsolete specials:", " ".join(specials)
|
||||
ws = leader(lines[i])
|
||||
insertion = ws + baseindent + "[specials]\n"
|
||||
for special in specials:
|
||||
if special.startswith("plague("):
|
||||
insertion += ws + baseindent*2 + "{WEAPON_SPECIAL_PLAGUE_TYPE " + special[7:-1] + "}\n"
|
||||
elif special in ("backstab", "berserk", "charge", "drain",
|
||||
"firststrike", "magical", "marksman", "plague",
|
||||
"poison", "slow", "stone", "swarm",):
|
||||
insertion += ws + baseindent*2 + "{WEAPON_SPECIAL_" + special.upper() + "}\n"
|
||||
else:
|
||||
print "Don't know how to convert '%s'" % special
|
||||
insertion += ws + baseindent + "[/specials]\n"
|
||||
lines[lastspecial] = insertion
|
||||
modcount += 1
|
||||
elif "[/unit]" in lines[i]:
|
||||
if abilities:
|
||||
if verbose:
|
||||
print "Lifting obsolete abilities:", " ".join(abilities)
|
||||
ws = leader(lines[i])
|
||||
insertion = ws + baseindent + "[abilities]\n"
|
||||
for ability in abilities:
|
||||
if ability == "leadership":
|
||||
if level is None:
|
||||
print "warning: can't convert ancient leadership ability"
|
||||
else:
|
||||
insertion += ws + baseindent*2 + "{ABILITY_LEADERSHIP_LEVEL_"+level+"}\n"
|
||||
elif ability in ("cures", "heals", "nightstalk", "regenerates",
|
||||
"skirmisher", "steadfast", "illuminates",
|
||||
"teleport", "ambush",):
|
||||
insertion += ws + baseindent*2 + "{ABILITY_" + ability.upper() + "}\n"
|
||||
else:
|
||||
print "Don't know how to convert '%s'" % ability
|
||||
insertion += ws + baseindent + "[/abilities]\n"
|
||||
lines[lastability] = insertion
|
||||
modcount += 1
|
||||
elif lines[i].count("=") == 1:
|
||||
(tag, value) = lines[i].strip().split("=")
|
||||
if tag == "level":
|
||||
level = value
|
||||
if tag == "ability":
|
||||
for able in value.split(","):
|
||||
abilities.append(able.strip())
|
||||
lastability = i
|
||||
lines[i] = ""
|
||||
if tag == "special":
|
||||
specials.append(value)
|
||||
lastspecial = i
|
||||
lines[i] = ""
|
||||
# Lift [frame] declarations directly within attacks
|
||||
in_attack = False
|
||||
attackname = None
|
||||
|
@ -1383,71 +1448,6 @@ def hack_syntax(filename, lines):
|
|||
postframe.append(lines[i])
|
||||
lines[i] = ""
|
||||
modcount += 1
|
||||
# Upconvert ancient ability declarations from 1.x
|
||||
level = None
|
||||
abilities = []
|
||||
specials = []
|
||||
lastability = None
|
||||
lastspecial = None
|
||||
for i in range(len(lines)):
|
||||
if "no-syntax-rewrite" in lines[i]:
|
||||
break
|
||||
if "[unit]" in lines[i]:
|
||||
abilities = []
|
||||
if "[attack]" in lines[i]:
|
||||
specials = []
|
||||
elif "[/attack]" in lines[i]:
|
||||
if specials:
|
||||
if verbose:
|
||||
print "Lifting obsolete specials:", " ".join(specials)
|
||||
ws = leader(lines[i])
|
||||
insertion = ws + baseindent + "[specials]\n"
|
||||
for special in specials:
|
||||
if special.startswith("plague("):
|
||||
insertion += ws + baseindent*2 + "{WEAPON_SPECIAL_PLAGUE_TYPE " + special[7:-1] + "}\n"
|
||||
elif special in ("backstab", "berserk", "charge", "drain",
|
||||
"firststrike", "magical", "marksman", "plague",
|
||||
"poison", "slow", "stone", "swarm",):
|
||||
insertion += ws + baseindent*2 + "{WEAPON_SPECIAL_" + special.upper() + "}\n"
|
||||
else:
|
||||
print "Don't know how to convert '%s'" % special
|
||||
insertion += ws + baseindent + "[/specials]\n"
|
||||
lines[lastspecial] = insertion
|
||||
modcount += 1
|
||||
elif "[/unit]" in lines[i]:
|
||||
if abilities:
|
||||
if verbose:
|
||||
print "Lifting obsolete abilities:", " ".join(abilities)
|
||||
ws = leader(lines[i])
|
||||
insertion = ws + baseindent + "[abilities]\n"
|
||||
for ability in abilities:
|
||||
if ability == "leadership":
|
||||
if level is None:
|
||||
print "warning: can't convert ancient leadership ability"
|
||||
else:
|
||||
insertion += ws + baseindent*2 + "{ABILITY_LEADERSHIP_LEVEL_"+level+"}\n"
|
||||
elif ability in ("cures", "heals", "nightstalk", "regenerates",
|
||||
"skirmisher", "steadfast", "illuminates",
|
||||
"teleport", "ambush",):
|
||||
insertion += ws + baseindent*2 + "{ABILITY_" + ability.upper() + "}\n"
|
||||
else:
|
||||
print "Don't know how to convert '%s'" % ability
|
||||
insertion += ws + baseindent + "[/abilities]\n"
|
||||
lines[lastability] = insertion
|
||||
modcount += 1
|
||||
elif lines[i].count("=") == 1:
|
||||
(tag, value) = lines[i].strip().split("=")
|
||||
if tag == "level":
|
||||
level = value
|
||||
if tag == "ability":
|
||||
for able in value.split(","):
|
||||
abilities.append(able.strip())
|
||||
lastability = i
|
||||
lines[i] = ""
|
||||
if tag == "special":
|
||||
specials.append(value)
|
||||
lastspecial = i
|
||||
lines[i] = ""
|
||||
# Upconvert old radius usage
|
||||
if upconvert and "1.3.7" in versions and "older" not in versions:
|
||||
radius_pos = wmlfind("radius=", WmlIterator(lines, filename))
|
||||
|
|
Loading…
Add table
Reference in a new issue