limboai/limbo_utility.cpp

49 lines
1.1 KiB
C++

/* limbo_utility.cpp */
#include "limbo_utility.h"
#include "bt/bt_task.h"
#include "core/variant/variant.h"
LimboUtility *LimboUtility::singleton = nullptr;
LimboUtility *LimboUtility::get_singleton() {
return singleton;
}
String LimboUtility::decorate_var(String p_variable) const {
String var = p_variable.trim_prefix("$").trim_prefix("\"").trim_suffix("\"");
if (var.find(" ") == -1 and not var.is_empty()) {
return vformat("$%s", var);
} else {
return vformat("$\"%s\"", var);
}
}
String LimboUtility::get_status_name(int p_status) const {
switch (p_status) {
case BTTask::FRESH:
return "FRESH";
case BTTask::RUNNING:
return "RUNNING";
case BTTask::FAILURE:
return "FAILURE";
case BTTask::SUCCESS:
return "SUCCESS";
default:
return "";
}
}
void LimboUtility::_bind_methods() {
ClassDB::bind_method(D_METHOD("decorate_var", "p_variable"), &LimboUtility::decorate_var);
ClassDB::bind_method(D_METHOD("get_status_name", "p_status"), &LimboUtility::get_status_name);
}
LimboUtility::LimboUtility() {
singleton = this;
}
LimboUtility::~LimboUtility() {
singleton = nullptr;
}