Skip to content

Commit

Permalink
swap movie running status to be IMovieRunner property
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddio0141 committed Aug 20, 2024
1 parent a3f6f49 commit 8bd1718
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 35 deletions.
37 changes: 6 additions & 31 deletions UniTAS/Patcher/Implementations/GUI/TerminalCommands/MovieStatus.cs
Original file line number Diff line number Diff line change
@@ -1,50 +1,25 @@
using System;
using JetBrains.Annotations;
using MoonSharp.Interpreter;
using UniTAS.Patcher.Interfaces.GUI;
using UniTAS.Patcher.Services.Movie;

namespace UniTAS.Patcher.Implementations.GUI.TerminalCommands;

public class MovieStatus(IMovieRunnerEvents movieRunnerEvents) : TerminalCmd
public class MovieStatus(IMovieRunner movieRunner) : TerminalCmd
{
public override string Name => "movie_status";
public override string Description => "gets an object that contains movie status";
public override Delegate Callback => Execute;

private Status Execute()
{
return new(movieRunnerEvents);
return new(movieRunner);
}

private class Status : IDisposable
[method: MoonSharpHidden]
private class Status(IMovieRunner movieRunner)
{
private readonly IMovieRunnerEvents _movieRunnerEvents;

[MoonSharpHidden]
public Status(IMovieRunnerEvents movieRunnerEvents)
{
_movieRunnerEvents = movieRunnerEvents;
movieRunnerEvents.OnMovieSetup += SetupStart;
movieRunnerEvents.OnMovieEnd += MovieEnd;
}

private void SetupStart()
{
BasicallyRunning = true;
}

private void MovieEnd()
{
BasicallyRunning = false;
}

// ReSharper disable once UnusedAutoPropertyAccessor.Local
public bool BasicallyRunning { get; private set; }

public void Dispose()
{
_movieRunnerEvents.OnMovieSetup -= SetupStart;
_movieRunnerEvents.OnMovieEnd -= MovieEnd;
}
[UsedImplicitly] public bool BasicallyRunning => movieRunner.SetupOrMovieRunning;
}
}
6 changes: 3 additions & 3 deletions UniTAS/Patcher/Implementations/Movie/MovieRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class MovieRunner : IMovieRunner, IOnInputUpdateActual, IMovieRunnerEvent
private readonly IGameRestart _gameRestart;

public bool MovieEnd { get; private set; } = true;
public bool SetupOrMovieRunning { get; private set; }
private bool _setup;

private readonly IMovieParser _parser;
Expand Down Expand Up @@ -63,8 +64,7 @@ public void RunFromInput(string input)
{
if (_setup) throw new MovieAlreadySettingUpException();
_setup = true;

OnMovieSetup?.Invoke();
SetupOrMovieRunning = true;

if (!MovieEnd)
{
Expand Down Expand Up @@ -158,6 +158,7 @@ private void MovieRunningStatusChange(bool running)
}
else
{
SetupOrMovieRunning = false;
OnMovieEnd?.Invoke();
}

Expand All @@ -175,5 +176,4 @@ private IEnumerable<CoroutineWait> FinishMovieCleanup()

public event Action OnMovieStart;
public event Action OnMovieEnd;
public event Action OnMovieSetup;
}
1 change: 1 addition & 0 deletions UniTAS/Patcher/Services/Movie/IMovieRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace UniTAS.Patcher.Services.Movie;
public interface IMovieRunner
{
bool MovieEnd { get; }
bool SetupOrMovieRunning { get; }
IMovieLogger MovieLogger { get; }
void RunFromInput(string input);
UpdateType UpdateType { set; }
Expand Down
1 change: 0 additions & 1 deletion UniTAS/Patcher/Services/Movie/IMovieRunnerEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ public interface IMovieRunnerEvents
{
event Action OnMovieStart;
event Action OnMovieEnd;
event Action OnMovieSetup;
}

0 comments on commit 8bd1718

Please sign in to comment.