sp2
Module¶
Source code: sp2.py
The sp2
module provides an Sp2
class which derives
from ReadWriteFile
and is used to read and write Quake
sp2 data.
- vgio.quake2.sp2.is_sp2file(filename)¶
Quickly see if a file is a sp2 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.
Sp2
Class¶
- class vgio.quake2.sp2.Sp2¶
Class for working with Sp2 files
Example
Basic usage:
from vgio.quake2.sp2 import Sp2 s = sp2.Sp2.open(file)
- identity¶
The identity of the file. Should be b’IDS2’
- version¶
The version of the file. Should be 2.
- number_of_frames¶
The number of sprite frames.
- frames¶
A sequence of SpriteFrame objects.
- Sp2.__init__()¶
Constructs a Sp2 object.
- classmethod Sp2.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.
- Sp2.close()¶
Closes the file pointer if possible. If mode is ‘w’ or ‘a’, the file will be written to.
- Sp2.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.quake2.sp2.SpriteFrame(width, height, origin_x, origin_y, name)¶
Class for working with sprite frames
- width¶
Width of the frame.
- height¶
Height of the frame.
- origin¶
The offset of the frame.
- name¶
The name of the pcx file to use for the frame.
- SpriteFrame.__init__(width, height, origin_x, origin_y, name)¶
Constructs a SpriteFrame object.