Concepts
This page explains the various concepts used in Prism. The whole of these concepts make up most of the public API.
A mod's ModInfo
contains the internal and display name of the mod, its version, and other information. The mod info is saved in its manifest.json
file, that must be placed at Prism\Mods\<Mod internal name>\manifest.json
. It is required for a mod to load, as it is used to locate the mod's ModDef
class.
The mod's ModInfo
is also used to identify a mod at runtime.
An example of a well-formed manifest.json
file can be found here.
The ModInfo
must declare the namespace and type name of the ModDef
class of the mod. Without specifying the ModDef
, a mod cannot be loaded because it is required in order to load its content.
A ModDef
is a mod definition. Every mod must have a class that inherits from Prism.API.ModDef
. It contains a few basic hooks, as well as a method that must be overridden that creates the mod's ContentHandler
.
An example of a well-formed ModDef
class can be found here.
The mod's ContentHandler
declares all ObjectDef
s, as well as the mod's global behaviours, such as GameBehaviour
. It is a class that inherits from Prism.API.ContentHandler
.
An example of a well-formed ContentHandler
class can be found here.
An ObjectDef
is a definition of a contentent object, such as Prism.API.Defs.ItemDef
and NPrism.API.Defs.pcDef
. ObjectDef
s contain stat info, references to its used resoruces (e.g. texture files), as well as the constructor for its behaviour.
ObjectDef
s are declared in the ConntentHandler
implementation of a mod.
An ObjectRef
is a reference to an ObjectDef
. It can point to any ObjectDef
of any mod, or any vanilla object. Examples of these are Prism.API.Defs.ItemRef
and Prism.API.Defs.NpcRef
.
ObjectRef
s were created to make the lookup of ObjectDef
more safe than using a single ID (such as vanilla does) or or a string dictionary lookup (such as tConfig and tAPI did).
It is better not to create new ObjectRef
s 'by hand' in a mod, use the methods described in the next subsection instead.
Several methods of resolving an object reference exist. These depend on the information present when resolving the reference.
When given a vanilla ID, it is best to use <object def type name>.Defs[<id>]
.
When given an ObjectRef
, it is best to simply call <object ref>.Resolve()
on it, or, if that isn't possible, use <object def type name>.Defs[<object ref>]
.
When given the mod's ModInfo
or internal name and the object's internal name, it is best ot use <object def type name>.Defs[<object name>, <mod info or internal name>]
. If the mod info or internal name is not specified, Prism will look for an item either in the current mod or vanilla Terraria.
An ObjectBehaviour
defines the behaviour of an ObjectDef
by overriding several hook methods. It is a class that inherits from Prism.API.Behaviours.<type>Behaviour
.
An example of a well-formed ObjectBehaviour
class can be found here.
Hooks are a special kind of method used in ObjectBehaviour
s. These are usually used to add extra functionality or to override vanilla behaviour.
If a distinction from other kinds of 'hooks' is required, these are called Mod hooks.
Resources are mod assets, such as textures and audio files. Resources can be located either in the mod assembly's embedded resources, or in the mod's folder.
Resources are accessed using the ContentHandler.GetResource
and ContentHandler.GetEmbeddedResource
methods. It is best to cache the return value of these methods, instead of loading the resource over and over again. Resource paths are specified as Path/To/Resource.ext
.
Resources can exist of many different types, from textures to JSON files. It is possible to define one's own resource reader for a specific resource type.
In order to do this, one needs to create a type that inherits from either Prism.Mods.Resources.IResourceReader
or Prism.Mods.Resources.ResourceReader
(with generic parameter) and implement its ReadResource
or ReadTypedResource
method.
Then, in ModDef.OnLoad
, create a new instance of your resource reader and call Prism.Mods.Resources.ResourceLoader.RegisterReader
.
Resource readers for types that can be loaded with XNA's ContentLoader
, a new class isn't needed, an instance of Prism.Mods.Resources.ContentResourceReader<T>
can be used instead.