コード例 #1
0
        protected void PasteBase(MapObject o, IDGenerator generator, bool performUnclone = false)
        {
            Visgroups.Clear();
            AutoVisgroups.Clear();
            Children.Clear();

            if (performUnclone && o.ID != ID)
            {
                var parent = Parent;
                var setPar = Parent != null && Parent.Children.ContainsKey(ID) && Parent.Children[ID] == this;
                if (setPar)
                {
                    SetParent(null);
                }
                ID = o.ID;
                if (setPar)
                {
                    SetParent(parent);
                }
            }
            ClassName = o.ClassName;
            Visgroups.AddRange(o.Visgroups);
            AutoVisgroups.AddRange(o.AutoVisgroups);
            Parent           = o.Parent;
            Colour           = o.Colour;
            IsSelected       = o.IsSelected;
            IsCodeHidden     = o.IsCodeHidden;
            IsRenderHidden2D = o.IsRenderHidden2D;
            IsRenderHidden3D = o.IsRenderHidden3D;
            IsVisgroupHidden = o.IsVisgroupHidden;
            BoundingBox      = o.BoundingBox.Clone();
            MetaData         = o.MetaData.Clone();

            var children = o.GetChildren().Select(x => performUnclone ? x.Clone() : x.Copy(generator));

            foreach (var c in children)
            {
                c.SetParent(this);
            }
        }
コード例 #2
0
        private static IEnumerable <string> GetAllTexturesRecursive(MapObject obj)
        {
            if (obj is Entity && obj.ChildCount == 0)
            {
                var ent = (Entity)obj;
                if (ent.EntityData.Name == "infodecal")
                {
                    var tex = ent.EntityData.Properties.FirstOrDefault(x => x.Key == "texture");
                    if (tex != null)
                    {
                        return new[] { tex.Value }
                    }
                    ;
                }
            }
            else if (obj is Solid)
            {
                return(((Solid)obj).Faces.Select(f => f.Texture.Name));
            }

            return(obj.GetChildren().SelectMany(GetAllTexturesRecursive));
        }
コード例 #3
0
ファイル: MapObject.cs プロジェクト: KonstantinUb/sledge
        protected void PasteBase(MapObject o, IDGenerator generator, bool performUnclone = false)
        {
            Visgroups.Clear();
            AutoVisgroups.Clear();
            Children.Clear();

            if (performUnclone && o.ID != ID)
            {
                var parent = Parent;
                var setPar = Parent != null && Parent.Children.ContainsKey(ID) && Parent.Children[ID] == this;
                if (setPar) SetParent(null);
                ID = o.ID;
                if (setPar) SetParent(parent);
            }
            ClassName = o.ClassName;
            Visgroups.AddRange(o.Visgroups);
            AutoVisgroups.AddRange(o.AutoVisgroups);
            Parent = o.Parent;
            Colour = o.Colour;
            IsSelected = o.IsSelected;
            IsCodeHidden = o.IsCodeHidden;
            IsRenderHidden2D = o.IsRenderHidden2D;
            IsRenderHidden3D = o.IsRenderHidden3D;
            IsVisgroupHidden = o.IsVisgroupHidden;
            BoundingBox = o.BoundingBox.Clone();
            MetaData = o.MetaData.Clone();

            var children = o.GetChildren().Select(x => performUnclone ? x.Clone() : x.Copy(generator));
            foreach (var c in children)
            {
                c.SetParent(this);
            }
        }
コード例 #4
0
ファイル: MapFormatProvider.cs プロジェクト: silky/sledge
 private void CollectSolids(List<Solid> solids, MapObject parent)
 {
     solids.AddRange(parent.GetChildren().OfType<Solid>());
     parent.GetChildren().OfType<Group>().ToList().ForEach(x => CollectSolids(solids, x));
 }
コード例 #5
0
ファイル: MapFormatProvider.cs プロジェクト: silky/sledge
 private void CollectEntities(List<Entity> entities, MapObject parent)
 {
     entities.AddRange(parent.GetChildren().OfType<Entity>());
     parent.GetChildren().OfType<Group>().ToList().ForEach(x => CollectEntities(entities, x));
 }
コード例 #6
0
ファイル: DecalExtensions.cs プロジェクト: silky/sledge
        private static bool UpdateDecals(Document document, MapObject mo)
        {
            var updatedChildren = false;
            foreach (var child in mo.GetChildren()) updatedChildren |= UpdateDecals(document, child);

            var e = mo as Entity;
            if (e == null || !ShouldHaveDecal(e))
            {
                var has = e != null && HasDecal(e);
                if (has) SetDecal(e, null);
                return updatedChildren || has;
            }

            var decal = e.EntityData.Properties.FirstOrDefault(x => x.Key == "texture");
            var existingDecal = e.MetaData.Get<string>(DecalNameMetaKey);
            if (decal == null || String.Equals(decal.Value, existingDecal, StringComparison.InvariantCultureIgnoreCase)) return updatedChildren;

            e.SetDecal(document.GetTexture(decal.Value.ToLowerInvariant()));
            return true;
        }
コード例 #7
0
ファイル: MapTreeWindow.cs プロジェクト: silky/sledge
 private void LoadMapNode(TreeNode parent, MapObject obj)
 {
     var text = GetNodeText(obj);
     var node = new TreeNode(obj.GetType().Name + text) { Tag = obj };
     if (obj is World)
     {
         var w = (World)obj;
         node.Nodes.AddRange(GetEntityNodes(w.EntityData).ToArray());
     }
     else if (obj is Entity)
     {
         var e = (Entity)obj;
         node.Nodes.AddRange(GetEntityNodes(e.EntityData).ToArray());
     }
     else if (obj is Solid)
     {
         var s = (Solid)obj;
         node.Nodes.AddRange(GetFaceNodes(s.Faces).ToArray());
     }
     foreach (var mo in obj.GetChildren())
     {
         LoadMapNode(node, mo);
     }
     if (parent == null) MapTree.Nodes.Add(node);
     else parent.Nodes.Add(node);
 }
