Exemplo n.º 1
0
        internal Entity AllocEntity(string prototypeName, EntityUid?uid = null)
        {
            if (uid == null)
            {
                uid = new EntityUid(NextUid++);
            }

            if (EntityExists(uid.Value))
            {
                throw new InvalidOperationException($"UID already taken: {uid}");
            }

            EntityPrototype prototype = PrototypeManager.Index <EntityPrototype>(prototypeName);

            return(prototype.AllocEntity(uid.Value, this, EntityNetworkManager));
        }
Exemplo n.º 2
0
        private static void PushInheritance(EntityPrototype source, EntityPrototype target)
        {
            foreach (KeyValuePair <string, YamlMappingNode> component in source.Components)
            {
                if (target.Components.TryGetValue(component.Key, out YamlMappingNode targetComponent))
                {
                    // Copy over values the target component does not have.
                    foreach (YamlNode key in component.Value.Children.Keys)
                    {
                        if (!targetComponent.Children.ContainsKey(key))
                        {
                            targetComponent.Children[key] = component.Value[key];
                        }
                    }
                }
                else
                {
                    // Copy component into the target, since it doesn't have it yet.
                    target.Components[component.Key] = new YamlMappingNode(component.Value.AsEnumerable());
                }
            }

            if (target.Name == null)
            {
                target.Name = source.Name;
            }

            if (target.ClassType == null)
            {
                target.ClassType = source.ClassType;
            }

            if (target.Children == null)
            {
                return;
            }

            // TODO: remove recursion somehow.
            foreach (EntityPrototype child in target.Children)
            {
                PushInheritance(target, child);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates an entity and adds it to the entity dictionary
        /// </summary>
        /// <param name="prototypeName">name of entity template to execute</param>
        /// <param name="uid">UID to give to the new entity.</param>
        /// <returns>spawned entity</returns>
        public Entity SpawnEntity(string prototypeName, EntityUid?uid = null)
        {
            if (uid == null)
            {
                uid = new EntityUid(NextUid++);
            }

            if (EntityExists(uid.Value))
            {
                throw new InvalidOperationException($"UID already taken: {uid}");
            }

            EntityPrototype prototype = PrototypeManager.Index <EntityPrototype>(prototypeName);
            Entity          entity    = prototype.CreateEntity(uid.Value, this, EntityNetworkManager, ComponentFactory);

            Entities[uid.Value] = entity;
            _allEntities.Add(entity);

            return(entity);
        }
Exemplo n.º 4
0
        private static void PushInheritance(EntityPrototype source, EntityPrototype target)
        {
            foreach (KeyValuePair <string, Dictionary <string, YamlNode> > component in source.Components)
            {
                Dictionary <string, YamlNode> targetComponent;
                if (target.Components.TryGetValue(component.Key, out targetComponent))
                {
                    // Copy over values the target component does not have.
                    foreach (string key in component.Value.Keys)
                    {
                        if (!targetComponent.ContainsKey(key))
                        {
                            targetComponent[key] = component.Value[key];
                        }
                    }
                }
                else
                {
                    // Copy component into the target, since it doesn't have it yet.
                    target.Components[component.Key] = new Dictionary <string, YamlNode>(component.Value);
                }
            }

            if (target.Name == null)
            {
                target.Name = source.Name;
            }

            if (target.Children == null)
            {
                return;
            }

            // TODO: remove recursion somehow.
            foreach (EntityPrototype child in target.Children)
            {
                PushInheritance(target, child);
            }
        }
Exemplo n.º 5
0
        private static void PushInheritance(EntityPrototype source, EntityPrototype target)
        {
            foreach (KeyValuePair <string, YamlMappingNode> component in source.Components)
            {
                if (target.Components.TryGetValue(component.Key, out YamlMappingNode targetComponent))
                {
                    // Copy over values the target component does not have.
                    foreach (YamlNode key in component.Value.Children.Keys)
                    {
                        if (!targetComponent.Children.ContainsKey(key))
                        {
                            targetComponent.Children[key] = component.Value[key];
                        }
                    }
                }
                else
                {
                    // Copy component into the target, since it doesn't have it yet.
                    target.Components[component.Key] = new YamlMappingNode(component.Value.AsEnumerable());
                }
            }

            if (!target._placementOverriden)
            {
                target.PlacementMode = source.PlacementMode;
            }

            if (!target._placementOverriden)
            {
                target.PlacementOffset = source.PlacementOffset;
            }

            if (target.MountingPoints == null && source.MountingPoints != null)
            {
                target.MountingPoints = new List <int>(source.MountingPoints);
            }

            if (target.PlacementRange == DEFAULT_RANGE)
            {
                target.PlacementRange = source.PlacementRange;
            }

            if (!target._snapOverriden)
            {
                foreach (var flag in source._snapFlags)
                {
                    target._snapFlags.Add(flag);
                }
            }

            if (target.Name == null)
            {
                target.Name = source.Name;
            }

            if (target.ClassType == null)
            {
                target.ClassType = source.ClassType;
            }

            if (target.Children == null)
            {
                return;
            }

            // TODO: remove recursion somehow.
            foreach (EntityPrototype child in target.Children)
            {
                PushInheritance(target, child);
            }
        }
Exemplo n.º 6
0
        private static void PushInheritance(EntityPrototype source, EntityPrototype target)
        {
            // Copy component data over.
            foreach (KeyValuePair <string, YamlMappingNode> component in source.Components)
            {
                if (target.Components.TryGetValue(component.Key, out YamlMappingNode targetComponent))
                {
                    // Copy over values the target component does not have.
                    foreach (YamlNode key in component.Value.Children.Keys)
                    {
                        if (!targetComponent.Children.ContainsKey(key))
                        {
                            targetComponent.Children[key] = component.Value[key];
                        }
                    }
                }
                else
                {
                    // Copy component into the target, since it doesn't have it yet.
                    // Unless it'd cause a conflict.
                    var factory = IoCManager.Resolve <IComponentFactory>();
                    foreach (var refType in factory.GetRegistration(component.Key).References)
                    {
                        if (target.ReferenceTypes.Contains(refType))
                        {
                            // yeah nope the child's got it!! NEXT!!
                            goto next;
                        }
                    }
                    target.Components[component.Key] = new YamlMappingNode(component.Value.AsEnumerable());
                }
                next :;
            }

            // Copy all simple data over.
            if (!target._placementOverriden)
            {
                target.PlacementMode = source.PlacementMode;
            }

            if (!target._placementOverriden)
            {
                target.PlacementOffset = source.PlacementOffset;
            }

            if (target.MountingPoints == null && source.MountingPoints != null)
            {
                target.MountingPoints = new List <int>(source.MountingPoints);
            }

            if (target.PlacementRange == DEFAULT_RANGE)
            {
                target.PlacementRange = source.PlacementRange;
            }

            if (!target._snapOverriden)
            {
                foreach (var flag in source._snapFlags)
                {
                    target._snapFlags.Add(flag);
                }
            }

            if (target.Name == null)
            {
                target.Name = source.Name;
            }

            if (target.ClassType == null)
            {
                target.ClassType = source.ClassType;
            }

            if (target.Children == null)
            {
                return;
            }

            // TODO: remove recursion somehow.
            foreach (EntityPrototype child in target.Children)
            {
                PushInheritance(target, child);
            }
        }