develop #30

Merged
cromer merged 55 commits from develop into master 2022-08-26 10:53:59 -04:00
6 changed files with 76 additions and 9 deletions
Showing only changes of commit 2a7b20ed54 - Show all commits

View File

@ -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://Main.gdns" type="Script" id=1]
[ext_resource path="res://levels/Level2.tscn" type="PackedScene" id=2] [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"] [node name="Main" type="Node"]
pause_mode = 2 pause_mode = 2
@ -12,7 +10,3 @@ level = ExtResource( 2 )
[node name="Level" type="Node" parent="."] [node name="Level" type="Node" parent="."]
pause_mode = 1 pause_mode = 1
[node name="Monitor" parent="." instance=ExtResource( 3 )]
[node name="CRT" parent="." instance=ExtResource( 4 )]

View File

@ -1,6 +1,9 @@
extends Node extends Node
signal monitor_loaded()
export var monitor_enabled: bool = false export var monitor_enabled: bool = false
export var development_url: String = "http://localhost:4050/api/v1" export var development_url: String = "http://localhost:4050/api/v1"
var url_real: String = "https://alai.cromer.cl/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 monitor_enabled:
if has_node("MonitorGUI") and not $MonitorGUI.visible: if has_node("MonitorGUI") and not $MonitorGUI.visible:
$MonitorGUI.visible = true $MonitorGUI.visible = true
emit_signal("monitor_loaded")
if started and not get_tree().paused: if started and not get_tree().paused:
var frame = empty_frame.duplicate(true) var frame = empty_frame.duplicate(true)

View File

@ -9,11 +9,13 @@ void Main::_register_methods()
{ {
register_method("_ready", &Main::_ready); register_method("_ready", &Main::_ready);
register_method("_physics_process", &Main::_physics_process); register_method("_physics_process", &Main::_physics_process);
register_method("_on_monitor_loaded", &Main::_on_monitor_loaded);
register_property<Main, String>("game_version", &Main::set_game_version, &Main::get_game_version, String(main::game_version.c_str())); register_property<Main, String>("game_version", &Main::set_game_version, &Main::get_game_version, String(main::game_version.c_str()));
register_property<Main, Ref<PackedScene>>("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<Main, Ref<PackedScene>>("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<Main, bool>("full_screen", &Main::set_full_screen, &Main::get_full_screen, main::full_screen); register_property<Main, bool>("full_screen", &Main::set_full_screen, &Main::get_full_screen, main::full_screen);
register_property<Main, Vector2>("window_size", &Main::set_window_size, &Main::get_window_size, main::window_size); register_property<Main, Vector2>("window_size", &Main::set_window_size, &Main::get_window_size, main::window_size);
register_property<Main, int8_t>("launch_screen", &Main::set_launch_screen, &Main::get_launch_screen, main::launch_screen); register_property<Main, int8_t>("launch_screen", &Main::set_launch_screen, &Main::get_launch_screen, main::launch_screen);
register_signal<Main>("monitor_loaded");
} }
Main::Main() Main::Main()
@ -28,6 +30,8 @@ void Main::_init()
{ {
_os = OS::get_singleton(); _os = OS::get_singleton();
_input = Input::get_singleton(); _input = Input::get_singleton();
_project_settings = ProjectSettings::get_singleton();
_resource_loader = ResourceLoader::get_singleton();
game_version = String(main::game_version.c_str()); game_version = String(main::game_version.c_str());
full_screen = main::full_screen; full_screen = main::full_screen;
@ -37,7 +41,32 @@ void Main::_init()
void Main::_ready() 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<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);
}
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);
}
else
{
// There is no monitor included
_on_monitor_loaded();
}
if (get_full_screen()) if (get_full_screen())
{ {
_os->set_window_fullscreen(true); _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<PackedScene> 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<PackedScene> crt_scene = _resource_loader->load("res://shaders/crt/crt.tscn");
add_child(crt_scene->instance());
}
}
void Main::_on_monitor_loaded() {
if (level != NULL) if (level != NULL)
{ {
get_node("Level")->add_child(level->instance()); 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);
} }
} }

View File

@ -8,6 +8,8 @@
#include <Input.hpp> #include <Input.hpp>
#include <PackedScene.hpp> #include <PackedScene.hpp>
#include <Ref.hpp> #include <Ref.hpp>
#include <ProjectSettings.hpp>
#include <ResourceLoader.hpp>
/** /**
* @brief This is the godot namespace for all the code included in the library. * @brief This is the godot namespace for all the code included in the library.
@ -64,6 +66,16 @@ namespace godot
* *
*/ */
Input *_input; Input *_input;
/**
* @brief ProjectSettings singleton.
*
*/
ProjectSettings *_project_settings;
/**
* @brief ResourceLoader singleton.
*
*/
ResourceLoader *_resource_loader;
/** /**
* @brief The first level to load * @brief The first level to load
@ -204,6 +216,8 @@ namespace godot
* @return int8_t The launch screen. * @return int8_t The launch screen.
*/ */
int8_t get_launch_screen(); int8_t get_launch_screen();
void _on_monitor_loaded();
}; };
} }
} }

View File

@ -19,6 +19,7 @@ void Player::_register_methods()
register_method("set_velocity", &Player::set_velocity); register_method("set_velocity", &Player::set_velocity);
register_method("get_velocity", &Player::get_velocity); register_method("get_velocity", &Player::get_velocity);
register_method("_on_player_touched", &Player::_on_player_touched); register_method("_on_player_touched", &Player::_on_player_touched);
register_method("_on_monitor_loaded", &Player::_on_monitor_loaded);
//register_property<Player, Ref<SpriteFrames>>("sprite_frames", &Player::set_sprite_frames, &Player::get_sprite_frames, Ref<SpriteFrames>(), GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, String("SpriteFrames")); //register_property<Player, Ref<SpriteFrames>>("sprite_frames", &Player::set_sprite_frames, &Player::get_sprite_frames, Ref<SpriteFrames>(), GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, String("SpriteFrames"));
register_property<Player, float>("speed", &Player::set_speed, &Player::get_speed, player::speed); register_property<Player, float>("speed", &Player::set_speed, &Player::get_speed, player::speed);
register_property<Player, float>("jump_force", &Player::set_jump_force, &Player::get_jump_force, player::jump_force); register_property<Player, float>("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!"); WARN_PRINT("Middleground not found!");
} }
}
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()->get_node("Main")->find_node("Monitor", true);
if (object_node != nullptr) if (object_node != nullptr)
{ {

View File

@ -280,6 +280,8 @@ namespace godot
* *
*/ */
void _on_player_touched(); void _on_player_touched();
void _on_monitor_loaded();
}; };
} }
} }