Ribbiks
Member
Posts: 627
Registered: 02-11 |
I wrote a simple python script that generates a list of all unique textures/flats given a directory of wads. it was pretty trivial to implement, but who knows maybe someone will find this useful.
code:
#!/usr/bin/env python
# encoding: utf-8
"""
texList.py
Author: Ribbiks
Date: 12/29/2012
Generates list of unique textures & flats in a set of wads, given their directory
USAGE: python texList.py wadFolder/
"""
import os
import sys
import numpy as np
def main():
wadDir = sys.argv[-1]
wadList = os.listdir(wadDir)
wadList = [n for n in wadList if n[-4:] == '.wad']
dictT = {}
dictF = {}
for wad in wadList:
# open file, get header info
f = open(wadDir+wad,'rb')
[pwad,nLmp,dirP] = np.fromfile(f,'<i4',3)
# find all SIDEDEFS and SECTORS lumps
f.seek(dirP)
todoT = [] # todo[i] = (sidedefs_pointer, num_sidedefs)
todoF = []
for n in range(nLmp):
[lmpP,lmpS] = np.fromfile(f,'<i4',2)
name = f.read(8)
if name == 'SIDEDEFS':
todoT.append((lmpP,lmpS/30))
elif name[:7] == 'SECTORS':
todoF.append((lmpP,lmpS/26))
# read textures from SIDEDEFS lumps
for (pos,num) in todoT:
f.seek(pos)
for n in range(num):
f.read(4) # skip offset bytes
dictT[f.read(8)] = 1
dictT[f.read(8)] = 1
dictT[f.read(8)] = 1
f.read(2) # skip sector bytes
# read flats from SECTORS lumps
for (pos,num) in todoF:
f.seek(pos)
for n in range(num):
f.read(4) # skip height bytes
dictF[f.read(8)] = 1
dictF[f.read(8)] = 1
f.read(6) # skip light/type/tag bytes
f.close()
of = open('output.txt','w')
of.write('### TEXTURES ###\n\n')
for i in dictT.keys():
of.write(i+'\n')
of.write('\n### FLATS ###\n\n')
for i in dictF.keys():
of.write(i+'\n')
of.close()
if __name__ == '__main__':
main()
not extensively tested. requires numpy (just because np.fromfile is convenient), but what self-respecting python install doesn't have numpy nowadays.
|