Exemplo n.º 1
0
            // Serialization
            public void RegisterGrid(IMapGrid grid)
            {
                if (GridIDMap.ContainsKey(grid.Index))
                {
                    throw new InvalidOperationException();
                }

                Grids.Add(grid);
                GridIDMap.Add(grid.Index, GridIDMap.Count);
            }
Exemplo n.º 2
0
            public override bool TryTypeToNode(object obj, out YamlNode node)
            {
                switch (obj)
                {
                case GridId gridId:
                    if (!GridIDMap.TryGetValue(gridId, out var gridMapped))
                    {
                        Logger.WarningS("map", "Cannot write grid ID '{0}', falling back to nullspace.", gridId);
                        break;
                    }
                    else
                    {
                        node = new YamlScalarNode(gridMapped.ToString(CultureInfo.InvariantCulture));
                        return(true);
                    }

                case EntityUid entityUid:
                    if (!EntityUidMap.TryGetValue(entityUid, out var entityUidMapped))
                    {
                        // Terrible hack to mute this warning on the grids themselves when serializing blueprints.
                        if (!IsBlueprintMode || !CurrentWritingEntity.HasComponent <MapGridComponent>() ||
                            CurrentWritingComponent != "Transform")
                        {
                            Logger.WarningS("map", "Cannot write entity UID '{0}'.", entityUid);
                        }

                        node = new YamlScalarNode("null");
                        return(true);
                    }
                    else
                    {
                        node = new YamlScalarNode(entityUidMapped.ToString(CultureInfo.InvariantCulture));
                        return(true);
                    }

                case IEntity entity:
                    if (!EntityUidMap.TryGetValue(entity.Uid, out var entityMapped))
                    {
                        Logger.WarningS("map", "Cannot write entity UID '{0}'.", entity.Uid);
                        break;
                    }
                    else
                    {
                        node = new YamlScalarNode(entityMapped.ToString(CultureInfo.InvariantCulture));
                        return(true);
                    }
                }
                node = null;
                return(false);
            }
Exemplo n.º 3
0
            private bool IsMapSavable(IEntity entity)
            {
                if (entity.Prototype?.MapSavable == false || !GridIDMap.ContainsKey(entity.Transform.GridID))
                {
                    return(false);
                }

                // Don't serialize things parented to un savable things.
                // For example clothes inside a person.
                var current = entity.Transform;

                while (current.Parent != null)
                {
                    if (current.Parent.Owner.Prototype?.MapSavable == false)
                    {
                        return(false);
                    }

                    current = current.Parent;
                }

                return(true);
            }