Skip to content

Managers

Webmilio edited this page Feb 19, 2019 · 3 revisions

What They Are & How To Use Them

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>, where TManagerOf is the type the manager contains (such as Ability, PrimaryAttributeDefinition, etc.) and TManagerType is the class itself.
  • The managers can all be accessed using Manager.Instance (Manager being the manager's class, such as AbilitiesManager or PrimaryAttributeDefinitionsManager). Instance is a singleton property of type TManagerType.
  • Any GenericManager has duplication verification by using the Name property of the TManagerOf instance.
  • The Initialized property is set to true once Leveled finishes initializing the Manager with its default content.

The methods all the managers have are as follow:

  • Get(int index) : returns the instance of T found at the corresponding index.
  • Get(string name) : returns the instance of T found with the given name; null if there is no entry.
  • GetIndex(TManagerOf item) : returns the index for the specified instance of TManagerOf; -1 if not found.
  • GetIndex(string name) : returns the index for the specified instance of TManagerOf; -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.

Clearing A Manager

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 AllowsRemoval property 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 AllowsRemoval set to true, but if an item has its own CanBeRemoved property set to false, the item will not be removed. An example of this would be the LifePoints attribute in SecondaryAttributeDefinitionsManager.
  • 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.

Leveled Managers

  • AbilityManager (extends the GenericManager<Ability, AbilitiesManager>) : contains all the registered player Abilities.
  • LeveledCallableManager (extends the GenericManager<LeveledCallable, LeveledCallablesManager>) : contains all the methods usable by the Call method from tModLoader.
  • PrimaryAttributeDefinitionManager (extends the GenericManager<PrimaryAttributeDefinitions, PrimaryAttributeDefinitionsManager>) : contains all the registered PrimaryAttributeDefinition.
  • SecondaryAttributeDefinitionManager (extends the GenericManager<SecondaryAttributeDefinition, SecondaryAttributeDefinitionsManager>) : contains all the SecondaryAttributeDefinition.

Clone this wiki locally