mirror of
https://github.com/Caraxi/mare.client.git
synced 2025-12-12 20:07:21 +01:00
[Draft] Update 0.8 (#46)
* move stuff out into file transfer manager * obnoxious unsupported version text, adjustments to filetransfermanager * add back file upload transfer progress * restructure code * cleanup some more stuff I guess * downloadids by playername * individual anim/sound bs * fix migration stuff, finalize impl of individual sound/anim pause * fixes with logging stuff * move download manager to transient * rework dl ui first iteration * some refactoring and cleanup * more code cleanup * refactoring * switch to hostbuilder * some more rework I guess * more refactoring * clean up mediator calls and disposal * fun code cleanup * push error message when log level is set to anything but information in non-debug builds * remove notificationservice * move message to after login * add download bars to gameworld * fixes download progress bar * set gpose ui min and max size * remove unnecessary usings * adjustments to reconnection logic * add options to set visible/offline groups visibility * add impl of uploading display, transfer list in settings ui * attempt to fix issues with server selection * add back download status to compact ui * make dl bar fixed size based * some fixes for upload/download handling * adjust text from Syncing back to Uploading --------- Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com> Co-authored-by: Stanley Dimant <stanley.dimant@varian.com>
This commit is contained in:
parent
0824ba434b
commit
0c87e84f25
109 changed files with 7323 additions and 6488 deletions
|
|
@ -1,131 +0,0 @@
|
|||
using MareSynchronos.API.Data.Enum;
|
||||
using MareSynchronos.Factories;
|
||||
using MareSynchronos.Mediator;
|
||||
using MareSynchronos.Models;
|
||||
using MareSynchronos.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MareSynchronos.Managers;
|
||||
|
||||
public class CacheCreationService : MediatorSubscriberBase, IDisposable
|
||||
{
|
||||
private readonly CharacterDataFactory _characterDataFactory;
|
||||
private Task? _cacheCreationTask;
|
||||
private readonly Dictionary<ObjectKind, GameObjectHandler> _cachesToCreate = new();
|
||||
private readonly CharacterData _playerData = new();
|
||||
private readonly CancellationTokenSource _cts = new();
|
||||
private readonly List<GameObjectHandler> _playerRelatedObjects = new();
|
||||
private CancellationTokenSource _palettePlusCts = new();
|
||||
private SemaphoreSlim _cacheCreateLock = new(1);
|
||||
|
||||
public CacheCreationService(ILogger<CacheCreationService> logger, MareMediator mediator, GameObjectHandlerFactory gameObjectHandlerFactory,
|
||||
CharacterDataFactory characterDataFactory, DalamudUtil dalamudUtil) : base(logger, mediator)
|
||||
{
|
||||
_characterDataFactory = characterDataFactory;
|
||||
|
||||
Mediator.Subscribe<CreateCacheForObjectMessage>(this, (msg) =>
|
||||
{
|
||||
var actualMsg = (CreateCacheForObjectMessage)msg;
|
||||
_cacheCreateLock.Wait();
|
||||
_cachesToCreate[actualMsg.ObjectToCreateFor.ObjectKind] = actualMsg.ObjectToCreateFor;
|
||||
_cacheCreateLock.Release();
|
||||
});
|
||||
|
||||
_playerRelatedObjects.AddRange(new List<GameObjectHandler>()
|
||||
{
|
||||
gameObjectHandlerFactory.Create(ObjectKind.Player, () => dalamudUtil.PlayerPointer, isWatched: true),
|
||||
gameObjectHandlerFactory.Create(ObjectKind.MinionOrMount, () => dalamudUtil.GetMinionOrMount(), isWatched: true),
|
||||
gameObjectHandlerFactory.Create(ObjectKind.Pet, () => dalamudUtil.GetPet(), isWatched: true),
|
||||
gameObjectHandlerFactory.Create(ObjectKind.Companion, () => dalamudUtil.GetCompanion(), isWatched: true),
|
||||
});
|
||||
|
||||
Mediator.Subscribe<ClearCacheForObjectMessage>(this, (msg) =>
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
var actualMsg = (ClearCacheForObjectMessage)msg;
|
||||
_playerData.FileReplacements.Remove(actualMsg.ObjectToCreateFor.ObjectKind);
|
||||
_playerData.GlamourerString.Remove(actualMsg.ObjectToCreateFor.ObjectKind);
|
||||
Mediator.Publish(new CharacterDataCreatedMessage(_playerData.ToAPI()));
|
||||
});
|
||||
});
|
||||
|
||||
Mediator.Subscribe<DelayedFrameworkUpdateMessage>(this, (msg) => ProcessCacheCreation());
|
||||
Mediator.Subscribe<CustomizePlusMessage>(this, async (_) => await AddPlayerCacheToCreate().ConfigureAwait(false));
|
||||
Mediator.Subscribe<HeelsOffsetMessage>(this, async (_) => await AddPlayerCacheToCreate().ConfigureAwait(false));
|
||||
Mediator.Subscribe<PalettePlusMessage>(this, (_) => PalettePlusChanged());
|
||||
Mediator.Subscribe<PenumbraModSettingChangedMessage>(this, async (msg) => await AddPlayerCacheToCreate().ConfigureAwait(false));
|
||||
}
|
||||
|
||||
private async Task AddPlayerCacheToCreate()
|
||||
{
|
||||
await _cacheCreateLock.WaitAsync().ConfigureAwait(false);
|
||||
_cachesToCreate[ObjectKind.Player] = _playerRelatedObjects.First(p => p.ObjectKind == ObjectKind.Player);
|
||||
_cacheCreateLock.Release();
|
||||
}
|
||||
|
||||
private void PalettePlusChanged()
|
||||
{
|
||||
_palettePlusCts?.Cancel();
|
||||
_palettePlusCts?.Dispose();
|
||||
_palettePlusCts = new();
|
||||
var token = _palettePlusCts.Token;
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(1), token).ConfigureAwait(false);
|
||||
await AddPlayerCacheToCreate().ConfigureAwait(false);
|
||||
}, token);
|
||||
}
|
||||
|
||||
private void ProcessCacheCreation()
|
||||
{
|
||||
if (_cachesToCreate.Any() && (_cacheCreationTask?.IsCompleted ?? true))
|
||||
{
|
||||
_cacheCreateLock.Wait();
|
||||
var toCreate = _cachesToCreate.ToList();
|
||||
_cachesToCreate.Clear();
|
||||
_cacheCreateLock.Release();
|
||||
|
||||
_cacheCreationTask = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var obj in toCreate)
|
||||
{
|
||||
await _characterDataFactory.BuildCharacterData(_playerData, obj.Value, _cts.Token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
int maxWaitingTime = 10000;
|
||||
while (!_playerData.IsReady && maxWaitingTime > 0)
|
||||
{
|
||||
await Task.Delay(100).ConfigureAwait(false);
|
||||
maxWaitingTime -= 100;
|
||||
_logger.LogTrace("Waiting for Cache to be ready");
|
||||
}
|
||||
|
||||
Mediator.Publish(new CharacterDataCreatedMessage(_playerData.ToAPI()));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogCritical(ex, "Error during Cache Creation Processing");
|
||||
}
|
||||
finally
|
||||
{
|
||||
_logger.LogDebug("Cache Creation complete");
|
||||
}
|
||||
}, _cts.Token);
|
||||
}
|
||||
else if (_cachesToCreate.Any())
|
||||
{
|
||||
_logger.LogDebug("Cache Creation stored until previous creation finished");
|
||||
}
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
base.Dispose();
|
||||
_playerRelatedObjects.ForEach(p => p.Dispose());
|
||||
_cts.Dispose();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue