spr
Module¶
Source code: spr.py
The spr
module provides an Spr
class which derives
from ReadWriteFile
and is used to read and write Quake
spr data.
- vgio.quake.spr.is_sprfile(filename)¶
Quickly see if a file is an spr file by checking the magic number.
The filename argument may be a file for file-like object.
- Parameters
filename – File to check as string or file-like object.
- Returns
True if given file’s magic number is correct.
Spr
Class¶
- class vgio.quake.spr.Spr¶
Class for working with Spr files
Example
Basic usage:
from vgio.quake.spr import Spr s = Spr.open(file)
- identity¶
The magic number of the model, must be b’IDSP’
- version¶
The version of the model, should be 1
- type¶
Type of model. Defines how the sprite orients itself relative to the camera.
- bounding_radius¶
The bounding radius of the model.
- width¶
The width of the model.
- height¶
The height of the model.
- number_of_frames¶
The number of frames (sprites or groups).
- beam_length¶
???
- sync_type¶
The syncronization type for the model. It is either SYNC or RAND.
- fp¶
The file-like object to read data from.
- mode¶
The file mode for the file-like object.
- Spr.__init__()¶
Initializes a ReadWriteFile object. Derving classes must call this.
- classmethod Spr.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.
- Spr.close()¶
Closes the file pointer if possible. If mode is ‘w’ or ‘a’, the file will be written to.
- Spr.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.
SpriteFrame
Class¶
- class vgio.quake.spr.SpriteFrame¶
Class for representing a single sprite frame
- origin¶
The offset of the model. Used to correctly position the model.
- width¶
The pixel width of the sprite.
- height¶
The pixel height of the sprite.
- pixels¶
A tuple of unstructured indexed pixel data represented as integers. A palette must be used to obtain RGB data. The size of this tuple is:
spr_sprite_frame.width * spr_sprite_frame.skin_height.
- SpriteFrame.__init__()¶
- static SpriteFrame.read(file)¶
- static SpriteFrame.write(file, sprite_frame)¶
SpriteGroup
Class¶
- class vgio.quake.spr.SpriteGroup¶
Class for representing a sprite group
- number_of_frames¶
The number of sprite frames in this group.
- intervals¶
A sequence of timings for each frame.
- frames¶
A sequence of SprSpriteFrame objects.
- SpriteGroup.__init__()¶
- static SpriteGroup.read(file)¶
- static SpriteGroup.write(file, sprite_group)¶