Added Reset()s and Initialize()s made public in Factories + Fix & Upgrades

This commit is contained in:
Syntriax 2022-03-18 16:04:44 +03:00
parent 785f6be5b9
commit c54605a967
5 changed files with 28 additions and 13 deletions

View File

@ -6,7 +6,7 @@ namespace Syntriax.Modules.Movement.Config
{
public class MovementDefinitionFactory : MonoBehaviour
{
private const string Name = "Movement Definer Factory";
private const string Name = "Movement Definition Factory";
private const int InitialCapacity = 64;
private const string ResourceDirectoryToDefinitions = "Modules/Syntriax/Movement/Definitions/";
@ -42,27 +42,32 @@ namespace Syntriax.Modules.Movement.Config
Destroy(this);
}
private void Initialize()
public void Initialize()
{
if (_definitions == null)
_definitions = new Dictionary<string, MovementDefinition>(InitialCapacity);
Reset();
foreach (TextAsset definitionTextAsset in UnityEngine.Resources.LoadAll<TextAsset>(ResourceDirectoryToDefinitions))
{
MovementDefinition movementDefinition = JsonUtility.FromJson<MovementDefinition>(definitionTextAsset.text);
AddDefinerToFactory(movementDefinition);
AddDefinitionToFactory(movementDefinition);
}
}
public void AddDefinersToFactory(List<MovementDefinition> movementDefinitions)
public void Reset() => _definitions?.Clear();
public void AddDefinitionsToFactory(List<MovementDefinition> movementDefinitions)
{
foreach (MovementDefinition movementDefinition in movementDefinitions)
AddDefinerToFactory(movementDefinition);
AddDefinitionToFactory(movementDefinition);
}
public void AddDefinerToFactory(MovementDefinition movementDefinition)
public void AddDefinitionToFactory(MovementDefinition movementDefinition)
{
if (Definitions.ContainsKey(movementDefinition.Name))
throw new System.ArgumentException($"{ movementDefinition.Name } is already in the Movement Definer Factory");
throw new System.ArgumentException($"{ movementDefinition.Name } is already in the Movement Definition Factory");
Definitions.Add(movementDefinition.Name, movementDefinition);
}

View File

@ -45,14 +45,19 @@ namespace Syntriax.Modules.Movement.Config
Destroy(this);
}
private void Initialize()
public void Initialize()
{
if (_types == null)
_types = new Dictionary<string, Type>(InitialCapacity);
Reset();
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
AddAssemblyToFactory(assembly);
}
public void Reset() => _types?.Clear();
public void AddAssemblyToFactory(Assembly assembly)
{
foreach (Type type in assembly.GetTypes().Where(predicate))

View File

@ -45,10 +45,13 @@ namespace Syntriax.Modules.Movement.Config
Destroy(this);
}
private void Initialize()
public void Initialize()
{
if (_collections == null)
_collections = new Dictionary<string, VMCollection>(InitialCapacity);
Reset();
foreach (TextAsset definitionTextAsset in UnityEngine.Resources.LoadAll<TextAsset>(ResourceDirectoryToCollections))
{
VMCollection collection = JsonUtility.FromJson<VMCollection>(definitionTextAsset.text);
@ -56,6 +59,8 @@ namespace Syntriax.Modules.Movement.Config
}
}
public void Reset() => _collections?.Clear();
public void AddCollectionsToFactory(List<VMCollection> collections)
{
foreach (VMCollection collection in collections)

View File

@ -1,5 +1,5 @@
{
"name": "Movement",
"name": "Syntriax.Modules.Movement",
"rootNamespace": "",
"references": [
"GUID:75469ad4d38634e559750d17036d5f7c"