Author: esr
Date: Mon Apr 23 20:52:27 2007
New Revision: 17006
URL: http://svn.gna.org/viewcvs/wesnoth?rev=17006&view=rev
Log:
First cut at integrating map conversion.
Modified:
trunk/data/tools/upconvert
Modified: trunk/data/tools/upconvert
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/upconvert?rev=17006&r1=17005&r2=17006&view=diff
==============================================================================
--- trunk/data/tools/upconvert (original)
+++ trunk/data/tools/upconvert Mon Apr 23 20:52:27 2007
@@ -2,7 +2,7 @@
#
# Up-convert UMC between versions.
-import sys, os, getopt
+import sys, os, re, getopt
filemoves = {
# Older includes all previous to 1.3.1.
@@ -64,6 +64,46 @@
"1.3.2" : (),
}
+# 1.3.1 -> 1.3.2 terrain conversions
+terrain_conversions = {
+ "Bww|" : "Ww^Bw|",
+ "Bww/" : "Ww^Bw/",
+ "Bww\\" : "Ww^Bw\\",
+ "Bwo|" : "Wo^Bw|",
+ "Bwo/" : "Wo^Bw/",
+ "Bwo\\" : "Wo^Bw\\",
+ "Bss|" : "Ss^Bw|",
+ "Bss/" : "Ss^Bw/",
+ "Bss\\" : "Ss^Bw\\",
+ "Dc" : "Dd^Dc",
+ "Dr" : "Dd^Dr",
+ "Do" : "Dd^Do",
+ "Fa" : "Aa^Fpa",
+ "Fet" : "Gg^Fet",
+ "Ff" : "Gs^Fp",
+ "Ft" : "Gs^Ft",
+ "Rfvs" : "Re^Gvs",
+ "Uf" : "Uu^Uf",
+ "Uui" : "Uu^Ii",
+ "Uhi" : "Uh^Ii",
+ "Vda" : "Dd^Vda",
+ "Vdt" : "Dd^Vdt",
+ "Vea" : "Aa^Vea",
+ "Veg" : "Gg^Ve",
+ "Vha" : "Aa^Vha",
+ "Vhg" : "Gg^Vh",
+ "Vhh" : "Hh^Vhh",
+ "Vhha" : "Ha^Vhha",
+ "Vhm" : "Mm^Vhh",
+ "Vht" : "Gs^Vht",
+ "Vu" : "Uu^Vu",
+ "Vud" : "Uu^Vud",
+ "Vwm" : "Ww^Vm",
+ "Vs" : "Ss^Vhs",
+ "Vsm" : "Ss^Vm",
+ "Xm" : "Mm^Xm"
+ }
+
def allcfgfiles(dir):
"Get the names of all .cfg files under dir, ignoring .svn directories."
datafiles = []
@@ -71,7 +111,7 @@
lambda arg, dir, names: datafiles.extend(map(lambda x:
os.path.normpath(os.path.join(dir, x)), names)),
None)
datafiles = filter(lambda x: ".svn" not in x, datafiles)
- datafiles = filter(lambda x: x.endswith(".cfg"), datafiles)
+ datafiles = filter(lambda x: x.endswith(".cfg") or 'maps' in x, datafiles)
return datafiles
def help():
@@ -83,6 +123,12 @@
-d, --dryrun List changes but don't perform them.
-o, --oldversion Specify version to begin with.
""")
+
+def mapconvert2(mapline):
+ "Convert a map line from 1.3.1 multiletter format to 1.3.2 format."
+ for (old, new) in terrain_conversions.items():
+ mapline = re.sub(r"\b" + re.escape(old) + r"\b", new, mapline)
+ return mapline
if __name__ == '__main__':
(options, arguments) = getopt.getopt(sys.argv[1:], "o:", [
@@ -114,7 +160,7 @@
for i in range(len(versions)-1):
explain += " %s -> %s," % (versions[i], versions[i+1])
sys.stdout.write(explain[:-1] + ".\n")
- conversions = map(lambda x: filemoves[x], versions[:-1])
+ fileconversions = map(lambda x: filemoves[x], versions[:-1])
# Perform resource file substitutions
ofp = None
@@ -128,19 +174,27 @@
modified = False
for (i, line) in enumerate(ifp):
transformed = line
- for step in conversions:
- for (old, new) in step:
- transformed = transformed.replace(old, new)
+ # Filename conversions
+ if ".cfg" in fn:
+ for step in fileconversions:
+ for (old, new) in step:
+ transformed = transformed.replace(old, new)
+ # Map-format conversions (not yet ready for production)
+ #if "1.3.2" in versions:
+ # transformed = mapconvert2(transformed)
if ofp:
ofp.write(transformed)
if transformed != line:
- print "%s, line %d: %s -> %s" % \
- (fn, i+1, line.strip(), transformed.strip())
+ if not 'maps' in fn:
+ print "%s, line %d: %s -> %s" % \
+ (fn, i+1, line.strip(), transformed.strip())
modified = True
if ofp:
ofp.close()
if not modified:
# Nothing changed, move the backup file back into place.
os.rename(fn + "-bak", fn)
+ elif 'maps' in fn:
+ print "%s modified."
# upconvert ends here
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits