예제 #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
        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
 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
 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
        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
 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
 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
 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
        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
 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);
     }
 }