84 lines
2.9 KiB
C#
84 lines
2.9 KiB
C#
using Fluxor;
|
|
using KoogleApp.Services;
|
|
using KoogleApp.Store.Game.ThrowPanel;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
|
|
namespace KoogleApp.Store.Game.UndoRedo
|
|
{
|
|
public class UndoRedoEffects
|
|
{
|
|
private readonly ILogger<UndoRedoEffects> _logger;
|
|
private readonly HubConnectionService _sharedHubService;
|
|
private readonly IState<UndoRedoState> _state;
|
|
private readonly IGameStatusDataService _dataService;
|
|
|
|
public UndoRedoEffects(
|
|
ILogger<UndoRedoEffects> logger,
|
|
HubConnectionService sharedHubService,
|
|
IState<UndoRedoState> state,
|
|
IGameStatusDataService dataService
|
|
)
|
|
{
|
|
_logger = logger;
|
|
_sharedHubService = sharedHubService;
|
|
_state = state;
|
|
_dataService = dataService;
|
|
}
|
|
|
|
[EffectMethod]
|
|
public Task HandelUndoAction(UndoAction action, IDispatcher dispatcher)
|
|
{
|
|
var success = _dataService.Undo();
|
|
|
|
if (success)
|
|
{
|
|
var currentData = _dataService.GetCurrentData();
|
|
dispatcher.Dispatch(new UpdateStateAfterUndoRedo(currentData.Status.ThrowPanelState, currentData.Status.ParticipantsState, currentData.Status.GameModel));
|
|
}
|
|
dispatcher.Dispatch(new UpdateUndoRedoStateAction());
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
[EffectMethod]
|
|
public Task HandelRedoAction(RedoAction action, IDispatcher dispatcher)
|
|
{
|
|
var success = _dataService.Redo();
|
|
|
|
if (success)
|
|
{
|
|
var currentData = _dataService.GetCurrentData();
|
|
dispatcher.Dispatch(new UpdateStateAfterUndoRedo(currentData.Status.ThrowPanelState, currentData.Status.ParticipantsState, currentData.Status.GameModel));
|
|
}
|
|
dispatcher.Dispatch(new UpdateUndoRedoStateAction());
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
[EffectMethod]
|
|
public Task HandleUpdateUndoRedoStateAction(UpdateUndoRedoStateAction action, IDispatcher dispatcher)
|
|
{
|
|
var canUndo = _dataService.CanUndo();
|
|
var canRedo = _dataService.CanRedo();
|
|
var currentData = _dataService.GetCurrentData();
|
|
|
|
dispatcher.Dispatch(new CanUndoRedoAction(canUndo,canRedo, currentData.Version, currentData.LastModified, currentData.LastModifiedBy));
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
[EffectMethod]
|
|
public Task HandleCanUndoRedoAction(CanUndoRedoAction action, IDispatcher dispatcher)
|
|
{
|
|
dispatcher.Dispatch(new BroadcastUndoRedoStateAction(_state.Value));
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
[EffectMethod]
|
|
public async Task HandelBroadcastUndoRedoStateAction(BroadcastUndoRedoStateAction action, IDispatcher dispatcher)
|
|
{
|
|
await _sharedHubService.BroadcastUndoRedoState(action.State, dispatcher);
|
|
}
|
|
}
|
|
|
|
}
|