First cut at integrating map conversion.
This commit is contained in:
parent
91aa2bd860
commit
e0a0645049
1 changed files with 62 additions and 8 deletions
|
@ -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 @@ filemoves = {
|
|||
"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 @@ def allcfgfiles(dir):
|
|||
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():
|
||||
|
@ -84,6 +124,12 @@ Usage: upconvert [options]
|
|||
-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:", [
|
||||
"help",
|
||||
|
@ -114,7 +160,7 @@ if __name__ == '__main__':
|
|||
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 @@ if __name__ == '__main__':
|
|||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue