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; firstLoad = false;
FullGameFields.Init(__instance); FullGameFields.Init(__instance);
//Application.Application.SetFullGameCompositionRoot(__instance);
Logging.Log("Dispatching App Init event"); Logging.Log("Dispatching App Init event");
EventManager.GetEventEmitter("GamecraftModdingAPIApplicationInitializedEventEmitter").Emit(); EventManager.GetEventEmitter("GamecraftModdingAPIApplicationInitializedEventEmitter").Emit();
} }

View file

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