#include "clue_finder.h" #include "scene/3d/xr/xr_nodes.h" #include "ydi_client.h" #include "you_done_it/client_node.h" #include "you_done_it/clue_db.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(); } if (XRController3D * controller{ cast_to(get_parent()) }) { controller->connect("button_pressed", callable_mp(this, &self_type::on_button_pressed)); } } void ClueFinder::exit_tree() { if (singleton_instance == this) { singleton_instance = nullptr; } } void ClueFinder::on_button_pressed(String button) { if (button == "trigger_click") { take_photo(); } } 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::remove_clue_marker(ClueMarker *marker) { this->clue_markers.erase(marker); } void ClueFinder::take_photo() { print_line("TAKING PHOTO"); if (ClueMarker * found{ find_current_clue() }) { found->reveal(); print_line("FOUND MARKER: ", found->get_path()); } }