Skip to content

Commit

Permalink
[KK, KKS] Add GameAPI.DayChange, PeriodChange and NewGame events
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Oct 8, 2021
1 parent b3bb9e5 commit c7e0c9f
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/KKAPI/MainGame/GameApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ public static partial class GameAPI
/// </summary>
public static event EventHandler<GameSaveLoadEventArgs> GameSave;

/// <summary>
/// Triggered when the current day changes in story mode.
/// Runs immediately after all <see cref="GameCustomFunctionController"/> objects trigger their events.
/// </summary>
public static event EventHandler<DayChangeEventArgs> DayChange;

/// <summary>
/// Triggered when the current time of the day changes in story mode.
/// Runs immediately after all <see cref="GameCustomFunctionController"/> objects trigger their events.
/// </summary>
public static event EventHandler<PeriodChangeEventArgs> PeriodChange;

/// <summary>
/// Triggered when a new game is started in story mode.
/// Runs immediately after all <see cref="GameCustomFunctionController"/> objects trigger their events.
/// </summary>
public static event EventHandler NewGame;

/// <summary>
/// True if any sort of H scene is currently loaded.
/// </summary>
Expand Down Expand Up @@ -364,6 +382,15 @@ private static void OnDayChange(Cycle.Week day)
KoikatuAPI.Logger.LogError(e);
}
}

try
{
DayChange?.Invoke(KoikatuAPI.Instance, new DayChangeEventArgs(day));
}
catch (Exception e)
{
KoikatuAPI.Logger.LogError(e);
}
}

private static void OnPeriodChange(Cycle.Type period)
Expand All @@ -379,6 +406,15 @@ private static void OnPeriodChange(Cycle.Type period)
KoikatuAPI.Logger.LogError(e);
}
}

try
{
PeriodChange?.Invoke(KoikatuAPI.Instance, new PeriodChangeEventArgs(period));
}
catch (Exception e)
{
KoikatuAPI.Logger.LogError(e);
}
}

private static void OnNewGame()
Expand All @@ -394,6 +430,35 @@ private static void OnNewGame()
KoikatuAPI.Logger.LogError(e);
}
}

try
{
NewGame?.Invoke(KoikatuAPI.Instance, EventArgs.Empty);
}
catch (Exception e)
{
KoikatuAPI.Logger.LogError(e);
}
}

public class DayChangeEventArgs : EventArgs
{
public DayChangeEventArgs(Cycle.Week newDay)
{
NewDay = newDay;
}

public Cycle.Week NewDay { get; }
}

public class PeriodChangeEventArgs : EventArgs
{
public PeriodChangeEventArgs(Cycle.Type period)
{
NewPeriod = period;
}

public Cycle.Type NewPeriod { get; }
}
}
}
65 changes: 65 additions & 0 deletions src/KKSAPI/MainGame/GameApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ public static partial class GameAPI
/// </summary>
public static event EventHandler<GameSaveLoadEventArgs> GameSave;

/// <summary>
/// Triggered when the current day changes in story mode.
/// Runs immediately after all <see cref="GameCustomFunctionController"/> objects trigger their events.
/// </summary>
public static event EventHandler<DayChangeEventArgs> DayChange;

/// <summary>
/// Triggered when the current time of the day changes in story mode.
/// Runs immediately after all <see cref="GameCustomFunctionController"/> objects trigger their events.
/// </summary>
public static event EventHandler<PeriodChangeEventArgs> PeriodChange;

/// <summary>
/// Triggered when a new game is started in story mode.
/// Runs immediately after all <see cref="GameCustomFunctionController"/> objects trigger their events.
/// </summary>
public static event EventHandler NewGame;

/// <summary>
/// True if any sort of H scene is currently loaded.
/// </summary>
Expand Down Expand Up @@ -357,6 +375,15 @@ private static void OnDayChange(Cycle.Week day)
KoikatuAPI.Logger.LogError(e);
}
}

try
{
DayChange?.Invoke(KoikatuAPI.Instance, new DayChangeEventArgs(day));
}
catch (Exception e)
{
KoikatuAPI.Logger.LogError(e);
}
}

private static void OnPeriodChange(Cycle.Type period)
Expand All @@ -372,6 +399,15 @@ private static void OnPeriodChange(Cycle.Type period)
KoikatuAPI.Logger.LogError(e);
}
}

try
{
PeriodChange?.Invoke(KoikatuAPI.Instance, new PeriodChangeEventArgs(period));
}
catch (Exception e)
{
KoikatuAPI.Logger.LogError(e);
}
}

private static void OnNewGame()
Expand All @@ -387,6 +423,35 @@ private static void OnNewGame()
KoikatuAPI.Logger.LogError(e);
}
}

try
{
NewGame?.Invoke(KoikatuAPI.Instance, EventArgs.Empty);
}
catch (Exception e)
{
KoikatuAPI.Logger.LogError(e);
}
}

public class DayChangeEventArgs : EventArgs
{
public DayChangeEventArgs(Cycle.Week newDay)
{
NewDay = newDay;
}

public Cycle.Week NewDay { get; }
}

public class PeriodChangeEventArgs : EventArgs
{
public PeriodChangeEventArgs(Cycle.Type period)
{
NewPeriod = period;
}

public Cycle.Type NewPeriod { get; }
}
}
}

0 comments on commit c7e0c9f

Please sign in to comment.