-
Notifications
You must be signed in to change notification settings - Fork 0
/
diodeblock.cpp
46 lines (38 loc) · 1.04 KB
/
diodeblock.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "diodeblock.h"
#include "robotgame.h"
DiodeBlock::DiodeBlock(const DiodeBlock& other) : Block(other)
{
this->state = other.state;
}
std::string DiodeBlock::GetDescription()
{
return "Diode block. Any non-zero value at its input turns it on, zero value turns it off.";
}
std::shared_ptr<olc::Sprite> DiodeBlock::GetDefaultSprite()
{
return this->sm->GetSprite("diode_off");
}
DiodeBlock* DiodeBlock::Clone()
{
return new DiodeBlock(*this);
}
void DiodeBlock::Update(float timedelta)
{
Block::Update(timedelta);
auto s = this->ports["diode_val"]->GetData();
if (std::holds_alternative<bool>(s))
this->state = std::get<bool>(s);
else if (std::holds_alternative<int64_t>(s))
this->state = std::get<int64_t>(s) != 0;
else if (std::holds_alternative<double>(s))
this->state = std::get<double>(s) != 0.0;
if (this->state)
this->SetSprite("diode_on");
else
this->SetSprite("diode_off");
}
void DiodeBlock::Stop()
{
this->state = false;
this->SetSprite("diode_off");
}