Fix double event call, jankily

This commit is contained in:
NGnius (Graham) 2020-06-13 15:23:52 -04:00
parent 62318b0843
commit d2c9cde1d2
2 changed files with 14 additions and 0 deletions

View file

@ -31,6 +31,7 @@ namespace GamecraftModdingAPI.Events
{
firstLoad = false;
FullGameFields.Init(__instance);
//Application.Application.SetFullGameCompositionRoot(__instance);
Logging.Log("Dispatching App Init event");
EventManager.GetEventEmitter("GamecraftModdingAPIApplicationInitializedEventEmitter").Emit();
}

View file

@ -20,6 +20,10 @@ namespace GamecraftModdingAPI.Events
private bool isActivated = false;
private bool jankActivateFix = false;
private bool jankDestroyFix = false;
private readonly Action<EntitiesDB> onActivated;
private readonly Action<EntitiesDB> onDestroyed;
@ -32,6 +36,8 @@ namespace GamecraftModdingAPI.Events
{
if (entityView.type.Equals(this.type))
{
jankActivateFix = !jankActivateFix;
if (jankActivateFix) return;
isActivated = true;
onActivatedInvokeCatchError(entitiesDB);
}
@ -51,12 +57,19 @@ namespace GamecraftModdingAPI.Events
}
}
public void Deactivate()
{
isActivated = false;
}
public void Ready() { }
public void Remove(ref ModEventEntityStruct entityView, EGID egid)
{
if (entityView.type.Equals(this.type) && isActivated)
{
jankDestroyFix = !jankDestroyFix;
if (jankDestroyFix) return;
isActivated = false;
onDestroyedInvokeCatchError(entitiesDB);
}