2024-01-07 05:51:34 +00:00
|
|
|
/**
|
2024-03-21 20:38:57 +00:00
|
|
|
* limbo_compat.cpp
|
2024-01-07 05:51:34 +00:00
|
|
|
* =============================================================================
|
2024-03-21 20:38:57 +00:00
|
|
|
* Copyright 2021-2024 Serhii Snitsaruk
|
2024-01-07 05:51:34 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
|
|
|
|
2024-01-09 12:34:24 +00:00
|
|
|
#include "limbo_compat.h"
|
2024-01-07 16:33:05 +00:00
|
|
|
|
|
|
|
#ifdef LIMBOAI_MODULE
|
|
|
|
|
2024-01-10 22:26:24 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
2024-01-10 21:45:42 +00:00
|
|
|
#include "core/io/resource.h"
|
2024-01-23 14:31:56 +00:00
|
|
|
#include "core/variant/variant.h"
|
2024-01-10 21:45:42 +00:00
|
|
|
#include "editor/editor_node.h"
|
|
|
|
#include "editor/plugins/script_editor_plugin.h"
|
2024-01-13 16:10:42 +00:00
|
|
|
#endif // TOOLS_ENABLED
|
2024-01-07 16:33:05 +00:00
|
|
|
|
2024-01-10 21:45:42 +00:00
|
|
|
#endif // ! LIMBOAI_MODULE
|
2024-01-07 05:51:34 +00:00
|
|
|
|
|
|
|
#ifdef LIMBOAI_GDEXTENSION
|
|
|
|
|
2024-01-07 16:33:05 +00:00
|
|
|
#include "godot_cpp/classes/editor_interface.hpp"
|
2024-01-09 15:25:28 +00:00
|
|
|
#include "godot_cpp/core/error_macros.hpp"
|
|
|
|
#include "godot_cpp/variant/typed_array.hpp"
|
2024-01-07 05:51:34 +00:00
|
|
|
#include <godot_cpp/classes/editor_settings.hpp>
|
2024-01-09 12:34:24 +00:00
|
|
|
#include <godot_cpp/classes/project_settings.hpp>
|
2024-01-07 16:33:05 +00:00
|
|
|
#include <godot_cpp/classes/resource_loader.hpp>
|
|
|
|
#include <godot_cpp/classes/script.hpp>
|
2024-01-09 15:25:28 +00:00
|
|
|
#include <godot_cpp/classes/script_editor.hpp>
|
|
|
|
#include <godot_cpp/classes/script_editor_base.hpp>
|
2024-01-07 12:36:59 +00:00
|
|
|
#include <godot_cpp/classes/translation_server.hpp>
|
2024-01-07 05:51:34 +00:00
|
|
|
|
|
|
|
using namespace godot;
|
|
|
|
|
|
|
|
Variant _EDITOR_GET(const String &p_setting) {
|
|
|
|
Ref<EditorSettings> es = EditorInterface::get_singleton()->get_editor_settings();
|
2024-08-18 10:41:16 +00:00
|
|
|
ERR_FAIL_COND_V_MSG(es.is_null() || !es->has_setting(p_setting), Variant(), "Couldn't get editor setting: " + p_setting);
|
2024-01-07 05:51:34 +00:00
|
|
|
return es->get(p_setting);
|
|
|
|
}
|
|
|
|
|
2024-01-07 12:36:59 +00:00
|
|
|
String TTR(const String &p_text, const String &p_context) {
|
|
|
|
if (TranslationServer::get_singleton()) {
|
|
|
|
return TranslationServer::get_singleton()->translate(p_text, p_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
return p_text;
|
|
|
|
}
|
|
|
|
|
2024-01-09 12:34:24 +00:00
|
|
|
Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default, bool p_restart_if_changed, bool p_ignore_value_in_docs, bool p_basic, bool p_internal) {
|
|
|
|
Variant ret;
|
|
|
|
if (!ProjectSettings::get_singleton()->has_setting(p_var)) {
|
|
|
|
ProjectSettings::get_singleton()->set(p_var, p_default);
|
|
|
|
}
|
|
|
|
ret = GLOBAL_GET(p_var);
|
|
|
|
|
|
|
|
ProjectSettings::get_singleton()->set_initial_value(p_var, p_default);
|
|
|
|
// ProjectSettings::get_singleton()->set_builtin_order(p_var);
|
|
|
|
ProjectSettings::get_singleton()->set_as_basic(p_var, p_basic);
|
|
|
|
ProjectSettings::get_singleton()->set_restart_if_changed(p_var, p_restart_if_changed);
|
|
|
|
// ProjectSettings::get_singleton()->set_ignore_value_in_docs(p_var, p_ignore_value_in_docs);
|
|
|
|
ProjectSettings::get_singleton()->set_as_internal(p_var, p_internal);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant _GLOBAL_DEF(const PropertyInfo &p_info, const Variant &p_default, bool p_restart_if_changed, bool p_ignore_value_in_docs, bool p_basic, bool p_internal) {
|
|
|
|
Variant ret = _GLOBAL_DEF(p_info.name, p_default, p_restart_if_changed, p_ignore_value_in_docs, p_basic, p_internal);
|
|
|
|
|
|
|
|
Dictionary dic_info;
|
|
|
|
dic_info["type"] = p_info.type;
|
|
|
|
dic_info["name"] = p_info.name;
|
|
|
|
dic_info["class_name"] = p_info.class_name;
|
|
|
|
dic_info["hint"] = p_info.hint;
|
|
|
|
dic_info["hint_string"] = p_info.hint_string;
|
|
|
|
dic_info["usage"] = p_info.usage;
|
|
|
|
|
|
|
|
ProjectSettings::get_singleton()->add_property_info(dic_info);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-01-10 21:45:42 +00:00
|
|
|
#endif // ! LIMBOAI_GDEXTENSION
|
|
|
|
|
|
|
|
// **** Shared
|
|
|
|
|
2024-01-23 14:31:56 +00:00
|
|
|
Variant VARIANT_DEFAULT(Variant::Type p_type) {
|
|
|
|
switch (p_type) {
|
|
|
|
case Variant::Type::NIL: {
|
|
|
|
return Variant();
|
|
|
|
} break;
|
|
|
|
case Variant::Type::BOOL: {
|
|
|
|
return Variant(false);
|
|
|
|
} break;
|
|
|
|
case Variant::Type::INT: {
|
|
|
|
return Variant(0);
|
|
|
|
} break;
|
|
|
|
case Variant::Type::FLOAT: {
|
|
|
|
return Variant(0.0);
|
|
|
|
} break;
|
|
|
|
case Variant::Type::STRING: {
|
|
|
|
return Variant("");
|
|
|
|
} break;
|
|
|
|
case Variant::Type::VECTOR2: {
|
|
|
|
return Variant(Vector2());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::VECTOR2I: {
|
|
|
|
return Variant(Vector2i());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::RECT2: {
|
|
|
|
return Variant(Rect2());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::RECT2I: {
|
|
|
|
return Variant(Rect2i());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::VECTOR3: {
|
|
|
|
return Variant(Vector3());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::VECTOR3I: {
|
|
|
|
return Variant(Vector3i());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::TRANSFORM2D: {
|
|
|
|
return Variant(Transform2D());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::VECTOR4: {
|
|
|
|
return Variant(Vector4());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::VECTOR4I: {
|
|
|
|
return Variant(Vector4i());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::PLANE: {
|
|
|
|
return Variant(Plane());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::QUATERNION: {
|
|
|
|
return Variant(Quaternion());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::AABB: {
|
|
|
|
return Variant(AABB());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::BASIS: {
|
|
|
|
return Variant(Basis());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::TRANSFORM3D: {
|
|
|
|
return Variant(Transform3D());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::PROJECTION: {
|
|
|
|
return Variant(Projection());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::COLOR: {
|
|
|
|
return Variant(Color());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::STRING_NAME: {
|
|
|
|
return Variant(StringName());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::NODE_PATH: {
|
|
|
|
return Variant(NodePath());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::RID: {
|
|
|
|
return Variant(RID());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::OBJECT: {
|
|
|
|
return Variant();
|
|
|
|
} break;
|
|
|
|
case Variant::Type::CALLABLE: {
|
|
|
|
return Variant();
|
|
|
|
} break;
|
|
|
|
case Variant::Type::SIGNAL: {
|
|
|
|
return Variant();
|
|
|
|
} break;
|
|
|
|
case Variant::Type::DICTIONARY: {
|
|
|
|
return Variant(Dictionary());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::ARRAY: {
|
|
|
|
return Variant(Array());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::PACKED_BYTE_ARRAY: {
|
|
|
|
return Variant(PackedByteArray());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::PACKED_INT32_ARRAY: {
|
|
|
|
return Variant(PackedInt32Array());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::PACKED_INT64_ARRAY: {
|
|
|
|
return Variant(PackedInt64Array());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::PACKED_FLOAT32_ARRAY: {
|
|
|
|
return Variant(PackedFloat32Array());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::PACKED_FLOAT64_ARRAY: {
|
|
|
|
return Variant(PackedFloat64Array());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::PACKED_STRING_ARRAY: {
|
|
|
|
return Variant(PackedStringArray());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::PACKED_VECTOR2_ARRAY: {
|
|
|
|
return Variant(PackedVector2Array());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::PACKED_VECTOR3_ARRAY: {
|
|
|
|
return Variant(PackedVector3Array());
|
|
|
|
} break;
|
|
|
|
case Variant::Type::PACKED_COLOR_ARRAY: {
|
|
|
|
return Variant(PackedColorArray());
|
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-10 22:26:24 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
2024-08-05 13:46:02 +00:00
|
|
|
void SHOW_BUILTIN_DOC(const String &p_topic) {
|
2024-01-09 15:25:28 +00:00
|
|
|
#ifdef LIMBOAI_MODULE
|
2024-01-10 21:45:42 +00:00
|
|
|
ScriptEditor::get_singleton()->goto_help(p_topic);
|
2024-01-09 15:25:28 +00:00
|
|
|
EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
|
2024-01-13 16:10:42 +00:00
|
|
|
#elif LIMBOAI_GDEXTENSION
|
2024-01-09 15:25:28 +00:00
|
|
|
TypedArray<ScriptEditorBase> open_editors = EditorInterface::get_singleton()->get_script_editor()->get_open_script_editors();
|
|
|
|
ERR_FAIL_COND_MSG(open_editors.size() == 0, "Can't open help page. Need at least one script open in the script editor.");
|
|
|
|
ScriptEditorBase *seb = Object::cast_to<ScriptEditorBase>(open_editors.front());
|
|
|
|
ERR_FAIL_NULL(seb);
|
|
|
|
seb->emit_signal("go_to_help", p_topic);
|
2024-01-13 16:10:42 +00:00
|
|
|
#endif
|
2024-01-09 15:25:28 +00:00
|
|
|
}
|
|
|
|
|
2024-01-10 21:45:42 +00:00
|
|
|
void EDIT_SCRIPT(const String &p_path) {
|
|
|
|
#ifdef LIMBOAI_MODULE
|
|
|
|
Ref<Resource> res = ScriptEditor::get_singleton()->open_file(p_path);
|
|
|
|
ERR_FAIL_COND_MSG(res.is_null(), "Failed to load script: " + p_path);
|
|
|
|
EditorNode::get_singleton()->edit_resource(res);
|
2024-01-13 16:10:42 +00:00
|
|
|
#elif LIMBOAI_GDEXTENSION
|
2024-01-10 21:45:42 +00:00
|
|
|
Ref<Script> res = RESOURCE_LOAD(p_path, "Script");
|
|
|
|
ERR_FAIL_COND_MSG(res.is_null(), "Failed to load script: " + p_path);
|
|
|
|
EditorInterface::get_singleton()->edit_script(res);
|
|
|
|
EditorInterface::get_singleton()->set_main_screen_editor("Script");
|
2024-01-13 16:10:42 +00:00
|
|
|
#endif
|
2024-01-10 21:45:42 +00:00
|
|
|
}
|
2024-01-10 22:26:24 +00:00
|
|
|
|
|
|
|
#endif // ! TOOLS_ENABLED
|