Compare commits
3 Commits
c85947f187
...
1dd1d3b961
Author | SHA1 | Date |
---|---|---|
Sara | 1dd1d3b961 | |
Sara | e6c3d0988d | |
Sara | 51c9090d10 |
|
@ -138,6 +138,14 @@ void GameRoot::set_game_mode(Ref<GameMode> prototype) {
|
|||
} 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) {
|
||||
UtilityFunctions::push_error("GameRoot::spawn_player not implemented");
|
||||
return nullptr;
|
||||
|
@ -202,7 +210,7 @@ void GameRoot3D::set_first_boot_level(Ref<PackedScene> level) {
|
|||
return;
|
||||
}
|
||||
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");
|
||||
this->first_boot_level.unref();
|
||||
return;
|
||||
|
@ -239,7 +247,7 @@ bool GameRoot3D::is_valid_level(Ref<PackedScene> &level) {
|
|||
return false;
|
||||
}
|
||||
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");
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@ public:
|
|||
// override the current gamemode
|
||||
// force-respawns all players
|
||||
void set_game_mode(Ref<GameMode> prototype);
|
||||
Ref<GameMode> get_game_mode() const;
|
||||
Ref<GameState> get_game_state() const;
|
||||
protected:
|
||||
// attempt to make 'this' the current singleton instance
|
||||
void grab_singleton();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "player_input.hpp"
|
||||
#include "godot_cpp/variant/utility_functions.hpp"
|
||||
#include "godot_macros.h"
|
||||
#include "godot_cpp/classes/input.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_")} {}
|
||||
|
||||
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) {
|
||||
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;
|
||||
else if(action.ends_with("_left"))
|
||||
return vector.x < 0.f ? -vector.x : 0.f;
|
||||
else
|
||||
return std::nullopt;
|
||||
} else if(action.is_empty()) {
|
||||
}
|
||||
if(action.is_empty()) {
|
||||
return 0.f;
|
||||
} else {
|
||||
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) {
|
||||
return (
|
||||
(!event->is_class("InputEventMouseMotion") ||
|
||||
this->isMouseEvent) ||
|
||||
event->is_action(this->actionNegative) ||
|
||||
event->is_action(this->actionPositive)
|
||||
);
|
||||
bool const mouse_changed{this->isMouseEvent && event->is_class("InputEventMouseMotion")};
|
||||
bool const negative_changed{!this->actionNegative.is_empty() && event->is_action(this->actionNegative)};
|
||||
bool const positive_changed{!this->actionPositive.is_empty() && event->is_action(this->actionPositive)};
|
||||
return mouse_changed || negative_changed || positive_changed;
|
||||
}
|
||||
|
||||
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) {
|
||||
PlayerInput::lastMouseMotion = {0.f, 0.f};
|
||||
if(this->isPrimary)
|
||||
PlayerInput::lastMouseMotion = {0.f, 0.f};
|
||||
}
|
||||
|
||||
void PlayerInput::listen_to(Listener const& listener) {
|
||||
|
|
Loading…
Reference in New Issue