MovieZone - pass in some dependencies and use globals less
This commit is contained in:
parent
0207575695
commit
68e45d6108
|
@ -48,7 +48,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
OverlayBox.Enabled = CurrentMovie is TasMovie;
|
OverlayBox.Enabled = CurrentMovie is TasMovie;
|
||||||
PlaceNum.Enabled = CurrentMovie is TasMovie;
|
PlaceNum.Enabled = CurrentMovie is TasMovie;
|
||||||
|
|
||||||
var main = new MovieZone(CurrentMovie, 0, CurrentMovie.InputLogLength)
|
var main = new MovieZone(CurrentMovie, Emulator, Tools, 0, CurrentMovie.InputLogLength)
|
||||||
{
|
{
|
||||||
Name = "Entire Movie"
|
Name = "Entire Movie"
|
||||||
};
|
};
|
||||||
|
@ -142,7 +142,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var newZone = new MovieZone(CurrentMovie, (int) StartNum.Value, (int) (EndNum.Value - StartNum.Value + 1))
|
var newZone = new MovieZone(CurrentMovie, Emulator, Tools, (int) StartNum.Value, (int) (EndNum.Value - StartNum.Value + 1))
|
||||||
{
|
{
|
||||||
Name = $"Zone {_zones.Count}"
|
Name = $"Zone {_zones.Count}"
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,30 +9,20 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
public class MovieZone
|
public class MovieZone
|
||||||
{
|
{
|
||||||
public string Name { get; set; }
|
private readonly IEmulator _emulator;
|
||||||
public int Start { get; set; }
|
private readonly ToolManager _tools;
|
||||||
public int Length { get; set; }
|
|
||||||
|
|
||||||
private string _inputKey;
|
|
||||||
public string InputKey
|
|
||||||
{
|
|
||||||
get => _inputKey;
|
|
||||||
set { _inputKey = value; ReSetLog(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly string[] _log;
|
private readonly string[] _log;
|
||||||
|
|
||||||
public bool Replace { get; set; } = true;
|
|
||||||
public bool Overlay { get; set; }
|
|
||||||
|
|
||||||
private readonly Bk2ControllerAdapter _targetController;
|
private readonly Bk2ControllerAdapter _targetController;
|
||||||
|
private string _inputKey;
|
||||||
private Bk2ControllerAdapter _controller;
|
private Bk2ControllerAdapter _controller;
|
||||||
|
|
||||||
public MovieZone(IMovie movie, int start, int length, string key = "")
|
public MovieZone(IMovie movie, IEmulator emulator, ToolManager tools, int start, int length, string key = "")
|
||||||
{
|
{
|
||||||
var lg = (Bk2LogEntryGenerator)Global.MovieSession.LogGeneratorInstance();
|
_emulator = emulator;
|
||||||
|
_tools = tools;
|
||||||
|
var lg = (Bk2LogEntryGenerator)movie.LogGeneratorInstance();
|
||||||
lg.SetSource(Global.MovieSession.MovieControllerAdapter);
|
lg.SetSource(Global.MovieSession.MovieControllerAdapter);
|
||||||
_targetController = new Bk2ControllerAdapter { Definition = Global.Emulator.ControllerDefinition };
|
_targetController = new Bk2ControllerAdapter { Definition = _emulator.ControllerDefinition };
|
||||||
_targetController.LatchFromSource(_targetController); // Reference and create all buttons
|
_targetController.LatchFromSource(_targetController); // Reference and create all buttons
|
||||||
|
|
||||||
if (key == "")
|
if (key == "")
|
||||||
|
@ -52,7 +42,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
var d = new ControllerDefinition();
|
var d = new ControllerDefinition();
|
||||||
foreach (var k in keys)
|
foreach (var k in keys)
|
||||||
{
|
{
|
||||||
if (Global.Emulator.ControllerDefinition.BoolButtons.Contains(k))
|
if (_emulator.ControllerDefinition.BoolButtons.Contains(k))
|
||||||
{
|
{
|
||||||
d.BoolButtons.Add(k);
|
d.BoolButtons.Add(k);
|
||||||
}
|
}
|
||||||
|
@ -86,6 +76,19 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
public int Start { get; set; }
|
||||||
|
public int Length { get; set; }
|
||||||
|
|
||||||
|
public bool Replace { get; set; } = true;
|
||||||
|
public bool Overlay { get; set; }
|
||||||
|
|
||||||
|
public string InputKey
|
||||||
|
{
|
||||||
|
get => _inputKey;
|
||||||
|
set { _inputKey = value; ReSetLog(); }
|
||||||
|
}
|
||||||
|
|
||||||
private void ReSetLog()
|
private void ReSetLog()
|
||||||
{
|
{
|
||||||
// Get a IController that only contains buttons in key.
|
// Get a IController that only contains buttons in key.
|
||||||
|
@ -93,7 +96,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
var d = new ControllerDefinition();
|
var d = new ControllerDefinition();
|
||||||
foreach (var key in keys)
|
foreach (var key in keys)
|
||||||
{
|
{
|
||||||
if (Global.Emulator.ControllerDefinition.BoolButtons.Contains(key))
|
if (_emulator.ControllerDefinition.BoolButtons.Contains(key))
|
||||||
{
|
{
|
||||||
d.BoolButtons.Add(key);
|
d.BoolButtons.Add(key);
|
||||||
}
|
}
|
||||||
|
@ -165,7 +168,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
if (movie is TasMovie tasMovie3) // Assume TAStudio is open?
|
if (movie is TasMovie tasMovie3) // Assume TAStudio is open?
|
||||||
{
|
{
|
||||||
tasMovie3.ChangeLog.EndBatch();
|
tasMovie3.ChangeLog.EndBatch();
|
||||||
if (Global.Emulator.Frame > Start)
|
if (_emulator.Frame > Start)
|
||||||
{
|
{
|
||||||
// TODO: Go to start of macro? Ask TAStudio to do that?
|
// TODO: Go to start of macro? Ask TAStudio to do that?
|
||||||
|
|
||||||
|
@ -173,21 +176,21 @@ namespace BizHawk.Client.EmuHawk
|
||||||
// Load last state, Emulate to Start
|
// Load last state, Emulate to Start
|
||||||
|
|
||||||
// Or do this, if TAStudio has to be open.
|
// Or do this, if TAStudio has to be open.
|
||||||
if (GlobalWin.Tools.IsLoaded<TAStudio>())
|
if (_tools.IsLoaded<TAStudio>())
|
||||||
{
|
{
|
||||||
(GlobalWin.Tools.Get<TAStudio>() as TAStudio).GoToFrame(Start);
|
_tools.TAStudio.GoToFrame(Start);
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalWin.Tools.UpdateBefore();
|
_tools.UpdateBefore();
|
||||||
GlobalWin.Tools.UpdateAfter();
|
_tools.UpdateAfter();
|
||||||
}
|
}
|
||||||
else if (GlobalWin.Tools.IsLoaded<TAStudio>())
|
else if (_tools.IsLoaded<TAStudio>())
|
||||||
{
|
{
|
||||||
GlobalWin.Tools.Get<TAStudio>().UpdateValues();
|
_tools.TAStudio.UpdateValues();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (movie.InputLogLength >= Global.Emulator.Frame)
|
if (movie.InputLogLength >= _emulator.Frame)
|
||||||
{
|
{
|
||||||
movie.SwitchToPlay();
|
movie.SwitchToPlay();
|
||||||
Global.Config.MovieEndAction = MovieEndAction.Record;
|
Global.Config.MovieEndAction = MovieEndAction.Record;
|
||||||
|
@ -201,8 +204,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
// Save whether or not the macro should use overlay input, and/or replace
|
// Save whether or not the macro should use overlay input, and/or replace
|
||||||
string[] header = new string[4];
|
string[] header = new string[4];
|
||||||
header[0] = InputKey;
|
header[0] = InputKey;
|
||||||
header[1] = Global.Emulator.ControllerDefinition.Name;
|
header[1] = _emulator.ControllerDefinition.Name;
|
||||||
header[2] = Global.Emulator.ControllerDefinition.PlayerCount.ToString();
|
header[2] = _emulator.ControllerDefinition.PlayerCount.ToString();
|
||||||
header[3] = $"{Overlay},{Replace}";
|
header[3] = $"{Overlay},{Replace}";
|
||||||
|
|
||||||
File.WriteAllLines(fileName, header);
|
File.WriteAllLines(fileName, header);
|
||||||
|
@ -250,13 +253,13 @@ namespace BizHawk.Client.EmuHawk
|
||||||
Name = Path.GetFileNameWithoutExtension(fileName);
|
Name = Path.GetFileNameWithoutExtension(fileName);
|
||||||
|
|
||||||
// Adapters
|
// Adapters
|
||||||
_targetController = new Bk2ControllerAdapter { Definition = Global.Emulator.ControllerDefinition };
|
_targetController = new Bk2ControllerAdapter { Definition = _emulator.ControllerDefinition };
|
||||||
_targetController.LatchFromSource(_targetController); // Reference and create all buttons
|
_targetController.LatchFromSource(_targetController); // Reference and create all buttons
|
||||||
string[] keys = _inputKey.Split('|');
|
string[] keys = _inputKey.Split('|');
|
||||||
var d = new ControllerDefinition();
|
var d = new ControllerDefinition();
|
||||||
foreach (var k in keys)
|
foreach (var k in keys)
|
||||||
{
|
{
|
||||||
if (Global.Emulator.ControllerDefinition.BoolButtons.Contains(k))
|
if (_emulator.ControllerDefinition.BoolButtons.Contains(k))
|
||||||
{
|
{
|
||||||
d.BoolButtons.Add(k);
|
d.BoolButtons.Add(k);
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,6 +240,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
var macro = new MovieZone(
|
var macro = new MovieZone(
|
||||||
CurrentTasMovie,
|
CurrentTasMovie,
|
||||||
|
Emulator,
|
||||||
|
Tools,
|
||||||
TasView.FirstSelectedIndex ?? 0,
|
TasView.FirstSelectedIndex ?? 0,
|
||||||
TasView.LastSelectedIndex ?? 0 - TasView.FirstSelectedIndex ?? 0 + 1);
|
TasView.LastSelectedIndex ?? 0 - TasView.FirstSelectedIndex ?? 0 + 1);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue