Ejemplo n.º 1
0
 public override MapObject Copy(IDGenerator generator)
 {
     var e = new Entity(generator.GetNextObjectID())
                {
                    GameData = GameData,
                    EntityData = EntityData.Clone(),
                    Origin = Origin.Clone()
                };
     CopyBase(e, generator);
     return e;
 }
Ejemplo n.º 2
0
        public void CopyEntityTest()
        {
            var idGen = new IDGenerator();
            var box = new Box(Coordinate.One * -100, Coordinate.One * 100);

            // Create an entity with children
            var ent = new Entity(idGen.GetNextObjectID());
            ent.EntityData.Name = "Test";
            ent.EntityData.Properties.Add(new Property { Key = "key1", Value = "value1"});
            ent.EntityData.Properties.Add(new Property { Key = "key2", Value = "value2"});
            ent.EntityData.Flags = 12345;

            var solids = new BlockBrush().Create(idGen, box, null, 0);
            foreach (var mo in solids) mo.SetParent(ent);

            // Copy and reconstruct
            var gs = VmfProvider.CreateCopyStream(new List<MapObject> {ent});
            var pasted = VmfProvider.ExtractCopyStream(gs, idGen).ToList();

            // Test object
            Assert.AreEqual(1, pasted.Count);
            Assert.IsInstanceOfType(pasted[0], typeof(Entity));

            // Test entity
            var pastedEnt = (Entity) pasted[0];
            Assert.AreEqual("Test", pastedEnt.EntityData.Name);
            Assert.AreEqual(12345, pastedEnt.EntityData.Flags);

            // Test properties
            Assert.AreEqual(2, pastedEnt.EntityData.Properties.Count);
            var k1 = pastedEnt.EntityData.Properties.FirstOrDefault(x => x.Key == "key1");
            var k2 = pastedEnt.EntityData.Properties.FirstOrDefault(x => x.Key == "key1");
            Assert.IsNotNull(k1);
            Assert.IsNotNull(k2);
            Assert.AreEqual(k1.Value, "value1");
            Assert.AreEqual(k2.Value, "value1");

            // Test child
            Assert.AreEqual(1, pastedEnt.ChildCount);
            Assert.IsInstanceOfType(pastedEnt.GetChildren().ToList()[0], typeof(Solid));

            // Check number of sides, values of sides not so important
            var pastedSolid = (Solid) pastedEnt.GetChildren().ToList()[0];
            Assert.AreEqual(6, pastedSolid.Faces.Count);
        }
Ejemplo n.º 3
0
 public override MapObject Clone()
 {
     var e = new Entity(ID) {GameData = GameData, EntityData = EntityData.Clone(), Origin = Origin.Clone()};
     CopyBase(e, null, true);
     return e;
 }
Ejemplo n.º 4
0
        private void CreateDecal(Coordinate origin)
        {
            var gd = Document.GameData.Classes.FirstOrDefault(x => x.Name == "infodecal");
            if (gd == null)
            {
                System.Windows.Forms.MessageBox.Show("`infodecal` was not found in the entity list.", "FGD Data Not Found",
                    System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
                return;
            }
            var selected = Document.TextureCollection.SelectedTexture;
            var textureName = selected == null ? "{TARGET" : selected.Name;

            if (Document.TextureCollection.GetItem(textureName) == null)
            {
                return;
            }

            var decal = new Entity(Document.Map.IDGenerator.GetNextObjectID())
            {
                EntityData = new EntityData(gd),
                ClassName = gd.Name,
                Colour = Colour.GetRandomBrushColour(),
                Origin = origin
            };
            decal.SetDecal(TextureHelper.Get(textureName.ToLowerInvariant()));
            decal.EntityData.SetPropertyValue("texture", textureName);

            Document.PerformAction("Apply decal", new Create(Document.Map.WorldSpawn.ID, decal));
        }
Ejemplo n.º 5
0
        private void CreateDecal(Coordinate origin)
        {
            var gd = Document.GameData.Classes.First(x => x.Name == "infodecal");
            var selected = Editor.Instance.GetSelectedTexture();
            var textureName = selected == null ? "{TARGET" : selected.Name;

            if (Document.TextureCollection.GetItem(textureName) == null)
            {
                return;
            }

            var decal = new Entity(Document.Map.IDGenerator.GetNextObjectID())
            {
                EntityData = new EntityData(gd),
                ClassName = gd.Name,
                Colour = Colour.GetRandomBrushColour(),
                Decal = TextureHelper.Get(textureName.ToLowerInvariant()),
                Origin = origin
            };
            decal.EntityData.SetPropertyValue("texture", textureName);

            Document.PerformAction("Apply decal", new Create(decal));
        }
Ejemplo n.º 6
0
        private void CreateEntity(Coordinate origin)
        {
            var gd = Document.GetSelectedEntity();
            if (gd == null) return;

            var col = gd.Behaviours.Where(x => x.Name == "color").ToArray();
            var colour = col.Any() ? col[0].GetColour(0) : Colour.GetDefaultEntityColour();

            var entity = new Entity(Document.Map.IDGenerator.GetNextObjectID())
            {
                EntityData = new EntityData(gd),
                ClassName = gd.Name,
                Colour = colour,
                Origin = origin
            };

            IAction action = new Create(Document.Map.WorldSpawn.ID, entity);
            if (Select.SelectCreatedEntity)
            {
                entity.IsSelected = true;
                if (Select.DeselectOthersWhenSelectingCreation)
                {
                    action = new ActionCollection(new ChangeSelection(new MapObject[0], Document.Selection.GetSelectedObjects()), action);
                }
            }

            Document.PerformAction("Create entity: " + gd.Name, action);
            if (Select.SwitchToSelectAfterEntity)
            {
                Mediator.Publish(HotkeysMediator.SwitchTool, HotkeyTool.Selection);
            }
        }
Ejemplo n.º 7
0
 private void SetEntityData(Entity ent, EntityData data, GameData gameData)
 {
     ent.EntityData = data;
     ent.GameData = gameData.Classes.FirstOrDefault(x => x.Name.ToLower() == data.Name.ToLower());
 }