コード例 #8
0
ファイル: Map.cs プロジェクト: silky/sledge
        private static IEnumerable<string> GetAllTexturesRecursive(MapObject obj)
        {
            if (obj is Entity && obj.ChildCount == 0)
            {
                var ent = (Entity) obj;
                if (ent.EntityData.Name == "infodecal")
                {
                    var tex = ent.EntityData.Properties.FirstOrDefault(x => x.Key == "texture");
                    if (tex != null) return new[] {tex.Value};
                }
            }
            else if (obj is Solid)
            {
                return ((Solid) obj).Faces.Select(f => f.Texture.Name);
            }

            return obj.GetChildren().SelectMany(GetAllTexturesRecursive);
        }
コード例 #9
0
ファイル: VmfProvider.cs プロジェクト: KonstantinUb/sledge
 private static void FlattenTree(MapObject parent, List<Solid> solids, List<Entity> entities, List<Group> groups)
 {
     foreach (var mo in parent.GetChildren())
     {
         if (mo is Solid)
         {
             solids.Add((Solid) mo);
         }
         else if (mo is Entity)
         {
             entities.Add((Entity) mo);
         }
         else if (mo is Group)
         {
             groups.Add((Group) mo);
             FlattenTree(mo, solids, entities, groups);
         }
     }
 }
コード例 #10
0
ファイル: MainForm.cs プロジェクト: silky/sledge
 private void LoadMapNode(TreeNode parent, MapObject obj)
 {
     var node = new TreeNode(obj.GetType().Name);
     if (obj is World)
     {
         var w = (World) obj;
         node.Nodes.Add(GetEntityNode(w.EntityData));
     }
     else if (obj is Entity)
     {
         var e = (Entity) obj;
         node.Nodes.Add(GetEntityNode(e.EntityData));
     }
     else if (obj is Solid)
     {
         var s = (Solid) obj;
         node.Nodes.Add(GetFacesNode(s.Faces));
     }
     foreach (var mo in obj.GetChildren())
     {
         LoadMapNode(node, mo);
     }
     if (parent == null) treeMap.Nodes.Add(node);
     else parent.Nodes.Add(node);
 }
コード例 #11
0
        private static bool UpdateModels(Document document, MapObject mo)
        {
            var updatedChildren = false;
            foreach (var child in mo.GetChildren()) updatedChildren |= UpdateModels(document, child);

            var e = mo as Entity;
            if (e == null || !ShouldHaveModel(e))
            {
                var has = e != null && HasModel(e);
                if (has) UnsetModel(e);
                return updatedChildren || has;
            }

            var model = GetModelName(e);
            var existingModel = e.MetaData.Get<string>(ModelNameMetaKey);
            if (String.Equals(model, existingModel, StringComparison.InvariantCultureIgnoreCase)) return updatedChildren; // Already set; No need to continue

            var file = document.Environment.Root.TraversePath(model);
            if (file == null || !ModelProvider.CanLoad(file))
            {
                // Model not valid, get rid of it
                UnsetModel(e);
                return true;
            }

            try
            {
                SetModel(e, ModelProvider.CreateModelReference(file));
                return true;
            }
            catch
            {
                // Couldn't load
                return updatedChildren;
            }
        }
コード例 #12
0
ファイル: ModernRenderer.cs プロジェクト: KonstantinUb/sledge
 private static void FindRecursive(ICollection<MapObject> items, MapObject root, Predicate<MapObject> matcher)
 {
     if (!matcher(root)) return;
     items.Add(root);
     foreach (var mo in root.GetChildren())
     {
         FindRecursive(items, mo, matcher);
     }
 }
コード例 #13
0
ファイル: SpriteExtensions.cs プロジェクト: silky/sledge
        private static bool UpdateSprites(Document document, MapObject mo)
        {
            var updatedChildren = false;
            foreach (var child in mo.GetChildren()) updatedChildren |= UpdateSprites(document, child);

            var e = mo as Entity;
            if (e == null || !ShouldHaveSprite(e))
            {
                var has = e != null && HasSprite(e);
                if (has) UnsetSprite(e);
                return updatedChildren || has;
            }

            var sprite = GetSpriteName(e);
            var existingSprite = e.MetaData.Get<string>(SpriteMetaKey);
            if (String.Equals(sprite, existingSprite, StringComparison.InvariantCultureIgnoreCase)) return updatedChildren; // Already set; No need to continue

            var tex = document.TextureCollection.GetItem(sprite);
            if (tex == null)
            {
                UnsetSprite(e);
                return true;
            }
            SetSprite(e, tex);
            return true;
        }
コード例 #14
0
ファイル: RmfProvider.cs プロジェクト: KonstantinUb/sledge
 private static void WriteMapBase(BinaryWriter bw, MapObject obj)
 {
     bw.Write(obj.Visgroups.Except(obj.AutoVisgroups).FirstOrDefault());
     bw.WriteRGBColour(obj.Colour);
     bw.Write(obj.ChildCount);
     foreach (var mo in obj.GetChildren())
     {
         WriteMapObject(bw, mo);
     }
 }