mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
feat: add OnLogin and OnLogout events to ClientState
This commit is contained in:
parent
e4b59a1777
commit
283eb49f17
2 changed files with 42 additions and 1 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue