limboai/util/limbo_utility.cpp

645 lines
19 KiB
C++
Raw Permalink Normal View History

/**
* limbo_utility.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-08-28 10:54:34 +00:00
#include "limbo_utility.h"
2023-07-20 16:35:36 +00:00
2024-01-13 16:10:42 +00:00
#include "../bt/tasks/bt_task.h"
#include "../util/limbo_compat.h"
2023-07-20 16:35:36 +00:00
2024-01-13 16:10:42 +00:00
#ifdef LIMBOAI_MODULE
#include "core/config/project_settings.h"
#include "core/error/error_macros.h"
2023-10-28 11:09:03 +00:00
#include "core/object/script_language.h"
2024-01-13 21:40:27 +00:00
#include "core/os/os.h"
#include "core/variant/variant.h"
#include "scene/resources/texture.h"
2022-08-28 10:54:34 +00:00
2023-04-26 12:45:03 +00:00
#ifdef TOOLS_ENABLED
#include "editor/editor_node.h"
#endif // TOOLS_ENABLED
2024-01-13 16:10:42 +00:00
#endif // ! LIMBOAI_MODULE
#ifdef LIMBOAI_GDEXTENSION
2024-01-09 12:34:24 +00:00
#include "godot_cpp/classes/input_event_key.hpp"
#include "godot_cpp/classes/project_settings.hpp"
#include "godot_cpp/variant/dictionary.hpp"
2024-01-09 12:34:24 +00:00
#include "godot_cpp/variant/utility_functions.hpp"
2024-01-13 21:40:27 +00:00
#include <godot_cpp/classes/os.hpp>
2024-01-07 05:51:34 +00:00
#include <godot_cpp/classes/resource_loader.hpp>
#include <godot_cpp/classes/script.hpp>
2024-01-10 00:17:09 +00:00
#include <godot_cpp/classes/texture2d.hpp>
2024-01-07 05:51:34 +00:00
#include <godot_cpp/classes/theme.hpp>
#include <godot_cpp/core/error_macros.hpp>
2024-01-13 16:10:42 +00:00
#endif // ! LIMBOAI_GDEXTENSION
2022-09-21 21:56:04 +00:00
LimboUtility *LimboUtility::singleton = nullptr;
LimboUtility *LimboUtility::get_singleton() {
return singleton;
}
2022-11-01 13:03:20 +00:00
String LimboUtility::decorate_var(String p_variable) const {
2022-09-21 21:56:04 +00:00
String var = p_variable.trim_prefix("$").trim_prefix("\"").trim_suffix("\"");
2023-07-28 22:35:47 +00:00
if (var.find(" ") == -1 && !var.is_empty()) {
2022-09-21 21:56:04 +00:00
return vformat("$%s", var);
} else {
return vformat("$\"%s\"", var);
2022-08-28 10:54:34 +00:00
}
}
String LimboUtility::decorate_output_var(String p_variable) const {
return LW_NAME(output_var_prefix) + decorate_var(p_variable);
}
2022-11-01 13:03:20 +00:00
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 "";
}
}
Ref<Texture2D> LimboUtility::get_task_icon(String p_class_or_script_path) const {
ERR_FAIL_COND_V_MSG(p_class_or_script_path.is_empty(), Variant(), "BTTask: script path or class cannot be empty.");
// * Using editor theme
#if defined(TOOLS_ENABLED) && defined(LIMBOAI_MODULE)
if (Engine::get_singleton()->is_editor_hint()) {
Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
ERR_FAIL_COND_V(theme.is_null(), nullptr);
if (p_class_or_script_path.begins_with("res:")) {
Ref<Script> s = ResourceLoader::load(p_class_or_script_path, "Script");
if (s.is_null()) {
return theme->get_icon(SNAME("FileBroken"), SNAME("EditorIcons"));
}
EditorData &ed = EditorNode::get_editor_data();
Ref<Texture2D> script_icon = ed.get_script_icon(s);
if (script_icon.is_valid()) {
return script_icon;
}
StringName base_type = s->get_instance_base_type();
if (theme->has_icon(base_type, SNAME("EditorIcons"))) {
return theme->get_icon(base_type, SNAME("EditorIcons"));
}
}
if (theme->has_icon(p_class_or_script_path, SNAME("EditorIcons"))) {
return theme->get_icon(p_class_or_script_path, SNAME("EditorIcons"));
}
2023-08-09 13:38:24 +00:00
// Use an icon of one of the base classes: look up max 3 parents.
StringName class_name = p_class_or_script_path;
for (int i = 0; i < 3; i++) {
class_name = ClassDB::get_parent_class(class_name);
if (theme->has_icon(class_name, SNAME("EditorIcons"))) {
return theme->get_icon(class_name, SNAME("EditorIcons"));
}
2023-08-09 13:38:24 +00:00
}
// Return generic resource icon as a fallback.
return theme->get_icon(SNAME("Resource"), SNAME("EditorIcons"));
2023-08-09 13:38:24 +00:00
}
2024-01-10 00:17:09 +00:00
#endif // ! TOOLS_ENABLED && LIMBOAI_MODULE
String path;
#ifdef LIMBOAI_GDEXTENSION
2024-01-10 00:17:09 +00:00
if (p_class_or_script_path.begins_with("res://")) {
TypedArray<Dictionary> classes = ProjectSettings::get_singleton()->get_global_class_list();
for (int i = 0; i < classes.size(); i++) {
if (classes[i].get("path") == p_class_or_script_path) {
path = classes[i].get("icon");
break;
}
}
if (path.is_empty()) {
Ref<Script> sc = RESOURCE_LOAD(p_class_or_script_path, "Script");
if (sc.is_valid()) {
path = "res://addons/limboai/icons/" + sc->get_instance_base_type() + ".svg";
}
}
2024-01-10 00:17:09 +00:00
}
#endif // LIMBOAI_GDEXTENSION
2023-08-09 13:38:24 +00:00
if (path.is_empty() && !p_class_or_script_path.begins_with("res://")) {
// Trying addons/limboai/icons/
path = "res://addons/limboai/icons/" + p_class_or_script_path + ".svg";
}
if (RESOURCE_EXISTS(path, "Texture2D")) {
Ref<Texture2D> icon = RESOURCE_LOAD(path, "Texture2D");
return icon;
}
2024-01-07 12:36:59 +00:00
2023-08-09 13:38:24 +00:00
// * Class icons are not available at runtime as they are part of the editor theme.
2023-04-26 12:45:03 +00:00
return nullptr;
}
String LimboUtility::get_check_operator_string(CheckType p_check_type) const {
2023-08-10 11:04:53 +00:00
switch (p_check_type) {
case LimboUtility::CheckType::CHECK_EQUAL: {
return "==";
} break;
case LimboUtility::CheckType::CHECK_LESS_THAN: {
return "<";
} break;
case LimboUtility::CheckType::CHECK_LESS_THAN_OR_EQUAL: {
return "<=";
} break;
case LimboUtility::CheckType::CHECK_GREATER_THAN: {
return ">";
} break;
case LimboUtility::CheckType::CHECK_GREATER_THAN_OR_EQUAL: {
return ">=";
} break;
case LimboUtility::CheckType::CHECK_NOT_EQUAL: {
return "!=";
} break;
default: {
return "?";
} break;
}
}
bool LimboUtility::perform_check(CheckType p_check_type, const Variant &left_value, const Variant &right_value) {
Variant ret;
2023-08-10 11:04:53 +00:00
switch (p_check_type) {
case LimboUtility::CheckType::CHECK_EQUAL: {
VARIANT_EVALUATE(Variant::OP_EQUAL, left_value, right_value, ret);
2023-08-10 11:04:53 +00:00
} break;
case LimboUtility::CheckType::CHECK_LESS_THAN: {
2024-01-09 12:34:24 +00:00
VARIANT_EVALUATE(Variant::OP_LESS, left_value, right_value, ret);
2023-08-10 11:04:53 +00:00
} break;
case LimboUtility::CheckType::CHECK_LESS_THAN_OR_EQUAL: {
2024-01-09 12:34:24 +00:00
VARIANT_EVALUATE(Variant::OP_LESS_EQUAL, left_value, right_value, ret);
2023-08-10 11:04:53 +00:00
} break;
case LimboUtility::CheckType::CHECK_GREATER_THAN: {
2024-01-09 12:34:24 +00:00
VARIANT_EVALUATE(Variant::OP_GREATER, left_value, right_value, ret);
2023-08-10 11:04:53 +00:00
} break;
case LimboUtility::CheckType::CHECK_GREATER_THAN_OR_EQUAL: {
2024-01-09 12:34:24 +00:00
VARIANT_EVALUATE(Variant::OP_GREATER_EQUAL, left_value, right_value, ret);
2023-08-10 11:04:53 +00:00
} break;
case LimboUtility::CheckType::CHECK_NOT_EQUAL: {
2024-01-09 12:34:24 +00:00
VARIANT_EVALUATE(Variant::OP_NOT_EQUAL, left_value, right_value, ret);
2023-08-10 11:04:53 +00:00
} break;
default: {
return false;
} break;
}
return ret;
2023-08-10 11:04:53 +00:00
}
String LimboUtility::get_operation_string(Operation p_operation) const {
switch (p_operation) {
case OPERATION_NONE: {
return "";
} break;
case OPERATION_ADDITION: {
return "+";
} break;
case OPERATION_SUBTRACTION: {
return "-";
} break;
case OPERATION_MULTIPLICATION: {
return "*";
} break;
case OPERATION_DIVISION: {
return "/";
} break;
case OPERATION_MODULO: {
return "%";
} break;
case OPERATION_POWER: {
return "**";
} break;
case OPERATION_BIT_SHIFT_LEFT: {
return "<<";
} break;
case OPERATION_BIT_SHIFT_RIGHT: {
return ">>";
} break;
case OPERATION_BIT_AND: {
return "&";
} break;
case OPERATION_BIT_OR: {
return "|";
} break;
case OPERATION_BIT_XOR: {
return "^";
} break;
}
2023-11-19 15:26:00 +00:00
return "";
}
Variant LimboUtility::perform_operation(Operation p_operation, const Variant &left_value, const Variant &right_value) {
Variant ret;
switch (p_operation) {
case OPERATION_NONE: {
ret = right_value;
} break;
case OPERATION_ADDITION: {
2024-01-09 12:34:24 +00:00
VARIANT_EVALUATE(Variant::OP_ADD, left_value, right_value, ret);
} break;
case OPERATION_SUBTRACTION: {
2024-01-09 12:34:24 +00:00
VARIANT_EVALUATE(Variant::OP_SUBTRACT, left_value, right_value, ret);
} break;
case OPERATION_MULTIPLICATION: {
2024-01-09 12:34:24 +00:00
VARIANT_EVALUATE(Variant::OP_MULTIPLY, left_value, right_value, ret);
} break;
case OPERATION_DIVISION: {
2024-01-09 12:34:24 +00:00
VARIANT_EVALUATE(Variant::OP_DIVIDE, left_value, right_value, ret);
} break;
case OPERATION_MODULO: {
2024-01-09 12:34:24 +00:00
VARIANT_EVALUATE(Variant::OP_MODULE, left_value, right_value, ret);
} break;
case OPERATION_POWER: {
2024-01-10 22:26:24 +00:00
// TODO: Fix when godot-cpp https://github.com/godotengine/godot-cpp/issues/1348 is resolved.
#ifdef LIMBOAI_MODULE
VARIANT_EVALUATE(Variant::OP_POWER, left_value, right_value, ret);
2024-01-13 16:10:42 +00:00
#elif LIMBOAI_GDEXTENSION
2024-01-09 12:34:24 +00:00
ERR_PRINT("LimboUtility: Operation POWER is not available due to https://github.com/godotengine/godot-cpp/issues/1348");
2024-01-10 22:26:24 +00:00
ret = left_value;
2024-01-13 16:10:42 +00:00
#endif
} break;
case OPERATION_BIT_SHIFT_LEFT: {
2024-01-09 12:34:24 +00:00
VARIANT_EVALUATE(Variant::OP_SHIFT_LEFT, left_value, right_value, ret);
} break;
case OPERATION_BIT_SHIFT_RIGHT: {
2024-01-09 12:34:24 +00:00
VARIANT_EVALUATE(Variant::OP_SHIFT_RIGHT, left_value, right_value, ret);
} break;
case OPERATION_BIT_AND: {
2024-01-09 12:34:24 +00:00
VARIANT_EVALUATE(Variant::OP_BIT_AND, left_value, right_value, ret);
} break;
case OPERATION_BIT_OR: {
2024-01-09 12:34:24 +00:00
VARIANT_EVALUATE(Variant::OP_BIT_OR, left_value, right_value, ret);
} break;
case OPERATION_BIT_XOR: {
2024-01-09 12:34:24 +00:00
VARIANT_EVALUATE(Variant::OP_BIT_XOR, left_value, right_value, ret);
} break;
}
2024-01-10 22:26:24 +00:00
return ret;
2024-01-09 12:34:24 +00:00
}
2024-01-24 22:11:09 +00:00
String LimboUtility::get_property_hint_text(PropertyHint p_hint) const {
switch (p_hint) {
case PROPERTY_HINT_NONE: {
return "NONE";
}
case PROPERTY_HINT_RANGE: {
return "RANGE";
}
case PROPERTY_HINT_ENUM: {
return "ENUM";
}
case PROPERTY_HINT_ENUM_SUGGESTION: {
return "ENUM_SUGGESTION";
2024-01-24 22:11:09 +00:00
}
case PROPERTY_HINT_EXP_EASING: {
return "EXP_EASING";
}
case PROPERTY_HINT_LINK: {
return "LINK";
}
case PROPERTY_HINT_FLAGS: {
return "FLAGS";
}
case PROPERTY_HINT_LAYERS_2D_RENDER: {
return "LAYERS_2D_RENDER";
}
case PROPERTY_HINT_LAYERS_2D_PHYSICS: {
return "LAYERS_2D_PHYSICS";
}
case PROPERTY_HINT_LAYERS_2D_NAVIGATION: {
return "LAYERS_2D_NAVIGATION";
}
case PROPERTY_HINT_LAYERS_3D_RENDER: {
return "LAYERS_3D_RENDER";
}
case PROPERTY_HINT_LAYERS_3D_PHYSICS: {
return "LAYERS_3D_PHYSICS";
}
case PROPERTY_HINT_LAYERS_3D_NAVIGATION: {
return "LAYERS_3D_NAVIGATION";
}
case PROPERTY_HINT_FILE: {
return "FILE";
}
case PROPERTY_HINT_DIR: {
return "DIR";
}
case PROPERTY_HINT_GLOBAL_FILE: {
return "GLOBAL_FILE";
}
case PROPERTY_HINT_GLOBAL_DIR: {
return "GLOBAL_DIR";
}
case PROPERTY_HINT_RESOURCE_TYPE: {
return "RESOURCE_TYPE";
}
case PROPERTY_HINT_MULTILINE_TEXT: {
return "MULTILINE_TEXT";
}
case PROPERTY_HINT_EXPRESSION: {
return "EXPRESSION";
}
case PROPERTY_HINT_PLACEHOLDER_TEXT: {
return "PLACEHOLDER_TEXT";
}
case PROPERTY_HINT_COLOR_NO_ALPHA: {
return "COLOR_NO_ALPHA";
}
case PROPERTY_HINT_OBJECT_ID: {
return "OBJECT_ID";
}
case PROPERTY_HINT_TYPE_STRING: {
return "TYPE_STRING";
}
case PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE: {
return "NODE_PATH_TO_EDITED_NODE";
}
case PROPERTY_HINT_OBJECT_TOO_BIG: {
return "OBJECT_TOO_BIG";
}
case PROPERTY_HINT_NODE_PATH_VALID_TYPES: {
return "NODE_PATH_VALID_TYPES";
}
case PROPERTY_HINT_SAVE_FILE: {
return "SAVE_FILE";
}
case PROPERTY_HINT_GLOBAL_SAVE_FILE: {
return "GLOBAL_SAVE_FILE";
}
case PROPERTY_HINT_INT_IS_OBJECTID: {
return "INT_IS_OBJECTID";
}
case PROPERTY_HINT_INT_IS_POINTER: {
return "INT_IS_POINTER";
}
case PROPERTY_HINT_ARRAY_TYPE: {
return "ARRAY_TYPE";
}
case PROPERTY_HINT_LOCALE_ID: {
return "LOCALE_ID";
}
case PROPERTY_HINT_LOCALIZABLE_STRING: {
return "LOCALIZABLE_STRING";
}
case PROPERTY_HINT_NODE_TYPE: {
return "NODE_TYPE";
}
case PROPERTY_HINT_HIDE_QUATERNION_EDIT: {
return "HIDE_QUATERNION_EDIT";
}
case PROPERTY_HINT_PASSWORD: {
return "PASSWORD";
}
case PROPERTY_HINT_LAYERS_AVOIDANCE: {
return "LAYERS_AVOIDANCE";
}
case PROPERTY_HINT_MAX: {
return "MAX";
}
}
return "";
}
PackedInt32Array LimboUtility::get_property_hints_allowed_for_type(Variant::Type p_type) const {
PackedInt32Array hints;
hints.append(PROPERTY_HINT_NONE);
// * According to editor/editor_properties.cpp
switch (p_type) {
case Variant::Type::NIL:
case Variant::Type::RID:
case Variant::Type::CALLABLE:
case Variant::Type::SIGNAL:
case Variant::Type::BOOL: {
} break;
case Variant::Type::INT: {
hints.append(PROPERTY_HINT_RANGE);
hints.append(PROPERTY_HINT_ENUM);
hints.append(PROPERTY_HINT_FLAGS);
hints.append(PROPERTY_HINT_LAYERS_2D_RENDER);
hints.append(PROPERTY_HINT_LAYERS_2D_PHYSICS);
hints.append(PROPERTY_HINT_LAYERS_2D_NAVIGATION);
hints.append(PROPERTY_HINT_LAYERS_3D_RENDER);
hints.append(PROPERTY_HINT_LAYERS_3D_PHYSICS);
hints.append(PROPERTY_HINT_LAYERS_3D_NAVIGATION);
hints.append(PROPERTY_HINT_LAYERS_AVOIDANCE);
} break;
case Variant::Type::FLOAT: {
hints.append(PROPERTY_HINT_RANGE);
hints.append(PROPERTY_HINT_EXP_EASING);
} break;
case Variant::Type::STRING: {
hints.append(PROPERTY_HINT_ENUM);
hints.append(PROPERTY_HINT_ENUM_SUGGESTION);
hints.append(PROPERTY_HINT_FILE);
hints.append(PROPERTY_HINT_DIR);
hints.append(PROPERTY_HINT_GLOBAL_FILE);
hints.append(PROPERTY_HINT_GLOBAL_DIR);
hints.append(PROPERTY_HINT_MULTILINE_TEXT);
hints.append(PROPERTY_HINT_EXPRESSION);
hints.append(PROPERTY_HINT_PLACEHOLDER_TEXT);
// hints.append(PROPERTY_HINT_TYPE_STRING); // ! Causes a crash.
hints.append(PROPERTY_HINT_SAVE_FILE);
hints.append(PROPERTY_HINT_GLOBAL_SAVE_FILE);
hints.append(PROPERTY_HINT_LOCALE_ID);
hints.append(PROPERTY_HINT_PASSWORD);
} break;
case Variant::Type::VECTOR2:
case Variant::Type::VECTOR2I:
case Variant::Type::VECTOR3:
case Variant::Type::VECTOR3I:
case Variant::Type::VECTOR4:
case Variant::Type::VECTOR4I: {
hints.append(PROPERTY_HINT_RANGE);
hints.append(PROPERTY_HINT_LINK);
} break;
case Variant::Type::RECT2:
case Variant::Type::RECT2I:
case Variant::Type::TRANSFORM2D:
case Variant::Type::PLANE:
case Variant::Type::AABB:
case Variant::Type::BASIS:
case Variant::Type::TRANSFORM3D:
case Variant::Type::PROJECTION: {
hints.append(PROPERTY_HINT_RANGE);
} break;
case Variant::Type::QUATERNION: {
hints.append(PROPERTY_HINT_RANGE);
hints.append(PROPERTY_HINT_HIDE_QUATERNION_EDIT);
} break;
case Variant::Type::COLOR: {
hints.append(PROPERTY_HINT_COLOR_NO_ALPHA);
} break;
case Variant::Type::STRING_NAME: {
hints.append(PROPERTY_HINT_ENUM);
hints.append(PROPERTY_HINT_ENUM_SUGGESTION);
hints.append(PROPERTY_HINT_PLACEHOLDER_TEXT);
hints.append(PROPERTY_HINT_PASSWORD);
} break;
case Variant::Type::NODE_PATH: {
hints.append(PROPERTY_HINT_NODE_PATH_VALID_TYPES);
hints.append(PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT);
} break;
case Variant::Type::OBJECT: {
hints.append(PROPERTY_HINT_RESOURCE_TYPE);
hints.append(PROPERTY_HINT_NODE_TYPE);
} break;
case Variant::Type::DICTIONARY: {
hints.append(PROPERTY_HINT_LOCALIZABLE_STRING);
} break;
case Variant::Type::ARRAY:
case Variant::Type::PACKED_BYTE_ARRAY:
case Variant::Type::PACKED_INT32_ARRAY:
case Variant::Type::PACKED_INT64_ARRAY:
case Variant::Type::PACKED_FLOAT32_ARRAY:
case Variant::Type::PACKED_FLOAT64_ARRAY:
case Variant::Type::PACKED_STRING_ARRAY:
case Variant::Type::PACKED_VECTOR2_ARRAY:
case Variant::Type::PACKED_VECTOR3_ARRAY:
case Variant::Type::PACKED_COLOR_ARRAY:
case Variant::Type::VARIANT_MAX: {
} break;
}
return hints;
}
#ifdef TOOLS_ENABLED
2024-01-09 12:34:24 +00:00
Ref<Shortcut> LimboUtility::add_shortcut(const String &p_path, const String &p_name, Key p_keycode) {
Ref<Shortcut> sc = memnew(Shortcut);
sc->set_name(p_name);
2024-01-09 12:34:24 +00:00
Array events;
2024-01-14 20:48:15 +00:00
Key keycode = p_keycode;
2024-01-09 12:34:24 +00:00
Ref<InputEventKey> ev = memnew(InputEventKey);
2024-01-14 20:48:15 +00:00
if (((int)LW_KEY_MASK(CMD_OR_CTRL) & (int)keycode) == (int)LW_KEY_MASK(CMD_OR_CTRL)) {
keycode = (Key)((int)keycode & (~((int)LW_KEY_MASK(CMD_OR_CTRL))));
ev->set_ctrl_pressed(true);
}
if (((int)LW_KEY_MASK(ALT) & (int)keycode) == (int)LW_KEY_MASK(ALT)) {
keycode = (Key)((int)keycode & (~((int)LW_KEY_MASK(ALT))));
ev->set_alt_pressed(true);
}
if (((int)LW_KEY_MASK(SHIFT) & (int)keycode) == (int)LW_KEY_MASK(SHIFT)) {
keycode = (Key)((int)keycode & (~((int)LW_KEY_MASK(SHIFT))));
ev->set_shift_pressed(true);
}
ev->set_keycode(keycode);
ev->set_pressed(true);
2024-01-09 12:34:24 +00:00
events.append(ev);
sc->set_events(events);
shortcuts[p_path] = sc;
return sc;
}
bool LimboUtility::is_shortcut(const String &p_path, const Ref<InputEvent> &p_event) const {
HashMap<String, Ref<Shortcut>>::ConstIterator E = shortcuts.find(p_path);
ERR_FAIL_COND_V_MSG(!E, false, vformat("LimboUtility: Shortcut not found: %s.", p_path));
return E->value->matches_event(p_event);
}
Ref<Shortcut> LimboUtility::get_shortcut(const String &p_path) const {
HashMap<String, Ref<Shortcut>>::ConstIterator SC = shortcuts.find(p_path);
if (SC) {
return SC->value;
}
return nullptr;
}
2024-01-13 21:40:27 +00:00
void LimboUtility::open_doc_introduction() {
OS::get_singleton()->shell_open(vformat("https://limboai.readthedocs.io/en/%s/getting-started/introduction.html",
2024-01-13 21:40:27 +00:00
LIMBO_DOC_VERSION));
}
void LimboUtility::open_doc_online() {
OS::get_singleton()->shell_open(vformat("https://limboai.readthedocs.io/en/%s/index.html",
LIMBO_DOC_VERSION));
}
void LimboUtility::open_doc_gdextension_limitations() {
OS::get_singleton()->shell_open(vformat("https://limboai.readthedocs.io/en/%s/getting-started/gdextension.html#limitations-of-the-gdextension-version",
LIMBO_DOC_VERSION));
}
void LimboUtility::open_doc_custom_tasks() {
OS::get_singleton()->shell_open(vformat("https://limboai.readthedocs.io/en/%s/getting-started/custom-tasks.html",
LIMBO_DOC_VERSION));
}
2024-01-13 21:40:27 +00:00
void LimboUtility::open_doc_class(const String &p_class_name) {
if (p_class_name.begins_with("res://")) {
SHOW_DOC(vformat("class_name:\"%s\"", p_class_name));
return;
}
#ifdef LIMBOAI_MODULE
SHOW_DOC("class_name:" + p_class_name);
#elif LIMBOAI_GDEXTENSION
OS::get_singleton()->shell_open(vformat("https://limboai.readthedocs.io/en/%s/classes/class_%s.html",
LIMBO_DOC_VERSION, p_class_name.to_lower()));
#endif
}
#endif // ! TOOLS_ENABLED
2022-08-28 10:54:34 +00:00
void LimboUtility::_bind_methods() {
2022-09-21 21:56:04 +00:00
ClassDB::bind_method(D_METHOD("decorate_var", "p_variable"), &LimboUtility::decorate_var);
ClassDB::bind_method(D_METHOD("decorate_output_var", "p_variable"), &LimboUtility::decorate_output_var);
2022-11-01 13:03:20 +00:00
ClassDB::bind_method(D_METHOD("get_status_name", "p_status"), &LimboUtility::get_status_name);
2023-07-20 20:15:30 +00:00
ClassDB::bind_method(D_METHOD("get_task_icon", "p_class_or_script_path"), &LimboUtility::get_task_icon);
2023-08-10 11:04:53 +00:00
BIND_ENUM_CONSTANT(CHECK_EQUAL);
BIND_ENUM_CONSTANT(CHECK_LESS_THAN);
BIND_ENUM_CONSTANT(CHECK_LESS_THAN_OR_EQUAL);
BIND_ENUM_CONSTANT(CHECK_GREATER_THAN);
BIND_ENUM_CONSTANT(CHECK_GREATER_THAN_OR_EQUAL);
BIND_ENUM_CONSTANT(CHECK_NOT_EQUAL);
BIND_ENUM_CONSTANT(OPERATION_NONE);
BIND_ENUM_CONSTANT(OPERATION_ADDITION);
BIND_ENUM_CONSTANT(OPERATION_SUBTRACTION);
BIND_ENUM_CONSTANT(OPERATION_MULTIPLICATION);
BIND_ENUM_CONSTANT(OPERATION_DIVISION);
BIND_ENUM_CONSTANT(OPERATION_MODULO);
BIND_ENUM_CONSTANT(OPERATION_POWER);
BIND_ENUM_CONSTANT(OPERATION_BIT_SHIFT_LEFT);
BIND_ENUM_CONSTANT(OPERATION_BIT_SHIFT_RIGHT);
BIND_ENUM_CONSTANT(OPERATION_BIT_AND);
BIND_ENUM_CONSTANT(OPERATION_BIT_OR);
BIND_ENUM_CONSTANT(OPERATION_BIT_XOR);
2022-09-21 21:56:04 +00:00
}
LimboUtility::LimboUtility() {
singleton = this;
}
LimboUtility::~LimboUtility() {
singleton = nullptr;
2022-08-28 10:54:34 +00:00
}