Skip to content

Commit

Permalink
Merge pull request #227 from altseed/fix-to-propagate-is-drawn-actually
Browse files Browse the repository at this point in the history
Fix to propagate 'IsDrawnActually'
  • Loading branch information
wraikny authored Sep 1, 2021
2 parents 7231c5d + a530a5a commit 1a19ef0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
24 changes: 18 additions & 6 deletions Engine/Node/IDrawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,27 @@ internal static class DrawnExtension
/// <summary>
/// 自身と子孫ノードの IsDrawnActually プロパティを更新します。
/// </summary>
internal static void UpdateIsDrawnActuallyOfDescendants<T>(this T node)
where T : Node, ICullableDrawn
internal static void UpdateIsDrawnActuallyOfDescendants(this Node node)
{
node.IsDrawnActually = node.IsDrawn && (node.GetAncestorSpecificNode<T>()?.IsDrawnActually ?? true);
static void UpdateRecursive(Node n, bool ancestorsIsDawnActually)
{
var dn = (ICullableDrawn)n;

var isDrawnActually = dn.IsDrawn && ancestorsIsDawnActually;
dn.IsDrawnActually = isDrawnActually;
foreach (var child in n.Children)
{
if (child is ICullableDrawn)
{
UpdateRecursive(child, isDrawnActually);
}
}
}

foreach (var child in node.Children)
if (node is ICullableDrawn)
{
if (child is T d)
d.UpdateIsDrawnActuallyOfDescendants();
var ancestorsIsDrawnActually = node.GetAncestorSpecificNode<ICullableDrawn>()?.IsDrawnActually ?? true;
UpdateRecursive(node, ancestorsIsDrawnActually);
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions Test/DrawnNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,6 @@ string infoText(AnchorTransformerNode n) =>
tc.End();
}


[Test, Apartment(ApartmentState.STA)]
public void IsDrawn()
{
Expand All @@ -597,7 +596,8 @@ public void IsDrawn()
node2.CenterPosition = texture.Size / 2;
node2.Position = new Vector2F(200, 200);

var node3 = new SpriteNode();
var node3 = new RectangleNode();
node3.RectangleSize = texture.Size;
node3.Texture = texture;
node3.CenterPosition = texture.Size / 2;
node3.Position = new Vector2F(300, 300);
Expand All @@ -608,29 +608,27 @@ public void IsDrawn()
{
node.AddChildNode(node2);
}
if (c == 4)
else if (c == 4)
{
node.IsDrawn = false;
Assert.IsFalse(node.IsDrawnActually);
Assert.IsFalse(node2.IsDrawnActually);
}
if (c == 6)
else if (c == 6)
{
node2.AddChildNode(node3);
}
if (c == 8)
else if (c == 8)
{
node.IsDrawn = true;
Assert.IsTrue(node.IsDrawnActually);
Assert.IsTrue(node2.IsDrawnActually);
Assert.IsTrue(node3.IsDrawnActually);
}
if (c == 10)
else if (c == 10)
{
node2.IsDrawn = false;
Expand Down

0 comments on commit 1a19ef0

Please sign in to comment.