Ejemplo n.º 1
0
        /// <summary>
        /// Creates an entity from this template
        /// </summary>
        /// <returns></returns>
        public IEntity CreateEntity(IEntityManager manager, IEntityNetworkManager networkManager, IComponentFactory componentFactory)
        {
            var entity = (IEntity)Activator.CreateInstance(ClassType, manager, networkManager);

            foreach (KeyValuePair <string, Dictionary <string, YamlNode> > componentData in components)
            {
                IComponent component;
                try
                {
                    component = componentFactory.GetComponent(componentData.Key);
                }
                catch (UnknowComponentException)
                {
                    // Ignore nonexistant ones.
                    // This is kind of inefficient but we'll do the sanity on prototype creation
                    // Once the dependency injection stack is fixed.
                    Log.Logger.Log(string.Format("Unable to load prototype component. UnknowComponentException occured for componentKey `{0}`", componentData.Key));
                    continue;
                }
                component.LoadParameters(componentData.Value);

                entity.AddComponent(component.Family, component);
            }

            entity.Name      = Name;
            entity.Prototype = this;
            return(entity);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an entity from this prototype.
        /// Do not call this directly, use the server entity manager instead.
        /// </summary>
        /// <returns></returns>
        public Entity CreateEntity(EntityUid uid, IEntityManager manager, IEntityNetworkManager networkManager, IComponentFactory componentFactory)
        {
            var entity = (Entity)Activator.CreateInstance(ClassType ?? typeof(Entity));

            entity.SetManagers(manager, networkManager);
            entity.SetUid(uid);
            entity.Name      = Name;
            entity.Prototype = this;

            if (DataNode != null)
            {
                entity.ExposeData(new YamlEntitySerializer(DataNode));
            }

            foreach (var componentData in Components)
            {
                var component = (Component)componentFactory.GetComponent(componentData.Key);

                component.Owner = entity;
                component.LoadParameters(componentData.Value);
                component.ExposeData(new YamlEntitySerializer(componentData.Value));

                entity.AddComponent(component);
            }

            return(entity);
        }
Ejemplo n.º 3
0
 public void SetManagers(IEntityManager entityManager, IEntityNetworkManager networkManager)
 {
     if (EntityManager != null)
     {
         throw new InvalidOperationException("Entity already has initialized managers.");
     }
     EntityManager        = entityManager;
     EntityNetworkManager = networkManager;
 }
Ejemplo n.º 4
0
 public Entity(EntityManager entityManager)
 {
     EntityManager        = entityManager;
     EntityNetworkManager = EntityManager.EntityNetworkManager;
     if (EntityManager.EngineType == EngineType.Client)
     {
         Initialize();
     }
 }
Ejemplo n.º 5
0
        public Entity(IEntityManager entityManager, IEntityNetworkManager networkManager)
        {
            EntityManager        = entityManager;
            EntityNetworkManager = networkManager;
            var name = Assembly.GetEntryAssembly().GetName().Name;

            if (name == "SS14.Client")
            {
                Initialize();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates an entity from this template
        /// </summary>
        /// <returns></returns>
        public IEntity CreateEntity(IEntityManager manager, IEntityNetworkManager networkManager, IComponentFactory componentFactory)
        {
            var entity = (IEntity)Activator.CreateInstance(ClassType, manager, networkManager, componentFactory);

            entity.Name      = Name;
            entity.Prototype = this;

            foreach (KeyValuePair <string, YamlMappingNode> componentData in Components)
            {
                IComponent component = componentFactory.GetComponent(componentData.Key);

                component.LoadParameters(componentData.Value);

                entity.AddComponent(component);
            }

            entity.LoadData(DataNode);

            return(entity);
        }
Ejemplo n.º 7
0
        public EntityManager(EngineType engineType, IEntityNetworkManager entityNetworkManager)
        {
            EngineType = engineType;
            switch (EngineType)
            {
            case EngineType.Client:
                _componentNamespace = "SS14.Client.GameObjects";
                break;

            case EngineType.Server:
                _componentNamespace = "SS14.Server.GameObjects";
                break;
            }
            EntitySystemManager    = new EntitySystemManager(this);
            ComponentFactory       = new ComponentFactory(this, _componentNamespace);
            EntityNetworkManager   = entityNetworkManager;
            ComponentManager       = new ComponentManager();
            EntityTemplateDatabase = new EntityTemplateDatabase(this);
            EntityFactory          = new EntityFactory(EntityTemplateDatabase);
            Clock = 0f;
            Initialize();
        }
Ejemplo n.º 8
0
 protected EntitySystem()
 {
     EntityManager        = IoCManager.Resolve <IEntityManager>();
     EntitySystemManager  = IoCManager.Resolve <IEntitySystemManager>();
     EntityNetworkManager = IoCManager.Resolve <IEntityNetworkManager>();
 }
Ejemplo n.º 9
0
 public EntitySystem()
 {
     EntityManager        = IoCManager.Resolve <IEntityManager>();
     EntitySystemManager  = IoCManager.Resolve <IEntitySystemManager>();
     EntityNetworkManager = IoCManager.Resolve <IEntityNetworkManager>();
 }