#include "level_end.h" #include "break_utopia/level_status.h" #include "break_utopia/player_body.h" #include "core/config/engine.h" #include "core/error/error_macros.h" #include "scene/main/scene_tree.h" void LevelResult::_bind_methods() { BIND_PROPERTY(Variant::INT, style); BIND_PROPERTY(Variant::INT, score); BIND_PROPERTY(Variant::INT, destroyed); BIND_PROPERTY(Variant::INT, total_objects); BIND_HPROPERTY(Variant::OBJECT, next_level, PROPERTY_HINT_RESOURCE_TYPE, "PackedScene"); } void LevelResult::store_current_state() { ERR_FAIL_COND_EDMSG(!LevelStatus::get_instance(), "attempt to store current level status with no extant instance"); LevelStatus *status{ LevelStatus::get_instance() }; this->style = (int)Math::floor(status->get_style()); this->score = status->get_score(); } void LevelEnd::_bind_methods() { BIND_HPROPERTY(Variant::OBJECT, intermission_screen, PROPERTY_HINT_RESOURCE_TYPE, "PackedScene"); } void LevelEnd::body_entered(Node *body) { if (cast_to(body) != nullptr) { Node *scene{ this->intermission_screen->instantiate() }; Ref result{ memnew(LevelResult) }; result->store_current_state(); if (IntermissionScreen * intermission{ cast_to(scene->get_node(NodePath("%IntermissionScreen"))) }) { intermission->set_result(result); } callable_mp(get_tree(), &SceneTree::change_scene_to_node).call_deferred(scene); } } void LevelEnd::_notification(int what) { if (Engine::get_singleton()->is_editor_hint()) { return; } switch (what) { default: return; case NOTIFICATION_READY: connect("body_entered", callable_mp(this, &self_type::body_entered)); return; } } void IntermissionScreen::_bind_methods() { BIND_HPROPERTY(Variant::OBJECT, result, PROPERTY_HINT_RESOURCE_TYPE, "LevelResult"); }