Actually use the IConsoleProgram interface where appropriate. (we may trim this down later to only use the actual IConsole where appropriate...)
This commit is contained in:
parent
c998f088f6
commit
cd9ee88172
|
@ -10,7 +10,7 @@ namespace IngameScript
|
||||||
public bool Triggered { get; set; } = false;
|
public bool Triggered { get; set; } = false;
|
||||||
public IMyDoor Door { get; private set; }
|
public IMyDoor Door { get; private set; }
|
||||||
|
|
||||||
public AirDoor(Program program, IMyDoor door)
|
public AirDoor(IMyDoor door)
|
||||||
{
|
{
|
||||||
Door = door;
|
Door = door;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ namespace IngameScript
|
||||||
|
|
||||||
public List<IMyAirVent> Vents { get; } = new List<IMyAirVent>();
|
public List<IMyAirVent> Vents { get; } = new List<IMyAirVent>();
|
||||||
|
|
||||||
private Program _program;
|
private IConsoleProgram _program;
|
||||||
|
|
||||||
// private List<IMyTextSurface> _displays = new List<IMyTextSurface>(); // TODO: add single-zone displays
|
// private List<IMyTextSurface> _displays = new List<IMyTextSurface>(); // TODO: add single-zone displays
|
||||||
private List<IMyLightingBlock> _lights = new List<IMyLightingBlock>();
|
private List<IMyLightingBlock> _lights = new List<IMyLightingBlock>();
|
||||||
|
@ -48,7 +48,7 @@ namespace IngameScript
|
||||||
|
|
||||||
private const float TriggerLevel = 0.75F;
|
private const float TriggerLevel = 0.75F;
|
||||||
|
|
||||||
public AirZone(Program program, string zoneName)
|
public AirZone(IConsoleProgram program, string zoneName)
|
||||||
{
|
{
|
||||||
Name = zoneName;
|
Name = zoneName;
|
||||||
_program = program;
|
_program = program;
|
||||||
|
|
|
@ -77,7 +77,7 @@ namespace IngameScript
|
||||||
|
|
||||||
else if (block is IMyDoor)
|
else if (block is IMyDoor)
|
||||||
{
|
{
|
||||||
AirDoor door = new AirDoor(this, block as IMyDoor);
|
AirDoor door = new AirDoor(block as IMyDoor);
|
||||||
_doors.Add(door);
|
_doors.Add(door);
|
||||||
foreach (string zone in zones) _zones[zone].AddDoor(door);
|
foreach (string zone in zones) _zones[zone].AddDoor(door);
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ namespace IngameScript
|
||||||
private const int CooldownTicks = 12;
|
private const int CooldownTicks = 12;
|
||||||
private const int SealTimeoutTicks = 30;
|
private const int SealTimeoutTicks = 30;
|
||||||
|
|
||||||
public Airlock(string name, Program _program)
|
public Airlock(string name, IConsoleProgram _program)
|
||||||
{
|
{
|
||||||
_ini = _program.Ini;
|
_ini = _program.Ini;
|
||||||
_name = name;
|
_name = name;
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
// Provides a Print() function that will both call MyGridProgram.Echo()
|
// Provides a Print() function that will both call MyGridProgram.Echo()
|
||||||
// and also output to the Programmable Block's LCD.
|
// and also output to the Programmable Block's LCD.
|
||||||
|
|
||||||
using Sandbox.Common.ObjectBuilders;
|
|
||||||
using Sandbox.ModAPI.Ingame;
|
using Sandbox.ModAPI.Ingame;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using VRage.Game.GUI.TextPanel;
|
using VRage.Game.GUI.TextPanel;
|
||||||
|
@ -11,18 +11,23 @@ using VRage.Game.ModAPI.Ingame.Utilities;
|
||||||
|
|
||||||
namespace IngameScript
|
namespace IngameScript
|
||||||
{
|
{
|
||||||
|
// To use this library, your Program class must implement this interface.
|
||||||
|
//
|
||||||
// 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
|
||||||
{
|
{
|
||||||
|
// Properties that should be defined by the implementer.
|
||||||
MyIni Ini { get; }
|
MyIni Ini { get; }
|
||||||
Program.IConsole Console { get; }
|
Program.IConsole Console { get; }
|
||||||
|
|
||||||
|
// Inherited properties that we need access to
|
||||||
IMyGridProgramRuntimeInfo Runtime { get; }
|
IMyGridProgramRuntimeInfo Runtime { get; }
|
||||||
|
IMyProgrammableBlock Me { get; }
|
||||||
|
Action<string> Echo { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
partial class Program
|
partial class Program
|
||||||
|
@ -41,13 +46,13 @@ namespace IngameScript
|
||||||
private List<string> _buffer = new List<string>();
|
private List<string> _buffer = new List<string>();
|
||||||
private StringBuilder _builder = new StringBuilder();
|
private StringBuilder _builder = new StringBuilder();
|
||||||
private int _tickCount = 0;
|
private int _tickCount = 0;
|
||||||
private Program _program;
|
private IConsoleProgram _program;
|
||||||
private string _programName;
|
private string _programName;
|
||||||
private int _maxLines = 10;
|
private int _maxLines = 10;
|
||||||
|
|
||||||
private const int DefaultMaxLines = 10;
|
private const int DefaultMaxLines = 10;
|
||||||
|
|
||||||
public MainConsole(Program program, string programName)
|
public MainConsole(IConsoleProgram program, string programName)
|
||||||
{
|
{
|
||||||
_program = program;
|
_program = program;
|
||||||
_programName = programName;
|
_programName = programName;
|
||||||
|
@ -57,7 +62,6 @@ namespace IngameScript
|
||||||
_program.Ini.TryParse(program.Me.CustomData);
|
_program.Ini.TryParse(program.Me.CustomData);
|
||||||
_maxLines = _program.Ini.Get("console", "maxLines").ToInt32(DefaultMaxLines);
|
_maxLines = _program.Ini.Get("console", "maxLines").ToInt32(DefaultMaxLines);
|
||||||
|
|
||||||
|
|
||||||
// Setup the block's screens
|
// Setup the block's screens
|
||||||
_program.Me.GetSurface(0).ContentType = ContentType.TEXT_AND_IMAGE;
|
_program.Me.GetSurface(0).ContentType = ContentType.TEXT_AND_IMAGE;
|
||||||
_program.Me.GetSurface(0).WriteText("Initializing...");
|
_program.Me.GetSurface(0).WriteText("Initializing...");
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace IngameScript
|
||||||
private IMyDoor _door;
|
private IMyDoor _door;
|
||||||
|
|
||||||
public SequenceableDoor(
|
public SequenceableDoor(
|
||||||
Program _program,
|
IConsoleProgram _program,
|
||||||
IMyDoor door,
|
IMyDoor door,
|
||||||
string sectionName)
|
string sectionName)
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace IngameScript
|
||||||
public class SequenceableFactory
|
public class SequenceableFactory
|
||||||
{
|
{
|
||||||
public static ISequenceable MakeSequenceable(
|
public static ISequenceable MakeSequenceable(
|
||||||
Program program,
|
IConsoleProgram program,
|
||||||
IMyTerminalBlock block,
|
IMyTerminalBlock block,
|
||||||
string sectionName = "sequence")
|
string sectionName = "sequence")
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,13 +12,13 @@ namespace IngameScript
|
||||||
public bool Running { get; private set; } = false;
|
public bool Running { get; private set; } = false;
|
||||||
public int Step { get; set; }
|
public int Step { get; set; }
|
||||||
|
|
||||||
private Program _program;
|
private IConsoleProgram _program;
|
||||||
private IMyPistonBase _piston;
|
private IMyPistonBase _piston;
|
||||||
private float _deployPosition;
|
private float _deployPosition;
|
||||||
private float _stowPosition;
|
private float _stowPosition;
|
||||||
private float _velocity;
|
private float _velocity;
|
||||||
|
|
||||||
public SequenceablePiston(Program program, IMyPistonBase piston, string sectionName)
|
public SequenceablePiston(IConsoleProgram program, IMyPistonBase piston, string sectionName)
|
||||||
{
|
{
|
||||||
_program = program;
|
_program = program;
|
||||||
_piston = piston;
|
_piston = piston;
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace IngameScript
|
||||||
public bool Running { get; private set; } = false;
|
public bool Running { get; private set; } = false;
|
||||||
public int Step { get; set; }
|
public int Step { get; set; }
|
||||||
|
|
||||||
private Program _program;
|
private IConsoleProgram _program;
|
||||||
private float _velocity;
|
private float _velocity;
|
||||||
private float _deployAngle;
|
private float _deployAngle;
|
||||||
private float _stowAngle;
|
private float _stowAngle;
|
||||||
|
@ -21,7 +21,7 @@ namespace IngameScript
|
||||||
private MyRotationDirection _stowDirection;
|
private MyRotationDirection _stowDirection;
|
||||||
|
|
||||||
public SequenceableRotor(
|
public SequenceableRotor(
|
||||||
Program program,
|
IConsoleProgram program,
|
||||||
IMyMotorStator rotor,
|
IMyMotorStator rotor,
|
||||||
string sectionName)
|
string sectionName)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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(Program program, string name)
|
public Sequencer(IConsoleProgram program, string name)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
_console = new PrefixedConsole(program.Console, Name);
|
_console = new PrefixedConsole(program.Console, Name);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user