Implement MVP for the statue decoration minigame (#65)
MVP implemented with: - placing, removing etc. decorations - saving the state, displaying it on the map, restoring when game restarts - saving screenshots to folder on device Co-authored-by: Michal Pikulski <michal@foolhardyhorizons.com> Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com> Reviewed-on: #65
This commit is contained in:
63
Assets/Scripts/Minigames/StatueDressup/IReadyNotifier.cs
Normal file
63
Assets/Scripts/Minigames/StatueDressup/IReadyNotifier.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
|
||||
namespace Minigames.StatueDressup
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for managers that load asynchronously and notify when ready.
|
||||
/// Allows dependent components to safely access the manager via WhenReady callbacks.
|
||||
/// </summary>
|
||||
public interface IReadyNotifier
|
||||
{
|
||||
/// <summary>
|
||||
/// True when the manager has finished initialization and is ready to use
|
||||
/// </summary>
|
||||
bool IsReady { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Event invoked when the manager becomes ready
|
||||
/// </summary>
|
||||
event Action OnReady;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for IReadyNotifier to provide common callback behavior
|
||||
/// </summary>
|
||||
public static class ReadyNotifierExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Execute callback when ready. If already ready, executes immediately.
|
||||
/// If not ready yet, subscribes to OnReady event and executes when fired.
|
||||
/// </summary>
|
||||
public static void WhenReady(this IReadyNotifier notifier, Action callback)
|
||||
{
|
||||
if (notifier == null)
|
||||
{
|
||||
Core.Logging.Warning("[ReadyNotifierExtensions] Notifier is null, cannot execute callback");
|
||||
return;
|
||||
}
|
||||
|
||||
if (callback == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (notifier.IsReady)
|
||||
{
|
||||
// Already ready - execute immediately
|
||||
callback.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not ready yet - subscribe to event and auto-unsubscribe after invocation
|
||||
Action handler = null;
|
||||
handler = () =>
|
||||
{
|
||||
callback.Invoke();
|
||||
notifier.OnReady -= handler; // Unsubscribe to prevent memory leaks
|
||||
};
|
||||
notifier.OnReady += handler;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user