First commit
This commit is contained in:
commit
1d890b728a
24 changed files with 1814 additions and 0 deletions
105
SECommon/Output.cs
Normal file
105
SECommon/Output.cs
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
using Sandbox.Game.EntityComponents;
|
||||
using Sandbox.ModAPI.Ingame;
|
||||
using Sandbox.ModAPI.Interfaces;
|
||||
|
||||
using SpaceEngineers.Game.ModAPI.Ingame;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using VRage;
|
||||
using VRage.Collections;
|
||||
using VRage.Game;
|
||||
using VRage.Game.Components;
|
||||
using VRage.Game.GUI.TextPanel;
|
||||
using VRage.Game.ModAPI.Ingame;
|
||||
using VRage.Game.ModAPI.Ingame.Utilities;
|
||||
using VRage.Game.ObjectBuilders.Definitions;
|
||||
|
||||
using VRageMath;
|
||||
|
||||
namespace IngameScript
|
||||
{
|
||||
class Output
|
||||
{
|
||||
IList<IMyTextSurface> outputs;
|
||||
int maxNbLines;
|
||||
|
||||
public Output(IList<IMyTextSurface> surfaces, int maxNbLines = 10)
|
||||
{
|
||||
foreach (var s in surfaces)
|
||||
{
|
||||
s.ContentType = ContentType.TEXT_AND_IMAGE;
|
||||
s.WriteText("");
|
||||
}
|
||||
|
||||
this.outputs = surfaces;
|
||||
this.maxNbLines = maxNbLines;
|
||||
}
|
||||
|
||||
public Output(IMyCockpit cockpit, int maxNbLines = 10)
|
||||
{
|
||||
this.outputs = new List<IMyTextSurface>();
|
||||
for (int n = 0; n < cockpit.SurfaceCount; n++)
|
||||
{
|
||||
var surface = cockpit.GetSurface(n);
|
||||
surface.ContentType = ContentType.TEXT_AND_IMAGE;
|
||||
surface.WriteText("");
|
||||
this.outputs.Add(surface);
|
||||
}
|
||||
this.maxNbLines = maxNbLines;
|
||||
}
|
||||
|
||||
public Output(IMyTextSurface surface, int maxNbLines = 10)
|
||||
: this(new List<IMyTextSurface> { surface }, maxNbLines)
|
||||
{ }
|
||||
|
||||
public void Print(string text, int outputNumber = 0)
|
||||
{
|
||||
if (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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
output.WriteText(Environment.NewLine + text, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintError(string text, int outputNumber = 0)
|
||||
{
|
||||
this.Print($"Error: {text}", outputNumber);
|
||||
}
|
||||
|
||||
|
||||
public void Display(string text, int outputNumber = 0)
|
||||
{
|
||||
if (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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
14
SECommon/SECommon.projitems
Normal file
14
SECommon/SECommon.projitems
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' < '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||
<HasSharedItems>true</HasSharedItems>
|
||||
<SharedGUID>9e97399c-4fe6-495b-aa87-acc2213647cd</SharedGUID>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration">
|
||||
<Import_RootNamespace>SECommon</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Output.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
13
SECommon/SECommon.shproj
Normal file
13
SECommon/SECommon.shproj
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>9e97399c-4fe6-495b-aa87-acc2213647cd</ProjectGuid>
|
||||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
|
||||
<PropertyGroup />
|
||||
<Import Project="SECommon.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
|
||||
</Project>
|
||||
Loading…
Add table
Add a link
Reference in a new issue