Don't actually use the IConsoleProgram interface in code since it would require a huge number of casts and everything is inside Program anyway.

This commit is contained in:
Anna Rose 2025-02-11 14:36:24 -05:00
parent 06be2bf30e
commit 66fff69396
5 changed files with 10 additions and 7 deletions

View File

@ -14,7 +14,7 @@ namespace IngameScript
public bool Triggered { get; private set; } = false; public bool Triggered { get; private set; } = false;
public List<IMyAirVent> Vents { get; } = new List<IMyAirVent>(); public List<IMyAirVent> Vents { get; } = new List<IMyAirVent>();
private IConsoleProgram _program; private Program _program;
private List<IMyDoor> _doors = new List<IMyDoor>(); private List<IMyDoor> _doors = new List<IMyDoor>();
private List<IMyTextSurface> _displays = new List<IMyTextSurface>(); private List<IMyTextSurface> _displays = new List<IMyTextSurface>();
private List<IMyLightingBlock> _lights = new List<IMyLightingBlock>(); private List<IMyLightingBlock> _lights = new List<IMyLightingBlock>();
@ -23,12 +23,12 @@ namespace IngameScript
private const float TriggerLevel = 0.75F; private const float TriggerLevel = 0.75F;
public AirZone(string zoneName, IConsoleProgram program) public AirZone(Program program, string zoneName)
{ {
Name = zoneName; Name = zoneName;
_program = program; _program = program;
_console = new PrefixedConsole(program.Console, zoneName); _console = new PrefixedConsole(_program.Console, Name);
_sequencer = new Sequencer(program, zoneName); _sequencer = new Sequencer(_program, Name);
} }
public void AddBlock(IMyTerminalBlock block) public void AddBlock(IMyTerminalBlock block)

View File

@ -72,7 +72,7 @@ namespace IngameScript
{ {
if (!_zones.ContainsKey(zone)) if (!_zones.ContainsKey(zone))
{ {
_zones[zone] = new AirZone(zone, this); _zones[zone] = new AirZone(this, zone);
} }
_zones[zone].AddBlock(block); _zones[zone].AddBlock(block);
} }

View File

@ -86,7 +86,7 @@ namespace IngameScript
private const int CooldownTicks = 120; private const int CooldownTicks = 120;
private const int SealTimeoutTicks = 30; private const int SealTimeoutTicks = 30;
public Airlock(string name, IConsoleProgram _program) public Airlock(string name, Program _program)
{ {
_ini = _program.Ini; _ini = _program.Ini;
_name = name; _name = name;

View File

@ -11,6 +11,9 @@ namespace IngameScript
{ {
// A Program that supports consoles by initializing a MyIni instance // A Program that supports consoles by initializing a MyIni instance
// and providing a public console for member objects to refer back to. // and providing a public console for member objects to refer back to.
// If you're using this library it is highly advised that you implement this interface
// for a clean, consistent way to avoid errors.
//
// (It is probably an anti-pattern that this lives outside of the Program class, // (It is probably an anti-pattern that this lives outside of the Program class,
// but we can't find a cleaner way to implement this.) // but we can't find a cleaner way to implement this.)
public interface IConsoleProgram public interface IConsoleProgram

View File

@ -18,7 +18,7 @@ namespace IngameScript
private SortedDictionary<int, List<ISequenceable>> _sequence = new SortedDictionary<int, List<ISequenceable>>(); private SortedDictionary<int, List<ISequenceable>> _sequence = new SortedDictionary<int, List<ISequenceable>>();
public Sequencer(IConsoleProgram program, string name) public Sequencer(Program program, string name)
{ {
Name = name; Name = name;
_console = new PrefixedConsole(program.Console, Name); _console = new PrefixedConsole(program.Console, Name);