Compare commits

...

3 Commits

3 changed files with 22 additions and 13 deletions

View File

@ -138,6 +138,14 @@ void GameRoot::set_game_mode(Ref<GameMode> prototype) {
} while(new_player_id != 0); } while(new_player_id != 0);
} }
Ref<GameMode> GameRoot::get_game_mode() const {
return this->game_mode;
}
Ref<GameState> GameRoot::get_game_state() const {
return this->game_mode->get_game_state();
}
IPlayer *GameRoot::spawn_player(uint32_t id) { IPlayer *GameRoot::spawn_player(uint32_t id) {
UtilityFunctions::push_error("GameRoot::spawn_player not implemented"); UtilityFunctions::push_error("GameRoot::spawn_player not implemented");
return nullptr; return nullptr;
@ -202,7 +210,7 @@ void GameRoot3D::set_first_boot_level(Ref<PackedScene> level) {
return; return;
} }
StringName const root_type = level->get_state()->get_node_type(0); StringName const root_type = level->get_state()->get_node_type(0);
if(!ClassDB::is_parent_class("Level3D", root_type)) { if(!ClassDB::is_parent_class(root_type, "Level3D")) {
UtilityFunctions::push_error("First boot level cannot be of type '", root_type, "'. First boot level has to inherit from Level3D"); UtilityFunctions::push_error("First boot level cannot be of type '", root_type, "'. First boot level has to inherit from Level3D");
this->first_boot_level.unref(); this->first_boot_level.unref();
return; return;
@ -239,7 +247,7 @@ bool GameRoot3D::is_valid_level(Ref<PackedScene> &level) {
return false; return false;
} }
StringName const root_type = level->get_state()->get_node_type(0); StringName const root_type = level->get_state()->get_node_type(0);
if(!ClassDB::is_parent_class("Level3D", root_type)) { if(!ClassDB::is_parent_class(root_type, "Level3D")) {
UtilityFunctions::push_error("Can't load level with root type '", root_type, "'. Root node has to be of type Level3D"); UtilityFunctions::push_error("Can't load level with root type '", root_type, "'. Root node has to be of type Level3D");
return false; return false;
} }

View File

@ -45,6 +45,8 @@ public:
// override the current gamemode // override the current gamemode
// force-respawns all players // force-respawns all players
void set_game_mode(Ref<GameMode> prototype); void set_game_mode(Ref<GameMode> prototype);
Ref<GameMode> get_game_mode() const;
Ref<GameState> get_game_state() const;
protected: protected:
// attempt to make 'this' the current singleton instance // attempt to make 'this' the current singleton instance
void grab_singleton(); void grab_singleton();

View File

@ -1,4 +1,5 @@
#include "player_input.hpp" #include "player_input.hpp"
#include "godot_cpp/variant/utility_functions.hpp"
#include "godot_macros.h" #include "godot_macros.h"
#include "godot_cpp/classes/input.hpp" #include "godot_cpp/classes/input.hpp"
#include "godot_cpp/classes/input_event.hpp" #include "godot_cpp/classes/input_event.hpp"
@ -20,7 +21,7 @@ PlayerInput::Listener::Listener(String positive, String negative, Node *object,
, isMouseEvent{positive.begins_with("_mouse_") || negative.begins_with("_mouse_")} {} , isMouseEvent{positive.begins_with("_mouse_") || negative.begins_with("_mouse_")} {}
PlayerInput::Listener::Listener(String action, Node *object, String method) PlayerInput::Listener::Listener(String action, Node *object, String method)
: PlayerInput::Listener::Listener(action, "", object, method) {} : PlayerInput::Listener::Listener(action, String(), object, method) {}
std::optional<float> PlayerInput::Listener::evaluate_action(String const &action) { std::optional<float> PlayerInput::Listener::evaluate_action(String const &action) {
Input *input = Input::get_singleton(); Input *input = Input::get_singleton();
@ -34,9 +35,8 @@ std::optional<float> PlayerInput::Listener::evaluate_action(String const &action
return vector.x > 0.f ? vector.x : 0.f; return vector.x > 0.f ? vector.x : 0.f;
else if(action.ends_with("_left")) else if(action.ends_with("_left"))
return vector.x < 0.f ? -vector.x : 0.f; return vector.x < 0.f ? -vector.x : 0.f;
else }
return std::nullopt; if(action.is_empty()) {
} else if(action.is_empty()) {
return 0.f; return 0.f;
} else { } else {
return float(input->is_action_pressed(action)); return float(input->is_action_pressed(action));
@ -44,12 +44,10 @@ std::optional<float> PlayerInput::Listener::evaluate_action(String const &action
} }
bool PlayerInput::Listener::has_changed(Ref<InputEvent> const &event) { bool PlayerInput::Listener::has_changed(Ref<InputEvent> const &event) {
return ( bool const mouse_changed{this->isMouseEvent && event->is_class("InputEventMouseMotion")};
(!event->is_class("InputEventMouseMotion") || bool const negative_changed{!this->actionNegative.is_empty() && event->is_action(this->actionNegative)};
this->isMouseEvent) || bool const positive_changed{!this->actionPositive.is_empty() && event->is_action(this->actionPositive)};
event->is_action(this->actionNegative) || return mouse_changed || negative_changed || positive_changed;
event->is_action(this->actionPositive)
);
} }
float PlayerInput::Listener::evaluate(Ref<InputEvent> const &event) { float PlayerInput::Listener::evaluate(Ref<InputEvent> const &event) {
@ -102,7 +100,8 @@ void PlayerInput::_unhandled_input(Ref<InputEvent> const &event) {
} }
void PlayerInput::_process(double deltaTime) { void PlayerInput::_process(double deltaTime) {
PlayerInput::lastMouseMotion = {0.f, 0.f}; if(this->isPrimary)
PlayerInput::lastMouseMotion = {0.f, 0.f};
} }
void PlayerInput::listen_to(Listener const& listener) { void PlayerInput::listen_to(Listener const& listener) {