2023-07-21 09:50:06 +00:00
|
|
|
/**
|
|
|
|
* bt_console_print.cpp
|
|
|
|
* =============================================================================
|
|
|
|
* Copyright 2021-2023 Serhii Snitsaruk
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style
|
|
|
|
* license that can be found in the LICENSE file or at
|
|
|
|
* https://opensource.org/licenses/MIT.
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
2022-09-06 11:08:52 +00:00
|
|
|
|
|
|
|
#include "bt_console_print.h"
|
2023-07-20 16:35:36 +00:00
|
|
|
|
|
|
|
#include "modules/limboai/bt/actions/bt_action.h"
|
|
|
|
|
2022-12-15 07:26:52 +00:00
|
|
|
#include "core/object/object.h"
|
|
|
|
#include "core/string/print_string.h"
|
2022-09-06 11:08:52 +00:00
|
|
|
|
|
|
|
String BTConsolePrint::_generate_name() const {
|
|
|
|
String tx = text;
|
|
|
|
if (text.length() > 30) {
|
|
|
|
tx = text.substr(0, 30) + "...";
|
|
|
|
}
|
|
|
|
tx = tx.replace("\"", "\\\"");
|
2022-12-17 10:26:48 +00:00
|
|
|
if (bb_format_parameters.size() > 0) {
|
|
|
|
return vformat("ConsolePrint text: \"%s\" format_parameters: %s", tx, bb_format_parameters);
|
2022-09-06 11:08:52 +00:00
|
|
|
}
|
|
|
|
return vformat("ConsolePrint \"%s\"", tx);
|
|
|
|
}
|
|
|
|
|
2023-04-10 08:08:11 +00:00
|
|
|
int BTConsolePrint::_tick(double p_delta) {
|
2022-12-17 10:26:48 +00:00
|
|
|
switch (bb_format_parameters.size()) {
|
2022-09-06 11:08:52 +00:00
|
|
|
case 0: {
|
|
|
|
print_line(text);
|
|
|
|
} break;
|
|
|
|
case 1: {
|
2022-12-17 10:26:48 +00:00
|
|
|
print_line(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], "")));
|
2022-09-06 11:08:52 +00:00
|
|
|
} break;
|
|
|
|
case 2: {
|
2022-12-17 10:26:48 +00:00
|
|
|
print_line(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""),
|
|
|
|
get_blackboard()->get_var(bb_format_parameters[1], "")));
|
2022-09-06 11:08:52 +00:00
|
|
|
} break;
|
|
|
|
case 3: {
|
2022-12-17 10:26:48 +00:00
|
|
|
print_line(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""),
|
|
|
|
get_blackboard()->get_var(bb_format_parameters[1], ""),
|
|
|
|
get_blackboard()->get_var(bb_format_parameters[2], "")));
|
2022-09-06 11:08:52 +00:00
|
|
|
} break;
|
|
|
|
case 4: {
|
2022-12-17 10:26:48 +00:00
|
|
|
print_line(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""),
|
|
|
|
get_blackboard()->get_var(bb_format_parameters[1], ""),
|
|
|
|
get_blackboard()->get_var(bb_format_parameters[2], ""),
|
|
|
|
get_blackboard()->get_var(bb_format_parameters[3], "")));
|
2022-09-06 11:08:52 +00:00
|
|
|
} break;
|
|
|
|
case 5:
|
|
|
|
default: {
|
2022-12-17 10:26:48 +00:00
|
|
|
print_line(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""),
|
|
|
|
get_blackboard()->get_var(bb_format_parameters[1], ""),
|
|
|
|
get_blackboard()->get_var(bb_format_parameters[2], ""),
|
|
|
|
get_blackboard()->get_var(bb_format_parameters[3], ""),
|
|
|
|
get_blackboard()->get_var(bb_format_parameters[4], "")));
|
2022-09-06 11:08:52 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
String BTConsolePrint::get_configuration_warning() const {
|
|
|
|
String warning = BTAction::get_configuration_warning();
|
2022-12-15 07:26:52 +00:00
|
|
|
if (!warning.is_empty()) {
|
2022-09-06 11:08:52 +00:00
|
|
|
warning += "\n";
|
|
|
|
}
|
2022-12-17 10:26:48 +00:00
|
|
|
if (bb_format_parameters.size() > 5) {
|
2022-09-06 11:08:52 +00:00
|
|
|
warning += "ConsolePrint supports up to 5 format arguments.\n";
|
|
|
|
}
|
|
|
|
return warning;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BTConsolePrint::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("set_text", "p_text"), &BTConsolePrint::set_text);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_text"), &BTConsolePrint::get_text);
|
2022-12-17 10:26:48 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bb_format_parameters", "p_variables"), &BTConsolePrint::set_bb_format_parameters);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bb_format_parameters"), &BTConsolePrint::get_bb_format_parameters);
|
2022-09-06 11:08:52 +00:00
|
|
|
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT), "set_text", "get_text");
|
2022-12-17 10:26:48 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "bb_format_parameters"), "set_bb_format_parameters", "get_bb_format_parameters");
|
2022-09-06 11:08:52 +00:00
|
|
|
}
|