コード例 #1
0
ファイル: txdef.py プロジェクト: nicokruger/py-wad2json
    def to_lumps(self):
        """Returns two lumps TEXTURE1, PNAMES"""
        textures = self.items()
        textures.sort()

        pnames = []
        # Count unique patch names, assign correct num to each patch
        used_pnames = {}
        for name, data in textures:
            for p in data.patches:
                if p.name not in used_pnames:
                    used_pnames[p.name] = len(used_pnames)
                p.id = used_pnames[p.name]
        pnmap = sorted([(i, name) for (name, i) in used_pnames.iteritems()])
        pnames = pack32(len(pnmap)) + \
            ''.join(zpad(safe_name(name)) for i, name in pnmap)

        texture1 = []
        pointers = []
        ptr = 4 + len(self) * 4
        for name, data in textures:
            data.npatches = len(data.patches)
            texture1.append(data.pack())
            texture1.append(''.join(p.pack() for p in data.patches))
            pointers.append(ptr)
            ptr += 22 + data.npatches * 10

        a = pack32(len(textures))
        #print "a", len(a)
        b = ''.join([pack32(p) for p in pointers])
        #print "b", len(b)
        #print "texture1", type(texture1), len(texture1)
        #print texture1
        c = ''.join(texture1)
        texture1 = ''.join([a, b, c])

        g = TxdefGroup('txdefs', Lump, ['TEXTURE?', 'PNAMES'])
        g['TEXTURE1'], g['PNAMES'] = Lump(texture1), Lump(pnames)
        return g
コード例 #2
0
 def to_lump(self):
     """Compile to a Doom-ready PLAYPAL Lump."""
     return Lump(join([p.bytes for p in self.palettes]))