示例#1
0
        public List <WDOMNode> GetMapEntities()
        {
            var loadedActors = new List <WDOMNode>();

            foreach (var chunk in m_chunkList)
            {
                m_reader.BaseStream.Position = chunk.ChunkOffset;
                MapActorDescriptor template = Globals.ActorDescriptors.Find(x => x.FourCC == chunk.FourCC);
                if (template == null)
                {
                    Console.WriteLine("Unsupported FourCC: {0}", chunk.FourCC);
                    continue;
                }

                switch (chunk.FourCC)
                {
                // Don't turn these into map actors, as they will be handled elsewhere.
                //case "RTBL":
                case FourCC.MECO:
                case FourCC.MEMA:
                    break;

                default:
                    for (int i = 0; i < chunk.ElementCount; i++)
                    {
                        Type actorType             = Type.GetType($"WindEditor.{template.ClassName}");
                        SerializableDOMNode entity = (SerializableDOMNode)Activator.CreateInstance(actorType, chunk.FourCC, m_world);
                        entity.Load(m_reader);
                        entity.PostLoad();
                        entity.Layer = chunk.Layer;

                        loadedActors.Add(entity);
                    }
                    break;
                }
            }

            // var dict = new Dictionary<string, List<WDOMNode>>();
            // foreach(var actor in loadedActors)
            // {
            //     if (!dict.ContainsKey(actor.FourCC))
            //         dict[actor.FourCC] = new List<WDOMNode>();
            //     dict[actor.FourCC].Add(actor);
            // }
            //
            // string[] nodes = new[] { "EnvR", "Pale", "Virt", "Colo" };
            // foreach(var node in nodes)
            // {
            //     if (dict.ContainsKey(node))
            //         Console.WriteLine("{0} Count: {1}", node, dict[node].Count);
            //
            // }

            return(loadedActors);
        }
