#include "clue_finder.h" #include "ydi_client.h" #include "you_done_it/client_node.h" #include #include ClueFinder *ClueFinder::singleton_instance{ nullptr }; void ClueFinder::_bind_methods() { ClassDB::bind_method(D_METHOD("take_photo"), &ClueFinder::take_photo); } void ClueFinder::enter_tree() { if (singleton_instance == nullptr) { singleton_instance = this; } else { queue_free(); } } void ClueFinder::exit_tree() { if (singleton_instance == this) { singleton_instance = nullptr; } } void ClueFinder::_notification(int what) { if (Engine::get_singleton()->is_editor_hint()) { return; } switch (what) { case NOTIFICATION_ENTER_TREE: enter_tree(); return; case NOTIFICATION_EXIT_TREE: exit_tree(); return; default: return; } } ClueFinder *ClueFinder::get_singleton() { return singleton_instance; } ClueMarker *ClueFinder::find_current_clue() { for (ClueMarker *marker : this->clue_markers) { if (marker->is_visible()) { return marker; } } return nullptr; } void ClueFinder::register_clue_marker(ClueMarker *marker) { this->clue_markers.insert(marker); } void ClueFinder::take_photo() { if (ClueMarker * found{ find_current_clue() }) { ClientNode::get_singleton()->get_clue(found->get_clue_id())->reveal(); } }