mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Merge pull request #99712 from KoBeWi/bug_spawner_spawns_new_bugs_to_fix
Fix UID support in MultiplayerSpawner
This commit is contained in:
commit
ab58a339df
3 changed files with 11 additions and 13 deletions
|
@ -145,7 +145,12 @@ String ResourceUID::uid_to_path(const String &p_uid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
String ResourceUID::path_to_uid(const String &p_path) {
|
String ResourceUID::path_to_uid(const String &p_path) {
|
||||||
return singleton->id_to_text(ResourceLoader::get_resource_uid(p_path));
|
const ID id = ResourceLoader::get_resource_uid(p_path);
|
||||||
|
if (id == INVALID_ID) {
|
||||||
|
return p_path;
|
||||||
|
} else {
|
||||||
|
return singleton->id_to_text(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String ResourceUID::ensure_path(const String &p_uid_or_path) {
|
String ResourceUID::ensure_path(const String &p_uid_or_path) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ bool MultiplayerSpawner::_set(const StringName &p_name, const Variant &p_value)
|
||||||
if (ns.begins_with("scenes/")) {
|
if (ns.begins_with("scenes/")) {
|
||||||
uint32_t index = ns.get_slicec('/', 1).to_int();
|
uint32_t index = ns.get_slicec('/', 1).to_int();
|
||||||
ERR_FAIL_UNSIGNED_INDEX_V(index, spawnable_scenes.size(), false);
|
ERR_FAIL_UNSIGNED_INDEX_V(index, spawnable_scenes.size(), false);
|
||||||
spawnable_scenes[index].path = p_value;
|
spawnable_scenes[index].path = ResourceUID::ensure_path(p_value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ bool MultiplayerSpawner::_get(const StringName &p_name, Variant &r_ret) const {
|
||||||
if (ns.begins_with("scenes/")) {
|
if (ns.begins_with("scenes/")) {
|
||||||
uint32_t index = ns.get_slicec('/', 1).to_int();
|
uint32_t index = ns.get_slicec('/', 1).to_int();
|
||||||
ERR_FAIL_UNSIGNED_INDEX_V(index, spawnable_scenes.size(), false);
|
ERR_FAIL_UNSIGNED_INDEX_V(index, spawnable_scenes.size(), false);
|
||||||
r_ret = spawnable_scenes[index].path;
|
r_ret = ResourceUID::path_to_uid(spawnable_scenes[index].path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,15 +97,9 @@ PackedStringArray MultiplayerSpawner::get_configuration_warnings() const {
|
||||||
|
|
||||||
void MultiplayerSpawner::add_spawnable_scene(const String &p_path) {
|
void MultiplayerSpawner::add_spawnable_scene(const String &p_path) {
|
||||||
SpawnableScene sc;
|
SpawnableScene sc;
|
||||||
if (p_path.begins_with("uid://")) {
|
sc.path = ResourceUID::ensure_path(p_path);
|
||||||
sc.uid = p_path;
|
|
||||||
sc.path = ResourceUID::uid_to_path(p_path);
|
|
||||||
} else {
|
|
||||||
sc.uid = ResourceUID::path_to_uid(p_path);
|
|
||||||
sc.path = p_path;
|
|
||||||
}
|
|
||||||
if (Engine::get_singleton()->is_editor_hint()) {
|
if (Engine::get_singleton()->is_editor_hint()) {
|
||||||
ERR_FAIL_COND(!ResourceLoader::exists(p_path));
|
ERR_FAIL_COND(!ResourceLoader::exists(sc.path));
|
||||||
}
|
}
|
||||||
spawnable_scenes.push_back(sc);
|
spawnable_scenes.push_back(sc);
|
||||||
#ifdef TOOLS_ENABLED
|
#ifdef TOOLS_ENABLED
|
||||||
|
@ -145,7 +139,7 @@ Vector<String> MultiplayerSpawner::_get_spawnable_scenes() const {
|
||||||
Vector<String> ss;
|
Vector<String> ss;
|
||||||
ss.resize(spawnable_scenes.size());
|
ss.resize(spawnable_scenes.size());
|
||||||
for (int i = 0; i < ss.size(); i++) {
|
for (int i = 0; i < ss.size(); i++) {
|
||||||
ss.write[i] = spawnable_scenes[i].uid;
|
ss.write[i] = ResourceUID::path_to_uid(spawnable_scenes[i].path);
|
||||||
}
|
}
|
||||||
return ss;
|
return ss;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,6 @@ public:
|
||||||
private:
|
private:
|
||||||
struct SpawnableScene {
|
struct SpawnableScene {
|
||||||
String path;
|
String path;
|
||||||
String uid;
|
|
||||||
Ref<PackedScene> cache;
|
Ref<PackedScene> cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue