Skip to content

Commit

Permalink
clean up card instantiation (hackily - transform parent dancing)
Browse files Browse the repository at this point in the history
  • Loading branch information
cryy22 committed May 19, 2024
1 parent 19ed6d4 commit 05d933b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
14 changes: 14 additions & 0 deletions Runtime/Helpers/CoroutineRandomDelayExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections;
using UnityEngine;

namespace Crysc.Helpers
{
public static class CoroutineRandomDelayExtensions
{
public static IEnumerator WithRandomDelay(this IEnumerator enumerator, float maxDelay)
{
yield return new WaitForSeconds(Random.Range(minInclusive: 0f, maxInclusive: maxDelay));
yield return enumerator;
}
}
}
3 changes: 3 additions & 0 deletions Runtime/Helpers/CoroutineRandomDelayExtensions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 15 additions & 6 deletions Runtime/Presentation/Arrangements/Arrangement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public enum Alignment
Right,
}

public event EventHandler ElementArrangeStarted;
public event EventHandler ElementArrangeEnded;
public event EventHandler<ArrangementEventArgs> ElementArrangeStarted;
public event EventHandler<ArrangementEventArgs> ElementArrangeEnded;

public const float ZOffset = 0.01f;

Expand Down Expand Up @@ -51,6 +51,8 @@ public enum Alignment
public Vector2 Pivot { get; private set; } = new(x: 0.5f, y: 0.5f);
public Vector2 SizeMultiplier { get; private set; } = Vector2.zero;

public Transform ElementsParent => ElementsParentInput;

private readonly List<IElement> _elements = new();
private readonly Dictionary<IElement, ElementPlacement> _elementsPlacements = new();
private readonly Dictionary<IElement, ElementMovementPlan> _elementsMovementPlans = new();
Expand Down Expand Up @@ -142,8 +144,15 @@ IEnumerator Run()
foreach (ElementMovementPlan plan in _elementsMovementPlans.Values)
{
if (!plan.IsStarted)
if (_animationTime > plan.StartTime) startedPlans.Add(plan);
else continue;
if (_animationTime > plan.StartTime)
{
plan.Element.Transform.SetParent(ElementsParentInput);
startedPlans.Add(plan);
}
else
{
continue;
}

IncrementPlan(plan: plan, time: _animationTime);

Expand All @@ -154,13 +163,13 @@ IEnumerator Run()
foreach (ElementMovementPlan plan in startedPlans)
{
_elementsMovementPlans[plan.Element] = plan.Copy(isStarted: true);
ElementArrangeStarted?.Invoke(sender: this, e: EventArgs.Empty);
ElementArrangeStarted?.Invoke(sender: this, e: new ArrangementEventArgs(plan));
}

foreach (ElementMovementPlan plan in endedPlans)
{
_elementsMovementPlans.Remove(plan.Element);
ElementArrangeEnded?.Invoke(sender: this, e: EventArgs.Empty);
ElementArrangeEnded?.Invoke(sender: this, e: new ArrangementEventArgs(plan));
}

startedPlans.Clear();
Expand Down
10 changes: 10 additions & 0 deletions Runtime/Presentation/Arrangements/ArrangementEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace Crysc.Presentation.Arrangements
{
public class ArrangementEventArgs : EventArgs
{
public ElementMovementPlan Plan { get; }
public ArrangementEventArgs(ElementMovementPlan plan) { Plan = plan; }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 05d933b

Please sign in to comment.