From 8177ea24efca71b84a34fcc30106376858335f59 Mon Sep 17 00:00:00 2001 From: copygirl Date: Fri, 4 Nov 2022 21:43:36 +0100 Subject: [PATCH] Rename ModuleInfo properties --- src/gaemstone/ECS/Universe+Modules.cs | 50 ++++++++++++++------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/gaemstone/ECS/Universe+Modules.cs b/src/gaemstone/ECS/Universe+Modules.cs index 76dca61..f31a298 100644 --- a/src/gaemstone/ECS/Universe+Modules.cs +++ b/src/gaemstone/ECS/Universe+Modules.cs @@ -52,9 +52,9 @@ public class ModuleManager var path = GetModulePath(type); var module = new ModuleInfo(Universe, type, path); - _modules.Add(module.ModuleEntity, module); + _modules.Add(module.Entity, module); TryEnableModule(module); - return module.ModuleEntity; + return module.Entity; } } @@ -67,14 +67,16 @@ public class ModuleManager // Find other modules that might be missing this module as a dependency. foreach (var other in _modules.Values) { if (other.IsActive) continue; - if (!other.UnmetDependencies.Contains(module.ModuleEntity)) continue; + if (!other.UnmetDependencies.Contains(module.Entity)) continue; // Move the just enabled module from unmet to met depedencies. - other.UnmetDependencies.Remove(module.ModuleEntity); + other.UnmetDependencies.Remove(module.Entity); other.MetDependencies.Add(module); TryEnableModule(other); } + + Console.WriteLine("Enabled module " + module.Path); } public static EntityPath GetModulePath(Type type) @@ -103,10 +105,10 @@ public class ModuleManager internal class ModuleInfo { public Universe Universe { get; } - public Type ModuleType { get; } - public EntityPath ModulePath { get; } + public Type Type { get; } + public EntityPath Path { get; } - public EntityRef ModuleEntity { get; } + public EntityRef Entity { get; } public object? Instance { get; internal set; } public bool IsActive => Instance != null; @@ -115,19 +117,19 @@ internal class ModuleInfo public ModuleInfo(Universe universe, Type type, EntityPath path) { - Universe = universe; - ModuleType = type; - ModulePath = path; + Universe = universe; + Type = type; + Path = path; - if (ModuleType.IsAbstract || ModuleType.IsSealed) throw new Exception( - $"Module {ModuleType} must not be abstract or sealed"); - if (ModuleType.GetConstructor(Type.EmptyTypes) == null) throw new Exception( - $"Module {ModuleType} must define public parameterless constructor"); + if (Type.IsAbstract || Type.IsSealed) throw new Exception( + $"Module {Type} must not be abstract or sealed"); + if (Type.GetConstructor(Type.EmptyTypes) == null) throw new Exception( + $"Module {Type} must define public parameterless constructor"); var module = Universe.New(path).Add(); // Add module dependencies from [DependsOn] attributes. - foreach (var dependsAttr in ModuleType.GetMultiple()) { + foreach (var dependsAttr in Type.GetMultiple()) { var dependsPath = ModuleManager.GetModulePath(dependsAttr.Type); var dependency = Universe.Lookup(dependsPath) ?? Universe.New(dependsPath).Add().Disable().Build(); @@ -139,26 +141,26 @@ internal class ModuleInfo module.Add(dependency); } - ModuleEntity = module.Build().CreateLookup(type); + Entity = module.Build().CreateLookup(type); } public void Enable() { - ModuleEntity.Enable(); - Instance = Activator.CreateInstance(ModuleType)!; + Entity.Enable(); + Instance = Activator.CreateInstance(Type)!; RegisterNestedTypes(); - (Instance as IModuleInitializer)?.Initialize(ModuleEntity); + (Instance as IModuleInitializer)?.Initialize(Entity); RegisterMethods(Instance); } private void RegisterNestedTypes() { - foreach (var type in ModuleType.GetNestedTypes()) { + foreach (var type in Type.GetNestedTypes()) { if (type.Get() is not EntityAttribute attr) continue; if (attr.Name?.Contains(EntityPath.Separator) == true) throw new Exception( $"{type} must not contain '{EntityPath.Separator}'"); var name = attr.Name ?? type.Name; - var entity = ModuleEntity.NewChild(name).Symbol(name); + var entity = Entity.NewChild(name).Symbol(name); switch (attr) { case TagAttribute: @@ -183,11 +185,11 @@ internal class ModuleInfo private void RegisterMethods(object? instance) { - foreach (var method in ModuleType.GetMethods()) { + foreach (var method in Type.GetMethods()) { if (method.Has()) - Universe.RegisterSystem(instance, method).ChildOf(ModuleEntity); + Universe.RegisterSystem(instance, method).ChildOf(Entity); if (method.Has()) - Universe.RegisterObserver(instance, method).ChildOf(ModuleEntity); + Universe.RegisterObserver(instance, method).ChildOf(Entity); } } }