From 6f62e8b59191ee622591c91a55d02bb6c808e85a Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Mon, 8 Jul 2024 16:21:51 -0400 Subject: Quote "LLAppearance" op="wearOutfit" folder_id and folder_name args --- indra/newview/llappearancelistener.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/newview/llappearancelistener.cpp b/indra/newview/llappearancelistener.cpp index 75eaf29186..b8aca96b43 100644 --- a/indra/newview/llappearancelistener.cpp +++ b/indra/newview/llappearancelistener.cpp @@ -38,7 +38,7 @@ LLAppearanceListener::LLAppearanceListener() "API to wear a specified outfit and wear/remove individual items") { add("wearOutfit", - "Wear outfit by folder id: [folder_id] OR by folder name: [folder_name]\n" + "Wear outfit by folder id: [\"folder_id\"] OR by folder name: [\"folder_name\"]\n" "When [\"append\"] is true, outfit will be added to COF\n" "otherwise it will replace current oufit", &LLAppearanceListener::wearOutfit); -- cgit v1.2.3 From 2918ebc081f63bffd5c482375f7fcbbb2faea175 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Mon, 8 Jul 2024 16:23:29 -0400 Subject: Combine LLAppearanceMgr::wearOutfit() and wearOutfitByName() into new private wearOutfit(LLInventoryCategory*) method. --- indra/newview/llappearancemgr.cpp | 63 +++++++++++++++------------------------ indra/newview/llappearancemgr.h | 4 +++ 2 files changed, 28 insertions(+), 39 deletions(-) diff --git a/indra/newview/llappearancemgr.cpp b/indra/newview/llappearancemgr.cpp index 7a34006323..a8bc9d8e52 100644 --- a/indra/newview/llappearancemgr.cpp +++ b/indra/newview/llappearancemgr.cpp @@ -2904,6 +2904,17 @@ void LLAppearanceMgr::wearInventoryCategoryOnAvatar( LLInventoryCategory* catego LLAppearanceMgr::changeOutfit(TRUE, category->getUUID(), append); } +bool LLAppearanceMgr::wearOutfitByName(const std::string& name, bool append) +{ + std::string error_msg; + if(!wearOutfitByName(name, error_msg, append)) + { + LL_WARNS() << error_msg << LL_ENDL; + return false; + } + return true; +} + bool LLAppearanceMgr::wearOutfitByName(const std::string& name, std::string& error_msg, bool append) { LL_INFOS("Avatar") << self_av_string() << "Wearing category " << name << LL_ENDL; @@ -2937,63 +2948,37 @@ bool LLAppearanceMgr::wearOutfitByName(const std::string& name, std::string& err } } - if(cat) - { - // don't allow wearing a system folder - if (LLFolderType::lookupIsProtectedType(cat->getPreferredType())) - { - error_msg = stringize(LLTrans::getString("SystemFolderNotWorn"), std::quoted(name)); - return false; - } - bool can_wear = append ? getCanAddToCOF(cat->getUUID()) : getCanReplaceCOF(cat->getUUID()); - if (!can_wear) - { - std::string msg = append ? LLTrans::getString("OutfitNotAdded") : LLTrans::getString("OutfitNotReplaced"); - error_msg = stringize(msg, std::quoted(name), ", id: ", cat->getUUID()); - return false; - } - LLAppearanceMgr::wearInventoryCategory(cat, copy_items, append); - } - else - { - error_msg = stringize(LLTrans::getString("OutfitNotFound"), std::quoted(name)); - return false; - } - return true; + return wearOutfit(std::quoted(name), cat, error_msg, copy_items, append); } bool LLAppearanceMgr::wearOutfit(const LLUUID &cat_id, std::string &error_msg, bool append) { LLViewerInventoryCategory *cat = gInventory.getCategory(cat_id); + return wearOutfit(stringize(cat_id), cat, error_msg, false, append); +} + +bool LLAppearanceMgr::wearOutfit(const std::string &desc, LLInventoryCategory* cat, + std::string &error_msg, bool copy_items, bool append) +{ if (!cat) { - error_msg = stringize(LLTrans::getString("OutfitNotFound"), cat_id); + error_msg = stringize(LLTrans::getString("OutfitNotFound"), desc); return false; } + // don't allow wearing a system folder if (LLFolderType::lookupIsProtectedType(cat->getPreferredType())) { - error_msg = stringize(LLTrans::getString("SystemFolderNotWorn"), cat_id); + error_msg = stringize(LLTrans::getString("SystemFolderNotWorn"), std::quoted(cat->getName())); return false; } - bool can_wear = append ? LLAppearanceMgr::instance().getCanAddToCOF(cat_id) : LLAppearanceMgr::instance().getCanReplaceCOF(cat_id); + bool can_wear = append ? getCanAddToCOF(cat->getUUID()) : getCanReplaceCOF(cat->getUUID()); if (!can_wear) { std::string msg = append ? LLTrans::getString("OutfitNotAdded") : LLTrans::getString("OutfitNotReplaced"); - error_msg = stringize(msg, std::quoted(cat->getName()), " , id: ", cat_id); - return false; - } - LLAppearanceMgr::instance().wearInventoryCategory(cat, false, append); - return true; -} - -bool LLAppearanceMgr::wearOutfitByName(const std::string& name, bool append) -{ - std::string error_msg; - if(!wearOutfitByName(name, error_msg, append)) - { - LL_WARNS() << error_msg << LL_ENDL; + error_msg = stringize(msg, std::quoted(cat->getName()), " , id: ", cat->getUUID()); return false; } + wearInventoryCategory(cat, copy_items, append); return true; } diff --git a/indra/newview/llappearancemgr.h b/indra/newview/llappearancemgr.h index b795494f94..11d209e6b5 100644 --- a/indra/newview/llappearancemgr.h +++ b/indra/newview/llappearancemgr.h @@ -263,6 +263,10 @@ private: static void onOutfitRename(const LLSD& notification, const LLSD& response); + // used by both wearOutfit(LLUUID) and wearOutfitByName(std::string) + bool wearOutfit(const std::string &desc, LLInventoryCategory* cat, + std::string &error_msg, bool copy_items, bool append); + bool mAttachmentInvLinkEnabled; bool mOutfitIsDirty; bool mIsInUpdateAppearanceFromCOF; // to detect recursive calls. -- cgit v1.2.3 From 0e5cee5d6ddad76ccd37b5ed6bf8d692435bb7dc Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Mon, 8 Jul 2024 16:40:02 -0400 Subject: Slightly simplify LLAppearanceListener::wearItems(), detachItems(). --- indra/newview/llappearancelistener.cpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/indra/newview/llappearancelistener.cpp b/indra/newview/llappearancelistener.cpp index b8aca96b43..c39799c5e9 100644 --- a/indra/newview/llappearancelistener.cpp +++ b/indra/newview/llappearancelistener.cpp @@ -91,36 +91,38 @@ void LLAppearanceListener::wearOutfit(LLSD const &data) void LLAppearanceListener::wearItems(LLSD const &data) { - if (data["items_id"].isArray()) + const LLSD& items_id{ data["items_id"] }; + uuid_vec_t ids; + if (! items_id.isArray()) { - uuid_vec_t ids; - for (const auto &id : llsd::inArray(data["items_id"])) + ids.push_back(items_id.asUUID()); + } + else // array + { + for (const auto &id : llsd::inArray(items_id)) { ids.push_back(id); } - LLAppearanceMgr::instance().wearItemsOnAvatar(ids, true, data["replace"].asBoolean()); - } - else - { - LLAppearanceMgr::instance().wearItemOnAvatar(data["items_id"].asUUID(), true, data["replace"].asBoolean()); } + LLAppearanceMgr::instance().wearItemsOnAvatar(ids, true, data["replace"].asBoolean()); } void LLAppearanceListener::detachItems(LLSD const &data) { - if (data["items_id"].isArray()) + const LLSD& items_id{ data["items_id"] }; + uuid_vec_t ids; + if (! items_id.isArray()) { - uuid_vec_t ids; - for (const auto &id : llsd::inArray(data["items_id"])) + ids.push_back(items_id.asUUID()); + } + else // array + { + for (const auto &id : llsd::inArray(items_id)) { ids.push_back(id); } - LLAppearanceMgr::instance().removeItemsFromAvatar(ids); - } - else - { - LLAppearanceMgr::instance().removeItemFromAvatar(data["items_id"].asUUID()); } + LLAppearanceMgr::instance().removeItemsFromAvatar(ids); } void LLAppearanceListener::getOutfitsList(LLSD const &data) -- cgit v1.2.3 From b8c09ed80d076f44b08d6aaa59fffd98abd55811 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Mon, 8 Jul 2024 17:18:48 -0400 Subject: The I/O manipulator std::quoted() must be passed to an ostream. --- indra/newview/llappearancemgr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/newview/llappearancemgr.cpp b/indra/newview/llappearancemgr.cpp index a8bc9d8e52..26c41b19ed 100644 --- a/indra/newview/llappearancemgr.cpp +++ b/indra/newview/llappearancemgr.cpp @@ -2948,7 +2948,7 @@ bool LLAppearanceMgr::wearOutfitByName(const std::string& name, std::string& err } } - return wearOutfit(std::quoted(name), cat, error_msg, copy_items, append); + return wearOutfit(stringize(std::quoted(name)), cat, error_msg, copy_items, append); } bool LLAppearanceMgr::wearOutfit(const LLUUID &cat_id, std::string &error_msg, bool append) -- cgit v1.2.3 From f009f8da6b140f02f6463a43d336ab2644782fa1 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 9 Jul 2024 10:24:32 -0400 Subject: Introduce LLSDParam> and LLSDParam>. Use LLSDParam in LLAppearanceListener::wearItems() and detachItems() to build the vector of LLUUIDs from the passed LLSD array. --- indra/llcommon/llsdutil.h | 61 ++++++++++++++++++++++++++++++++++ indra/newview/llappearancelistener.cpp | 33 +++--------------- 2 files changed, 66 insertions(+), 28 deletions(-) diff --git a/indra/llcommon/llsdutil.h b/indra/llcommon/llsdutil.h index 7c31dc8aa0..3f59222e9b 100644 --- a/indra/llcommon/llsdutil.h +++ b/indra/llcommon/llsdutil.h @@ -524,6 +524,67 @@ private: } // namespace llsd +/***************************************************************************** +* LLSDParam> +*****************************************************************************/ +// Given an LLSD array, return a const std::vector&, where T is a type +// supported by LLSDParam. Bonus: if the LLSD value is actually a scalar, +// return a single-element vector containing the converted value. +template +class LLSDParam>: public LLSDParamBase +{ +public: + LLSDParam(const LLSD& array) + { + // treat undefined "array" as empty vector + if (array.isDefined()) + { + // what if it's a scalar? + if (! array.isArray()) + { + v.push_back(LLSDParam(array)); + } + else // really is an array + { + // reserve space for the array entries + v.reserve(array.size()); + for (const auto& item : llsd::inArray(array)) + { + v.push_back(LLSDParam(item)); + } + } + } + } + + operator const std::vector&() const { return v; } + +private: + std::vector v; +}; + +/***************************************************************************** +* LLSDParam> +*****************************************************************************/ +// Given an LLSD map, return a const std::map&, where T is a +// type supported by LLSDParam. +template +class LLSDParam>: public LLSDParamBase +{ +public: + LLSDParam(const LLSD& map) + { + for (const auto& pair : llsd::inMap(map)) + { + m[pair.first] = LLSDParam(pair.second); + } + } + + operator const std::map&() const { return m; } + +private: + std::map m; +}; + /***************************************************************************** * deep and shallow clone *****************************************************************************/ diff --git a/indra/newview/llappearancelistener.cpp b/indra/newview/llappearancelistener.cpp index c39799c5e9..0dab352311 100644 --- a/indra/newview/llappearancelistener.cpp +++ b/indra/newview/llappearancelistener.cpp @@ -91,38 +91,15 @@ void LLAppearanceListener::wearOutfit(LLSD const &data) void LLAppearanceListener::wearItems(LLSD const &data) { - const LLSD& items_id{ data["items_id"] }; - uuid_vec_t ids; - if (! items_id.isArray()) - { - ids.push_back(items_id.asUUID()); - } - else // array - { - for (const auto &id : llsd::inArray(items_id)) - { - ids.push_back(id); - } - } - LLAppearanceMgr::instance().wearItemsOnAvatar(ids, true, data["replace"].asBoolean()); + LLAppearanceMgr::instance().wearItemsOnAvatar( + LLSDParam(data["items_id"]), + true, data["replace"].asBoolean()); } void LLAppearanceListener::detachItems(LLSD const &data) { - const LLSD& items_id{ data["items_id"] }; - uuid_vec_t ids; - if (! items_id.isArray()) - { - ids.push_back(items_id.asUUID()); - } - else // array - { - for (const auto &id : llsd::inArray(items_id)) - { - ids.push_back(id); - } - } - LLAppearanceMgr::instance().removeItemsFromAvatar(ids); + LLAppearanceMgr::instance().removeItemsFromAvatar( + LLSDParam(data["items_id"])); } void LLAppearanceListener::getOutfitsList(LLSD const &data) -- cgit v1.2.3