wal
Module¶
Source code: wal.py
The wal
module provides an Wal
class which derives
from ReadWriteFile
and is used to read and write Quake
wal data.
Wal
Class¶
- class vgio.quake2.wal.Wal¶
Class for working with Wal files
Example
Basic usage:
from vgio.quake2.wal import Wal with open(path) as file: w = Wal.read(file)
- name¶
The name of the wal texture.
- width¶
The width of the wal texture.
Note
This is the width at mipmap level 0.
- height¶
The height of the wal texture.
Note
This is the height at mipmap level 0.
- offsets¶
The offsets for each of the mipmaps. This is a tuple of size four (this is the number of mipmap levels).
- animation_name¶
The name of the next wal texture in the animation sequence.
- flags¶
A bitfield of surface behaviors.
- contents¶
- value¶
- pixels¶
A bytes object of unstructured indexed color data. A palette must be used to obtain RGB data.
Note
This is the pixel data for all four mip levels. The size is calculated using the simplified form of the geometric series where r = 1/4 and n = 4.
The size of this tuple is:
wal.width * wal.height * 85 / 64
- Wal.__init__()¶
Initializes a ReadWriteFile object. Derving classes must call this.
- classmethod Wal.open(file, mode='r')¶
Open a ReadWriteFile object where file can be a path to a file (a string), or a file-like object.
The mode parameter should be ‘r’ to read an existing file, ‘w’ to truncate and write a new file, or ‘a’ to append to an existing file.
open() is also a context manager and supports the with statement:
with ReadWriteFile.open('file.ext') as file: file.save('file2.ext')
- Parameters
file – Either the path to the file, a file-like object, or bytes.
mode – An optional string that indicates which mode to open the file
- Returns
An ReadWriteFile object constructed from the information read from the file-like object.
- Raises
ValueError – If an invalid file mode is given.
TypeError – If attempting to write to a bytes object.
OSError – If the file argument is not a file-like object.
- Wal.close()¶
Closes the file pointer if possible. If mode is ‘w’ or ‘a’, the file will be written to.
- Wal.save(file)¶
Writes data to file.
- Parameters
file – Either the path to the file, or a file-like object.
- Raises
OSError – If file argument is not a file-like object.