95 lines
3.4 KiB
C#
95 lines
3.4 KiB
C#
using System;
|
|
using Gamecraft.Wires;
|
|
using TechbloxModdingAPI;
|
|
using TechbloxModdingAPI.Commands;
|
|
using TechbloxModdingAPI.Utility;
|
|
|
|
namespace BuildingTools
|
|
{
|
|
public class CommandUtils
|
|
{
|
|
private readonly BlockSelections _blockSelections;
|
|
|
|
public CommandUtils(BlockSelections blockSelections)
|
|
{
|
|
_blockSelections = blockSelections;
|
|
}
|
|
|
|
private void RegisterBlockCommandInternal(string name, string desc, Action<string, Block[], Block> action)
|
|
{
|
|
CommandBuilder.Builder(name, desc).Action<string>(a1 =>
|
|
{
|
|
action(a1, _blockSelections.blocks, _blockSelections.refBlock);
|
|
}).Build();
|
|
}
|
|
|
|
public void RegisterBlockCommand(string name, string desc, Action<float, float, float, Block[], Block> action)
|
|
{
|
|
RegisterBlockCommandInternal(name, desc, (args, bs, b) =>
|
|
{
|
|
var argsa = args.Split(' ');
|
|
if (argsa.Length < 3)
|
|
{
|
|
Logging.CommandLogError("Too few arguments. Needed arguments are: <x> <y> <z> and [id] is optional.");
|
|
return;
|
|
}
|
|
|
|
if (!float.TryParse(argsa[0], out float x) || !float.TryParse(argsa[1], out float y) ||
|
|
!float.TryParse(argsa[2], out float z))
|
|
{
|
|
Logging.CommandLogError("Could not parse arguments as floats.");
|
|
return;
|
|
}
|
|
|
|
if (argsa.Length > 3)
|
|
{
|
|
if (argsa[3].Length == 0)
|
|
{
|
|
Logging.CommandLogError("Missing object ID.");
|
|
return;
|
|
}
|
|
|
|
var blocks = _blockSelections.SelectBlocks(argsa[3][0]);
|
|
if (_blockSelections.CheckNoBlocks(blocks)) return;
|
|
action(x, y, z, blocks, blocks[0]);
|
|
}
|
|
else if (!_blockSelections.CheckNoBlocks(bs))
|
|
action(x, y, z, bs, b);
|
|
});
|
|
}
|
|
|
|
public void RegisterBlockCommand(string name, string desc, Action<string, byte, Block[], Block> action)
|
|
{
|
|
RegisterBlockCommandInternal(name, desc, (args, bs, b) =>
|
|
{
|
|
var argsa = args.Split(' ');
|
|
if (argsa.Length < 2)
|
|
{
|
|
Logging.CommandLogError("Too few arguments. Needed arguments are: <color> <darkness> and [id] is optional.");
|
|
return;
|
|
}
|
|
|
|
if (!byte.TryParse(argsa[1], out byte darkness))
|
|
{
|
|
Logging.CommandLogError("Could not parse color darkness.");
|
|
return;
|
|
}
|
|
|
|
if (argsa.Length > 2)
|
|
{
|
|
if (argsa[2].Length == 0)
|
|
{
|
|
Logging.CommandLogError("Missing channel.");
|
|
return;
|
|
}
|
|
|
|
var blocks = _blockSelections.SelectBlocks(argsa[2][0]);
|
|
if (_blockSelections.CheckNoBlocks(blocks)) return;
|
|
action(argsa[0], darkness, blocks, blocks[0]);
|
|
}
|
|
else if(!_blockSelections.CheckNoBlocks(bs))
|
|
action(argsa[0], darkness, bs, b);
|
|
});
|
|
}
|
|
}
|
|
} |