@implements IDisposable
@using LANCommander.Client.Data.Models
@using LANCommander.Client.Models
@using System.Diagnostics
@using LANCommander.SDK.Helpers
@inject GameService GameService
@inject LibraryService LibraryService
@inject DownloadService DownloadService
@inject ScriptService ScriptService
@inject ModalService ModalService
@inject MessageBusService MessageBusService
@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; }
Settings Settings;
protected override async Task OnInitializedAsync()
{
MessageBusService.OnGameStarted += UpdateState;
MessageBusService.OnGameStopped += UpdateState;
Settings = SettingService.GetSettings();
}
protected override async Task OnParametersSetAsync()
{
Game = await GameService.Get(GameId);
GameActions = new List();
if (Game.Installed)
{
var manifest = ManifestHelper.Read(Game.InstallDirectory, Game.Id);
GameActions = manifest.Actions.Where(a => !a.IsPrimaryAction).ToList();
}
}
async Task UpdateState(Game game)
{
if (GameId == game.Id)
{
await InvokeAsync(StateHasChanged);
}
}
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 = $"Play {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 Run(Game game, SDK.Models.Action action)
{
LibraryService.Run(Game, action);
await InvokeAsync(StateHasChanged);
}
async Task Stop()
{
await LibraryService.Stop(Game);
await InvokeAsync(StateHasChanged);
}
async Task BrowseFiles()
{
Process.Start("explorer", Game.InstallDirectory);
}
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",
Centered = true,
Icon = @
});
if (confirmed)
await GameService.Uninstall(Game);
DownloadService.Remove(Game.Id);
await LibraryService.LibraryChanged();
}
async Task RunInstallScripts()
{
var manifests = GameService.GetGameManifests(Game);
foreach (var manifest in manifests)
{
ScriptService.RunInstallScript(Game, manifest.Id);
}
}
async Task RunNameChangeScripts()
{
var manifests = GameService.GetGameManifests(Game);
foreach (var manifest in manifests)
{
ScriptService.RunNameChangeScript(Game, manifest.Id);
}
}
async Task RunKeyChangeScripts()
{
var manifests = GameService.GetGameManifests(Game);
foreach (var manifest in manifests)
{
ScriptService.RunKeyChangeScript(Game, manifest.Id);
}
}
async Task OpenManual(Media media)
{
var modalOptions = new ModalOptions()
{
Title = media.Name,
Maximizable = true,
DefaultMaximized = true,
Closable = true,
Footer = null,
Draggable = true,
Resizable = true,
WrapClassName = "pdf-reader-dialog",
};
var modalRef = await ModalService.CreateModalAsync(modalOptions, media);
}
public void Dispose()
{
MessageBusService.OnGameStarted -= UpdateState;
MessageBusService.OnGameStopped -= UpdateState;
}
}