Example #1
0
        public bool MergeEntityNodes(YamlMappingNode ours, YamlMappingNode based, YamlMappingNode other)
        {
            // Copy to intermediate
            var otherMapped = (YamlMappingNode)YamlTools.CopyYamlNodes(other);

            if (!MapEntity(otherMapped))
            {
                return(false);
            }
            // Merge stuff that isn't components
            var path = "Entity" + (other["uid"].ToString());

            YamlTools.MergeYamlMappings(ours, based, otherMapped, path, new string[] { "components" });
            // Components are special
            var ourComponents       = new Dictionary <string, YamlMappingNode>();
            var basedComponents     = new Dictionary <string, YamlMappingNode>();
            var ourComponentsNode   = (YamlSequenceNode)ours["components"];
            var basedComponentsNode = (YamlSequenceNode)based["components"];
            var otherComponentsNode = (YamlSequenceNode)otherMapped["components"];

            foreach (var component in ourComponentsNode)
            {
                var name = component["type"].ToString();
                ourComponents[name] = (YamlMappingNode)component;
            }
            foreach (var component in basedComponentsNode)
            {
                var name = component["type"].ToString();
                basedComponents[name] = (YamlMappingNode)component;
            }
            foreach (var otherComponent in otherComponentsNode)
            {
                var name = otherComponent["type"].ToString();
                if (ourComponents.ContainsKey(name))
                {
                    var ourComponent = ourComponents[name];
                    if (!basedComponents.TryGetValue(name, out var basedComponent))
                    {
                        basedComponent = new YamlMappingNode();
                    }

                    YamlTools.MergeYamlNodes(ourComponent, basedComponent, otherComponent, path + "/components/" + name);
                }
                else
                {
                    ourComponentsNode.Add(otherComponent);
                }
            }
            return(true);
        }
Example #2
0
        public bool MergeEntities()
        {
            bool success = true;

            foreach (var kvp in EntityMapFromOtherToOurs)
            {
                // For debug use.
                // Console.WriteLine("Entity C/" + kvp.Key + " -> A/" + kvp.Value);
                YamlMappingNode oursEnt;
                if (MapOurs.Entities.ContainsKey(kvp.Value))
                {
                    oursEnt = MapOurs.Entities[kvp.Value];
                    if (!MapBased.Entities.TryGetValue(kvp.Value, out var basedEnt))
                    {
                        basedEnt = oursEnt;
                    }

                    if (!MergeEntityNodes(oursEnt, basedEnt, MapOther.Entities[kvp.Key]))
                    {
                        Console.WriteLine("Unable to successfully merge entity C/" + kvp.Key);
                        success = false;
                    }
                }
                else
                {
                    oursEnt = (YamlMappingNode)YamlTools.CopyYamlNodes(MapOther.Entities[kvp.Key]);
                    if (!MapEntity(oursEnt))
                    {
                        Console.WriteLine("Unable to successfully import entity C/" + kvp.Key);
                        success = false;
                    }
                    else
                    {
                        MapOurs.Entities[kvp.Value] = oursEnt;
                    }
                }
                oursEnt.Children["uid"] = kvp.Value.ToString(CultureInfo.InvariantCulture);
            }
            return(success);
        }