feat: added print debug info interaction to player and unit

This commit is contained in:
Sara 2024-08-09 15:45:20 +02:00
parent 41f353eda3
commit 2c21845991
5 changed files with 63 additions and 6 deletions

View file

@ -82,6 +82,11 @@ rotate_right={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"echo":false,"script":null)
]
}
DEBUG_toggle_debug={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":96,"key_label":0,"unicode":96,"echo":false,"script":null)
]
}
[layer_names]

View file

@ -41,6 +41,10 @@ void RTSPlayer::setup_player_input(utils::PlayerInput *input) {
input->listen_to("rotate_left", "rotate_right", callable_mp(this, &RTSPlayer::on_rotate_horizontal));
input->listen_to("_mouse_left", "_mouse_right", callable_mp(this, &RTSPlayer::on_mouse_horizontal));
input->listen_to("_mouse_down", "_mouse_up", callable_mp(this, &RTSPlayer::on_mouse_vertical));
#ifdef DEBUG_ENABLED
input->listen_to("DEBUG_toggle_debug", callable_mp(this, &RTSPlayer::DEBUG_enable_debug));
gd::UtilityFunctions::print("!!! DEBUG_ENABLED");
#endif
}
gd::Node *RTSPlayer::to_node() {
@ -81,6 +85,12 @@ gd::Node3D *RTSPlayer::node_under_cursor(uint32_t layers) const {
void RTSPlayer::select_unit_under_cursor() {
Unit *unit = Object::cast_to<Unit>(this->node_under_cursor(0x2));
#ifdef DEBUG_ENABLED
if(unit != nullptr && this->DEBUG_debug_enabled) {
unit->DEBUG_print_debug_info();
return;
}
#endif
if(unit != nullptr)
this->select_unit(unit);
}
@ -192,3 +202,13 @@ void RTSPlayer::set_ground_marker_scene(gd::Ref<gd::PackedScene> scene) {
gd::Ref<gd::PackedScene> RTSPlayer::get_ground_marker_scene() const {
return this->ground_marker_scene;
}
#ifdef DEBUG_ENABLED
void RTSPlayer::DEBUG_enable_debug(gd::Ref<gd::InputEvent>, float value) {
if(value != 0) {
this->DEBUG_debug_enabled = !this->DEBUG_debug_enabled;
gd::UtilityFunctions::print("DEBUG toggled debug actions. Now ", this->DEBUG_debug_enabled);
}
}
#endif

View file

@ -72,13 +72,9 @@ private:
gd::Vector2 camera_keys_motion{0.f, 0.f};
float camera_keys_rotation{0.f};
gd::Vector2 total_cursor_motion{};
gd::Vector3 cursor_camera_normal{0.f, 0.f, 0.f};
gd::Camera3D *camera{nullptr};
gd::Ref<gd::PackedScene> ground_marker_scene{nullptr};
gd::Callable const on_selected_unit_destroyed{callable_mp(this, &RTSPlayer::clear_selected_unit)};
float const camera_keys_speed{10.f};
@ -86,6 +82,11 @@ private:
float const camera_mouse_speed{0.01f};
float const camera_mouse_rotation_speed{-0.003f};
double const time_to_held{0.1};
#ifdef DEBUG_ENABLED
private:
bool DEBUG_debug_enabled{false};
void DEBUG_enable_debug(gd::Ref<gd::InputEvent>, float value);
#endif // DEBUG_ENABLED
};
#endif // !RTS_PLAYER_HPP

View file

@ -135,13 +135,13 @@ void Unit::next_action() {
return;
goap::Action const *action{this->current_plan.get(0)};
if(!action->is_possible(this->world_state)) {
this->call_deferred("emit_signal", "plan_interrupted");
this->emit_signal("plan_interrupted");
return;
}
// pop next action and apply state
this->state = action->get_apply_state(this->world_state);
if(state == nullptr) {
this->call_deferred("emit_signal", "plan_interrupted");
this->emit_signal("plan_interrupted");
return;
}
this->current_plan.remove_at(0);
@ -197,3 +197,30 @@ void Unit::set_movement_speed(float speed) {
float Unit::get_movement_speed() const {
return this->movement_speed;
}
#ifdef DEBUG_ENABLED
gd::String Unit::DEBUG_print_debug_info() {
gd::String debug_info{"goal: "};
if(!this->current_goal.is_valid()) {
debug_info += "No goal assigned";
} else {
debug_info += this->current_goal->get_path();
debug_info += "\nplan:";
if(this->state != nullptr) {
debug_info += "\n ";
debug_info += this->state->get_action()->get_class();
debug_info += " (currently in-progress)";
}
for(goap::Action const *action : this->current_plan) {
debug_info += "\n ";
debug_info += action->get_class();
}
}
if(this->state != nullptr) {
debug_info += "\ncurrent state: ";
debug_info += this->state->get_class();
}
gd::UtilityFunctions::print(this->get_path(), "debug info:\n", debug_info);
return debug_info;
}
#endif

View file

@ -69,6 +69,10 @@ protected:
goap::Planner *planner{nullptr};
EntityHealth *health{nullptr};
UnitWorldState *world_state{nullptr};
#ifdef DEBUG_ENABLED
public:
gd::String DEBUG_print_debug_info();
#endif // DEBUG_ENABLED
};
#endif // !RTS_UNIT_HPP