OSCCollar/OSCCollar/ConsoleOutput.cs
2024-01-02 18:33:41 +01:00

111 lines
4.2 KiB
C#

using Spectre.Console;
namespace VRC_Console;
public partial class OSCCollar
{
private const byte CoordinateSystemSize = 16;
private void SetupConsoleOutput()
{
Layout layout = new Layout().SplitRows(
new Layout("Top"),
new Layout("Bottom").SplitColumns(
new Layout("Config-Values"),
new Layout("Variable-Values"),
new Layout("Position")
));
Table configTable = new Table();
configTable.AddColumn("ConVar");
configTable.AddColumn("Value");
configTable.AddRow("IP", this._config.Ip);
configTable.AddRow("Send-Osc-Port", this._config.PortSend.ToString());
configTable.AddRow("Receive-Osc-Port", _portReceive.ToString());
configTable.AddRow("HTTP-Port", this.OscQueryService?.TcpPort.ToString() ?? "");
Table variableTable = new Table();
variableTable.AddColumn("OscVar");
variableTable.AddColumn("Value");
layout["Top"].Update(new FigletText(FigletFont.Load("Alligator.flf"), "OSC Collar").LeftJustified());
layout["Config-Values"].Update(configTable);
layout["Variable-Values"].Update(variableTable);
layout["Position"].Update(new Panel(new Text(GetCoordinateSystem())));
variableTable.AddRow("Status", $"{(_allowMoving ? "enabled" : "disabled")}");
variableTable.AddRow("GPS 1", $"{_gps1.Distance:00.00000}");
variableTable.AddRow("GPS 2", $"{_gps2.Distance:00.00000}");
variableTable.AddRow("GPS 3", $"{_gps3.Distance:00.00000}");
variableTable.AddRow("Position Vector", $"{_unitVectorLeash}");
variableTable.AddRow("Leash Stretch", $"{_leashStretch:0.00000}");
variableTable.AddRow("Movement Vector", $"{_movementVector}");
AnsiConsole.Live(layout).StartAsync(async displayContext =>
{
while (true)
{
variableTable.Rows.Update(0, 1, new Text($"{(_allowMoving ? "enabled" : "disabled")}"));
variableTable.Rows.Update(1, 1, new Text($"{_gps1.Distance:00.00000}"));
variableTable.Rows.Update(2, 1, new Text($"{_gps2.Distance:00.00000}"));
variableTable.Rows.Update(3, 1, new Text($"{_gps3.Distance:00.00000}"));
variableTable.Rows.Update(4, 1, new Text($"{_unitVectorLeash}"));
variableTable.Rows.Update(5, 1, new Text($"{_leashStretch:0.00000}"));
variableTable.Rows.Update(6, 1, new Text($"{_movementVector}"));
layout["Position"].Update(new Panel(new Text(GetCoordinateSystem())));
displayContext.Refresh();
await Task.Delay(100);
}
});
}
private String GetCoordinateSystem()
{
string system = "";
byte width = CoordinateSystemSize;
byte height = CoordinateSystemSize / 2;
int positionX = Convert.ToInt32(Math.Floor(_unitVectorLeash.X * (width / 2.0))) + (width / 2);
int positionY = Convert.ToInt32(-Math.Floor(_unitVectorLeash.Y * (height / 2.0))) + (height / 2);
int movementX = Convert.ToInt32(Math.Floor(_movementVector.X * (width / 2.0))) + (width / 2);
int movementY = Convert.ToInt32(-Math.Floor(_movementVector.Y * (height / 2.0))) + (height / 2);
for (int y = 0; y <= height; y++)
{
for (int x = 0; x <= width; x++)
{
if (x == movementX && y == movementY)
{
system += "x";
continue;
}
if (x == positionX && y == positionY)
{
system += "x";
continue;
}
if (y == height / 2)
{
if (x == width / 2)
system += "+";
else
system += "-";
}
else
{
if (x == width / 2)
system += "|";
else
system += " ";
}
}
if (y != height)
system += "\n";
}
return system;
}
}