Exemple #1
0
        /// <summary>
        /// Should be called when a map is loaded. Sets up visgroups, object ids, gamedata, and textures.
        /// </summary>
        public void PostLoadProcess(GameData.GameData gameData, Func <string, ITexture> textureAccessor, Func <string, float> textureOpacity)
        {
            PartialPostLoadProcess(gameData, textureAccessor, textureOpacity);

            var all = WorldSpawn.FindAll();

            // Set maximum ids
            var maxObjectId = all.Max(x => x.ID);
            var faces       = all.OfType <Solid>().SelectMany(x => x.Faces).ToList();
            var maxFaceId   = faces.Any() ? faces.Max(x => x.ID) : 0;

            IDGenerator.Reset(maxObjectId, maxFaceId);

            // todo visgroups
            // WorldSpawn.ForEach(x => x.IsVisgroupHidden, x => x.IsVisgroupHidden = true, true);

            // Auto visgroup
            var auto      = AutoVisgroup.GetDefaultAutoVisgroup();
            var quickHide = new AutoVisgroup {
                ID = int.MinValue, IsHidden = true, Name = "Autohide", Parent = auto, Visible = false
            };

            auto.Children.Add(quickHide);
            Visgroups.Add(auto);
            UpdateAutoVisgroups(all, false);

            // Purge empty groups
            foreach (var emptyGroup in WorldSpawn.Find(x => x is Group && !x.HasChildren))
            {
                emptyGroup.SetParent(null);
            }
        }
Exemple #2
0
        public static AutoVisgroup GetDefaultAutoVisgroup()
        {
            var filters = typeof(IVisgroupFilter).Assembly.GetTypes()
                          .Where(x => typeof(IVisgroupFilter).IsAssignableFrom(x))
                          .Where(x => !x.IsInterface)
                          .Select(Activator.CreateInstance)
                          .OfType <IVisgroupFilter>();
            var i    = -1;
            var auto = new AutoVisgroup
            {
                ID       = i--,
                IsHidden = false,
                Name     = "Auto",
                Visible  = true
            };

            foreach (var f in filters)
            {
                var parent = auto.Children.OfType <AutoVisgroup>().FirstOrDefault(x => x.Name == f.Group);
                if (parent == null)
                {
                    parent = new AutoVisgroup
                    {
                        ID       = i--,
                        IsHidden = false,
                        Name     = f.Group,
                        Visible  = true,
                        Parent   = auto
                    };
                    auto.Children.Add(parent);
                }
                var vg = new AutoVisgroup
                {
                    ID       = i--,
                    Filter   = f.IsMatch,
                    IsHidden = false,
                    Name     = f.Name,
                    Visible  = true,
                    Parent   = parent
                };
                parent.Children.Add(vg);
            }
            return(auto);
        }