示例#2
0
        public void AddObjectToDictionary(SerializableDOMNode actor, Dictionary <FourCC, List <SerializableDOMNode> > actorCategories)
        {
            string rawFourCC       = FourCCConversion.GetStringFromEnum(actor.FourCC);
            string fixedFourCC     = ChunkHeader.LayerToFourCC(rawFourCC, actor.Layer);
            FourCC fixedFourCCEnum = FourCCConversion.GetEnumFromString(fixedFourCC);

            if (!actorCategories.ContainsKey(fixedFourCCEnum))
            {
                actorCategories[fixedFourCCEnum] = new List <SerializableDOMNode>();
            }

            actorCategories[fixedFourCCEnum].Add(actor);
        }
        public List <WDOMNode> GetMapEntities()
        {
            var loadedActors = new List <WDOMNode>();

            foreach (var chunk in m_chunkList)
            {
                m_reader.BaseStream.Position = chunk.ChunkOffset;
                MapActorDescriptor template = Globals.ActorDescriptors.Find(x => x.FourCC == chunk.FourCC);
                if (template == null)
                {
                    Console.WriteLine("Unsupported FourCC: {0}", chunk.FourCC);
                    continue;
                }

                switch (chunk.FourCC)
                {
                // Don't turn these into map actors, as they will be handled elsewhere.
                //case "RTBL":
                case FourCC.MECO:
                case FourCC.MEMA:
                    break;

                case FourCC.SCOB:
                case FourCC.SCO0:
                case FourCC.SCO1:
                case FourCC.SCO2:
                case FourCC.SCO3:
                case FourCC.SCO4:
                case FourCC.SCO5:
                case FourCC.SCO6:
                case FourCC.SCO7:
                case FourCC.SCO8:
                case FourCC.SCO9:
                case FourCC.SCOa:
                case FourCC.SCOb:
                case FourCC.TGSC:
                    for (int i = 0; i < chunk.ElementCount; i++)
                    {
                        // We need to read the entity name so we can load the right derived class for it
                        string entity_name = Encoding.ASCII.GetString(m_reader.PeekReadBytes(8)).Trim('\0');

                        Type actorType             = WResourceManager.GetTypeByName(entity_name);
                        SerializableDOMNode entity = (SerializableDOMNode)Activator.CreateInstance(actorType, chunk.FourCC, m_world);

                        entity.Load(m_reader);
                        entity.Layer = chunk.Layer;

                        entity.Transform.LocalScale = new Vector3(m_reader.ReadByte() / 10f, m_reader.ReadByte() / 10f, m_reader.ReadByte() / 10f);
                        int padding = m_reader.ReadByte();

                        loadedActors.Add(entity);
                    }
                    break;

                case FourCC.ACTR:
                case FourCC.ACT0:
                case FourCC.ACT1:
                case FourCC.ACT2:
                case FourCC.ACT3:
                case FourCC.ACT4:
                case FourCC.ACT5:
                case FourCC.ACT6:
                case FourCC.ACT7:
                case FourCC.ACT8:
                case FourCC.ACT9:
                case FourCC.ACTa:
                case FourCC.ACTb:
                case FourCC.TGOB:
                case FourCC.TGDR:
                    for (int i = 0; i < chunk.ElementCount; i++)
                    {
                        // We need to read the entity name so we can load the right derived class for it
                        string entity_name = Encoding.ASCII.GetString(m_reader.PeekReadBytes(8)).Trim('\0');

                        Type actorType             = WResourceManager.GetTypeByName(entity_name);
                        SerializableDOMNode entity = (SerializableDOMNode)Activator.CreateInstance(actorType, chunk.FourCC, m_world);

                        entity.Load(m_reader);
                        entity.Layer = chunk.Layer;

                        loadedActors.Add(entity);
                    }
                    break;

                case FourCC.RTBL:
                    for (int i = 0; i < chunk.ElementCount; i++)
                    {
                        int entry_offset = m_reader.ReadInt32();

                        int next_offset = (int)m_reader.BaseStream.Position;
                        m_reader.BaseStream.Seek(entry_offset, SeekOrigin.Begin);

                        RoomTableEntryNode rtbl_entry = new RoomTableEntryNode(chunk.FourCC, m_world, m_reader);
                        loadedActors.Add(rtbl_entry);

                        m_reader.BaseStream.Seek(next_offset, SeekOrigin.Begin);
                    }

                    break;

                default:
                    for (int i = 0; i < chunk.ElementCount; i++)
                    {
                        Type actorType             = Type.GetType($"WindEditor.{template.ClassName}");
                        SerializableDOMNode entity = (SerializableDOMNode)Activator.CreateInstance(actorType, chunk.FourCC, m_world);
                        entity.Load(m_reader);
                        entity.Layer = chunk.Layer;

                        loadedActors.Add(entity);
                    }
                    break;
                }
            }

            // var dict = new Dictionary<string, List<WDOMNode>>();
            // foreach(var actor in loadedActors)
            // {
            //     if (!dict.ContainsKey(actor.FourCC))
            //         dict[actor.FourCC] = new List<WDOMNode>();
            //     dict[actor.FourCC].Add(actor);
            // }
            //
            // string[] nodes = new[] { "EnvR", "Pale", "Virt", "Colo" };
            // foreach(var node in nodes)
            // {
            //     if (dict.ContainsKey(node))
            //         Console.WriteLine("{0} Count: {1}", node, dict[node].Count);
            //
            // }

            AssignPaths(loadedActors);

            return(loadedActors);
        }
示例#4
0
        protected virtual void LoadLevelEntitiesFromFile(string filePath)
        {
            SceneDataLoader actorLoader = new SceneDataLoader(filePath, m_world);

            Console.WriteLine(Path.GetFileName(filePath));
            List <WDOMNode> loadedActors = actorLoader.GetMapEntities();

            foreach (var child in loadedActors)
            {
                var fourCCEntity = (SerializableDOMNode)child;

                if (fourCCEntity.FourCC >= FourCC.ACTR && fourCCEntity.FourCC <= FourCC.ACTb)
                {
                    child.SetParent(m_fourCCGroups[FourCC.ACTR].Children[(int)fourCCEntity.Layer]);
                }

                else if (fourCCEntity.FourCC >= FourCC.SCOB && fourCCEntity.FourCC <= FourCC.SCOb)
                {
                    child.SetParent(m_fourCCGroups[FourCC.SCOB].Children[(int)fourCCEntity.Layer]);
                }

                else if (fourCCEntity.FourCC >= FourCC.TRES && fourCCEntity.FourCC <= FourCC.TREb)
                {
                    child.SetParent(m_fourCCGroups[FourCC.TRES].Children[(int)fourCCEntity.Layer]);
                }

                else
                {
                    child.SetParent(m_fourCCGroups[fourCCEntity.FourCC]);
                }

                //m_fourCCGroups[fourCCEntity.FourCC].Children.Add(fourCCEntity);
                //child.SetParent(m_fourCCGroups[fourCCEntity.FourCC]);
                child.IsVisible = true;
            }

            List <KeyValuePair <string, FourCC> > dispFourCCs = new List <KeyValuePair <string, FourCC> >();

            foreach (var item in m_fourCCGroups)
            {
                dispFourCCs.Add(new KeyValuePair <string, FourCC>(item.Value.ToString(), item.Key));
            }

            // Sort the FourCCs alphabetically by their ToString() value
            for (int i = 0; i < dispFourCCs.Count; i++)
            {
                for (int j = i; j < dispFourCCs.Count; j++)
                {
                    if (dispFourCCs[i].Key.CompareTo(dispFourCCs[j].Key) > 0)
                    {
                        KeyValuePair <string, FourCC> temp = dispFourCCs[i];
                        dispFourCCs[i] = dispFourCCs[j];
                        dispFourCCs[j] = temp;
                    }
                }
            }

            // Add entities to the DOM in the sorted order
            foreach (KeyValuePair <string, FourCC> keyVal in dispFourCCs)
            {
                m_fourCCGroups[keyVal.Value].SetParent(this);
            }

            foreach (var child in loadedActors)
            {
                if (child is SerializableDOMNode)
                {
                    SerializableDOMNode child_as_vis = child as SerializableDOMNode;
                    child_as_vis.PostLoad();
                }
            }
        }
