Skip to content

Commit

Permalink
Replays: final boss (#17621)
Browse files Browse the repository at this point in the history
* Replays: final boss

* Undo formatting change in EntryPoint
  • Loading branch information
PJB3005 authored Jun 24, 2023
1 parent 204f6ca commit bbd8ce8
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 24 deletions.
22 changes: 21 additions & 1 deletion Content.Client/Entry/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@
using Robust.Client;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Replays.Loading;
using Robust.Client.Replays.Playback;
using Robust.Client.State;
using Robust.Client.UserInterface;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.ContentPack;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Replays;

namespace Content.Client.Entry
{
Expand Down Expand Up @@ -64,6 +68,9 @@ public sealed class EntryPoint : GameClient
[Dependency] private readonly JobRequirementsManager _jobRequirements = default!;
[Dependency] private readonly ContentLocalizationManager _contentLoc = default!;
[Dependency] private readonly ContentReplayPlaybackManager _playbackMan = default!;
[Dependency] private readonly IResourceManager _resourceManager = default!;
[Dependency] private readonly IReplayLoadManager _replayLoad = default!;
[Dependency] private readonly ILogManager _logManager = default!;

public override void Init()
{
Expand Down Expand Up @@ -183,7 +190,20 @@ private void SwitchToDefaultState(bool disconnected = false)
{
// Fire off into state dependent on launcher or not.

if (_gameController.LaunchState.FromLauncher)
// Check if we're loading a replay via content bundle!
if (_configManager.GetCVar(CVars.LaunchContentBundle)
&& _resourceManager.ContentFileExists(
ReplayConstants.ReplayZipFolder.ToRootedPath() / ReplayConstants.FileMeta))
{
_logManager.GetSawmill("entry").Info("Loading content bundle replay from VFS!");

var reader = new ReplayFileReaderResources(
_resourceManager,
ReplayConstants.ReplayZipFolder.ToRootedPath());

_replayLoad.LoadAndStartReplay(reader);
}
else if (_gameController.LaunchState.FromLauncher)
{
_stateManager.RequestStateChange<LauncherConnecting>();
var state = (LauncherConnecting) _stateManager.CurrentState;
Expand Down
4 changes: 2 additions & 2 deletions Content.Client/Replay/ContentReplayPlaybackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public void Initialize()
_loadMan.LoadOverride += LoadOverride;
}

private void LoadOverride(IWritableDirProvider dir, ResPath resPath)
private void LoadOverride(IReplayFileReader fileReader)
{
var screen = _stateMan.RequestStateChange<LoadingScreen<bool>>();
screen.Job = new ContentLoadReplayJob(1/60f, dir, resPath, _loadMan, screen);
screen.Job = new ContentLoadReplayJob(1/60f, fileReader, _loadMan, screen);
screen.OnJobFinished += (_, e) => OnFinishedLoading(e);
}

Expand Down
5 changes: 2 additions & 3 deletions Content.Client/Replay/LoadReplayJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ public sealed class ContentLoadReplayJob : LoadReplayJob

public ContentLoadReplayJob(
float maxTime,
IWritableDirProvider dir,
ResPath path,
IReplayFileReader fileReader,
IReplayLoadManager loadMan,
LoadingScreen<bool> screen)
: base(maxTime, dir, path, loadMan)
: base(maxTime, fileReader, loadMan)
{
_screen = screen;
}
Expand Down
36 changes: 23 additions & 13 deletions Content.Replay/Menu/ReplayMainMenu.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.IO.Compression;
using System.Linq;
using Content.Client.Message;
using Content.Client.UserInterface.Systems.EscapeMenu;
Expand All @@ -13,7 +14,7 @@
using Robust.Shared.ContentPack;
using Robust.Shared.Serialization.Markdown.Value;
using Robust.Shared.Utility;
using static Robust.Shared.Replays.IReplayRecordingManager;
using static Robust.Shared.Replays.ReplayConstants;

namespace Content.Replay.Menu;

Expand Down Expand Up @@ -71,8 +72,10 @@ private void UpdateSelectedInfo()
return;
}

using var fileReader = new ReplayFileReaderZip(
new ZipArchive(_resMan.UserData.OpenRead(replay)), ReplayZipFolder);
if (!_resMan.UserData.Exists(replay)
|| _loadMan.LoadYamlMetadata(_resMan.UserData, replay) is not { } data)
|| _loadMan.LoadYamlMetadata(fileReader) is not { } data)
{
info.SetMarkup(Loc.GetString("replay-info-invalid"));
info.HorizontalAlignment = Control.HAlignment.Center;
Expand All @@ -82,16 +85,16 @@ private void UpdateSelectedInfo()
}

var file = replay.ToRelativePath().ToString();
data.TryGet<ValueDataNode>(Time, out var timeNode);
data.TryGet<ValueDataNode>(Duration, out var durationNode);
data.TryGet<ValueDataNode>(MetaKeyTime, out var timeNode);
data.TryGet<ValueDataNode>(MetaFinalKeyDuration, out var durationNode);
data.TryGet<ValueDataNode>("roundId", out var roundIdNode);
data.TryGet<ValueDataNode>(Hash, out var hashNode);
data.TryGet<ValueDataNode>(CompHash, out var compHashNode);
data.TryGet<ValueDataNode>(MetaKeyTypeHash, out var hashNode);
data.TryGet<ValueDataNode>(MetaKeyComponentHash, out var compHashNode);
DateTime.TryParse(timeNode?.Value, out var time);
TimeSpan.TryParse(durationNode?.Value, out var duration);

var forkId = string.Empty;
if (data.TryGet<ValueDataNode>(Fork, out var forkNode))
if (data.TryGet<ValueDataNode>(MetaKeyForkId, out var forkNode))
{
// TODO Replay client build info.
// When distributing the client we need to distribute a build.json or provide these cvars some other way?
Expand All @@ -105,7 +108,7 @@ private void UpdateSelectedInfo()
}

var forkVersion = string.Empty;
if (data.TryGet<ValueDataNode>(ForkVersion, out var versionNode))
if (data.TryGet<ValueDataNode>(MetaKeyForkVersion, out var versionNode))
{
forkVersion = versionNode.Value;
// Why does this not have a try-convert function? I just want to check if it looks like a hash code.
Expand Down Expand Up @@ -162,7 +165,7 @@ private void UpdateSelectedInfo()
}

var engineVersion = string.Empty;
if (data.TryGet<ValueDataNode>(Engine, out var engineNode))
if (data.TryGet<ValueDataNode>(MetaKeyEngineVersion, out var engineNode))
{
var clientVer = _cfg.GetCVar(CVars.BuildEngineVersion);
if (string.IsNullOrWhiteSpace(clientVer))
Expand All @@ -176,7 +179,7 @@ private void UpdateSelectedInfo()
// Strip milliseconds. Apparently there is no general format string that suppresses milliseconds.
duration = new((int)Math.Floor(duration.TotalDays), duration.Hours, duration.Minutes, duration.Seconds);

data.TryGet<ValueDataNode>(Name, out var nameNode);
data.TryGet<ValueDataNode>(MetaKeyName, out var nameNode);
var name = nameNode?.Value ?? string.Empty;

info.HorizontalAlignment = Control.HAlignment.Left;
Expand Down Expand Up @@ -205,7 +208,11 @@ private void OnFolderPressed(BaseButton.ButtonEventArgs obj)
private void OnLoadpressed(BaseButton.ButtonEventArgs obj)
{
if (_selected.HasValue)
_loadMan.LoadAndStartReplay(_resMan.UserData, _selected.Value);
{
var fileReader = new ReplayFileReaderZip(
new ZipArchive(_resMan.UserData.OpenRead(_selected.Value)), ReplayZipFolder);
_loadMan.LoadAndStartReplay(fileReader);
}
}

private void RefreshReplays()
Expand All @@ -217,11 +224,14 @@ private void RefreshReplays()
var file = _directory / entry;
try
{
var data = _loadMan.LoadYamlMetadata(_resMan.UserData, file);
using var fileReader = new ReplayFileReaderZip(
new ZipArchive(_resMan.UserData.OpenRead(file)), ReplayZipFolder);

var data = _loadMan.LoadYamlMetadata(fileReader);
if (data == null)
continue;

var name = data.Get<ValueDataNode>(Name).Value;
var name = data.Get<ValueDataNode>(MetaKeyName).Value;
_replays.Add((name, file));

}
Expand Down
5 changes: 0 additions & 5 deletions Resources/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@
windowIconSet: /Textures/Logo/icon
splashLogo: /Textures/Logo/logo.png

clientAssemblies:
- Content.Client
- Content.Shared
- Content.Shared.Database

# PJB PLEASE

0 comments on commit bbd8ce8

Please sign in to comment.