- Add an extension method to get all inventories.
- Update README and TODO
This commit is contained in:
parent
16040e5f5a
commit
169719ba4b
5 changed files with 135 additions and 28 deletions
|
|
@ -26,8 +26,8 @@ namespace IngameScript
|
|||
{
|
||||
class Output
|
||||
{
|
||||
IList<IMyTextSurface> outputs;
|
||||
int maxNbLines;
|
||||
readonly IList<IMyTextSurface> outputs;
|
||||
readonly int maxNbLines;
|
||||
|
||||
public Output(IList<IMyTextSurface> surfaces, int maxNbLines = 10)
|
||||
{
|
||||
|
|
@ -58,29 +58,41 @@ namespace IngameScript
|
|||
: this(new List<IMyTextSurface> { surface }, maxNbLines)
|
||||
{ }
|
||||
|
||||
public void Print(string text, int outputNumber = 0)
|
||||
public void Print(string text, int outputNumber = -1)
|
||||
{
|
||||
if (this.outputs.Count() <= outputNumber)
|
||||
if (outputNumber >= 0 && this.outputs.Count() <= outputNumber)
|
||||
{
|
||||
throw new Exception($"Output number {outputNumber} doesn't exist (number of output: {this.outputs.Count()}");
|
||||
}
|
||||
else
|
||||
{
|
||||
var output = this.outputs[outputNumber];
|
||||
var currentText = output.GetText();
|
||||
var lines = currentText.Split('\n');
|
||||
if (lines.Count() >= this.maxNbLines)
|
||||
if (outputNumber == -1)
|
||||
{
|
||||
output.WriteText(lines.Skip(lines.Count() - this.maxNbLines + 1).Append(text).Aggregate((a, b) => a + Environment.NewLine + b));
|
||||
}
|
||||
else if (lines.Count() == 0)
|
||||
{
|
||||
output.WriteText(text);
|
||||
foreach (var output in this.outputs)
|
||||
this.Print(text, output);
|
||||
}
|
||||
else
|
||||
{
|
||||
output.WriteText(Environment.NewLine + text, true);
|
||||
}
|
||||
this.Print(text, this.outputs[outputNumber]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Print(string text, IMyTextSurface surface)
|
||||
{
|
||||
var currentText = surface.GetText();
|
||||
var lines = currentText.Split('\n');
|
||||
if (lines.Count() >= this.maxNbLines)
|
||||
{
|
||||
surface.WriteText(lines.Skip(lines.Count() - this.maxNbLines + 1).Append(text).Aggregate((a, b) => a + Environment.NewLine + b));
|
||||
}
|
||||
else if (lines.Count() == 0)
|
||||
{
|
||||
surface.WriteText(text);
|
||||
}
|
||||
else
|
||||
{
|
||||
surface.WriteText(Environment.NewLine + text, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -90,15 +102,24 @@ namespace IngameScript
|
|||
}
|
||||
|
||||
|
||||
public void Display(string text, int outputNumber = 0)
|
||||
public void Display(string text, int outputNumber = -1)
|
||||
{
|
||||
if (this.outputs.Count() <= outputNumber)
|
||||
if (outputNumber >= 0 && this.outputs.Count() <= outputNumber)
|
||||
{
|
||||
throw new Exception($"Output number {outputNumber} doesn't exist (number of output: {this.outputs.Count()}");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.outputs[outputNumber].WriteText(text);
|
||||
if (outputNumber == -1)
|
||||
{
|
||||
foreach (var output in this.outputs)
|
||||
output.WriteText(text);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.outputs[outputNumber].WriteText(text);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue