#nullable disable
using System;
using System.Threading.Tasks;
using StardewValley;
namespace StardewModdingAPI.Framework
{
/// Invokes callbacks for mod hooks provided by the game.
internal class SModHooks : ModHooks
{
/*********
** Fields
*********/
/// A callback to invoke before runs.
private readonly Action BeforeNewDayAfterFade;
/// Writes messages to the console.
private readonly IMonitor Monitor;
/*********
** Public methods
*********/
/// Construct an instance.
/// A callback to invoke before runs.
/// Writes messages to the console.
public SModHooks(Action beforeNewDayAfterFade, IMonitor monitor)
{
this.BeforeNewDayAfterFade = beforeNewDayAfterFade;
this.Monitor = monitor;
}
/// A hook invoked when is called.
/// The vanilla logic.
public override void OnGame1_NewDayAfterFade(Action action)
{
this.BeforeNewDayAfterFade?.Invoke();
action();
}
/// Start an asynchronous task for the game.
/// The task to start.
/// A unique key which identifies the task.
public override Task StartTask(Task task, string id)
{
this.Monitor.Log($"Synchronizing '{id}' task...");
task.RunSynchronously();
this.Monitor.Log(" task complete.");
return task;
}
/// Start an asynchronous task for the game.
/// The task to start.
/// A unique key which identifies the task.
public override Task StartTask(Task task, string id)
{
this.Monitor.Log($"Synchronizing '{id}' task...");
task.RunSynchronously();
this.Monitor.Log(" task complete.");
return task;
}
}
}