-
Notifications
You must be signed in to change notification settings - Fork 1
Managers
NOTE: Most managers have a bunch of "obsolete" fields. Feel free to use them, as they're marked as obsolete for our own sake. Keep in mind that you should always check wether or not the fields you're using are null.
Leveled works with a system of Managers:
- The managers are all children of the
GenericManager<TManagerOf, TManagerType>, whereTManagerOfis the type the manager contains (such asAbility,PrimaryAttributeDefinition, etc.) andTManagerTypeis the class itself. - The managers can all be accessed using
Manager.Instance(Managerbeing the manager's class, such asAbilitiesManagerorPrimaryAttributeDefinitionsManager).Instanceis a singleton property of typeTManagerType. - Any
GenericManagerhas duplication verification by using theNameproperty of theTManagerOfinstance. - The
Initializedproperty is set to true once Leveled finishes initializing theManagerwith its default content.
The methods all the managers have are as follow:
-
Get(int index): returns the instance ofTfound at the corresponding index. -
Get(string name): returns the instance ofTfound with the given name; null if there is no entry. -
GetIndex(TManagerOf item): returns the index for the specified instance ofTManagerOf; -1 if not found. -
GetIndex(string name): returns the index for the specified instance ofTManagerOf; -1 if not found. -
RequestClear(): schedules the manager's content for deletion; see Clearing a Manager for more information. -
Register(TManagerOf item): adds the item to the manager if it does not already contain an entry with the same name and returns true if the item was succesfully added; false if the manager already contains an entry with the same name. This method is thread-safe. -
Remove(TManagerOf item): tries to remove an item from the manager and returns true if it succeeded; otherwise false. This method is thread-safe.
If your mod ever requires a clean manager to work with, all you need to do is Manager.Instance.RequestClear() (replacing Manager by the manager you want to clear, such as AbilitiesManager). One such use for this method would be removing all the default PrimaryAttributeDefinition and replacing them by your own, using Leveled as a base for a completely different experience.
There are a few rules to such a method however:
- If the manager's
AllowsRemovalproperty is set to false, the contents will never be cleared, regardless of what method is used. Only Leveled itself can directly clear a manager. - A manager might have
AllowsRemovalset to true, but if an item has its ownCanBeRemovedproperty set to false, the item will not be removed. An example of this would be theLifePointsattribute inSecondaryAttributeDefinitionsManager. - When
RequestClear()is called, it marks the manager's content for deletion. If there are more than two marks, the manager will not clear!
If a manager is cleared, the property ClearedAtRuntime will be set to true; otherwise, it will stay as false. It is thus recommended to verify this variable during the PostSetupContent() method of your Mod class.
-
AbilityManager(extends theGenericManager<Ability, AbilitiesManager>) : contains all the registered player Abilities. -
LeveledCallableManager(extends theGenericManager<LeveledCallable, LeveledCallablesManager>) : contains all the methods usable by the Call method from tModLoader. -
PrimaryAttributeDefinitionManager(extends theGenericManager<PrimaryAttributeDefinitions, PrimaryAttributeDefinitionsManager>) : contains all the registered PrimaryAttributeDefinition. -
SecondaryAttributeDefinitionManager(extends theGenericManager<SecondaryAttributeDefinition, SecondaryAttributeDefinitionsManager>) : contains all the SecondaryAttributeDefinition.