diff --git a/godot/Main.tscn b/godot/Main.tscn index 2b91627..06271a1 100644 --- a/godot/Main.tscn +++ b/godot/Main.tscn @@ -1,9 +1,7 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://Main.gdns" type="Script" id=1] [ext_resource path="res://levels/Level2.tscn" type="PackedScene" id=2] -[ext_resource path="res://monitor/Monitor.tscn" type="PackedScene" id=3] -[ext_resource path="res://shaders/crt/crt.tscn" type="PackedScene" id=4] [node name="Main" type="Node"] pause_mode = 2 @@ -12,7 +10,3 @@ level = ExtResource( 2 ) [node name="Level" type="Node" parent="."] pause_mode = 1 - -[node name="Monitor" parent="." instance=ExtResource( 3 )] - -[node name="CRT" parent="." instance=ExtResource( 4 )] diff --git a/godot/monitor/Monitor.gd b/godot/monitor/Monitor.gd index e8ae1b7..62dd86e 100644 --- a/godot/monitor/Monitor.gd +++ b/godot/monitor/Monitor.gd @@ -1,6 +1,9 @@ extends Node +signal monitor_loaded() + + export var monitor_enabled: bool = false export var development_url: String = "http://localhost:4050/api/v1" var url_real: String = "https://alai.cromer.cl/api/v1" @@ -101,6 +104,7 @@ func _physics_process(_delta: float) -> void: if monitor_enabled: if has_node("MonitorGUI") and not $MonitorGUI.visible: $MonitorGUI.visible = true + emit_signal("monitor_loaded") if started and not get_tree().paused: var frame = empty_frame.duplicate(true) diff --git a/src/Main.cpp b/src/Main.cpp index 4ade70b..17f9051 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -9,11 +9,13 @@ void Main::_register_methods() { register_method("_ready", &Main::_ready); register_method("_physics_process", &Main::_physics_process); + register_method("_on_monitor_loaded", &Main::_on_monitor_loaded); register_property("game_version", &Main::set_game_version, &Main::get_game_version, String(main::game_version.c_str())); register_property>("level", &Main::set_level, &Main::get_level, NULL, GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, String("PackedScene")); register_property("full_screen", &Main::set_full_screen, &Main::get_full_screen, main::full_screen); register_property("window_size", &Main::set_window_size, &Main::get_window_size, main::window_size); register_property("launch_screen", &Main::set_launch_screen, &Main::get_launch_screen, main::launch_screen); + register_signal
("monitor_loaded"); } Main::Main() @@ -28,6 +30,8 @@ void Main::_init() { _os = OS::get_singleton(); _input = Input::get_singleton(); + _project_settings = ProjectSettings::get_singleton(); + _resource_loader = ResourceLoader::get_singleton(); game_version = String(main::game_version.c_str()); full_screen = main::full_screen; @@ -37,7 +41,32 @@ void Main::_init() void Main::_ready() { - get_tree()->set_pause(true); + auto success = _project_settings->load_resource_pack("monitor.pck"); + if (success) + { + // Load monitor from pck + Godot::print("Monitor pck found, loading..."); + Ref monitor_scene = _resource_loader->load("res://monitor/Monitor.tscn"); + add_child(monitor_scene->instance()); + auto monitor = get_node("Monitor"); + monitor->connect("monitor_loaded", this, "_on_monitor_loaded"); + get_tree()->set_pause(true); + } + else if (_resource_loader->exists("res://monitor/Monitor.tscn")) + { + // Load monitor from alai's pck + Ref monitor_scene = _resource_loader->load("res://monitor/Monitor.tscn"); + add_child(monitor_scene->instance()); + auto monitor = get_node("Monitor"); + monitor->connect("monitor_loaded", this, "_on_monitor_loaded"); + get_tree()->set_pause(true); + } + else + { + // There is no monitor included + _on_monitor_loaded(); + } + if (get_full_screen()) { _os->set_window_fullscreen(true); @@ -50,9 +79,30 @@ void Main::_ready() ); } + success = _project_settings->load_resource_pack("crt.pck"); + if (success) + { + // Load crt from pck + Godot::print("CRT pck found, loading..."); + Ref crt_scene = _resource_loader->load("res://shaders/crt/crt.tscn"); + add_child(crt_scene->instance()); + } + else if (_resource_loader->exists("res://shaders/crt/crt.tscn")) + { + // Load crt from alai's pck + Ref crt_scene = _resource_loader->load("res://shaders/crt/crt.tscn"); + add_child(crt_scene->instance()); + } +} + +void Main::_on_monitor_loaded() { if (level != NULL) { - get_node("Level")->add_child(level->instance()); + auto path = level->get_path(); + Ref level_scene = _resource_loader->load(path); + auto loaded_level = level_scene->instance(); + connect("monitor_loaded", loaded_level, "_on_monitor_loaded"); + get_node("Level")->add_child(loaded_level); } } diff --git a/src/Main.h b/src/Main.h index b9270a9..5e8cfee 100644 --- a/src/Main.h +++ b/src/Main.h @@ -8,6 +8,8 @@ #include #include #include +#include +#include /** * @brief This is the godot namespace for all the code included in the library. @@ -64,6 +66,16 @@ namespace godot * */ Input *_input; + /** + * @brief ProjectSettings singleton. + * + */ + ProjectSettings *_project_settings; + /** + * @brief ResourceLoader singleton. + * + */ + ResourceLoader *_resource_loader; /** * @brief The first level to load @@ -204,6 +216,8 @@ namespace godot * @return int8_t The launch screen. */ int8_t get_launch_screen(); + + void _on_monitor_loaded(); }; } } diff --git a/src/player/Player.cpp b/src/player/Player.cpp index 70b2a81..4c3fab7 100644 --- a/src/player/Player.cpp +++ b/src/player/Player.cpp @@ -19,6 +19,7 @@ void Player::_register_methods() register_method("set_velocity", &Player::set_velocity); register_method("get_velocity", &Player::get_velocity); register_method("_on_player_touched", &Player::_on_player_touched); + register_method("_on_monitor_loaded", &Player::_on_monitor_loaded); //register_property>("sprite_frames", &Player::set_sprite_frames, &Player::get_sprite_frames, Ref(), GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, String("SpriteFrames")); register_property("speed", &Player::set_speed, &Player::get_speed, player::speed); register_property("jump_force", &Player::set_jump_force, &Player::get_jump_force, player::jump_force); @@ -77,7 +78,9 @@ void Player::_ready() { WARN_PRINT("Middleground not found!"); } +} +void Player::_on_monitor_loaded() { auto object_node = get_tree()->get_root()->get_node("Main")->find_node("Monitor", true); if (object_node != nullptr) { diff --git a/src/player/Player.h b/src/player/Player.h index cde3e9f..ee505a0 100644 --- a/src/player/Player.h +++ b/src/player/Player.h @@ -280,6 +280,8 @@ namespace godot * */ void _on_player_touched(); + + void _on_monitor_loaded(); }; } }