51 lines
1.2 KiB
D
51 lines
1.2 KiB
D
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;
|
|
|
|
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)
|
|
{
|
|
s ~= "[slot " ~ i.to!string ~ "] " ~ typeof(onCommands[i]).stringof
|
|
~ " " ~ typeof(offCommands[i]).stringof ~ "\n";
|
|
}
|
|
|
|
return s;
|
|
}
|
|
}
|