Skip to content

Commit

Permalink
[Akyui, Xd] fix: Fixed an issue where a shape was marked as unchanged…
Browse files Browse the repository at this point in the history
… when its color was changed.
  • Loading branch information
kyubuns committed Feb 23, 2024
1 parent 93d29b6 commit 8a0b5b1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Assets/AkyuiUnity.Xd/Editor/XdAkyuiLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public XdRenderer(XdArtboard xdArtboard, XdAssetHolder xdAssetHolder, IXdObjectP
if (rootArtboard.Style?.Fill != null && rootArtboard.Style.Fill.Type == "solid")
{
var color = rootArtboard.GetFillUnityColor();
rootComponents.Add(new ImageComponent(null, color, Vector2Int.one));
rootComponents.Add(new ImageComponent(null, color, Vector2Int.one, null));
}

var root = new ObjectElement(
Expand Down
3 changes: 2 additions & 1 deletion Assets/AkyuiUnity.Xd/Editor/XdGroupParser/SvgGroupParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public Rect CalcSize(XdObjectJson xdObject, Rect rect)
components.Add(new ImageComponent(
spriteUid,
new Color(1f, 1f, 1f, xdObject.Style?.Opacity ?? 1f),
Vector2Int.one
Vector2Int.one,
svgHash
));

return (components.ToArray(), assets.ToArray());
Expand Down
10 changes: 8 additions & 2 deletions Assets/AkyuiUnity.Xd/Editor/XdObjectParser/ShapeObjectParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,31 @@ public static (ImageComponent, IAsset[]) RenderImage(XdObjectJson xdObject, Obb
if (!string.IsNullOrWhiteSpace(ux?.Uid))
{
string spriteUid = null;
uint? hash = null;
if (!isPlaceholder)
{
spriteUid = $"{xdObject.GetSimpleName()}_{ux?.Uid.Substring(0, 8)}.png";
asset = new SpriteAsset(spriteUid, xdObject.Style.Fill.Pattern.Meta.Ux.HrefLastModifiedDate, obb.Size, null, border);
assetHolder.Save(spriteUid, xdObject.Style.Fill.Pattern.Meta);
hash = xdObject.Style.Fill.Pattern.Meta.Ux.HrefLastModifiedDate;
}
imageComponent = new ImageComponent(
spriteUid,
color,
direction
direction,
hash
);
}
else if (SvgUtil.Types.Contains(shapeType))
{
string spriteUid = null;
uint? hash = null;
if (!isPlaceholder)
{
spriteUid = $"{xdObject.GetSimpleName()}_{xdObject.Id.Substring(0, 8)}.png";
var svg = SvgUtil.CreateSvg(xdObject, null, false);
var svgHash = FastHash.CalculateHash(svg);
hash = svgHash;

var cachedSvg = assetHolder.GetCachedSvg(svgHash);
if (cachedSvg != null)
Expand All @@ -146,7 +151,8 @@ public static (ImageComponent, IAsset[]) RenderImage(XdObjectJson xdObject, Obb
imageComponent = new ImageComponent(
spriteUid,
new Color(1f, 1f, 1f, xdObject.Style?.Opacity ?? 1f),
direction
direction,
hash
);
}
else
Expand Down
1 change: 1 addition & 0 deletions Assets/AkyuiUnity/Loader/AkyuiCompressor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public static byte[] Compress(IAkyuiLoader loader)
if (imageComponent.Sprite != null) dict["sprite"] = ToSerializable(imageComponent.Sprite);
if (imageComponent.Color != null) dict["color"] = ToSerializable(imageComponent.Color.Value);
if (imageComponent.Direction != null) dict["direction"] = ToSerializable(imageComponent.Direction.Value);
if (imageComponent.SpriteHash != null) dict["hash"] = ToSerializable(imageComponent.SpriteHash.Value);
}
else if (source is MaskComponent maskComponent)
{
Expand Down
3 changes: 2 additions & 1 deletion Assets/AkyuiUnity/Loader/AkyuiLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ private static ImageComponent ParseImage(Dictionary<string, object> componentJso
return new ImageComponent(
componentJson.ContainsKey("sprite") ? JsonExtensions.ToString(componentJson["sprite"]) : null,
componentJson.ContainsKey("color") ? JsonExtensions.ToColor(componentJson["color"]) : (Color?) null,
componentJson.ContainsKey("direction") ? JsonExtensions.ToVector2Int(componentJson["direction"]) : (Vector2Int?) null
componentJson.ContainsKey("direction") ? JsonExtensions.ToVector2Int(componentJson["direction"]) : (Vector2Int?) null,
componentJson.ContainsKey("hash") ? JsonExtensions.ToUint(componentJson["hash"]) : (uint?) null
);
}

Expand Down
4 changes: 3 additions & 1 deletion Assets/AkyuiUnity/Runtime/Interface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ public class ImageComponent : IComponent
[CanBeNull] public readonly string Sprite;
[CanBeNull] public readonly Color? Color;
[CanBeNull] public readonly Vector2Int? Direction;
[CanBeNull] public readonly uint? SpriteHash;

public ImageComponent([CanBeNull] string sprite, [CanBeNull] Color? color, [CanBeNull] Vector2Int? direction)
public ImageComponent([CanBeNull] string sprite, [CanBeNull] Color? color, [CanBeNull] Vector2Int? direction, [CanBeNull] uint? spriteHash)
{
Sprite = sprite;
Color = color;
Direction = direction;
SpriteHash = spriteHash;
}
}

Expand Down

0 comments on commit 8a0b5b1

Please sign in to comment.