Skip to content

Commit

Permalink
fix: finall found the really annoying bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ewrogers committed Jun 30, 2023
1 parent 2071175 commit c9a2f68
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 29 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Lots of performance and under the hood optimizations
- Auto-save and load reliability
- Some UI bugs on auto-load
- Lots of performance and under the hood optimizations

## [4.10.1] - 2023-06-27

Expand Down
7 changes: 4 additions & 3 deletions SleepHunter/Models/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,8 @@ protected override void OnUpdate()
spellbook.TryUpdate();

var wasLoggedIn = IsLoggedIn;
IsLoggedIn = !string.IsNullOrWhiteSpace(Name) && stats.Level > 0;
var isNowLoggedIn = IsLoggedIn;

var isNowLoggedIn = !string.IsNullOrWhiteSpace(Name) && stats.Level > 0;

if (isNowLoggedIn && !wasLoggedIn)
OnLoggedIn();
else if (wasLoggedIn && !isNowLoggedIn)
Expand All @@ -247,6 +246,7 @@ private void UpdateName(ProcessMemoryAccessor accessor)

private void OnLoggedIn()
{
IsLoggedIn = true;
LoggedIn?.Invoke(this, EventArgs.Empty);
}

Expand All @@ -255,6 +255,7 @@ void OnLoggedOut()
// This memory gets re-allocated when a new character logs into the same client instance
skillbook.ResetCooldownPointer();

IsLoggedIn = false;
LoggedOut?.Invoke(this, EventArgs.Empty);
}

Expand Down
26 changes: 5 additions & 21 deletions SleepHunter/Models/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ private PlayerManager() { }
private bool showAllClients;

public event PlayerEventHandler PlayerAdded;
public event PropertyChangedEventHandler PlayerPropertyChanged;
public event PlayerEventHandler PlayerUpdated;
public event PlayerEventHandler PlayerRemoved;
public event PropertyChangedEventHandler PlayerPropertyChanged;

public event PropertyChangedEventHandler PropertyChanged;

Expand Down Expand Up @@ -97,9 +96,7 @@ public void AddPlayer(Player player)

players[player.Process.ProcessId] = player;

if (alreadyExists)
OnPlayerUpdated(player);
else
if (!alreadyExists)
OnPlayerAdded(player);
}

Expand All @@ -123,6 +120,7 @@ public Player GetPlayerByName(string playerName)
public bool RemovePlayer(int processId)
{
var wasRemoved = players.TryRemove(processId, out var removedPlayer);
removedPlayer.PropertyChanged -= Player_PropertyChanged;

if (wasRemoved)
{
Expand Down Expand Up @@ -160,25 +158,11 @@ public void UpdateClients(Predicate<Player> predicate = null)

private void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

private void OnPlayerAdded(Player player)
{
player.PropertyChanged += Player_PropertyChanged;
PlayerAdded?.Invoke(this, new PlayerEventArgs(player));
}
private void OnPlayerAdded(Player player) => PlayerAdded?.Invoke(this, new PlayerEventArgs(player));

private void OnPlayerPropertyChanged(Player player, string propertyName) => PlayerPropertyChanged?.Invoke(player, new PropertyChangedEventArgs(propertyName));

private void OnPlayerUpdated(Player player)
{
player.PropertyChanged += Player_PropertyChanged;
PlayerUpdated?.Invoke(this, new PlayerEventArgs(player));
}

private void OnPlayerRemoved(Player player)
{
player.PropertyChanged -= Player_PropertyChanged;
PlayerRemoved?.Invoke(this, new PlayerEventArgs(player));
}
private void OnPlayerRemoved(Player player) => PlayerRemoved?.Invoke(this, new PlayerEventArgs(player));

private void Player_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
Expand Down
1 change: 0 additions & 1 deletion SleepHunter/Views/FlowerTargetWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public FlowerTargetWindow()
private void InitializeViews()
{
PlayerManager.Instance.PlayerAdded += OnPlayerCollectionChanged;
PlayerManager.Instance.PlayerUpdated += OnPlayerCollectionChanged;
PlayerManager.Instance.PlayerRemoved += OnPlayerCollectionChanged;

PlayerManager.Instance.PlayerPropertyChanged += OnPlayerPropertyChanged;
Expand Down
1 change: 0 additions & 1 deletion SleepHunter/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ private void InitializeHotkeyHook()
private void InitializeViews()
{
PlayerManager.Instance.PlayerAdded += OnPlayerCollectionAdd;
PlayerManager.Instance.PlayerUpdated += OnPlayerCollectionAdd;
PlayerManager.Instance.PlayerRemoved += OnPlayerCollectionRemove;

PlayerManager.Instance.PlayerPropertyChanged += OnPlayerPropertyChanged;
Expand Down
3 changes: 1 addition & 2 deletions SleepHunter/Views/SpellTargetWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public SpellTargetWindow()
private void InitializeViews()
{
PlayerManager.Instance.PlayerAdded += OnPlayerCollectionChanged;
PlayerManager.Instance.PlayerUpdated += OnPlayerCollectionChanged;
PlayerManager.Instance.PlayerRemoved += OnPlayerCollectionChanged;

PlayerManager.Instance.PlayerPropertyChanged += OnPlayerPropertyChanged;
Expand All @@ -120,7 +119,7 @@ private async void OnPlayerPropertyChanged(object sender, PropertyChangedEventAr
if (string.Equals(nameof(player.Name), e.PropertyName, StringComparison.OrdinalIgnoreCase) ||
string.Equals(nameof(player.IsLoggedIn), e.PropertyName, StringComparison.OrdinalIgnoreCase))
{
BindingOperations.GetBindingExpression(characterComboBox, ListView.ItemsSourceProperty).UpdateTarget();
BindingOperations.GetBindingExpression(characterComboBox, ItemsControl.ItemsSourceProperty).UpdateTarget();
characterComboBox.Items.Refresh();
}
}
Expand Down

0 comments on commit c9a2f68

Please sign in to comment.