Note: this is ridiculously incomplete.
Optionally:
At the beginning of an interactive session, or as the first line in a Python script file, enter:
from omg import *
A WAD is an abstract representation of a WAD file. A WAD object can load content from a WAD file, or save content to a WAD file, but is entirely memory-resident.
The following are all equivalent:
a = WAD('wadfile.wad')
a = WAD(from_file='wadfile.wad')
f = open('wadfile.wad', 'rb')
a = WAD(from_file=f)
a = WAD()
a.from_file('wadfile.wad')
f = open('wadfile.wad', 'rb')
a = WAD()
a.from_file(f)
You can load more than one file to the same object:
a = WAD()
a.from_file(file1)
a.from_file(file2)
a.from_file(file3)
In this case, lumps from file2 will overwrite those from file1 with the same name, etc.
Lumps are stored in groups. Each WAD holds a number of groups, representing different categories of lumps. Each group is an ordered dictionary; that is, it works just like a Python dict object but remembers in which order lumps were inserted
All lumps are instances of the Lump class; see below for its documentation
To retrieve the sprite called CYBR1A from the WAD object a, do:
a.sprites['CYBR1A']
And to replace it with some other lump object called some_lump:
a.sprites['CYBR1A'] = some_lump
To add a new lump, simply do as above with a lump name that does not yet exist.
Renaming and deleting is done as follows:
a.sprites.rename('CYBR1A', 'NEW_NAME')
del a.sprites['CYBR1A']
By default, WADs recognize the following lump groups:
This scheme can be modified if desired; refer to wad.py for the details.
The maps and glmaps are special. These do not contain lumps, but additional groups of lumps, one for each map. So if you access E1M1:
a.maps['E1M1']
you will retrieve a group of lumps containing all the map’s data. To retrieve the individual lumps, do:
a.maps['E1M1']['SIDEDEFS']
etc.
To merge two WADs a and b:
c = a + b
Note that (for efficiency reasons) this only copies references to lumps, which means that subsequent changes to lumps in a or b will affect the corresponding lumps in c. To give c its own set of lumps, do:
c = (a + b).copy()
When lumps in a and b have the same name, lumps from b will replace those from a.
It is also possible to merge individual sections:
a.sprites += b.sprites
Use with care for sections of different types.
Note that some sections do more than just copy over the list of lumps when they merge. For example, adding two txdefs sections together will automagically merge the TEXTURE1, TEXTURE2 and PNAMES lumps. txdefs also get merged this way when two WAD objects are merged on the top level.
The Lump class holds a single lump. The class provides the following data and methods:
Creating a new lump called ‘FOOF’ containing the text ‘Hello!’ and inserting it into a WAD w would be done as follows:
w.data['FOOF'] = Lump('Hello!')
There are subclasses of Lump for different types of lumps. Currently, only two of these provide special functionality: Graphic and Flat.
Graphic, used to represent Doom format graphics, provides the following settable attributes:
Graphic defines the following methods in adddition to those defined by Lump:
For the argument lists used by these functions, refer to the code and the inline documenation in lump.py.
Flat works similarly to Graphic, but handles format conversions slightly differently.
Editors are used to edit lumps or lump groups. They represent lump data with high-level objects and structures, and provide methods to modify the data. The following editors have been implemented so far:
All editors provide the following methods:
.to_lump
.from_lump
or, if the editor represents more than one lump:
.to_lumps
.from_lumps
In the latter case, the editor is initialized with a lump group instead of a single lump.
Example (moving one vertex one unit):
m = MapEditor(wad.maps["E1M1"])
m.vertexes[103].x += 1
wad.maps["E1M1"] = m.to_lumps()
Refer to the source code for more information.