feature/fix_monitor #29

Merged
cromer merged 7 commits from feature/fix_monitor into develop 2022-08-26 10:53:10 -04:00
5 changed files with 40 additions and 23 deletions
Showing only changes of commit 563cdade00 - Show all commits

View File

@ -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)

View File

@ -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

View File

@ -46,20 +46,12 @@ void Main::_ready()
{
// Load monitor from pck
Godot::print("Monitor pck found, loading...");
Ref<PackedScene> 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<PackedScene> 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<PackedScene> 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<PackedScene> 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)

View File

@ -218,6 +218,9 @@ namespace godot
int8_t get_launch_screen();
void _on_monitor_loaded();
void load_monitor();
Node *load_level();
};
}
}

View File

@ -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)