Skip to content
PoroCYon edited this page May 28, 2016 · 4 revisions

Concepts

This page explains the various concepts used in Prism. The whole of these concepts make up most of the public API.

ModInfo, manifest.json

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.

ModDef location

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.

ModDef

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.

ContentHandler

The mod's ContentHandler declares all ObjectDefs, 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.

ObjectDef, ObjectRef

ObjectDef

An ObjectDef is a definition of a contentent object, such as Prism.API.Defs.ItemDef and NPrism.API.Defs.pcDef. ObjectDefs contain stat info, references to its used resoruces (e.g. texture files), as well as the constructor for its behaviour.

ObjectDefs are declared in the ConntentHandler implementation of a mod.

ObjectRef

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.

ObjectRefs 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 ObjectRefs 'by hand' in a mod, use the methods described in the next subsection instead.

Resolving an object definition reference.

Several methods of resolving an object reference exist. These depend on the information present when resolving the reference.

Vanilla ID

When given a vanilla ID, it is best to use <object def type name>.Defs[<id>].

ObjectRef instance

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>].

Mod and object name

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.

ObjectBehaviour

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

Hooks are a special kind of method used in ObjectBehaviours. 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

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.

Resource readers

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.