Ejemplo n.º 1
0
        private void AddComponentLazy(ModSessionComponent component, Ob_ModSessionComponent config)
        {
            foreach (var dep in component.Dependencies)
            {
                if (m_dependencySatisfyingComponents.ContainsKey(dep))
                {
                    continue;
                }
                ModSessionComponentRegistry.CreateComponent factory;
                if (!_factories.TryGetValue(dep, out factory))
                {
                    throw new ArgumentException("Can't add " + component.GetType() +
                                                " since we don't have dependency " + dep + " loaded or a factory for it");
                }
                AddComponentLazy(factory(), null);
            }
            // Safe to add to the end of the ordered list.
            var item = new RuntimeSessionComponent(component, config);

            foreach (var dep in component.Dependencies)
            {
                var depRes = m_dependencySatisfyingComponents[dep];
                depRes.Dependents.Add(item);
                item.Dependencies.Add(item);
                item.Component.SatisfyDependency(depRes.Component);
            }
            Insert(item);
            m_orderedComponentList.Add(item);
            if (item.Config != null)
            {
                item.Component.LoadConfiguration(item.Config);
            }
            item.Component.Attached(this);
            ComponentAttached?.Invoke(item.Component);
        }
Ejemplo n.º 2
0
 public void Attach()
 {
     if (m_attached)
     {
         return;
     }
     SortComponents();
     m_attached = true;
     foreach (var x in m_orderedComponentList)
     {
         if (x.Config != null)
         {
             x.Component.LoadConfiguration(x.Config);
         }
         x.Component.Attached(this);
         ComponentAttached?.Invoke(x.Component);
     }
     ApplyComponentChanges();
 }
 internal void AttachComponent(EntityComponent component)
 {
     _components.Add(component);
     ComponentAttached?.Invoke(this, component);
 }