Extend type-checking to more macros.

This commit is contained in:
Eric S. Raymond 2008-02-12 05:11:18 +00:00
parent ee17767905
commit 1e90674462
7 changed files with 59 additions and 58 deletions

View file

@ -12,7 +12,7 @@
# This one changes a unit from one type to another
#
#define CHG_TYPE FILTER TARGET
#define CHG_TYPE FILTER VALUE
[store_unit]
[filter]
{FILTER}
@ -25,7 +25,7 @@
{FOREACH chgtype_store i}
[set_variable]
name=chgtype_store[$i].type
value={TARGET}
value={VALUE}
[/set_variable]
[unstore_unit]

View file

@ -185,9 +185,9 @@
# y=14
# )}
#define RANDOM_TRAIT_UNIT STATS
#define RANDOM_TRAIT_UNIT STATS_WML
[unit]
{STATS}
{STATS_WML}
random_traits=yes
[/unit]
#enddef

View file

@ -3,81 +3,81 @@
# These don't rely on any other macros. Please don't change this.
#define DEFENSE_ANIM REACTION BASEFRAME HITSOUND
# Define a defensive animation moving from a specified BASEFRAME
# to REACTION, with HITSOUND playing only if a hit occurs.
#define DEFENSE_ANIM REACTION_IMAGE BASE_IMAGE HIT_SOUND
# Define a defensive animation moving from a specified BASE_IMAGE
# to REACTION_IMAGE, with HIT_SOUND playing only if a hit occurs.
[defend]
start_time=-126
[frame]
duration=1
image={BASEFRAME}
image={BASE_IMAGE}
[/frame]
[frame]
duration=100
image={REACTION}
image={REACTION_IMAGE}
[/frame]
[if]
hits=hit
[frame]
duration=150
image={REACTION}
sound={HITSOUND}
image={REACTION_IMAGE}
sound={HIT_SOUND}
[/frame]
[/if]
[else]
hits=miss,kill
[frame]
duration=150
image={REACTION}
image={REACTION_IMAGE}
[/frame]
[/else]
[frame]
duration=1
image={BASEFRAME}
image={BASE_IMAGE}
[/frame]
[/defend]
#enddef
#define DEFENSE_ANIM_FILTERED REACTION BASEFRAME HITSOUND FILTER
# Define a defensive animation moving from a specified BASEFRAME
# to REACTION, with HITSOUND playing only if a hit occurs. This
#define DEFENSE_ANIM_FILTERED REACTION_IMAGE BASE_IMAGE HIT_SOUND FILTER
# Define a defensive animation moving from a specified BASE_IMAGE
# to REACTION_IMAGE, with HIT_SOUND playing only if a hit occurs. This
# fires only if FILTER is matched.
[defend]
start_time=-126
{FILTER}
[frame]
duration=1
image={BASEFRAME}
image={BASE_IMAGE}
[/frame]
[frame]
duration=100
image={REACTION}
image={REACTION_IMAGE}
[/frame]
[if]
hits=hit
[frame]
duration=150
image={REACTION}
sound={HITSOUND}
image={REACTION_IMAGE}
sound={HIT_SOUND}
[/frame]
[/if]
[else]
hits=miss,kill
[frame]
duration=150
image={REACTION}
image={REACTION_IMAGE}
[/frame]
[/else]
[frame]
duration=1
image={BASEFRAME}
image={BASE_IMAGE}
[/frame]
[/defend]
#enddef
#define DEFENSE_ANIM_RANGE REACTION BASEFRAME HITSOUND RANGE
# Define a defensive animation moving from a specified BASEFRAME
# to REACTION, with HITSOUND playing only if a hit occurs. This
#define DEFENSE_ANIM_RANGE REACTION_IMAGE BASE_IMAGE HIT_SOUND RANGE
# Define a defensive animation moving from a specified BASE_IMAGE
# to REACTION_IMAGE, with HIT_SOUND playing only if a hit occurs. This
# fires only on the class of attacks specified by RANGE.
[defend]
start_time=-126
@ -86,37 +86,37 @@
[/attack_filter]
[frame]
duration=1
image={BASEFRAME}
image={BASE_IMAGE}
[/frame]
[frame]
duration=100
image={REACTION}
image={REACTION_IMAGE}
[/frame]
[if]
hits=hit
[frame]
duration=150
image={REACTION}
sound={HITSOUND}
image={REACTION_IMAGE}
sound={HIT_SOUND}
[/frame]
[/if]
[else]
hits=miss,kill
[frame]
duration=150
image={REACTION}
image={REACTION_IMAGE}
[/frame]
[/else]
[frame]
duration=1
image={BASEFRAME}
image={BASE_IMAGE}
[/frame]
[/defend]
#enddef
#define DEFENSE_ANIM_ELVEN_RANGE REACTION BASEFRAME HITSOUND RANGE
# Define a defensive animation moving from a specified BASEFRAME
# to REACTION, with HITSOUND playing only if a hit occurs and an
#define DEFENSE_ANIM_ELVEN_RANGE REACTION_IMAGE BASE_IMAGE HIT_SOUND RANGE
# Define a defensive animation moving from a specified BASE_IMAGE
# to REACTION_IMAGE, with HIT_SOUND playing only if a hit occurs and an
# elven halo waxing and waning during the animation. This
# fires only on the class of attacks specified by RANGE.
[defend]
@ -127,30 +127,30 @@
[frame]
duration=25
end=-150
image={BASEFRAME}
image={BASE_IMAGE}
halo=halo/elven/elven-shield-halo-20pct.png
[/frame]
[frame]
duration=25
image={BASEFRAME}
image={BASE_IMAGE}
halo=halo/elven/elven-shield-halo-40pct.png
[/frame]
[frame]
duration=50
image={REACTION}
image={REACTION_IMAGE}
halo=halo/elven/elven-shield-halo-60pct.png
[/frame]
[frame]
duration=50
image={REACTION}
image={REACTION_IMAGE}
halo=halo/elven/elven-shield-halo-80pct.png
[/frame]
[if]
hits=hit
[frame]
duration=100
image={REACTION}
sound={HITSOUND}
image={REACTION_IMAGE}
sound={HIT_SOUND}
halo=halo/elven/elven-shield-halo-100pct.png
[/frame]
[/if]
@ -158,28 +158,28 @@
hits=miss,kill
[frame]
duration=100
image={REACTION}
image={REACTION_IMAGE}
halo=halo/elven/elven-shield-halo-100pct.png
[/frame]
[/else]
[frame]
duration=50
image={REACTION}
image={REACTION_IMAGE}
halo=halo/elven/elven-shield-halo-80pct.png
[/frame]
[frame]
duration=25
image={BASEFRAME}
image={BASE_IMAGE}
halo=halo/elven/elven-shield-halo-60pct.png
[/frame]
[frame]
duration=25
image={BASEFRAME}
image={BASE_IMAGE}
halo=halo/elven/elven-shield-halo-40pct.png
[/frame]
[frame]
duration=25
image={BASEFRAME}
image={BASE_IMAGE}
halo=halo/elven/elven-shield-halo-20pct.png
[/frame]
[/defend]

