From 0b56f22f87acf840ed2ef7adb54edaba0716613c Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 11 May 2025 08:26:55 +0200 Subject: [PATCH] Use module names instead of indexes if they are available in User::_from_dict() and User::_to_dict(). --- modules/users/users/user.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/modules/users/users/user.cpp b/modules/users/users/user.cpp index 62a592c7b..978ee7e98 100644 --- a/modules/users/users/user.cpp +++ b/modules/users/users/user.cpp @@ -218,6 +218,7 @@ Dictionary User::_to_dict() { m->read_lock(); mdict["index"] = i; + mdict["module_name"] = m->get_module_name(); mdict["data"] = m->to_dict(); m->read_unlock(); @@ -246,15 +247,23 @@ void User::_from_dict(const Dictionary &dict) { for (int i = 0; i < marr.size(); ++i) { Dictionary mdict = marr[i]; - if (!mdict.has("index") || !mdict.has("data")) { - continue; + String module_name; + + if (mdict.has("module_name")) { + module_name = mdict["module_name"]; } - int index = mdict["index"]; - - ERR_CONTINUE(index < 0 || index >= _modules.size()); - - Ref m = _modules[index]; + Ref m; + + if (module_name.empty()) { + int index = mdict["index"]; + + ERR_CONTINUE(index < 0 || index >= _modules.size()); + + m = _modules[index]; + } else { + m = get_module_named(module_name); + } ERR_CONTINUE(!m.is_valid());