Resources¶
Container¶
-
class
pynwn.Container¶ A basic container for ContentObjects
-
__getitem__(name)¶ Get a content object associated with a file name or integer index.
-
add(content_obj)¶ Add a content object to a container.
-
add_file(fname)¶ Add a content object from a file to a container.
-
get_content_data(name)¶ Get content object data
Parameters: name – File name or int index.
-
get_content_object(name)¶ Get content object.
Parameters: name – File name or int index.
-
get_filenames()¶ Gets a list of the filenames of all content objects.
-
glob(glob_pattern)¶ Returns a list of objects or content objects for file names matching the glob pattern. i.e. Unix shell-style wildcards: *.utc Note: all file names are converted to lowercase.
-
has_file(fname)¶ Determines if container has a content object associated with a given filename.
-
hashes(hash_type='sha1')¶ Get content object hashes.
Parameters: hash_type – ‘sha1’, ‘sha256’ Returns: {filename: hexdigest}
-
remove(name)¶ Remove content object.
Parameters: name – File name
-
ContentObject¶
-
class
pynwn.ContentObject(resref, res_type, content=None, offset=None, size=None, abspath=None)¶ A ContentObject is an abstraction of any particular NWN resource object either in NWN container (i.e. a hak, mod, or erf) or in a file.
Note
Parameter abspath is ONLY used when the content object is in a DirectoryContainer. Since modifications to content objects are not immediately written to disk, if
iois changed from a file to cStringIO, it’s necessary to know where to write the file whenDirectoryContainer.save()is called.Parameters: - resref – Template resref name.
- res_type – Resource type.
- content – Either a file name or cStringIO.
- offset – Data offest in
io. - size – Data size.
- abspath – Absolute path to the file if one is contained in
io.
-
static
from_file(filename)¶ Instantiates a ContentObject from a file.
-
get(mode='rb')¶ Returns the actual data.
-
get_extension()¶ Determines the ContentObject’s file extention by resource type.
-
get_filename()¶ Determines the ContentObject’s base file name: <resref>.<ext>
DirectoryContainer¶
-
class
pynwn.DirectoryContainer(path, only_nwn=True)¶ Bases:
pynwn.resource.ContainerA Container that directly wraps a directory (e.g. override/).
Parameters: - path – Directory path.
- only_nwn – default
True, IfFalsetheDirectoryContainerwill attempt to load all files, even those that are not NWN resource types.
-
__getitem__(name)¶ Get a content object associated with a file name or integer index.
-
add(content_obj)¶ Add a content object to a container.
-
add_file(fname)¶ Add a content object from a file to a container.
-
get_content_data(name)¶ Get content object data
Parameters: name – File name or int index.
-
get_content_object(name)¶ Get content object.
Parameters: name – File name or int index.
-
get_filenames()¶ Gets a list of the filenames of all content objects.
-
glob(glob_pattern)¶ Returns a list of objects or content objects for file names matching the glob pattern. i.e. Unix shell-style wildcards: *.utc Note: all file names are converted to lowercase.
-
has_file(fname)¶ Determines if container has a content object associated with a given filename.
-
hashes(hash_type='sha1')¶ Get content object hashes.
Parameters: hash_type – ‘sha1’, ‘sha256’ Returns: {filename: hexdigest}
-
remove(name)¶ Remove content object.
Parameters: name – File name
-
save()¶ Saves modified content objects.
Note
Content objects are not immediately saved to disk when changed. So this function must be called in order to save the them to disk.
ResourceManager¶
-
class
pynwn.ResourceManager¶ A container for Container objects.
-
__getitem__(fname)¶ Gets a ContentObject by file name. The order of search is the order in which add_container was called. I.e. the first added will have the highest priority
-
add_container(container)¶ Adds a container
-
creatures(glob=None)¶ Returns a list of Creature objects contained in all of the resource managers containers.
-
static
from_module(mod, use_override=False, include_bioware=True, path='C:\\NeverwinterNights\\NWN\\')¶ Creates a ResourceManager object from a module or module directory.
Parameters: - mod – Path to module or module directory.
- use_override – default False, If true the overried directory in
pathwill be used. - include_bioware – default True, If false Bioware NWN BIF files will not be used.
- path – default “C:NeverwinterNightsNWN”, Path to NWN directory.
Note
- If a directory is passed in
modit must contain amodule.ifofile. - If
include_biowareisFalse,pathcan be any working directory that has the same directory stucture as the default NWN installation. I.e. hak files are in the subdirectory ‘hak’, overrides in directory ‘override’. - When loading the module’s HAKs .hak files will attempt to be loaded first.
If no file exists, then a directory with the
.hakfiles name will attempt to be loaded.
-
get_content_data(fname)¶ Gets the contents of a ContentObject that is contained in one of the containers.
-
get_filenames()¶ Gets a list of all file names.
-
glob(glob_pattern)¶ Returns a list of files matching a glob pattern... i.e. Unix shell-style wildcards: *.utc Note: all file names are converted to lowercase.
-
has_file(fname)¶ Determines if a file exists in one of the containers.
-