feat: updated godot version
This commit is contained in:
parent
0c508b0831
commit
42b028dbb5
4694 changed files with 236470 additions and 401376 deletions
|
|
@ -30,18 +30,14 @@
|
|||
|
||||
#include "csharp_script.h"
|
||||
|
||||
#include "godotsharp_defs.h"
|
||||
#include "godotsharp_dirs.h"
|
||||
#include "managed_callable.h"
|
||||
#include "mono_gd/gd_mono_cache.h"
|
||||
#include "signal_awaiter_utils.h"
|
||||
#include "utils/macros.h"
|
||||
#include "utils/naming_utils.h"
|
||||
#include "utils/string_utils.h"
|
||||
|
||||
#ifdef GD_MONO_HOT_RELOAD
|
||||
#include "managed_callable.h"
|
||||
#include "utils/path_utils.h"
|
||||
#endif
|
||||
#include "utils/string_utils.h"
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
#include "class_db_api_json.h"
|
||||
|
|
@ -52,12 +48,10 @@
|
|||
#include "editor/script_templates/templates.gen.h"
|
||||
#endif
|
||||
|
||||
#include "core/config/engine.h"
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/debugger/engine_debugger.h"
|
||||
#include "core/debugger/script_debugger.h"
|
||||
#include "core/io/file_access.h"
|
||||
#include "core/object/class_db.h"
|
||||
#include "core/os/mutex.h"
|
||||
#include "core/os/os.h"
|
||||
#include "core/os/thread.h"
|
||||
|
|
@ -65,20 +59,24 @@
|
|||
|
||||
#ifdef TOOLS_ENABLED
|
||||
#include "core/os/keyboard.h"
|
||||
#include "editor/docks/inspector_dock.h"
|
||||
#include "editor/docks/signals_dock.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/file_system/editor_file_system.h"
|
||||
#include "editor/settings/editor_settings.h"
|
||||
|
||||
#ifdef GD_MONO_HOT_RELOAD
|
||||
#include "editor/docks/inspector_dock.h"
|
||||
#include "editor/docks/signals_dock.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Types that will be skipped over (in favor of their base types) when setting up instance bindings.
|
||||
// This must be a superset of `ignored_types` in bindings_generator.cpp.
|
||||
const Vector<String> ignored_types = {};
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
static bool _create_project_solution_if_needed() {
|
||||
CRASH_COND(CSharpLanguage::get_singleton()->get_godotsharp_editor() == nullptr);
|
||||
return CSharpLanguage::get_singleton()->get_godotsharp_editor()->call("CreateProjectSolutionIfNeeded");
|
||||
}
|
||||
#endif
|
||||
|
||||
CSharpLanguage *CSharpLanguage::singleton = nullptr;
|
||||
|
||||
GDExtensionInstanceBindingCallbacks CSharpLanguage::_instance_binding_callbacks = {
|
||||
|
|
@ -402,6 +400,10 @@ String CSharpLanguage::validate_path(const String &p_path) const {
|
|||
return "";
|
||||
}
|
||||
|
||||
Script *CSharpLanguage::create_script() const {
|
||||
return memnew(CSharpScript);
|
||||
}
|
||||
|
||||
bool CSharpLanguage::supports_builtin_mode() const {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1151,12 +1153,12 @@ bool CSharpLanguage::setup_csharp_script_binding(CSharpScriptBinding &r_script_b
|
|||
// workaround to allow GDExtension classes to be used from C# so long as they're only used through base classes that
|
||||
// are registered from the engine. This will likely need to be removed whenever proper support for GDExtension
|
||||
// classes is added to C#. See #75955 for more details.
|
||||
while (classinfo && (!classinfo->exposed || classinfo->gdextension || ignored_types.has(classinfo->gdtype->get_name()))) {
|
||||
while (classinfo && (!classinfo->exposed || classinfo->gdextension || ignored_types.has(classinfo->name))) {
|
||||
classinfo = classinfo->inherits_ptr;
|
||||
}
|
||||
|
||||
ERR_FAIL_NULL_V(classinfo, false);
|
||||
type_name = classinfo->gdtype->get_name();
|
||||
type_name = classinfo->name;
|
||||
|
||||
bool parent_is_object_class = ClassDB::is_parent_class(p_object->get_class_name(), type_name);
|
||||
ERR_FAIL_COND_V_MSG(!parent_is_object_class, false,
|
||||
|
|
@ -2819,3 +2821,123 @@ void CSharpScript::get_members(HashSet<StringName> *p_members) {
|
|||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
}
|
||||
|
||||
/*************** RESOURCE ***************/
|
||||
|
||||
Ref<Resource> ResourceFormatLoaderCSharpScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
|
||||
if (r_error) {
|
||||
*r_error = ERR_FILE_CANT_OPEN;
|
||||
}
|
||||
|
||||
// TODO ignore anything inside bin/ and obj/ in tools builds?
|
||||
|
||||
String real_path = p_path;
|
||||
if (p_path.begins_with("csharp://")) {
|
||||
// This is a virtual path used by generic types, extract the real path.
|
||||
real_path = "res://" + p_path.trim_prefix("csharp://");
|
||||
real_path = real_path.substr(0, real_path.rfind_char(':'));
|
||||
}
|
||||
|
||||
Ref<CSharpScript> scr;
|
||||
|
||||
if (GDMonoCache::godot_api_cache_updated) {
|
||||
GDMonoCache::managed_callbacks.ScriptManagerBridge_GetOrCreateScriptBridgeForPath(&p_path, &scr);
|
||||
ERR_FAIL_COND_V_MSG(scr.is_null(), Ref<Resource>(), "Could not create C# script '" + real_path + "'.");
|
||||
} else {
|
||||
scr.instantiate();
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
Error err = scr->load_source_code(real_path);
|
||||
ERR_FAIL_COND_V_MSG(err != OK, Ref<Resource>(), "Cannot load C# script file '" + real_path + "'.");
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
// Only one instance of a C# script is allowed to exist.
|
||||
ERR_FAIL_COND_V_MSG(!scr->get_path().is_empty() && scr->get_path() != p_original_path, Ref<Resource>(),
|
||||
"The C# script path is different from the path it was registered in the C# dictionary.");
|
||||
|
||||
Ref<Resource> existing = ResourceCache::get_ref(p_path);
|
||||
switch (p_cache_mode) {
|
||||
case ResourceFormatLoader::CACHE_MODE_IGNORE:
|
||||
case ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP:
|
||||
break;
|
||||
case ResourceFormatLoader::CACHE_MODE_REUSE:
|
||||
if (existing.is_null()) {
|
||||
scr->set_path(p_original_path);
|
||||
} else {
|
||||
scr = existing;
|
||||
}
|
||||
break;
|
||||
case ResourceFormatLoader::CACHE_MODE_REPLACE:
|
||||
case ResourceFormatLoader::CACHE_MODE_REPLACE_DEEP:
|
||||
scr->set_path(p_original_path, true);
|
||||
break;
|
||||
}
|
||||
|
||||
scr->reload();
|
||||
|
||||
if (r_error) {
|
||||
*r_error = OK;
|
||||
}
|
||||
|
||||
return scr;
|
||||
}
|
||||
|
||||
void ResourceFormatLoaderCSharpScript::get_recognized_extensions(List<String> *p_extensions) const {
|
||||
p_extensions->push_back("cs");
|
||||
}
|
||||
|
||||
bool ResourceFormatLoaderCSharpScript::handles_type(const String &p_type) const {
|
||||
return p_type == "Script" || p_type == CSharpLanguage::get_singleton()->get_type();
|
||||
}
|
||||
|
||||
String ResourceFormatLoaderCSharpScript::get_resource_type(const String &p_path) const {
|
||||
return p_path.has_extension("cs") ? CSharpLanguage::get_singleton()->get_type() : "";
|
||||
}
|
||||
|
||||
Error ResourceFormatSaverCSharpScript::save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags) {
|
||||
Ref<CSharpScript> sqscr = p_resource;
|
||||
ERR_FAIL_COND_V(sqscr.is_null(), ERR_INVALID_PARAMETER);
|
||||
|
||||
String source = sqscr->get_source_code();
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (!FileAccess::exists(p_path)) {
|
||||
// The file does not yet exist, let's assume the user just created this script. In such
|
||||
// cases we need to check whether the solution and csproj were already created or not.
|
||||
if (!_create_project_solution_if_needed()) {
|
||||
ERR_PRINT("C# project could not be created; cannot add file: '" + p_path + "'.");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
Error err;
|
||||
Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::WRITE, &err);
|
||||
ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save C# script file '" + p_path + "'.");
|
||||
|
||||
file->store_string(source);
|
||||
|
||||
if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) {
|
||||
return ERR_CANT_CREATE;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (ScriptServer::is_reload_scripts_on_save_enabled()) {
|
||||
CSharpLanguage::get_singleton()->reload_tool_script(p_resource, false);
|
||||
}
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void ResourceFormatSaverCSharpScript::get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const {
|
||||
if (Object::cast_to<CSharpScript>(p_resource.ptr())) {
|
||||
p_extensions->push_back("cs");
|
||||
}
|
||||
}
|
||||
|
||||
bool ResourceFormatSaverCSharpScript::recognize(const Ref<Resource> &p_resource) const {
|
||||
return Object::cast_to<CSharpScript>(p_resource.ptr()) != nullptr;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue