public void LoadMSB(IMsb msb)
        {
            foreach (var m in msb.Models.GetEntries())
            {
                LoadedModels.Add(m.Name, m);
            }

            foreach (var p in msb.Parts.GetEntries())
            {
                var n = new MapEntity(this, p, MapEntity.MapEntityType.Part);
                Objects.Add(n);
                RootObject.AddChild(n);
            }

            foreach (var p in msb.Regions.GetEntries())
            {
                var n = new MapEntity(this, p, MapEntity.MapEntityType.Region);
                Objects.Add(n);
                RootObject.AddChild(n);
            }

            foreach (var p in msb.Events.GetEntries())
            {
                var n = new MapEntity(this, p, MapEntity.MapEntityType.Event);
                Objects.Add(n);
                RootObject.AddChild(n);
            }

            foreach (var m in Objects)
            {
                m.BuildReferenceMap();
            }
        }
Esempio n. 2
0
        public override Entity Clone()
        {
            MapEntity c = (MapEntity)base.Clone();

            c.Type = Type;
            return(c);
        }
        public Map(Universe u, string mapid)
        {
            Name     = mapid;
            Universe = u;
            var t = new TransformNode(mapid);

            RootObject = new MapEntity(this, t, MapEntity.MapEntityType.MapRoot);
        }
Esempio n. 4
0
        public override ActionEvent Execute()
        {
            bool clonesCached = Clones.Count() > 0;

            //foreach (var obj in Clonables)
            for (int i = 0; i < Clonables.Count(); i++)
            {
                var m = Universe.GetLoadedMap(Clonables[i].MapID);
                if (m != null)
                {
                    // If this was executed in the past we reused the cloned objects so because redo
                    // actions that follow this may reference the previously cloned object
                    MapEntity newobj = clonesCached ? Clones[i] : (MapEntity)Clonables[i].Clone();
                    newobj.Name = Clonables[i].Name + "_1";
                    m.Objects.Insert(m.Objects.IndexOf(Clonables[i]) + 1, newobj);
                    if (Clonables[i].Parent != null)
                    {
                        int idx = Clonables[i].Parent.ChildIndex(Clonables[i]);
                        Clonables[i].Parent.AddChild(newobj, idx);
                    }
                    newobj.UpdateRenderModel();
                    if (newobj.RenderSceneMesh != null)
                    {
                        newobj.RenderSceneMesh.SetSelectable(newobj);
                    }
                    if (!clonesCached)
                    {
                        Clones.Add(newobj);
                        CloneMaps.Add(m);
                        m.HasUnsavedChanges = true;
                    }
                    else
                    {
                        if (Clones[i].RenderSceneMesh != null)
                        {
                            Clones[i].RenderSceneMesh.AutoRegister = true;
                            Clones[i].RenderSceneMesh.Register();
                        }
                    }
                }
            }
            if (SetSelection)
            {
                Universe.Selection.ClearSelection();
                foreach (var c in Clones)
                {
                    Universe.Selection.AddSelection(c);
                }
            }
            return(ActionEvent.ObjectAddedRemoved);
        }
Esempio n. 5
0
        public override ActionEvent Execute()
        {
            bool clonesCached = Clones.Count() > 0;
            // foreach (var obj in Clonables)

            var objectnames = new Dictionary <string, HashSet <string> >();

            for (int i = 0; i < Clonables.Count(); i++)
            {
                var m = Universe.GetLoadedMap(Clonables[i].MapID);
                if (m != null)
                {
                    // Get list of names that exist so our duplicate names don't trample over them
                    if (!objectnames.ContainsKey(Clonables[i].MapID))
                    {
                        var nameset = new HashSet <string>();
                        foreach (var n in m.Objects)
                        {
                            nameset.Add(n.Name);
                        }
                        objectnames.Add(Clonables[i].MapID, nameset);
                    }

                    // If this was executed in the past we reused the cloned objects so because redo
                    // actions that follow this may reference the previously cloned object
                    MapEntity newobj = clonesCached ? Clones[i] : (MapEntity)Clonables[i].Clone();

                    // Use pattern matching to attempt renames based on appended ID
                    Match idmatch = TrailIDRegex.Match(Clonables[i].Name);
                    if (idmatch.Success)
                    {
                        var    idstring = idmatch.Result("${id}");
                        int    id       = int.Parse(idstring);
                        string newid    = idstring;
                        while (objectnames[Clonables[i].MapID].Contains(Clonables[i].Name.Substring(0, Clonables[i].Name.Length - idstring.Length) + newid))
                        {
                            id++;
                            newid = id.ToString("D" + idstring.Length.ToString());
                        }
                        newobj.Name = Clonables[i].Name.Substring(0, Clonables[i].Name.Length - idstring.Length) + newid;
                        objectnames[Clonables[i].MapID].Add(newobj.Name);
                    }
                    else
                    {
                        var    idstring = "0001";
                        int    id       = int.Parse(idstring);
                        string newid    = idstring;
                        while (objectnames[Clonables[i].MapID].Contains(Clonables[i].Name + "_" + newid))
                        {
                            id++;
                            newid = id.ToString("D" + idstring.Length.ToString());
                        }
                        newobj.Name = Clonables[i].Name + "_" + newid;
                        objectnames[Clonables[i].MapID].Add(newobj.Name);
                    }

                    m.Objects.Insert(m.Objects.IndexOf(Clonables[i]) + 1, newobj);
                    if (Clonables[i].Parent != null)
                    {
                        int idx = Clonables[i].Parent.ChildIndex(Clonables[i]);
                        Clonables[i].Parent.AddChild(newobj, idx);
                    }
                    newobj.UpdateRenderModel();
                    if (newobj.RenderSceneMesh != null)
                    {
                        newobj.RenderSceneMesh.SetSelectable(newobj);
                    }
                    if (!clonesCached)
                    {
                        Clones.Add(newobj);
                        CloneMaps.Add(m);
                        m.HasUnsavedChanges = true;
                    }
                    else
                    {
                        if (Clones[i].RenderSceneMesh != null)
                        {
                            Clones[i].RenderSceneMesh.AutoRegister = true;
                            Clones[i].RenderSceneMesh.Register();
                        }
                    }
                }
            }
            if (SetSelection)
            {
                Universe.Selection.ClearSelection();
                foreach (var c in Clones)
                {
                    Universe.Selection.AddSelection(c);
                }
            }
            return(ActionEvent.ObjectAddedRemoved);
        }