-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwitch.cpp
More file actions
40 lines (33 loc) · 759 Bytes
/
Switch.cpp
File metadata and controls
40 lines (33 loc) · 759 Bytes
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
//
// Created by iMer on 17.04.2016.
//
#include <iostream>
#include "Switch.hpp"
#include "MagicLight.hpp"
Switch::Switch(engine::Scene* scene): SpriteNode(scene), m_on(false) {
}
Switch::~Switch() {
}
bool Switch::initialize(Json::Value& root) {
if (!engine::SpriteNode::initialize(root)) {
return false;
}
m_target = root.get("target", "").asString();
return true;
}
void Switch::Flip() {
engine::Node* target = m_parent->GetChildByID(m_target);
switch (target->GetType()) {
case NT_MAGICLIGHT:
static_cast<MagicLight*>(target)->Toggle();
break;
default:
std::cerr << "Unknown target type for '"<< m_target << "'" << std::endl;
}
m_on = !m_on;
if (m_on) {
PlayAnimation("active");
} else {
PlayAnimation("default");
}
}