Add OnClose event.

Reboot shortcut resets steps to 0
This commit is contained in:
Alessandro Proto 2023-02-11 22:20:23 +01:00
parent 5a510c6eb6
commit b84db27f83
3 changed files with 19 additions and 2 deletions

View file

@ -21,6 +21,7 @@ public class EventEmitter
// Functional events
public event EventHandler<TickEvent> OnTick;
public event EventHandler OnInit;
public event EventHandler OnClose;
public event EventHandler OnScreenSizeChange;
public event EventHandler<OverlayEvent> OnOverlay;
@ -100,6 +101,14 @@ public class EventEmitter
}
}
public void RaiseClose()
{
if (OnClose is not null)
{
OnClose(this, EventArgs.Empty);
}
}
public void RaiseScreenSizeChange()
{
if (OnScreenSizeChange is not null)

View file

@ -71,7 +71,7 @@ internal class EventEmitter
{
heldReboot = 0;
RuntimeManager.ResetPanic();
RuntimeManager.Reboot();
RuntimeManager.Reset();
}
}

View file

@ -5,6 +5,7 @@ using KeraLua;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.IO;
using System.Linq;
using System.Text;
@ -17,8 +18,8 @@ internal class RuntimeManager : IPlugin
{
private LuaState luaState;
private EventEmitter emitter;
private int step = 0;
private static int step = 0;
private static bool close = false;
private static bool inPanic = false;
@ -65,6 +66,7 @@ internal class RuntimeManager : IPlugin
{
if (close || !luaState.ProcessQueue())
{
_game.EventEmitter.RaiseClose();
Start();
}
}
@ -143,6 +145,12 @@ internal class RuntimeManager : IPlugin
}
}
public static void Reset()
{
close = true;
step = 0;
}
public static void Reboot()
{
close = true;