mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-11-21 16:37:20 +01:00
Backpoered from Godot 4: Add is_built_in() method to Resource.
- KoBeWi
e393c2a734
This commit is contained in:
parent
70bd32682c
commit
60eb59ab19
@ -1598,7 +1598,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
|
|||||||
return; // don't save it
|
return; // don't save it
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res->get_path().length() && res->get_path().find("::") == -1) {
|
if (!res->is_built_in()) {
|
||||||
f->store_32(OBJECT_EXTERNAL_RESOURCE_INDEX);
|
f->store_32(OBJECT_EXTERNAL_RESOURCE_INDEX);
|
||||||
f->store_32(external_resources[res]);
|
f->store_32(external_resources[res]);
|
||||||
} else {
|
} else {
|
||||||
@ -1798,7 +1798,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!p_main && (!bundle_resources) && res->get_path().length() && res->get_path().find("::") == -1) {
|
if (!p_main && (!bundle_resources) && !res->is_built_in()) {
|
||||||
if (res->get_path() == path) {
|
if (res->get_path() == path) {
|
||||||
ERR_PRINT("Circular reference to resource being saved found: '" + local_path + "' will be null next time it's loaded.");
|
ERR_PRINT("Circular reference to resource being saved found: '" + local_path + "' will be null next time it's loaded.");
|
||||||
return;
|
return;
|
||||||
@ -2029,7 +2029,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
|
|||||||
|
|
||||||
for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) {
|
for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) {
|
||||||
RES r = E->get();
|
RES r = E->get();
|
||||||
if (r->get_path() == "" || r->get_path().find("::") != -1) {
|
if (!r->is_built_in()) {
|
||||||
if (r->get_subindex() != 0) {
|
if (r->get_subindex() != 0) {
|
||||||
if (used_indices.has(r->get_subindex())) {
|
if (used_indices.has(r->get_subindex())) {
|
||||||
r->set_subindex(0); //repeated
|
r->set_subindex(0); //repeated
|
||||||
@ -2042,7 +2042,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
|
|||||||
|
|
||||||
for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) {
|
for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) {
|
||||||
RES r = E->get();
|
RES r = E->get();
|
||||||
if (r->get_path() == "" || r->get_path().find("::") != -1) {
|
if (!r->is_built_in()) {
|
||||||
if (r->get_subindex() == 0) {
|
if (r->get_subindex() == 0) {
|
||||||
int new_subindex = 1;
|
int new_subindex = 1;
|
||||||
if (used_indices.size()) {
|
if (used_indices.size()) {
|
||||||
|
@ -1612,7 +1612,7 @@ void Object::_clear_internal_resource_paths(const Variant &p_var) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!r->get_path().begins_with("res://") || r->get_path().find("::") == -1) {
|
if (!r->is_built_in()) {
|
||||||
return; //not an internal resource
|
return; //not an internal resource
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,6 +101,7 @@ public:
|
|||||||
|
|
||||||
virtual void set_path(const String &p_path, bool p_take_over = false);
|
virtual void set_path(const String &p_path, bool p_take_over = false);
|
||||||
String get_path() const;
|
String get_path() const;
|
||||||
|
_FORCE_INLINE_ bool is_built_in() const { return path_cache.empty() || path_cache.find("::") != -1 || path_cache.begins_with("local://"); }
|
||||||
|
|
||||||
void set_subindex(int p_sub_index);
|
void set_subindex(int p_sub_index);
|
||||||
int get_subindex() const;
|
int get_subindex() const;
|
||||||
|
@ -3377,7 +3377,7 @@ void SceneTreeDock::_create_remap_for_node(Node *p_node, RBMap<RES, RES> &r_rema
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((res->get_path() == "" || res->get_path().find("::") > -1) && !r_remap.has(res)) {
|
if (res->is_built_in() && !r_remap.has(res)) {
|
||||||
_create_remap_for_resource(res, r_remap);
|
_create_remap_for_resource(res, r_remap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3404,7 +3404,7 @@ void SceneTreeDock::_create_remap_for_resource(RES p_resource, RBMap<RES, RES> &
|
|||||||
if (v.is_ref()) {
|
if (v.is_ref()) {
|
||||||
RES res = v;
|
RES res = v;
|
||||||
if (res.is_valid()) {
|
if (res.is_valid()) {
|
||||||
if ((res->get_path() == "" || res->get_path().find("::") > -1) && !r_remap.has(res)) {
|
if (res->is_built_in() && !r_remap.has(res)) {
|
||||||
_create_remap_for_resource(res, r_remap);
|
_create_remap_for_resource(res, r_remap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,12 +101,6 @@
|
|||||||
#include "shader_editor/shader_editor_plugin.h"
|
#include "shader_editor/shader_editor_plugin.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool _is_built_in_script(Script *p_script) {
|
|
||||||
String path = p_script->get_path();
|
|
||||||
|
|
||||||
return path.find("::") != -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
class EditorScriptCodeCompletionCache : public ScriptCodeCompletionCache {
|
class EditorScriptCodeCompletionCache : public ScriptCodeCompletionCache {
|
||||||
struct Cache {
|
struct Cache {
|
||||||
uint64_t time_loaded;
|
uint64_t time_loaded;
|
||||||
@ -496,7 +490,7 @@ void EditorScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back)
|
|||||||
Ref<Script> script = current->get_edited_resource();
|
Ref<Script> script = current->get_edited_resource();
|
||||||
if (p_save) {
|
if (p_save) {
|
||||||
// Do not try to save internal scripts
|
// Do not try to save internal scripts
|
||||||
if (!script.is_valid() || !(script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1)) {
|
if (!script.is_valid() || !(script->is_built_in())) {
|
||||||
save_current_script();
|
save_current_script();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -633,7 +627,7 @@ void EditorScriptEditor::_resave_scripts(const String &p_str) {
|
|||||||
|
|
||||||
RES script = se->get_edited_resource();
|
RES script = se->get_edited_resource();
|
||||||
|
|
||||||
if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1) {
|
if (script->is_built_in()) {
|
||||||
continue; //internal script, who cares
|
continue; //internal script, who cares
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -674,7 +668,7 @@ void EditorScriptEditor::reload_scripts() {
|
|||||||
|
|
||||||
RES edited_res = se->get_edited_resource();
|
RES edited_res = se->get_edited_resource();
|
||||||
|
|
||||||
if (edited_res->get_path() == "" || edited_res->get_path().find("local://") != -1 || edited_res->get_path().find("::") != -1) {
|
if (edited_res->is_built_in()) {
|
||||||
continue; //internal script, who cares
|
continue; //internal script, who cares
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -781,7 +775,7 @@ bool EditorScriptEditor::_test_script_times_on_disk(RES p_for_script) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (edited_res->get_path() == "" || edited_res->get_path().find("local://") != -1 || edited_res->get_path().find("::") != -1) {
|
if (edited_res->is_built_in()) {
|
||||||
continue; //internal script, who cares
|
continue; //internal script, who cares
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1439,7 +1433,7 @@ void EditorScriptEditor::close_builtin_scripts_from_scene(const String &p_scene)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (script->get_path().find("::") != -1 && script->get_path().begins_with(p_scene)) { //is an internal script and belongs to scene being closed
|
if (script->is_built_in() && script->get_path().begins_with(p_scene)) { //is an internal script and belongs to scene being closed
|
||||||
_close_tab(i, false);
|
_close_tab(i, false);
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
@ -2224,7 +2218,7 @@ void EditorScriptEditor::save_all_scripts() {
|
|||||||
se->apply_code();
|
se->apply_code();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (edited_res->get_path() != "" && edited_res->get_path().find("local://") == -1 && edited_res->get_path().find("::") == -1) {
|
if (!edited_res->is_built_in()) {
|
||||||
Ref<TextFile> text_file = edited_res;
|
Ref<TextFile> text_file = edited_res;
|
||||||
if (text_file != nullptr) {
|
if (text_file != nullptr) {
|
||||||
_save_text_file(text_file, text_file->get_path());
|
_save_text_file(text_file, text_file->get_path());
|
||||||
@ -2314,7 +2308,7 @@ void EditorScriptEditor::_add_callback(Object *p_obj, const String &p_function,
|
|||||||
script_list->select(script_list->find_metadata(i));
|
script_list->select(script_list->find_metadata(i));
|
||||||
|
|
||||||
// Save the current script so the changes can be picked up by an external editor.
|
// Save the current script so the changes can be picked up by an external editor.
|
||||||
if (!_is_built_in_script(script.ptr())) { // But only if it's not built-in script.
|
if (!script.ptr()->is_built_in()) { // But only if it's not built-in script.
|
||||||
save_current_script();
|
save_current_script();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -640,7 +640,7 @@ void EditorScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1) {
|
if (script->is_built_in()) {
|
||||||
continue; //internal script, who cares, though weird
|
continue; //internal script, who cares, though weird
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,18 +97,12 @@
|
|||||||
|
|
||||||
#include "editor_script_editor.h"
|
#include "editor_script_editor.h"
|
||||||
|
|
||||||
static bool _is_built_in_script(Script *p_script) {
|
|
||||||
String path = p_script->get_path();
|
|
||||||
|
|
||||||
return path.find("::") != -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EditorScriptEditorPlugin::edit(Object *p_object) {
|
void EditorScriptEditorPlugin::edit(Object *p_object) {
|
||||||
if (Object::cast_to<Script>(p_object)) {
|
if (Object::cast_to<Script>(p_object)) {
|
||||||
Script *p_script = Object::cast_to<Script>(p_object);
|
Script *p_script = Object::cast_to<Script>(p_object);
|
||||||
String res_path = p_script->get_path().get_slice("::", 0);
|
String res_path = p_script->get_path().get_slice("::", 0);
|
||||||
|
|
||||||
if (_is_built_in_script(p_script)) {
|
if (p_script->is_built_in()) {
|
||||||
if (ResourceLoader::get_resource_type(res_path) == "PackedScene") {
|
if (ResourceLoader::get_resource_type(res_path) == "PackedScene") {
|
||||||
if (!EditorNode::get_singleton()->is_scene_open(res_path)) {
|
if (!EditorNode::get_singleton()->is_scene_open(res_path)) {
|
||||||
EditorNode::get_singleton()->load_scene(res_path);
|
EditorNode::get_singleton()->load_scene(res_path);
|
||||||
|
@ -449,7 +449,7 @@ void ShaderEditor::_check_for_external_edit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// internal shader.
|
// internal shader.
|
||||||
if (shader->get_path() == "" || shader->get_path().find("local://") != -1 || shader->get_path().find("::") != -1) {
|
if (shader->is_built_in()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -496,7 +496,7 @@ void ShaderEditor::save_external_data(const String &p_str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
apply_shaders();
|
apply_shaders();
|
||||||
if (shader->get_path() != "" && shader->get_path().find("local://") == -1 && shader->get_path().find("::") == -1) {
|
if (!shader->is_built_in()) {
|
||||||
//external shader, save it
|
//external shader, save it
|
||||||
ResourceSaver::save(shader->get_path(), shader);
|
ResourceSaver::save(shader->get_path(), shader);
|
||||||
}
|
}
|
||||||
|
@ -1606,7 +1606,7 @@ Node *PackedScene::instance(GenEditState p_edit_state) const {
|
|||||||
s->set_scene_instance_state(state);
|
s->set_scene_instance_state(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_path() != "" && get_path().find("::") == -1) {
|
if (!is_built_in()) {
|
||||||
s->set_filename(get_path());
|
s->set_filename(get_path());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1307,7 +1307,7 @@ String ResourceFormatSaverTextInstance::_write_resource(const RES &res) {
|
|||||||
} else {
|
} else {
|
||||||
if (internal_resources.has(res)) {
|
if (internal_resources.has(res)) {
|
||||||
return "SubResource( " + itos(internal_resources[res]) + " )";
|
return "SubResource( " + itos(internal_resources[res]) + " )";
|
||||||
} else if (res->get_path().length() && res->get_path().find("::") == -1) {
|
} else if (!res->is_built_in()) {
|
||||||
if (res->get_path() == local_path) { //circular reference attempt
|
if (res->get_path() == local_path) { //circular reference attempt
|
||||||
return "null";
|
return "null";
|
||||||
}
|
}
|
||||||
@ -1330,7 +1330,7 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!p_main && (!bundle_resources) && res->get_path().length() && res->get_path().find("::") == -1) {
|
if (!p_main && (!bundle_resources) && !res->is_built_in()) {
|
||||||
if (res->get_path() == local_path) {
|
if (res->get_path() == local_path) {
|
||||||
ERR_PRINT("Circular reference to resource being saved found: '" + local_path + "' will be null next time it's loaded.");
|
ERR_PRINT("Circular reference to resource being saved found: '" + local_path + "' will be null next time it's loaded.");
|
||||||
return;
|
return;
|
||||||
@ -1523,7 +1523,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
|
|||||||
|
|
||||||
for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) {
|
for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) {
|
||||||
RES res = E->get();
|
RES res = E->get();
|
||||||
if (E->next() && (res->get_path() == "" || res->get_path().find("::") != -1)) {
|
if (E->next() && res->is_built_in()) {
|
||||||
if (res->get_subindex() != 0) {
|
if (res->get_subindex() != 0) {
|
||||||
if (used_indices.has(res->get_subindex())) {
|
if (used_indices.has(res->get_subindex())) {
|
||||||
res->set_subindex(0); //repeated
|
res->set_subindex(0); //repeated
|
||||||
|
Loading…
Reference in New Issue
Block a user