Beispiel #1
0
        public void RemoveTextures(Predicate <LevelTexture> askIfTextureToRemove)
        {
            Parallel.ForEach(Rooms.Where(room => room != null), room =>
            {
                foreach (Block sector in room.Blocks)
                {
                    for (BlockFace face = 0; face < BlockFace.Count; ++face)
                    {
                        TextureArea currentTextureArea = sector.GetFaceTexture(face);
                        LevelTexture currentTexture    = currentTextureArea.Texture as LevelTexture;
                        if (currentTexture != null && askIfTextureToRemove(currentTexture))
                        {
                            sector.SetFaceTexture(face, TextureArea.None);
                        }
                    }
                }
                room.RoomGeometry = new RoomGeometry(room);
            });

            foreach (AnimatedTextureSet set in Settings.AnimatedTextureSets)
            {
                set.Frames.RemoveAll(frame => askIfTextureToRemove(frame.Texture));
            }

            // Clean up empty texture sets as well
            Settings.AnimatedTextureSets.RemoveAll(set => set.Frames.Count == 0);
        }
Beispiel #2
0
        public void ApplyNewLevelSettings(LevelSettings newSettings, Action <ObjectInstance> objectChangedNotification)
        {
            LevelSettings oldSettings = Settings;

            Settings = newSettings;

            // Imported geometry
            {
                // Reuse old imported geometry objects to keep references up to date
                var oldLookup = new Dictionary <ImportedGeometry.UniqueIDType, ImportedGeometry>();
                foreach (ImportedGeometry oldImportedGeometry in oldSettings.ImportedGeometries)
                {
                    oldLookup.Add(oldImportedGeometry.UniqueID, oldImportedGeometry);
                }
                for (int i = 0; i < newSettings.ImportedGeometries.Count; ++i)
                {
                    ImportedGeometry newImportedGeometry = newSettings.ImportedGeometries[i];
                    ImportedGeometry oldImportedGeometry;
                    if (oldLookup.TryGetValue(newImportedGeometry.UniqueID, out oldImportedGeometry))
                    {
                        oldImportedGeometry.Assign(newImportedGeometry);
                        newSettings.ImportedGeometries[i] = oldImportedGeometry;
                        oldLookup.Remove(oldImportedGeometry.UniqueID); // The same object shouldn't be matched multiple times.
                    }
                }

                // Reset imported geometry objects if any objects are now missing
                if (oldLookup.Count != 0)
                {
                    foreach (Room room in Rooms.Where(room => room != null))
                    {
                        foreach (var instance in room.Objects.OfType <ImportedGeometryInstance>())
                        {
                            if (instance.Model != null && oldLookup.ContainsKey(instance.Model.UniqueID))
                            {
                                instance.Model = null;
                                objectChangedNotification(instance);
                            }
                        }
                    }
                }
            }

            // Level texture
            {
                // Reuse old level texture objects to keep references up to date
                var oldLookup = new Dictionary <LevelTexture.UniqueIDType, LevelTexture>();
                foreach (LevelTexture oldLevelTexture in oldSettings.Textures)
                {
                    oldLookup.Add(oldLevelTexture.UniqueID, oldLevelTexture);
                }
                for (int i = 0; i < newSettings.Textures.Count; ++i)
                {
                    LevelTexture newLevelTexture = newSettings.Textures[i];
                    LevelTexture oldLevelTexture;
                    if (oldLookup.TryGetValue(newLevelTexture.UniqueID, out oldLevelTexture))
                    {
                        oldLevelTexture.Assign(newLevelTexture);
                        newSettings.Textures[i] = oldLevelTexture;
                        oldLookup.Remove(oldLevelTexture.UniqueID); // The same object shouldn't be matched multiple times.
                    }
                }

                // Reset level texture objects if any objects are now missing
                if (oldLookup.Count != 0)
                {
                    RemoveTextures(texture => oldLookup.ContainsKey(texture.UniqueID));
                }
            }
        }