private static async Task <EntitySprite> CreateSpriteData(Entity entity, MapDocument doc, GameData gd, TextureCollection tc, string name) { if (!tc.HasTexture(name)) { return(null); } var texture = await tc.GetTextureItem(name); if (texture == null) { return(null); } var cls = gd?.GetClass(entity.EntityData.Name); var scale = 1f; var color = Color.White; SizeF?size = new SizeF(entity.BoundingBox.Width, entity.BoundingBox.Height); if (cls != null) { if (cls.Properties.Any(x => String.Equals(x.Name, "scale", StringComparison.CurrentCultureIgnoreCase))) { scale = entity.EntityData.Get <float>("scale", 1); if (scale <= 0.1f) { scale = 1; } } var colProp = cls.Properties.FirstOrDefault(x => x.VariableType == VariableType.Color255 || x.VariableType == VariableType.Color1); if (colProp != null) { var col = entity.EntityData.GetVector3(colProp.Name); if (colProp.VariableType == VariableType.Color255) { col /= 255f; } if (col.HasValue) { color = col.Value.ToColor(); } } if (cls.Behaviours.Any(x => string.Equals(x.Name, "sprite", StringComparison.InvariantCultureIgnoreCase))) { size = texture.Size; } } return(new EntitySprite(name, scale, color, size)); }
private static async Task <EntityDecal> CreateDecalData(Entity entity, MapDocument doc, TextureCollection tc, string name) { var texture = await tc.GetTextureItem(name); if (texture == null) { return(null); } var geometry = CalculateDecalGeometry(entity, texture, doc); return(new EntityDecal(name, geometry)); }