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:
@ -2,8 +2,8 @@
|
||||
// Provides a Print() function that will both call MyGridProgram.Echo()
|
||||
// and also output to the Programmable Block's LCD.
|
||||
|
||||
using Sandbox.Common.ObjectBuilders;
|
||||
using Sandbox.ModAPI.Ingame;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using VRage.Game.GUI.TextPanel;
|
||||
@ -11,18 +11,23 @@ using VRage.Game.ModAPI.Ingame.Utilities;
|
||||
|
||||
namespace IngameScript
|
||||
{
|
||||
// To use this library, your Program class must implement this interface.
|
||||
//
|
||||
// A Program that supports consoles by initializing a MyIni instance
|
||||
// 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,
|
||||
// but we can't find a cleaner way to implement this.)
|
||||
public interface IConsoleProgram
|
||||
{
|
||||
// Properties that should be defined by the implementer.
|
||||
MyIni Ini { get; }
|
||||
Program.IConsole Console { get; }
|
||||
|
||||
// Inherited properties that we need access to
|
||||
IMyGridProgramRuntimeInfo Runtime { get; }
|
||||
IMyProgrammableBlock Me { get; }
|
||||
Action<string> Echo { get; }
|
||||
}
|
||||
|
||||
partial class Program
|
||||
@ -41,13 +46,13 @@ namespace IngameScript
|
||||
private List<string> _buffer = new List<string>();
|
||||
private StringBuilder _builder = new StringBuilder();
|
||||
private int _tickCount = 0;
|
||||
private Program _program;
|
||||
private IConsoleProgram _program;
|
||||
private string _programName;
|
||||
private int _maxLines = 10;
|
||||
|
||||
private const int DefaultMaxLines = 10;
|
||||
|
||||
public MainConsole(Program program, string programName)
|
||||
public MainConsole(IConsoleProgram program, string programName)
|
||||
{
|
||||
_program = program;
|
||||
_programName = programName;
|
||||
@ -57,7 +62,6 @@ namespace IngameScript
|
||||
_program.Ini.TryParse(program.Me.CustomData);
|
||||
_maxLines = _program.Ini.Get("console", "maxLines").ToInt32(DefaultMaxLines);
|
||||
|
||||
|
||||
// Setup the block's screens
|
||||
_program.Me.GetSurface(0).ContentType = ContentType.TEXT_AND_IMAGE;
|
||||
_program.Me.GetSurface(0).WriteText("Initializing...");
|
||||
|
@ -18,7 +18,7 @@ namespace IngameScript
|
||||
private IMyDoor _door;
|
||||
|
||||
public SequenceableDoor(
|
||||
Program _program,
|
||||
IConsoleProgram _program,
|
||||
IMyDoor door,
|
||||
string sectionName)
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ namespace IngameScript
|
||||
public class SequenceableFactory
|
||||
{
|
||||
public static ISequenceable MakeSequenceable(
|
||||
Program program,
|
||||
IConsoleProgram program,
|
||||
IMyTerminalBlock block,
|
||||
string sectionName = "sequence")
|
||||
{
|
||||
|
@ -12,13 +12,13 @@ namespace IngameScript
|
||||
public bool Running { get; private set; } = false;
|
||||
public int Step { get; set; }
|
||||
|
||||
private Program _program;
|
||||
private IConsoleProgram _program;
|
||||
private IMyPistonBase _piston;
|
||||
private float _deployPosition;
|
||||
private float _stowPosition;
|
||||
private float _velocity;
|
||||
|
||||
public SequenceablePiston(Program program, IMyPistonBase piston, string sectionName)
|
||||
public SequenceablePiston(IConsoleProgram program, IMyPistonBase piston, string sectionName)
|
||||
{
|
||||
_program = program;
|
||||
_piston = piston;
|
||||
|
@ -12,7 +12,7 @@ namespace IngameScript
|
||||
public bool Running { get; private set; } = false;
|
||||
public int Step { get; set; }
|
||||
|
||||
private Program _program;
|
||||
private IConsoleProgram _program;
|
||||
private float _velocity;
|
||||
private float _deployAngle;
|
||||
private float _stowAngle;
|
||||
@ -21,7 +21,7 @@ namespace IngameScript
|
||||
private MyRotationDirection _stowDirection;
|
||||
|
||||
public SequenceableRotor(
|
||||
Program program,
|
||||
IConsoleProgram program,
|
||||
IMyMotorStator rotor,
|
||||
string sectionName)
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ namespace IngameScript
|
||||
|
||||
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;
|
||||
_console = new PrefixedConsole(program.Console, Name);
|
||||
|
Reference in New Issue
Block a user