Пример #1
0
        public static void ApplySkinnableInfo(this Drawable component, SkinnableInfo info)
        {
            // todo: can probably make this better via deserialisation directly using a common interface.
            component.Position = info.Position;
            component.Rotation = info.Rotation;
            component.Scale    = info.Scale;
            component.Anchor   = info.Anchor;
            component.Origin   = info.Origin;

            if (component is ISkinnableDrawable skinnable)
            {
                skinnable.UsesFixedAnchor = info.UsesFixedAnchor;

                foreach (var(_, property) in component.GetSettingsSourceProperties())
                {
                    if (!info.Settings.TryGetValue(property.Name.Underscore(), out object settingValue))
                    {
                        continue;
                    }

                    skinnable.CopyAdjustedSetting((IBindable)property.GetValue(component), settingValue);
                }
            }

            if (component is Container container)
            {
                foreach (var child in info.Children)
                {
                    container.Add(child.CreateInstance());
                }
            }
        }
Пример #2
0
 private static bool almostEqual(SkinnableInfo info, SkinnableInfo other) =>
 other != null &&
 info.Type == other.Type &&
 info.Anchor == other.Anchor &&
 info.Origin == other.Origin &&
 Precision.AlmostEquals(info.Position, other.Position, 1) &&
 Precision.AlmostEquals(info.Scale, other.Scale) &&
 Precision.AlmostEquals(info.Rotation, other.Rotation) &&
 info.Children.SequenceEqual(other.Children, new FuncEqualityComparer <SkinnableInfo>(almostEqual));
Пример #3
0
        public static void ApplySkinnableInfo(this Drawable component, SkinnableInfo info)
        {
            // todo: can probably make this better via deserialisation directly using a common interface.
            component.Position = info.Position;
            component.Rotation = info.Rotation;
            component.Scale    = info.Scale;
            component.Anchor   = info.Anchor;
            component.Origin   = info.Origin;

            if (component is Container container)
            {
                foreach (var child in info.Children)
                {
                    container.Add(child.CreateInstance());
                }
            }
        }