示例#5
0
        public void CreateEntity(string fourccStr)
        {
            if (fourccStr == null && !EditorSelection.SingleObjectSelected)
            {
                return;
            }

            SerializableDOMNode newNode         = null;
            WDOMNode            parentNode      = null;
            WDOMNode            selected        = EditorSelection.PrimarySelectedObject;
            WDOMNode            previousSibling = null;

            if (fourccStr != null)
            {
                // Creating an entity via the top menu.
                FourCC fourcc = FourCCConversion.GetEnumFromString(fourccStr);
                if (fourcc == FourCC.ACTR || fourcc == FourCC.SCOB || fourcc == FourCC.TRES)
                {
                    parentNode = World.Map.FocusedScene.GetChildrenOfType <WDOMLayeredGroupNode>().Find(x => x.FourCC == fourcc);
                }
                else
                {
                    parentNode = World.Map.FocusedScene.GetChildrenOfType <WDOMGroupNode>().Find(x => x.FourCC == fourcc);
                }
            }
            else if (selected is SerializableDOMNode)
            {
                // Creating an entity with an existing entity selected.
                parentNode      = selected.Parent;
                previousSibling = selected;
            }
            else
            {
                // Creating an entity with a group node selected.
                parentNode = selected;
            }

            if (parentNode is WDOMLayeredGroupNode)
            {
                WDOMLayeredGroupNode lyrNode = parentNode as WDOMLayeredGroupNode;
                Type   actorType             = null;
                string actorName             = null;

                if (lyrNode.FourCC.ToString().StartsWith("TRE"))
                {
                    // Only allow treasure chests in TRES.
                    actorName = "takara";
                    actorType = WResourceManager.GetTypeByName(actorName);
                }
                else
                {
                    WActorCreatorWindow actorCreator = new WActorCreatorWindow();

                    if (actorCreator.ShowDialog() == true && actorCreator.Descriptor != null)
                    {
                        actorName = actorCreator.Descriptor.ActorName;
                        if (actorName == "")
                        {
                            return;
                        }

                        actorType = WResourceManager.GetTypeByName(actorName);
                    }
                }

                if (actorType == null || actorType == typeof(Actor))
                {
                    return;
                }

                string   unlayedFourCC = lyrNode.FourCC.ToString();
                MapLayer layer         = ChunkHeader.FourCCToLayer(ref unlayedFourCC);
                FourCC   fourcc        = FourCCConversion.GetEnumFromString(unlayedFourCC);

                newNode = (SerializableDOMNode)Activator.CreateInstance(actorType, fourcc, World);
                newNode.SetParent(lyrNode);
                newNode.Name  = actorName;
                newNode.Layer = layer;
                newNode.PostLoad();
            }
            else if (parentNode is WDOMGroupNode)
            {
                WDOMGroupNode grpNode = parentNode as WDOMGroupNode;

                if (grpNode.FourCC == FourCC.ACTR || grpNode.FourCC == FourCC.SCOB || grpNode.FourCC == FourCC.TRES)
                {
                    return;
                }

                if (grpNode.FourCC == FourCC.TGDR || grpNode.FourCC == FourCC.TGSC || grpNode.FourCC == FourCC.TGOB)
                {
                    WActorCreatorWindow actorCreator = new WActorCreatorWindow();

                    if (actorCreator.ShowDialog() == true && actorCreator.Descriptor != null)
                    {
                        string actorName = actorCreator.Descriptor.ActorName;
                        if (actorName == "")
                        {
                            return;
                        }

                        Type actorType = WResourceManager.GetTypeByName(actorName);
                        if (actorType == typeof(Actor))
                        {
                            return;
                        }

                        newNode = (SerializableDOMNode)Activator.CreateInstance(actorType, grpNode.FourCC, World);
                        newNode.SetParent(grpNode);
                        newNode.Name = actorName;
                        newNode.PostLoad();
                    }
                }
                else
                {
                    Type newObjType = FourCCConversion.GetTypeFromEnum(grpNode.FourCC);
                    newNode = (SerializableDOMNode)Activator.CreateInstance(newObjType, grpNode.FourCC, World);
                    newNode.SetParent(grpNode);
                    newNode.Name = "New";
                    newNode.PostLoad();
                }
            }
            else
            {
                return;
            }

            if (newNode == null)
            {
                return;
            }

            newNode.Transform.Position = GetNewEntityPositionFromCamera();
            newNode.PopulateDefaultProperties();

            WDOMNode[] entitiesToCreate = { newNode };
            WDOMNode[] parents          = { newNode.Parent };
            WDOMNode[] previousSiblings = { previousSibling };

            newNode.Parent.IsExpanded = true;

            World.UndoStack.BeginMacro($"Create {newNode.Name}");
            var undoAction = new WCreateEntitiesAction(entitiesToCreate, parents, previousSiblings);

            BroadcastUndoEventGenerated(undoAction);
            EditorSelection.ClearSelection();
            EditorSelection.AddToSelection(newNode);
            World.UndoStack.EndMacro();

            OnSelectionChanged(); // Update the right sidebar to show the new entity's properties
        }
