From 8e5c035675764b466a0005486f2056a5a46b2130 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sun, 14 Aug 2022 12:42:49 -0400 Subject: [PATCH 1/7] fix monitor bug where player info wasn't being sent --- godot/monitor/Monitor.gd | 1 + 1 file changed, 1 insertion(+) diff --git a/godot/monitor/Monitor.gd b/godot/monitor/Monitor.gd index db4232a..e8ae1b7 100644 --- a/godot/monitor/Monitor.gd +++ b/godot/monitor/Monitor.gd @@ -129,6 +129,7 @@ func _on_input_validated(validated_player: Dictionary) -> void: $MonitorGUI.queue_free() get_tree().paused = false player = validated_player.duplicate(true) + game["player"] = player func _object_created(name: String, state: String, position: Vector2, velocity: Vector2) -> void: From 0000cd114c07d2fd09194928b0a31afea76d2e96 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sun, 14 Aug 2022 12:43:25 -0400 Subject: [PATCH 2/7] add default player info for quicker development --- godot/monitor/GUI.tscn | 4 +++- godot/monitor/MonitorGUI.gd | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 godot/monitor/MonitorGUI.gd diff --git a/godot/monitor/GUI.tscn b/godot/monitor/GUI.tscn index 8bdd81e..1be6fbf 100644 --- a/godot/monitor/GUI.tscn +++ b/godot/monitor/GUI.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=17 format=2] +[gd_scene load_steps=18 format=2] [ext_resource path="res://assets/fonts/data/PixelOperator.tres" type="DynamicFontData" id=1] [ext_resource path="res://assets/fonts/data/PixelOperator-Bold.tres" type="DynamicFontData" id=2] @@ -7,6 +7,7 @@ [ext_resource path="res://monitor/EnterButton.gd" type="Script" id=5] [ext_resource path="res://assets/sounds/ui_popup.wav" type="AudioStream" id=6] [ext_resource path="res://assets/sounds/ui_select.wav" type="AudioStream" id=7] +[ext_resource path="res://monitor/MonitorGUI.gd" type="Script" id=8] [sub_resource type="DynamicFont" id=1] font_data = ExtResource( 1 ) @@ -69,6 +70,7 @@ font_data = ExtResource( 2 ) [node name="MonitorGUI" type="CanvasLayer"] pause_mode = 2 +script = ExtResource( 8 ) [node name="ColorRect" type="ColorRect" parent="."] margin_right = 40.0 diff --git a/godot/monitor/MonitorGUI.gd b/godot/monitor/MonitorGUI.gd new file mode 100644 index 0000000..7502599 --- /dev/null +++ b/godot/monitor/MonitorGUI.gd @@ -0,0 +1,12 @@ +extends CanvasLayer + + +export var default_name = "" +export var default_rut = "" +export var default_email = "" + + +func _ready() -> void: + get_node("%Name").text = default_name + get_node("%Rut").text = default_rut + get_node("%Email").text = default_email From e7fb9dff03a3f4747b6de7bc55b6136b7c898750 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sun, 14 Aug 2022 13:18:09 -0400 Subject: [PATCH 3/7] fix incorrect name in log --- src/player/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/player/Player.cpp b/src/player/Player.cpp index 11aa417..70b2a81 100644 --- a/src/player/Player.cpp +++ b/src/player/Player.cpp @@ -96,7 +96,7 @@ void Player::_ready() } else { - WARN_PRINT("Data not found!"); + WARN_PRINT("Monitor not found!"); } } From 2a7b20ed540add0972c9567b30a072fd102f9d76 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sun, 14 Aug 2022 15:15:36 -0400 Subject: [PATCH 4/7] dynamically load monitor and crt shader --- godot/Main.tscn | 8 +----- godot/monitor/Monitor.gd | 4 +++ src/Main.cpp | 54 ++++++++++++++++++++++++++++++++++++++-- src/Main.h | 14 +++++++++++ src/player/Player.cpp | 3 +++ src/player/Player.h | 2 ++ 6 files changed, 76 insertions(+), 9 deletions(-) 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(); }; } } From 563cdade006fefea99c9679f2cb541518987b7a6 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sun, 14 Aug 2022 16:53:44 -0400 Subject: [PATCH 5/7] refactor code to be more decoupled --- godot/monitor/Monitor.gd | 10 ++++----- godot/monitor/Monitor.tscn | 1 - src/Main.cpp | 45 ++++++++++++++++++++++++-------------- src/Main.h | 3 +++ src/player/Player.cpp | 4 +++- 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/godot/monitor/Monitor.gd b/godot/monitor/Monitor.gd index 62dd86e..63fe282 100644 --- a/godot/monitor/Monitor.gd +++ b/godot/monitor/Monitor.gd @@ -137,18 +137,18 @@ func _on_input_validated(validated_player: Dictionary) -> void: func _object_created(name: String, state: String, position: Vector2, velocity: Vector2) -> void: - if monitor_enabled and started: + if monitor_enabled: add_object(name, state, position, velocity) func _object_updated(name: String, state: String, position: Vector2, velocity: Vector2) -> void: - if monitor_enabled and started: + if monitor_enabled: remove_object(name) add_object(name, state, position, velocity) func _object_removed(name: String) -> void: - if monitor_enabled and started: + if monitor_enabled: remove_object(name) @@ -179,8 +179,8 @@ func add_object(name: String, state: String, position: Vector2, velocity: Vector func remove_object(name: String) -> void: for i in range(0, objects.size()): - if objects[i]["name"] == name: - objects.remove(i) + if objects[i]["name"] == name: + objects.remove(i) func _on_coin_update(amount: int) -> void: diff --git a/godot/monitor/Monitor.tscn b/godot/monitor/Monitor.tscn index 977db82..ae8206b 100644 --- a/godot/monitor/Monitor.tscn +++ b/godot/monitor/Monitor.tscn @@ -7,7 +7,6 @@ pause_mode = 2 script = ExtResource( 1 ) monitor_enabled = true -use_development_url = true [node name="MonitorGUI" parent="." instance=ExtResource( 3 )] visible = false diff --git a/src/Main.cpp b/src/Main.cpp index 17f9051..6bc13fb 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -46,20 +46,12 @@ void Main::_ready() { // 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); + load_monitor(); } 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); + load_monitor(); } else { @@ -95,15 +87,36 @@ void Main::_ready() } } -void Main::_on_monitor_loaded() { - if (level != NULL) +void Main::_on_monitor_loaded() +{ + if (level != nullptr) + { + auto level_node = load_level(); + connect("monitor_loaded", level_node->get_child(0)->find_node("Player", true, false), "_on_monitor_loaded"); + emit_signal("monitor_loaded"); + } +} + +void Main::load_monitor() +{ + 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); +} + +Node *Main::load_level() +{ + if (level != nullptr) { 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); + auto loaded_level = level->instance(); + auto level_node = get_node("Level"); + level_node->add_child(loaded_level); + return level_node; } + return nullptr; } void Main::_physics_process(float delta) diff --git a/src/Main.h b/src/Main.h index 5e8cfee..4c04cc9 100644 --- a/src/Main.h +++ b/src/Main.h @@ -218,6 +218,9 @@ namespace godot int8_t get_launch_screen(); void _on_monitor_loaded(); + + void load_monitor(); + Node *load_level(); }; } } diff --git a/src/player/Player.cpp b/src/player/Player.cpp index 4c3fab7..868156b 100644 --- a/src/player/Player.cpp +++ b/src/player/Player.cpp @@ -81,7 +81,7 @@ void Player::_ready() } void Player::_on_monitor_loaded() { - auto object_node = get_tree()->get_root()->get_node("Main")->find_node("Monitor", true); + auto object_node = get_tree()->get_root()->find_node("Monitor", true, false); if (object_node != nullptr) { auto state = get_node("StateMachine")->get_child(0); @@ -97,10 +97,12 @@ void Player::_on_monitor_loaded() { WARN_PRINT("State not found!"); } } +#ifndef NDEBUG else { WARN_PRINT("Monitor not found!"); } +#endif } void Player::_physics_process(float delta) From bb0c4e302de60fb4088c572bc851fef90019c280 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Thu, 25 Aug 2022 10:11:46 -0400 Subject: [PATCH 6/7] submit form when enter is pressed --- godot/monitor/EnterButton.gd | 10 +++++++--- godot/monitor/GUI.tscn | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/godot/monitor/EnterButton.gd b/godot/monitor/EnterButton.gd index 48ed546..de051dd 100644 --- a/godot/monitor/EnterButton.gd +++ b/godot/monitor/EnterButton.gd @@ -114,6 +114,10 @@ func show_error_message(message: String) -> void: func _on_PopupDialog_gui_input(event: InputEvent) -> void: - if event.is_pressed(): - var popup = get_node("%PopupDialog") - popup.hide() + var popup = get_node("%PopupDialog") + if popup.visible and event.is_pressed(): + popup.call_deferred("hide") + + +func _on_text_entered(_new_text: String) -> void: + call_deferred("_on_Button_pressed") diff --git a/godot/monitor/GUI.tscn b/godot/monitor/GUI.tscn index 1be6fbf..c5d0203 100644 --- a/godot/monitor/GUI.tscn +++ b/godot/monitor/GUI.tscn @@ -237,9 +237,12 @@ valign = 1 autowrap = true [connection signal="focus_entered" from="GUI/VBoxContainer/CenterContainer2/VBoxContainer2/Name" to="GUI/Sounds" method="_play_ui_select_sound"] +[connection signal="text_entered" from="GUI/VBoxContainer/CenterContainer2/VBoxContainer2/Name" to="GUI/VBoxContainer/CenterContainer3/Button" method="_on_text_entered"] [connection signal="focus_entered" from="GUI/VBoxContainer/CenterContainer2/VBoxContainer2/Rut" to="GUI/Sounds" method="_play_ui_select_sound"] [connection signal="text_changed" from="GUI/VBoxContainer/CenterContainer2/VBoxContainer2/Rut" to="GUI/VBoxContainer/CenterContainer2/VBoxContainer2/Rut" method="_on_Rut_text_changed"] +[connection signal="text_entered" from="GUI/VBoxContainer/CenterContainer2/VBoxContainer2/Rut" to="GUI/VBoxContainer/CenterContainer3/Button" method="_on_text_entered"] [connection signal="focus_entered" from="GUI/VBoxContainer/CenterContainer2/VBoxContainer2/Email" to="GUI/Sounds" method="_play_ui_select_sound"] +[connection signal="text_entered" from="GUI/VBoxContainer/CenterContainer2/VBoxContainer2/Email" to="GUI/VBoxContainer/CenterContainer3/Button" method="_on_text_entered"] [connection signal="focus_entered" from="GUI/VBoxContainer/CenterContainer3/Button" to="GUI/Sounds" method="_play_ui_select_sound"] [connection signal="pressed" from="GUI/VBoxContainer/CenterContainer3/Button" to="GUI/VBoxContainer/CenterContainer3/Button" method="_on_Button_pressed"] [connection signal="focus_entered" from="PopupDialog" to="GUI/Sounds" method="_play_popup_sound"] From 0c8c3f6d1bc579ced774f2d9efd280a724b188c5 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Fri, 26 Aug 2022 10:51:16 -0400 Subject: [PATCH 7/7] fix level not loading when monitor is disabled --- godot/monitor/Monitor.gd | 1 + godot/monitor/Monitor.tscn | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/godot/monitor/Monitor.gd b/godot/monitor/Monitor.gd index 63fe282..004c1f9 100644 --- a/godot/monitor/Monitor.gd +++ b/godot/monitor/Monitor.gd @@ -126,6 +126,7 @@ func _physics_process(_delta: float) -> void: start_monitor() else: get_tree().paused = false + emit_signal("monitor_loaded") queue_free() diff --git a/godot/monitor/Monitor.tscn b/godot/monitor/Monitor.tscn index ae8206b..58f135d 100644 --- a/godot/monitor/Monitor.tscn +++ b/godot/monitor/Monitor.tscn @@ -6,9 +6,9 @@ [node name="Monitor" type="Node"] pause_mode = 2 script = ExtResource( 1 ) -monitor_enabled = true [node name="MonitorGUI" parent="." instance=ExtResource( 3 )] visible = false [node name="HTTPRequest" type="HTTPRequest" parent="."] +pause_mode = 2