private static void SetModel(Entity entity, ModelReference model) { entity.MetaData.Set(ModelMetaKey, model); entity.MetaData.Set(ModelNameMetaKey, GetModelName(entity)); entity.MetaData.Set(ModelBoundingBoxMetaKey, model.Model.GetBoundingBox()); entity.UpdateBoundingBox(); }
private static void SetSprite(Entity entity, TextureItem tex) { entity.MetaData.Set(SpriteMetaKey, tex.Name); var bb = new Coordinate(tex.Width, tex.Width, tex.Height); // Don't set the bounding box if the sprite comes from the iconsprite gamedata if (entity.GameData == null || !entity.GameData.Behaviours.Any(x => String.Equals(x.Name, "iconsprite", StringComparison.CurrentCultureIgnoreCase))) { entity.MetaData.Set(SpriteBoundingBoxMetaKey, new Box(-bb / 2, bb / 2)); entity.MetaData.Set("RotateBoundingBox", false); // todo rotations entity.UpdateBoundingBox(); } }
private static Entity ReadMapEntity(BinaryReader br, List<Visgroup> visgroups, IDGenerator generator) { var ent = new Entity(generator.GetNextObjectID()); ReadMapBase(br, ent, visgroups, generator); ent.EntityData = ReadEntityData(br); br.ReadBytes(2); // Unused ent.Origin = br.ReadCoordinate(); br.ReadBytes(4); // Unused ent.UpdateBoundingBox(false); return ent; }
private Entity ReadEntity(StreamReader rdr, IDGenerator generator) { var ent = new Entity(generator.GetNextObjectID()) { EntityData = new EntityData(), Colour = Colour.GetRandomBrushColour() }; string line; while ((line = CleanLine(rdr.ReadLine())) != null) { if (String.IsNullOrWhiteSpace(line)) continue; if (line[0] == '"') ReadProperty(ent, line); else if (line[0] == '{') { var s = ReadSolid(rdr, generator); if (s != null) s.SetParent(ent, false); } else if (line[0] == '}') break; } ent.UpdateBoundingBox(false); return ent; }
private static Entity ReadEntity(GenericStructure entity, IDGenerator generator) { var ret = new Entity(GetObjectID(entity, generator)) { ClassName = entity["classname"], EntityData = ReadEntityData(entity), Origin = entity.PropertyCoordinate("origin") }; var editor = entity.GetChildren("editor").FirstOrDefault() ?? new GenericStructure("editor"); ret.Colour = editor.PropertyColour("color", Colour.GetRandomBrushColour()); ret.Visgroups.AddRange(editor.GetAllPropertyValues("visgroupid").Select(int.Parse)); foreach (var child in entity.GetChildren("solid").Select(solid => ReadSolid(solid, generator)).Where(s => s != null)) { child.SetParent(ret); } ret.UpdateBoundingBox(false); return ret; }
private static void UnsetModel(Entity entity) { entity.MetaData.Unset(ModelMetaKey); entity.MetaData.Unset(ModelNameMetaKey); entity.MetaData.Unset(ModelBoundingBoxMetaKey); entity.UpdateBoundingBox(); }
private static void SetSprite(Entity entity, TextureItem tex) { entity.MetaData.Set(SpriteMetaKey, tex.Name); var scale = 1m; if (entity.GameData != null && entity.GameData.Properties.Any(x => String.Equals(x.Name, "scale", StringComparison.CurrentCultureIgnoreCase))) { var scaleStr = entity.GetEntityData().GetPropertyValue("scale"); if (!Decimal.TryParse(scaleStr, out scale)) scale = 1; if (scale <= 0.1m) scale = 1; } var bb = new Coordinate(tex.Width, tex.Width, tex.Height) * scale; // Don't set the bounding box if the sprite comes from the iconsprite gamedata if (entity.GameData == null || !entity.GameData.Behaviours.Any(x => String.Equals(x.Name, "iconsprite", StringComparison.CurrentCultureIgnoreCase))) { entity.MetaData.Set(SpriteBoundingBoxMetaKey, new Box(-bb / 2, bb / 2)); entity.MetaData.Set("RotateBoundingBox", false); // todo rotations entity.UpdateBoundingBox(); } }
private static void UnsetSprite(Entity entity) { entity.MetaData.Unset(SpriteMetaKey); entity.MetaData.Unset(SpriteBoundingBoxMetaKey); entity.MetaData.Unset("RotateBoundingBox"); entity.UpdateBoundingBox(); }