More wad fixes.
authorDan Olson <theoddone33@icculus.org>
Tue, 5 Aug 2008 11:17:45 +0000 (04:17 -0700)
committerDan Olson <theoddone33@icculus.org>
Tue, 5 Aug 2008 11:17:45 +0000 (04:17 -0700)
pyhexen/wad.py

index 8a733ba..bee8980 100644 (file)
@@ -42,8 +42,8 @@ class wad:
                        lumpinfo.append ((0, size, base.upper()[:8]))
 
                # Dump the info into our table of accumulated crap.
-               for (start, len, name) in lumpinfo:
-                       self.lumps.append ((fileHandle, start, len, name))
+               for (pos, length, name) in lumpinfo:
+                       self.lumps.append ((fileHandle, pos, length, name.rstrip('\x00')))
 
        def InitMultipleFiles (self, filenames):
                for f in filenames:
@@ -59,26 +59,26 @@ class wad:
                # meh sucky in-place crappy way to do
                # stuff :(
                searchName = name.upper()[:8]
-               searchLumps = [x for (x, y, z, w) in self.lumps]
-               lumpIndex = -1
-               while True:
-                       try:
-                               lumpIndex = searchLumps.index(searchName)
-                       except ValueError:
-                               break
-               return lumpIndex
+               for (x, y) in enumerate (reversed(self.lumps)):
+                       (handle, pos, length, name) = y
+                       if searchName == name:
+                               return len(self.lumps) - x - 1
+               return -1
 
        def GetNumForName (self, name):
-               return self.CheckNumForName (name)
+               index = self.CheckNumForName (name)
+               if index == -1:
+                       raise WadException ("%s not found!" % name)
+               return index
 
        def LumpLength (self, lump):
-               (handle, start, length, name) = self.lumps[lump]
+               (handle, pos, length, name) = self.lumps[lump]
                return length
 
-       def ReadLump (self, lump, dest):
-               (handle, start, len, name) = self.lumps[lump]
-               handle.seek (start)
-               dest.write (handle.read (len))
+       def ReadLump (self, lump):
+               (handle, pos, length, name) = self.lumps[lump]
+               handle.seek (pos)
+               return handle.read (length)
 
        def CacheLumpNum (self, lump, tag):
                pass