Factory Update

This commit is contained in:
Syntriax 2022-11-21 21:51:27 +03:00
parent c9d8b5617e
commit d03fa51010
2 changed files with 12 additions and 15 deletions

View File

@ -28,6 +28,7 @@ namespace Syntriax.Modules.Movement.Config
} }
} }
private void Start() private void Start()
{ {
if (FactorySingleton<MovementDefinitionFactory>.Instance == this) if (FactorySingleton<MovementDefinitionFactory>.Instance == this)
@ -43,17 +44,23 @@ namespace Syntriax.Modules.Movement.Config
/// <para> Automatically loads the definition files specificed path <see cref="ResourceDirectoryToDefinitions"/></para> /// <para> Automatically loads the definition files specificed path <see cref="ResourceDirectoryToDefinitions"/></para>
/// <para> The default is "Resources/Modules/Syntriax/Movement/Definitions/"</para> /// <para> The default is "Resources/Modules/Syntriax/Movement/Definitions/"</para>
/// </remarks> /// </remarks>
public override void Initialize() protected override void OnFactoryInitialize()
{ {
if (_definitions == null) if (_definitions == null)
_definitions = new Dictionary<string, MovementDefinition>(InitialCapacity); _definitions = new Dictionary<string, MovementDefinition>(InitialCapacity);
Reset();
foreach (TextAsset definitionTextAsset in UnityEngine.Resources.LoadAll<TextAsset>(ResourceDirectoryToDefinitions)) foreach (TextAsset definitionTextAsset in UnityEngine.Resources.LoadAll<TextAsset>(ResourceDirectoryToDefinitions))
AddToFactoryWithJSON(definitionTextAsset.text); AddToFactoryWithJSON(definitionTextAsset.text);
} }
/// <summary>
/// Clears all the definitions in the factory
/// </summary>
/// <remarks>
/// Does not reinitialize, please call <see cref="Initialize"/> to initialize it back
/// </remarks>
protected override void OnFactoryReset() => _definitions?.Clear();
/// <summary> /// <summary>
/// Manually registers a <see cref="MovementDefinition"/> to the factory with a JSON <see cref="string"/> /// Manually registers a <see cref="MovementDefinition"/> to the factory with a JSON <see cref="string"/>
/// </summary> /// </summary>
@ -64,14 +71,6 @@ namespace Syntriax.Modules.Movement.Config
AddDefinitionToFactory(movementDefinition); AddDefinitionToFactory(movementDefinition);
} }
/// <summary>
/// Clears all the definitions in the factory
/// </summary>
/// <remarks>
/// Does not reinitialize, please call <see cref="Initialize"/> to initialize it back
/// </remarks>
public override void Reset() => _definitions?.Clear();
/// <summary> /// <summary>
/// Registers a list of <see cref="MovementDefinition"/>s to the factory /// Registers a list of <see cref="MovementDefinition"/>s to the factory
/// </summary> /// </summary>

View File

@ -33,18 +33,16 @@ namespace Syntriax.Modules.Movement.Config
Destroy(this); Destroy(this);
} }
public override void Initialize() protected override void OnFactoryInitialize()
{ {
if (_types == null) if (_types == null)
_types = new Dictionary<string, Type>(InitialCapacity); _types = new Dictionary<string, Type>(InitialCapacity);
Reset();
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
AddAssemblyToFactory(assembly); AddAssemblyToFactory(assembly);
} }
public override void Reset() => _types?.Clear(); protected override void OnFactoryReset() => _types?.Clear();
public void AddAssemblyToFactory(Assembly assembly) public void AddAssemblyToFactory(Assembly assembly)
{ {