2022-11-15 13:51:22 +00:00
|
|
|
module command.remote.remotecontrol;
|
|
|
|
|
|
|
|
import command.remote.command;
|
|
|
|
import command.remote.nocommand;
|
|
|
|
import std.conv : to;
|
|
|
|
import std.stdio : writeln;
|
|
|
|
import std.algorithm.mutation : fill;
|
2022-11-15 19:11:46 +00:00
|
|
|
import std.array : split, back;
|
|
|
|
import std.format;
|
2022-11-15 13:51:22 +00:00
|
|
|
|
|
|
|
class RemoteControl
|
|
|
|
{
|
|
|
|
Command[] onCommands;
|
|
|
|
Command[] offCommands;
|
|
|
|
|
|
|
|
this()
|
|
|
|
{
|
|
|
|
onCommands = new Command[7];
|
|
|
|
offCommands = new Command[7];
|
|
|
|
Command noCommand = new NoCommand();
|
|
|
|
fill(onCommands, noCommand);
|
|
|
|
fill(offCommands, noCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setCommand(int slot, Command onCommand, Command offCommand)
|
|
|
|
{
|
|
|
|
onCommands[slot] = onCommand;
|
|
|
|
offCommands[slot] = offCommand;
|
|
|
|
}
|
|
|
|
|
|
|
|
void onButtonWasPressed(int slot)
|
|
|
|
{
|
|
|
|
onCommands[slot].execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
void offButtonWasPressed(int slot)
|
|
|
|
{
|
|
|
|
offCommands[slot].execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
override string toString() const
|
|
|
|
{
|
|
|
|
string s = "\n------ Remote Control -------\n";
|
|
|
|
for (int i = 0; i < 7; ++i)
|
|
|
|
{
|
2022-11-15 19:11:46 +00:00
|
|
|
s ~= "[slot " ~ i.to!string ~ "] "
|
|
|
|
~ format("%22s", (cast(Object)onCommands[i]).classinfo.name.split(".").back())
|
|
|
|
~ format("%23s", (cast(Object)offCommands[i]).classinfo.name.split(".").back())
|
|
|
|
~ "\n";
|
2022-11-15 13:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|