View file

@ -18,7 +18,7 @@
# NOTE the terrain _off^_usr gets its definition from the code since it's
# themable
#define FAKE_REFERENCE RESOURCE
#define FAKE_REFERENCE IMAGE
# Only used to fake references to resource files so they won't
# look unused to the cross-reference checker.
#enddef

View file

@ -1,33 +1,33 @@
#textdomain wesnoth
#define BUILDING LETTER IMAGELINE
#define BUILDING LETTER IMAGE_WML
[terrain_graphics]
[tile]
x=0
y=0
type={LETTER}
{IMAGELINE}
{IMAGE_WML}
[/tile]
set_flag=building-{LETTER}
no_flag=building-{LETTER}
[/terrain_graphics]
#enddef
#define BUILDING_FLAG LETTER IMAGELINE FLAG
#define BUILDING_FLAG LETTER IMAGE_WML FLAG
[terrain_graphics]
[tile]
x=0
y=0
type={LETTER}
has_flag={FLAG}
{IMAGELINE}
{IMAGE_WML}
[/tile]
set_flag=building-{LETTER}
no_flag=building-{LETTER}
[/terrain_graphics]
#enddef
#define BUILDING_FLAG_PROB LETTER IMAGELINE FLAG PROBABILITY
#define BUILDING_FLAG_PROB LETTER IMAGE_WML FLAG PROBABILITY
[terrain_graphics]
[tile]
x=0
@ -35,7 +35,7 @@
type={LETTER}
has_flag={FLAG}
set_flag=overlay
{IMAGELINE}
{IMAGE_WML}
[/tile]
probability={PROBABILITY}
set_flag=building-{LETTER}
@ -43,13 +43,13 @@
[/terrain_graphics]
#enddef
#define BUILDING_PROBABILITY LETTER IMAGELINE PROBABILITY
#define BUILDING_PROBABILITY LETTER IMAGE_WML PROBABILITY
[terrain_graphics]
[tile]
x=0
y=0
type={LETTER}
{IMAGELINE}
{IMAGE_WML}
[/tile]
probability={PROBABILITY}
set_flag=building-{LETTER}

View file

@ -10,13 +10,13 @@
[/unit]
#enddef
#define MPWILD_WALKING_CORPSE X Y VARIATION
#define MPWILD_WALKING_CORPSE X Y VARIATION_NAME
[unit]
type=Walking Corpse
side=5
x={X}
y={Y}
variation={VARIATION}
variation={VARIATION_NAME}
#random_traits=no
[/unit]
#enddef

View file

@ -6,6 +6,7 @@ wmltools.py -- Python routines for working with a Battle For Wesnoth WML tree
import sys, os, re, sre_constants, md5, glob
resource_extensions = ("png", "jpg", "ogg", "wav", "map")
image_reference = r"[A-Za-z0-9{}.][A-Za-z0-9_/+{}.-]*\.(png|jpg)(?=(~.*)?)"
class Forest:
"Return an iterable directory forest object."
@ -102,7 +103,7 @@ def actualtype(a):
atype = "range"
elif a.startswith("{") and a.endswith("}") or a.startswith("$"):
atype = None # Can't tell -- it's a macro expansion
elif a.endswith(".png") or a.endswith(".jpg"):
elif re.match(image_reference, a):
atype = "image"
elif a.endswith(".wav") or a.endswith(".ogg"):
atype = "sound"
@ -185,7 +186,7 @@ class Reference:
class CrossRef:
macro_reference = re.compile(r"\{([A-Z_][A-Z0-9_:]*[A-Za-z0-9_])(?!\.)\b")
file_reference = re.compile(r"[A-Za-z0-9{}.][A-Za-z0-9_/+{}.-]*\.(" + "|".join(resource_extensions) + ")")
file_reference = re.compile(r"[A-Za-z0-9{}.][A-Za-z0-9_/+{}.-]*\.(" + "|".join(resource_extensions) + ")(?=(~.*)?)")
def mark_matching_resources(self, pattern, fn, n):
"Mark all definitions matching a specified pattern with a reference."
pattern = pattern.replace("+", r"\+")