game/mario/editor_visitor.cpp
zvon 94d24e37fa
Some checks failed
continuous-integration/drone/push Build is failing
Playing around with buttons
2022-06-22 21:42:57 +02:00

133 lines
3.8 KiB
C++

#include "editor_visitor.hpp"
#include "../sdlpp/sdlpp_renderobject.hpp"
#include "blocks.hpp"
#include "objectids.hpp"
#include "edit_box.hpp"
#include "tool_box.hpp"
#include <memory>
#define SELECTED_LEFT_MAP 0x00000001
#define SELECTED_RIGHT_MAP 0x00000002
#define SELECTED_REMOVE_BLOCK 0x00000004
#define SELECTED_REMOVE_MODIFIER 0x00000008
#define SELECTED_RIGHT_TOOL 0x00000010
#define SELECTED_LEFT_TOOL 0x00000020
#define SELECTED_RIGHT_MOD 0x00000040
#define SELECTED_LEFT_MOD 0x00000080
#define SELECTED_RIGHT_CHARACTER 0x00000100
#define SELECTED_LEFT_CHARACTER 0x00000200
#define SELECTED_BUTTON 0x00000400
void MouseVisitor::visit(const SDLPP::RenderObject &obj) {
auto id = obj.getId();
switch (id) {
case EDITOR_LEFT_MAP_ID:
select_flags |= SELECTED_LEFT_MAP;
break;
case EDITOR_RIGHT_MAP_ID:
select_flags |= SELECTED_RIGHT_MAP;
break;
case EDITOR_LEFT_TOOL_ID:
select_flags |= SELECTED_LEFT_TOOL;
break;
case EDITOR_RIGHT_TOOL_ID:
select_flags |= SELECTED_RIGHT_TOOL;
break;
case EDITOR_LEFT_MOD_ID:
select_flags |= SELECTED_LEFT_MOD;
break;
case EDITOR_RIGHT_MOD_ID:
select_flags |= SELECTED_RIGHT_MOD;
break;
case EDITOR_LEFT_CHARACTER_ID:
select_flags |= SELECTED_LEFT_CHARACTER;
break;
case EDITOR_RIGHT_CHARACTER_ID:
select_flags |= SELECTED_RIGHT_CHARACTER;
break;
case EDITOR_EDIT_SQUARE:
edit_box = true;
edit_box_location = dynamic_cast<const EditBox &>(obj).getIndexes();
break;
case EDITOR_TOOL_ID:
tool_box = true;
tool_box_location = dynamic_cast<const ToolBox &>(obj).getIndexes();
tool_box_type = dynamic_cast<const ToolBox &>(obj).getType();
break;
case BUTTON_ID:
select_flags |= SELECTED_BUTTON;
cur_button = reinterpret_cast<const Button*>(&obj)->getButtonIndex();
break;
default:
break;
}
}
bool MouseVisitor::moveMapLeft(uint64_t flags) {
return flags & SELECTED_LEFT_MAP;
}
bool MouseVisitor::moveMapRight(uint64_t flags) {
return flags & SELECTED_RIGHT_MAP;
}
bool MouseVisitor::moveToolsLeft(uint64_t flags) {
return flags & SELECTED_LEFT_TOOL;
}
bool MouseVisitor::moveToolsRight(uint64_t flags) {
return flags & SELECTED_RIGHT_TOOL;
}
bool MouseVisitor::moveModsLeft(uint64_t flags) {
return flags & SELECTED_LEFT_MOD;
}
bool MouseVisitor::moveModsRight(uint64_t flags) {
return flags & SELECTED_RIGHT_MOD;
}
bool MouseVisitor::moveCharactersLeft(uint64_t flags) {
return flags & SELECTED_LEFT_CHARACTER;
}
bool MouseVisitor::moveCharactersRight(uint64_t flags) {
return flags & SELECTED_RIGHT_CHARACTER;
}
bool MouseVisitor::button(uint64_t flags) {
return flags & SELECTED_BUTTON;
}
void ToolVisitor::visit(const SDLPP::RenderObject &obj) {
auto id = obj.getCollisions()[0]->getId();
switch (id) {
case EDITOR_TERRAIN_ID: {
const auto &m_obj = dynamic_cast<const MarioBlock &>(obj);
remove_block = true;
if (obj.getId() == source_id &&
((m_obj.getType() == source_type &&
getVisitorType() == VisitorType::Terrain) ||
(m_obj.getData() == _data &&
getVisitorType() == VisitorType::Modifier))) {
add_block = false;
}
} break;
case EDITOR_CHARACTER_ID: {
const auto &m_obj = dynamic_cast<const MarioBlock &>(obj);
remove_block = true;
if (obj.getId() == source_id && m_obj.getType() == source_type &&
getVisitorType() == VisitorType::Character) {
add_block = false;
}
}
default:
break;
}
}
bool ToolVisitor::addBlock() const {
return add_block;
}
bool ToolVisitor::removeBlock() const {
return remove_block;
}