示例#6
0
        public void CreateEntity(string fourccStr)
        {
            if (fourccStr == null && !EditorSelection.SingleObjectSelected)
            {
                return;
            }

            SerializableDOMNode newNode         = null;
            WDOMNode            parentNode      = null;
            WDOMNode            selected        = EditorSelection.PrimarySelectedObject;
            WDOMNode            previousSibling = null;

            if (fourccStr != null)
            {
                // Creating an entity via the top menu.
                FourCC fourcc = FourCCConversion.GetEnumFromString(fourccStr);
                if (fourcc == FourCC.ACTR || fourcc == FourCC.SCOB || fourcc == FourCC.TRES)
                {
                    parentNode = World.Map.FocusedScene.GetChildrenOfType <WDOMLayeredGroupNode>().Find(x => x.FourCC == fourcc);
                }
                else if (fourcc == FourCC.PLYR)
                {
                    WScene targetScene;
                    WScene stage = World.Map.SceneList.First(x => x is WStage);
                    var    rooms = World.Map.SceneList.Where(x => x is WRoom);
                    if (stage.GetChildrenOfType <SpawnPoint>().Count > 0)
                    {
                        // If the stage file has any spawns, then room spawns will not work. So always add to the stage in this case.
                        targetScene = stage;
                    }
                    else if (rooms.Any(x => x.GetChildrenOfType <SpawnPoint>().Count > 0))
                    {
                        // If the stage has no spawns but at least one of the rooms does, we want to add the new spawn to a room.
                        // Otherwise, if we added it to the stage, it would break all existing room spawns.
                        if (World.Map.FocusedScene is WRoom)
                        {
                            targetScene = World.Map.FocusedScene;
                        }
                        else
                        {
                            targetScene = rooms.First();
                        }
                    }
                    else
                    {
                        // Otherwise there must not be any spawns in the map yet, so just put it in the scene the player has selected.
                        targetScene = World.Map.FocusedScene;
                    }
                    parentNode = targetScene.GetChildrenOfType <WDOMGroupNode>().Find(x => x.FourCC == fourcc);
                }
                else
                {
                    parentNode = World.Map.FocusedScene.GetChildrenOfType <WDOMGroupNode>().Find(x => x.FourCC == fourcc);
                }
            }
            else if (selected is SerializableDOMNode)
            {
                // Creating an entity with an existing entity selected.
                parentNode      = selected.Parent;
                previousSibling = selected;
            }
            else
            {
                // Creating an entity with a group node selected.
                parentNode = selected;
            }

            if (parentNode is WDOMLayeredGroupNode)
            {
                WDOMLayeredGroupNode lyrNode = parentNode as WDOMLayeredGroupNode;
                Type   actorType             = null;
                string actorName             = null;

                if (lyrNode.FourCC.ToString().StartsWith("TRE"))
                {
                    // Only allow treasure chests in TRES.
                    actorName = "takara";
                    actorType = WResourceManager.GetTypeByName(actorName);
                }
                else
                {
                    WActorCreatorWindow actorCreator = new WActorCreatorWindow();

                    if (actorCreator.ShowDialog() == true && actorCreator.Descriptor != null)
                    {
                        actorName = actorCreator.Descriptor.ActorName;
                        if (actorName == "")
                        {
                            return;
                        }

                        actorType = WResourceManager.GetTypeByName(actorName);
                    }
                }

                if (actorType == null || actorType == typeof(Actor))
                {
                    return;
                }

                string   unlayedFourCC = lyrNode.FourCC.ToString();
                MapLayer layer         = ChunkHeader.FourCCToLayer(ref unlayedFourCC);
                FourCC   fourcc        = FourCCConversion.GetEnumFromString(unlayedFourCC);

                newNode = (SerializableDOMNode)Activator.CreateInstance(actorType, fourcc, World);
                newNode.SetParent(lyrNode);
                newNode.Name  = actorName;
                newNode.Layer = layer;
                newNode.PostLoad();
            }
            else if (parentNode is WDOMGroupNode)
            {
                WDOMGroupNode grpNode = parentNode as WDOMGroupNode;

                if (grpNode.FourCC == FourCC.ACTR || grpNode.FourCC == FourCC.SCOB || grpNode.FourCC == FourCC.TRES)
                {
                    return;
                }

                if (grpNode.FourCC == FourCC.TGDR || grpNode.FourCC == FourCC.TGSC || grpNode.FourCC == FourCC.TGOB)
                {
                    WActorCreatorWindow actorCreator = new WActorCreatorWindow();

                    if (actorCreator.ShowDialog() == true && actorCreator.Descriptor != null)
                    {
                        string actorName = actorCreator.Descriptor.ActorName;
                        if (actorName == "")
                        {
                            return;
                        }

                        Type actorType = WResourceManager.GetTypeByName(actorName);
                        if (actorType == typeof(Actor))
                        {
                            return;
                        }

                        newNode = (SerializableDOMNode)Activator.CreateInstance(actorType, grpNode.FourCC, World);
                        newNode.SetParent(grpNode);
                        newNode.Name = actorName;
                        newNode.PostLoad();
                    }
                }
                else if (grpNode.FourCC == FourCC.RTBL)
                {
                    RoomTableEntryNode rtbl_entry = new RoomTableEntryNode(grpNode.FourCC, World);
                    rtbl_entry.Index = grpNode.Count();
                    newNode          = rtbl_entry;
                    newNode.SetParent(grpNode);
                    newNode.PostLoad();
                }
                else
                {
                    Type newObjType = FourCCConversion.GetTypeFromEnum(grpNode.FourCC);
                    newNode = (SerializableDOMNode)Activator.CreateInstance(newObjType, grpNode.FourCC, World);
                    newNode.SetParent(grpNode);
                    newNode.Name = "New";
                    newNode.PostLoad();
                }
            }
            else
            {
                return;
            }

            if (newNode == null)
            {
                return;
            }

            newNode.Transform.Position = GetNewEntityPositionFromCamera();
            newNode.PopulateDefaultProperties();

            WDOMNode[] entitiesToCreate = { newNode };
            WDOMNode[] parents          = { newNode.Parent };
            WDOMNode[] previousSiblings = { previousSibling };

            newNode.Parent.IsExpanded = true;

            World.UndoStack.BeginMacro($"Create {newNode.Name}");
            var undoAction = new WCreateEntitiesAction(entitiesToCreate, parents, previousSiblings);

            BroadcastUndoEventGenerated(undoAction);
            EditorSelection.ClearSelection();
            EditorSelection.AddToSelection(newNode);
            World.UndoStack.EndMacro();

            World.Map.FocusedScene = parentNode.Scene; // Focus the scene the new entity was added to (in case it's not the already focused scene).

            OnSelectionChanged();                      // Update the right sidebar to show the new entity's properties
        }
示例#7
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is SerializableDOMNode)
            {
                SerializableDOMNode srlNode = value as SerializableDOMNode;

                if (srlNode.FourCC.ToString().Contains("ACT") ||
                    srlNode.FourCC.ToString().Contains("SCO") || srlNode.FourCC.ToString().Contains("TRE"))
                {
                    return(true);
                }

                switch (srlNode.FourCC)
                {
                case FourCC.CAMR:
                case FourCC.DOOR:
                case FourCC.TGDR:
                case FourCC.TGOB:
                case FourCC.TGSC:
                case FourCC.RPPN:
                case FourCC.PPNT:
                case FourCC.PLYR:
                case FourCC.RARO:
                case FourCC.RCAM:
                case FourCC.SOND:
                case FourCC.SHIP:
                case FourCC.LGTV:
                case FourCC.LGHT:
                case FourCC.AROB:
                    return(true);
                }

                return(false);
            }
            else if (value is SerializableDOMNode || value is WDOMGroupNode)
            {
                WDOMGroupNode grpNode = value as WDOMGroupNode;

                if (grpNode.FourCC.ToString().Contains("ACT") ||
                    grpNode.FourCC.ToString().Contains("SCO") || grpNode.FourCC.ToString().Contains("TRE"))
                {
                    return(true);
                }

                switch (grpNode.FourCC)
                {
                case FourCC.DOOR:
                case FourCC.TGDR:
                case FourCC.TGOB:
                case FourCC.TGSC:
                case FourCC.RPPN:
                case FourCC.PPNT:
                case FourCC.PLYR:
                case FourCC.RARO:
                case FourCC.SOND:
                case FourCC.SHIP:
                case FourCC.LGTV:
                case FourCC.LGHT:
                case FourCC.AROB:
                    return(true);
                }

                return(false);
            }
            else if (value is WDOMLayeredGroupNode || value is CategoryDOMNode || value is J3DNode || value is WCollisionMesh)
            {
                return(true);
            }
            else if (value is WRoom || value is WStage)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#8
