Пример #1
0
        private void LoadEntities(Map newMap, EditorCore core, Dictionary<Scene, VirtualFilesystemDirectory> archiveMap, WWorld world)
        {
            MapEntityLoader entityLoader = new MapEntityLoader(core, newMap);

            // For each room/scene, find the associated dzr/dzs file and load its
            // contents into the entityLoader.
            foreach (var kvp in archiveMap)
            {
                // Check to see if this Archive has stage/room entity data.
                var roomEntData = kvp.Value.FindByExtension(".dzr");
                var stageEntData = kvp.Value.FindByExtension(".dzs");

                VirtualFilesystemFile vfsFile = null;
                if (roomEntData.Count > 0)
                    vfsFile = roomEntData[0];
                else if (stageEntData.Count > 0)
                    vfsFile = stageEntData[0];
                else
                    continue;

                using (EndianBinaryReader reader = new EndianBinaryReader(new System.IO.MemoryStream(vfsFile.File.GetData()), Endian.Big))
                {
                    WLog.Info(LogCategory.EntityLoading, null, "Loading .dzr/.dzs (Room/Stage Entity Dat) for {0}{1}...", vfsFile.Name, vfsFile.Extension);
                    entityLoader.LoadFromStream(kvp.Key, reader);
                    WLog.Info(LogCategory.EntityLoading, null, "Finished loading .dzr/.dzs (Room/Stage Entity Dat) for {0}{1}.", vfsFile.Name, vfsFile.Extension);
                }
            }

            // Once we've loaded all of the entities from the stream, we're going to
            // post-process them to resolve object references.
            entityLoader.PostProcessEntities();

            // Finally, we can actually convert these into map objects
            foreach (var roomOrStageData in entityLoader.GetData())
            {
                Stage stage = roomOrStageData.Key as Stage;
                Room room = roomOrStageData.Key as Room;

                if (stage != null)
                {
                    PostProcessStage(stage, roomOrStageData.Value);
                    foreach (var entity in stage.Entities)
                        entity.World = world;
                }
                if (room != null)
                {
                    PostProcessRoom(room, roomOrStageData.Value);
                    foreach (var entity in room.Entities)
                        entity.World = world;
                }
            }
        }
Пример #2
0
        private void LoadEntities(Map newMap, EditorCore core, Dictionary <Scene, VirtualFilesystemDirectory> archiveMap, WWorld world)
        {
            MapEntityLoader entityLoader = new MapEntityLoader(core, newMap);

            // For each room/scene, find the associated dzr/dzs file and load its
            // contents into the entityLoader.
            foreach (var kvp in archiveMap)
            {
                // Check to see if this Archive has stage/room entity data.
                var roomEntData  = kvp.Value.FindByExtension(".dzr");
                var stageEntData = kvp.Value.FindByExtension(".dzs");

                VirtualFilesystemFile vfsFile = null;
                if (roomEntData.Count > 0)
                {
                    vfsFile = roomEntData[0];
                }
                else if (stageEntData.Count > 0)
                {
                    vfsFile = stageEntData[0];
                }
                else
                {
                    continue;
                }

                using (EndianBinaryReader reader = new EndianBinaryReader(new System.IO.MemoryStream(vfsFile.File.GetData()), Endian.Big))
                {
                    WLog.Info(LogCategory.EntityLoading, null, "Loading .dzr/.dzs (Room/Stage Entity Dat) for {0}{1}...", vfsFile.Name, vfsFile.Extension);
                    entityLoader.LoadFromStream(kvp.Key, reader);
                    WLog.Info(LogCategory.EntityLoading, null, "Finished loading .dzr/.dzs (Room/Stage Entity Dat) for {0}{1}.", vfsFile.Name, vfsFile.Extension);
                }
            }

            // Once we've loaded all of the entities from the stream, we're going to
            // post-process them to resolve object references.
            entityLoader.PostProcessEntities();

            // Finally, we can actually convert these into map objects
            foreach (var roomOrStageData in entityLoader.GetData())
            {
                Stage stage = roomOrStageData.Key as Stage;
                Room  room  = roomOrStageData.Key as Room;

                if (stage != null)
                {
                    PostProcessStage(stage, roomOrStageData.Value);
                    foreach (var entity in stage.Entities)
                    {
                        entity.World = world;
                    }
                }
                if (room != null)
                {
                    PostProcessRoom(room, roomOrStageData.Value);
                    foreach (var entity in room.Entities)
                    {
                        entity.World = world;
                    }
                }
            }
        }
Пример #3
0
        public void SpawnEntityInWorld(MapObjectSpawnDescriptor dragData)
        {
            WLog.Info(LogCategory.EditorCore, null, "Caught object to be spawned {0} in scene: {1}", dragData, SelectedScene);

            // Meh.
            MapEntityLoader loader = new MapEntityLoader(m_editorCore, Map);

            // We can skip post-processing the entities via MapEntityLoader b/c that just does reference fixups, and
            // because this is a new entity there's no references so no point in trying to fix them up.
            var newEnt = loader.CreateEntity(dragData);

            if (SelectedScene is Stage)
                MapLoader.PostProcessStage((Stage)SelectedScene, new List<MapEntityLoader.RawMapEntity>(new[] { newEnt }));

            if(SelectedScene is Room)
                MapLoader.PostProcessRoom((Room)SelectedScene, new List<MapEntityLoader.RawMapEntity>(new[] { newEnt }));

            // meh more hacks.
            foreach (var ent in SelectedScene.Entities)
                ent.World = this;
        }