Automatically generate string-based resource IDs for all content.

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2864 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
mcmartin
2007-11-27 11:32:31 +00:00
parent 3543c7ae72
commit 73803cc42f
4 changed files with 146 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
The resmap tool is a set of utilities for generating subsidiary resource
index files based on the current system.
----
Currently available runnable files:
mastermap.py: Walks the content tree, finds all the .lst files, and
produces a master resource map mapping IDs to each file.
----
Currently available library files:
explorer.py: Provides routines for locating and parsing .lst files in
the content tree.
stridgen.py: This does most of the grunt work. It provides the
makeid() function, which, given a filename, produces a
suitable Resource ID string. This is handled with a huge
array of regular expressions at present; as the design
of the resource tree evolves, this script may be kept in
sync with it.
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/python
import sys
import os
import os.path
def get_lists(d):
result = []
for (dirpath, dirnames, filenames) in os.walk(d):
for l in [f for f in filenames if f.endswith('.lst')]:
result.append(os.path.join(dirpath, l))
return result
def read_list(f):
result = []
for line in file(f):
parsed = line.split()
if len(parsed) == 4:
result.append(((int(parsed[0]), int(parsed[1]), int(parsed[2])),
parsed[3]))
return result
if __name__ == "__main__":
print "This is a library and isn't intended to be run directly."
+43
View File
@@ -0,0 +1,43 @@
#!/usr/bin/python
import sys
import os
import os.path
import explorer
import stridgen
def process (res):
result = []
for line in res:
line = line.strip()
if len(line) == 0:
continue
mapline = stridgen.makeid(line)
if mapline is None:
toadd = "# NO MATCH FOR %s" % line
else:
toadd = "%s: %s" % (mapline, line)
if toadd not in result:
result.append(toadd)
result.sort()
return result
def get_resources(d):
result = []
packages = [explorer.read_list(x) for x in explorer.get_lists(d)]
for package in packages:
for line in package:
if line[1] not in result:
result.append(line[1])
return result
if __name__ == "__main__":
if len(sys.argv) < 2:
d = os.path.join(os.path.pardir, os.path.pardir, "sc2", "content")
else:
d = sys.argv[1]
resources = get_resources(d)
resmap = process(resources)
for r in resmap:
print r
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/python
import re
def stripdots(x):
while x.endswith('.'):
x = x[:-1]
while x.startswith('.'):
x = x[1:]
return x
patterns = [("comm/(.*)/(.*)\.mod", lambda m: "comm.%s.music" % m.group(1)),
("comm/(.*)/(.*)\.ogg", lambda m: "comm.%s.music" % m.group(2)),
("comm/(.*)/(.*)\.ani", lambda m: "comm.%s.graphics" % m.group(1)),
("comm/(.*)/(.*)\.ct", lambda m: "comm.%s.colortable" % m.group(1)),
("comm/(.*)/(.*)\.fon", lambda m: "comm.%s.font" % m.group(1)),
("comm/(.*)/(.*)\.txt", lambda m: "comm.%s.dialogue" % m.group(1)),
("comm/(.*)\.lst", lambda m: "comm.%s.resources" % m.group(1)),
("credits/(.*)\.fon", lambda m: "credits.font.%s" % m.group(1)),
("credits/credback\.ani", lambda m: "credits.background"),
("credits/(.*)\.txt", lambda m: "credits.%s" % m.group(1)),
("credits/(.*)\.ogg", lambda m: "credits.%smusic" % m.group(1)),
("ipanims/(.*)\.txt", lambda m: "text.%s" % m.group(1)),
("ipanims/(.*)\.ani", lambda m: "graphics.%s" % m.group(1)),
("ipanims/(.*)\.ct", lambda m: "colortable.%s" % m.group(1)),
("ipanims/(.*)\.xlt", lambda m: "translate.%s" % m.group(1)),
("ipanims/(.*)\.fon", lambda m: "font.%s" % m.group(1)),
("ipanims/(.*)\.snd", lambda m: "sounds.%s" % m.group(1)),
("ipanims/(.*)\.mod", lambda m: "music.%s" % m.group(1)),
("lbm/(.*)\.ani", lambda m: "graphics.%s" % m.group(1)),
("lbm/(.*)\.mod", lambda m: "music.%s" % m.group(1)),
("lbm/(.*)\.ct", lambda m: "colortable.%s" % m.group(1)),
("lbm/(.*)\.fon", lambda m: "font.%s" % m.group(1)),
("lbm/(.*)\.txt", lambda m: "text.%s" % m.group(1)),
("lbm/mainmenu\.ogg", lambda m: "music.mainmenu"),
("melee/melemenu\.ogg", lambda m: "music.meleemenu"),
("melee/(.*)\.ani", lambda m: "graphics.%s" % m.group(1)),
("slides/ending/sis_skel.ani", lambda m: "graphics.sisskeleton"),
("(.*)/(.*)micon\.ani", lambda m: "ship.%s.meleeicons" % m.group(1)),
("(.*)/(.*)icons\.ani", lambda m: "ship.%s.icons" % m.group(1)),
("(.*)/(.*)\.cod", lambda m: "ship.%s.code" % m.group(1)),
("(.*)/(.*)\.snd", lambda m: "ship.%s.sounds" % m.group(1)),
("(.*)/(.*)\.mod", lambda m: "ship.%s.ditty" % m.group(1)),
("(.*)/(.*)\.txt", lambda m: "ship.%s.text" % m.group(1)),
("(.*)/(.*)cap\.ani", lambda m: "ship.%s.graphics.captain" % m.group(1)),
("(.*)/(.*)big.*", lambda m: "ship.%s.graphics.%s.large" % (m.group(1), stripdots(m.group(2)))),
("(.*)/(.*)med.*", lambda m: "ship.%s.graphics.%s.medium" % (m.group(1), stripdots(m.group(2)))),
("(.*)/(.*)sml.*", lambda m: "ship.%s.graphics.%s.small" % (m.group(1), stripdots(m.group(2)))),
("(.*)/(.*)\.ani", lambda m: "ship.%s.graphics.%s" % (m.group(1), m.group(2))),
("(.*).lst", lambda m: "ship.%s.resources" % m.group(1))]
def makeid (fname):
for (pattern, response) in patterns:
m = re.match(pattern, fname)
if m is not None:
return response(m)
return None