0
        public void CreateEntity()
        {
            if (!EditorSelection.SingleObjectSelected)
            {
                return;
            }

            WDOMNode            selected = EditorSelection.PrimarySelectedObject;
            SerializableDOMNode newNode  = null;

            if (selected is SerializableDOMNode)
            {
                SerializableDOMNode origNode = selected as SerializableDOMNode;
                Type selType = selected.GetType();
                newNode = (SerializableDOMNode)Activator.CreateInstance(selType, origNode.FourCC, m_world);
                newNode.PostLoad();
                newNode.SetParent(selected.Parent);

                if (origNode.Parent is WDOMLayeredGroupNode)
                {
                    newNode.Layer = origNode.Layer;
                }
            }
            else if (selected is WDOMLayeredGroupNode)
            {
                WDOMLayeredGroupNode lyrNode = selected as WDOMLayeredGroupNode;
                Type newObjType = null;

                if (lyrNode.FourCC >= FourCC.ACTR && lyrNode.FourCC <= FourCC.ACTb)
                {
                    newObjType = typeof(Actor);
                }
                else if (lyrNode.FourCC >= FourCC.SCOB && lyrNode.FourCC <= FourCC.SCOb)
                {
                    newObjType = typeof(ScaleableObject);
                }
                else if (lyrNode.FourCC >= FourCC.TRES && lyrNode.FourCC <= FourCC.TREb)
                {
                    newObjType = typeof(TreasureChest);
                }

                string   unlayedFourCC = lyrNode.FourCC.ToString();
                MapLayer layer         = ChunkHeader.FourCCToLayer(ref unlayedFourCC);
                FourCC   enumVal       = FourCCConversion.GetEnumFromString(unlayedFourCC);

                newNode       = (SerializableDOMNode)Activator.CreateInstance(newObjType, enumVal, m_world);
                newNode.Layer = layer;
                newNode.PostLoad();
                newNode.SetParent(lyrNode);
            }
            else if (selected is WDOMGroupNode)
            {
                WDOMGroupNode grpNode = selected as WDOMGroupNode;

                if (grpNode.FourCC == FourCC.ACTR || grpNode.FourCC == FourCC.SCOB || grpNode.FourCC == FourCC.TRES)
                {
                    return;
                }

                Type newObjType = FourCCConversion.GetTypeFromEnum(grpNode.FourCC);
                newNode = (SerializableDOMNode)Activator.CreateInstance(newObjType, grpNode.FourCC, m_world);
                newNode.PostLoad();
                newNode.SetParent(grpNode);
            }
            else
            {
                return;
            }

            if (newNode != null)
            {
                EditorSelection.ClearSelection();
                EditorSelection.AddToSelection(newNode);
            }

            // ToDo: This can spawn specific classes the same way that the actor loader does.
        }