Author: esr
Date: Thu May 3 09:42:47 2007
New Revision: 17280
URL: http://svn.gna.org/viewcvs/wesnoth?rev=17280&view=rev
Log:
Arrange for both map transformations to be done on a 1.2.x map, and
simplify some code.
Modified:
trunk/data/tools/upconvert
Modified: trunk/data/tools/upconvert
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/upconvert?rev=17280&r1=17279&r2=17280&view=diff
==============================================================================
--- trunk/data/tools/upconvert (original)
+++ trunk/data/tools/upconvert Thu May 3 09:42:47 2007
@@ -319,11 +319,10 @@
def maptransform1(input, baseline, inmap, y):
"Transform a map line from 1.2.x to 1.3.x format."
format = "%%%d.%ds" % (width, max_len)
+ if "," in inmap[y]:
+ return inmap[y]
+ line = ''
x = 0
- if "," in inmap[y]:
- raise maptransform_error(2, input, baseline, None,
- "map file appears to be converted already")
- line = ''
for char in inmap[y]:
ohex = ''
if char in ('\n', '\r'):
@@ -331,7 +330,7 @@
elif char in conversion1:
ohex = format % conversion1[char] + ','
else:
- raise maptransform_error(0, input, baseline+y+1, (x, y),
+ raise maptransform_error(input, baseline+y+1, (x, y),
"unrecognized character %s (%d)" %
(`char`, ord(char)))
# ohex = format % char
sys.exit(1)
@@ -346,7 +345,7 @@
# Intentionally skipping 0 as it is original hex
a = adj[i];
if not a in conversion1:
- raise maptransform_error(0, input, baseline, (x, y),
+ raise maptransform_error(input, baseline, (x, y),
"error, %s in adjacent hexes" % a)
sys.exit(1)
ca = conversion1[a]
@@ -405,6 +404,7 @@
def maptransform2(input, baseline, inmap, y):
"Convert a map line from 1.3.1 multiletter format to 1.3.2 format."
mapline = inmap[y]
+ print "Called on:", mapline
for (old, new) in conversion2.items():
mapline = old.sub(new, mapline)
return mapline
@@ -413,8 +413,7 @@
class maptransform_error:
"Error object to be thrown by maptransform."
- def __init__(self, level, infile, inline, loc, type):
- self.level = level
+ def __init__(self, infile, inline, loc, type):
self.infile = infile
self.inline = inline
self.loc = loc
@@ -445,7 +444,7 @@
lineno = baseline = 0
while mfile:
line = mfile.pop(0)
- if verbose >= 4:
+ if verbose >= 3:
sys.stdout.write(line)
lineno += 1
# Exclude map_data= lines that are just 1 line without
@@ -458,7 +457,7 @@
and line.count("}") == 0):
baseline = 0
cont = True
- if verbose >= 4:
+ if verbose >= 3:
print "*** Entering map mode."
# Assumes map is more than 1 line long.
if not map_only:
@@ -467,7 +466,7 @@
outmap.append(line)
while cont and mfile:
line = mfile.pop(0)
- if verbose >= 4:
+ if verbose >= 3:
sys.stdout.write(line)
lineno += 1
if line and line[0] == '#':
@@ -475,7 +474,7 @@
continue
if '"' in line:
cont = False
- if verbose >= 4:
+ if verbose >= 3:
print "*** Exiting map mode."
line = line.split('"')[0]
if line and not line.endswith("\n"):
@@ -533,7 +532,6 @@
for name in files:
if interesting(os.path.join(root, name)):
datafiles.append(os.path.join(root, name))
- print datafiles
datafiles.sort() # So diffs for same campaigns will cluster in reports
return datafiles
@@ -545,10 +543,9 @@
-h, --help Emit this help message and quit.
-d, --dryrun List changes but don't perform them.
-o, --oldversion Specify version to begin with.
- -v, --verbose -v lists changes.
- -v -v warns of maps already converted.
- -v -v -v names each file before it's
processed.
- -v -v -v -v shows verbose parse details.
+ -v, --verbose -v lists changes.
+ -v -v names each file before it's processed.
+ -v -v -v shows verbose parse details.
-c, --clean Clean up -bak files.
-D, --diff Display diffs between unconverted and
unconverted files.
-r, --revert Revert the conversion from the -bak files.
@@ -695,7 +692,8 @@
if "1.3.1" in versions and "older" not in versions:
maptransform = maptransform2
else:
- maptransform = maptransform1
+ # Apply both map transforms. Haskell would be nice here...
+ maptransform = lambda input, baseline, inmap, y:
maptransform2(maptransform1(input, baseline, inmap, y), baseline, inmap, y)
if not arguments:
arguments = ["."]
@@ -703,7 +701,7 @@
for dir in arguments:
ofp = None
for fn in allcfgfiles(dir):
- if verbose >= 3:
+ if verbose >= 2:
print fn + ":"
backup = fn + "-bak"
if clean or revert:
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits