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...");
|
||||
|
Reference in New Issue
Block a user