Skip to content

Commit

Permalink
Add text surface provider support to lcd registration command
Browse files Browse the repository at this point in the history
  • Loading branch information
baratgabor committed Oct 27, 2020
1 parent dda456b commit 4be257a
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/GridOS/Core/GridOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,38 @@ private void TryExecuteCustomData(string customData)
}
}

// TODO: GridOS class shouldn't contain low-level logic, move this somewhere else.
private void CommandHandler_AddLcd(CommandItem sender, string param)
{
IMyTerminalBlock textSurface = _p.GridTerminalSystem.GetBlockWithName(param);
if ((textSurface == null) || !(textSurface is IMyTextSurface))
int surfaceIndex = 0;

{ // Extract optional surface index
int delimiter = param.IndexOf(' ');
if (delimiter > -1)
{
if (int.TryParse(
param.Substring(delimiter + 1, param.Length - (delimiter + 1)), out surfaceIndex))
{
surfaceIndex = Math.Max(0,
int.Parse(param.Substring(delimiter + 1, param.Length - (delimiter + 1)))
- 1);
}

param = param.Substring(0, delimiter);
}
}

IMyTerminalBlock target = _p.GridTerminalSystem.GetBlockWithName(param);

if (target == null)
return;

RegisterTextSurface(textSurface as IMyTextSurface);
if (target is IMyTextSurface)
RegisterTextSurface((IMyTextSurface)target);

if (target is IMyTextSurfaceProvider)
RegisterTextSurface(
((IMyTextSurfaceProvider)target).GetSurface(surfaceIndex));
}

private void CommandHandler_DisableUpdates(CommandItem sender, string param)
Expand Down

0 comments on commit 4be257a

Please sign in to comment.