Merge branch 'petnames'

This commit is contained in:
Stanley Dimant
2024-09-10 09:15:46 +02:00
9 changed files with 205 additions and 3 deletions

View File

@@ -217,6 +217,9 @@ public class PlayerDataFactory
{
previousData.MoodlesData = await _ipcManager.Moodles.GetStatusAsync(playerRelatedObject.Address).ConfigureAwait(false) ?? string.Empty;
_logger.LogDebug("Moodles is now: {moodles}", previousData.MoodlesData);
previousData.MoodlesData = _ipcManager.PetNames.GetLocalNames();
_logger.LogDebug("Pet Nicknames is now: {moodles}", previousData.MoodlesData);
}
if (previousData.FileReplacements.TryGetValue(objectKind, out HashSet<FileReplacement>? fileReplacements))

View File

@@ -344,6 +344,8 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
case PlayerChanges.Moodles:
await _ipcManager.Moodles.SetStatusAsync(handler.Address, charaData.MoodlesData).ConfigureAwait(false);
await _ipcManager.PetNames.SetPlayerData(handler.Address, charaData.MoodlesData).ConfigureAwait(false);
break;
case PlayerChanges.ForcedRedraw:
@@ -593,6 +595,8 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
await _ipcManager.Honorific.ClearTitleAsync(address).ConfigureAwait(false);
Logger.LogDebug("[{applicationId}] Restoring Moodles for {alias}/{name}", applicationId, Pair.UserData.AliasOrUID, name);
await _ipcManager.Moodles.RevertStatusAsync(address).ConfigureAwait(false);
Logger.LogDebug("[{applicationId}] Restoring Pet Nicknames for {alias}/{name}", applicationId, OnlineUser.User.AliasOrUID, name);
await _ipcManager.PetNames.ClearPlayerData(address).ConfigureAwait(false);
}
else if (objectKind == ObjectKind.MinionOrMount)
{

View File

@@ -6,4 +6,5 @@ public record OptionalPluginWarning
public bool ShownCustomizePlusWarning { get; set; } = false;
public bool ShownHonorificWarning { get; set; } = false;
public bool ShownMoodlesWarning { get; set; } = false;
public bool ShowPetNicknamesWarning { get; set; } = false;
}

View File

@@ -21,6 +21,7 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
private Task? _cacheCreationTask;
private CancellationTokenSource _honorificCts = new();
private CancellationTokenSource _moodlesCts = new();
private CancellationTokenSource _petNicknamesCts = new();
private bool _isZoning = false;
private readonly Dictionary<ObjectKind, CancellationTokenSource> _glamourerCts = new();
@@ -123,6 +124,15 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
MoodlesChanged();
}
});
Mediator.Subscribe<PetNamesMessage>(this, (msg) =>
{
if (_isZoning) return;
if (!string.Equals(msg.PetNicknamesData, _playerData.MoodlesData, StringComparison.Ordinal))
{
Logger.LogDebug("Received Pet Nicknames change, updating player");
PetNicknamesChanged();
}
});
Mediator.Subscribe<PenumbraModSettingChangedMessage>(this, (msg) =>
{
Logger.LogDebug("Received Penumbra Mod settings change, updating player");
@@ -192,6 +202,20 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
}, token);
}
private void PetNicknamesChanged()
{
_petNicknamesCts?.Cancel();
_petNicknamesCts?.Dispose();
_petNicknamesCts = new();
var token = _petNicknamesCts.Token;
_ = Task.Run(async () =>
{
await Task.Delay(TimeSpan.FromSeconds(3), token).ConfigureAwait(false);
await AddPlayerCacheToCreate().ConfigureAwait(false);
}, token);
}
private void ProcessCacheCreation()
{
if (_isZoning) return;