@using LANCommander.Client.Models
@using System.Diagnostics
@using LANCommander.SDK.Helpers
@inject GameService GameService
@inject LibraryService LibraryService
@inject DownloadService DownloadService
@inject ModalService ModalService
@if (LibraryService.IsRunning(Game))
{
}
else
{
}
@code {
[Parameter] public Guid GameId { get; set; }
[Parameter] public RenderFragment MenuExtra { get; set; }
Data.Models.Game Game { get; set; }
IEnumerable GameActions { get; set; }
protected override async Task OnParametersSetAsync()
{
Game = await GameService.Get(GameId);
}
async Task Run()
{
var actions = await GameService.GetActionsAsync(Game);
var primaryActions = actions.Where(a => a.IsPrimaryAction);
if (primaryActions.Count() == 1)
{
var task = LibraryService.Run(Game, primaryActions.First());
await InvokeAsync(StateHasChanged);
await task;
}
else
{
var modalOptions = new ModalOptions()
{
Title = Game.Title,
Maximizable = false,
DefaultMaximized = false,
Closable = true,
Footer = null,
Centered = true,
WrapClassName = "game-actions-dialog"
};
var model = new ActionSelectorDialogOptions
{
Actions = actions.Where(a => a.IsPrimaryAction),
Game = Game
};
var modalRef = ModalService.CreateModal(modalOptions, model);
}
}
async Task Stop()
{
await LibraryService.Stop(Game);
await InvokeAsync(StateHasChanged);
}
async Task Uninstall()
{
var manifest = ManifestHelper.Read(Game.InstallDirectory, Game.Id);
var message = $"Would you like to uninstall {Game.Title}?";
if (manifest.SavePaths != null && manifest.SavePaths.Any())
message += " Your save files have been uploaded to the server.";
else
message += " Your save files may be unrecoverable if they are contained within the game's install directory.";
var confirmed = await ModalService.ConfirmAsync(new ConfirmOptions
{
OkText = "Uninstall",
CancelText = "Cancel",
Title = "Uninstall",
Content = message,
OkType = "danger",
Icon = @
});
if (confirmed)
await GameService.Uninstall(Game);
DownloadService.Remove(Game.Id);
await LibraryService.LibraryChanged();
}
}