feat: add OnLogin and OnLogout events to ClientState

This commit is contained in:
goat 2020-08-12 01:17:37 +02:00
parent e4b59a1777
commit 283eb49f17
2 changed files with 42 additions and 1 deletions

View file

@ -148,8 +148,30 @@ namespace Dalamud.Game.ClientState
this.Actors.Dispose();
}
private bool lastConditionNone = true;
/// <summary>
/// Event that fires when a character is logging in.
/// </summary>
public event EventHandler OnLogin;
/// <summary>
/// Event that fires when a character is logging out.
/// </summary>
public event EventHandler OnLogout;
private void FrameworkOnOnUpdateEvent(Framework framework) {
// ignored
if (this.Condition.Any() && this.lastConditionNone == true) {
Log.Debug("Is login");
this.lastConditionNone = false;
OnLogin?.Invoke(this, null);
}
if (!this.Condition.Any() && this.lastConditionNone == false) {
Log.Debug("Is logout");
this.lastConditionNone = true;
OnLogout?.Invoke(this, null);
}
}
}
}

View file

@ -38,5 +38,24 @@ namespace Dalamud.Game.ClientState
return *( bool* )( this.conditionArrayBase + idx );
}
}
public bool Any() {
var didAny = false;
for (var i = 0; i < MaxConditionEntries; i++)
{
var typedCondition = (ConditionFlag)i;
var cond = this[typedCondition];
if (!cond)
{
continue;
}
didAny = true;
}
return didAny;
}
}
}