limboai/util/limbo_utility.h

118 lines
3.4 KiB
C
Raw Normal View History

/**
* limbo_utility.h
* =============================================================================
* 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
#ifndef LIMBO_UTILITY_H
#define LIMBO_UTILITY_H
2024-01-09 12:34:24 +00:00
#include "limbo_compat.h"
#ifdef LIMBOAI_MODULE
#include "core/object/object.h"
2023-08-15 15:49:13 +00:00
2024-01-09 12:34:24 +00:00
#include "core/input/shortcut.h"
2023-08-15 15:49:13 +00:00
#include "core/object/class_db.h"
#include "core/variant/binder_common.h"
2023-08-10 11:04:53 +00:00
#include "core/variant/variant.h"
#include "scene/resources/texture.h"
#endif // LIMBOAI_MODULE
#ifdef LIMBOAI_GDEXTENSION
#include <godot_cpp/classes/object.hpp>
2024-01-09 12:34:24 +00:00
#include <godot_cpp/classes/shortcut.hpp>
#include <godot_cpp/classes/texture2d.hpp>
#include <godot_cpp/core/binder_common.hpp>
#include <godot_cpp/core/class_db.hpp>
2024-01-09 12:34:24 +00:00
#include <godot_cpp/templates/hash_map.hpp>
using namespace godot;
#endif // LIMBOAI_GDEXTENSION
2022-08-28 10:54:34 +00:00
#define LOGICAL_XOR(a, b) (a) ? !(b) : (b)
2024-01-13 21:40:27 +00:00
#define LIMBO_DOC_VERSION "latest"
2022-08-28 10:54:34 +00:00
class LimboUtility : public Object {
GDCLASS(LimboUtility, Object);
2024-01-09 12:34:24 +00:00
private:
#ifdef TOOLS_ENABLED
2024-01-09 12:34:24 +00:00
HashMap<String, Ref<Shortcut>> shortcuts;
#endif // TOOLS_ENABLED
2024-01-09 12:34:24 +00:00
2023-08-10 11:04:53 +00:00
public:
enum CheckType : unsigned int {
CHECK_EQUAL,
CHECK_LESS_THAN,
CHECK_LESS_THAN_OR_EQUAL,
CHECK_GREATER_THAN,
CHECK_GREATER_THAN_OR_EQUAL,
CHECK_NOT_EQUAL
};
enum Operation {
OPERATION_NONE,
OPERATION_ADDITION,
OPERATION_SUBTRACTION,
OPERATION_MULTIPLICATION,
OPERATION_DIVISION,
OPERATION_MODULO,
OPERATION_POWER,
OPERATION_BIT_SHIFT_LEFT,
OPERATION_BIT_SHIFT_RIGHT,
OPERATION_BIT_AND,
OPERATION_BIT_OR,
OPERATION_BIT_XOR,
};
2022-08-28 10:54:34 +00:00
protected:
2022-09-21 21:56:04 +00:00
static LimboUtility *singleton;
2022-08-28 10:54:34 +00:00
static void _bind_methods();
public:
2022-09-21 21:56:04 +00:00
static LimboUtility *get_singleton();
2022-11-01 13:03:20 +00:00
String decorate_var(String p_variable) const;
String get_status_name(int p_status) const;
Ref<Texture2D> get_task_icon(String p_class_or_script_path) const;
2022-09-21 21:56:04 +00:00
String get_check_operator_string(CheckType p_check_type) const;
2023-08-10 11:04:53 +00:00
bool perform_check(CheckType p_check_type, const Variant &left_value, const Variant &right_value);
String get_operation_string(Operation p_operation) const;
Variant perform_operation(Operation p_operation, const Variant &left_value, const Variant &right_value);
2024-01-24 22:11:09 +00:00
String get_property_hint_text(PropertyHint p_hint) const;
PackedInt32Array get_property_hints_allowed_for_type(Variant::Type p_type) const;
2024-01-24 22:11:09 +00:00
#ifdef TOOLS_ENABLED
2024-01-09 12:34:24 +00:00
Ref<Shortcut> add_shortcut(const String &p_path, const String &p_name, Key p_keycode = LW_KEY(NONE));
bool is_shortcut(const String &p_path, const Ref<InputEvent> &p_event) const;
Ref<Shortcut> get_shortcut(const String &p_path) const;
2024-01-13 21:40:27 +00:00
void open_doc_introduction();
void open_doc_online();
void open_doc_gdextension_limitations();
void open_doc_custom_tasks();
2024-01-13 21:40:27 +00:00
void open_doc_class(const String &p_class_name);
#endif // TOOLS_ENABLED
2024-01-13 21:40:27 +00:00
2022-09-21 21:56:04 +00:00
LimboUtility();
~LimboUtility();
2022-08-28 10:54:34 +00:00
};
2023-08-10 11:04:53 +00:00
VARIANT_ENUM_CAST(LimboUtility::CheckType);
VARIANT_ENUM_CAST(LimboUtility::Operation);
2023-08-10 11:04:53 +00:00
2024-01-09 12:34:24 +00:00
#define LW_SHORTCUT(m_path, m_name, m_keycode) (LimboUtility::get_singleton()->add_shortcut(m_path, m_name, m_keycode))
#define LW_IS_SHORTCUT(m_path, m_event) (LimboUtility::get_singleton()->is_shortcut(m_path, m_event))
#define LW_GET_SHORTCUT(m_path) (LimboUtility::get_singleton()->get_shortcut(m_path))
2024-01-13 16:10:42 +00:00
#endif // LIMBO_UTILITY_H