public ObjectEntry Map(Tiled.Object src, ObjectEntry dst = null) { if (dst == null) { dst = new ObjectEntry(); } // Basic properties dst.Name = src.Name; dst.Type = src.Type; // Appearance dst.AnimationData = GetPropertyValue <string>(src.Properties, null, nameof(ObjectEntry.AnimationData)); dst.AnimationName = GetPropertyValue <string>(src.Properties, null, nameof(ObjectEntry.AnimationName)); dst.Direction = GetPropertyValue(src.Properties, Direction.Undefined, nameof(ObjectEntry.Direction)); dst.Visible = src.Visible; dst.HasShadow = GetPropertyValue(src.Properties, false, nameof(ObjectEntry.HasShadow)); // Layout dst.X = src.X; dst.Y = src.Y; dst.Z = GetPropertyValue(src.Properties, 0.0, nameof(ObjectEntry.Z)); dst.Width = src.Width; dst.Height = src.Height; dst.Flip = GetPropertyValue(src.Properties, Flip.None, nameof(ObjectEntry.Flip)); var id = GetPropertyValue(src.Properties, Guid.Empty, ExtensionId); if (id != Guid.Empty) { dst.Extension = CreateInstance(id); if (dst.Extension != null) { foreach (var property in dst.Extension.GetType().GetProperties()) { if (property.CanRead && property.CanWrite) { var value = GetPropertyValue(src.Properties, property.PropertyType, null, $"{Extension}.{property.Name}"); property.SetValue(dst.Extension, value); } } } } return(dst); }
public Tiled.Object Map(ObjectEntry src, Tiled.Object dst = null) { if (dst == null) { dst = new Tiled.Object(); } // Basic properties dst.Name = src.Name; dst.Type = src.Type; // Appearance dst.Properties[nameof(ObjectEntry.AnimationData)] = src.AnimationData; dst.Properties[nameof(ObjectEntry.AnimationName)] = src.AnimationName; dst.Visible = src.Visible; dst.Properties[nameof(ObjectEntry.HasShadow)] = src.HasShadow; dst.Properties[nameof(ObjectEntry.Direction)] = src.Direction; // Layout dst.X = src.X; dst.Y = src.Y; dst.Properties[nameof(ObjectEntry.Z)] = src.Z; dst.Width = src.Width; dst.Height = src.Height; dst.Properties[nameof(ObjectEntry.Flip)] = src.Flip; if (src.Extension != null) { var id = src.Extension.Id; if (id != Guid.Empty) { dst.Properties[ExtensionId] = id; foreach (var property in src.Extension.GetType().GetProperties()) { if (property.CanRead && property.CanWrite) { dst.Properties[$"{Extension}.{property.Name}"] = property.GetValue(src.Extension); } } } } return(dst); }