From 7553fda3e599be46ad3eb9064606ad254729d7af Mon Sep 17 00:00:00 2001 From: VodBox Date: Thu, 5 Mar 2020 22:34:18 +1300 Subject: [PATCH] UI: Fix scenes as sources for SL import The previous fix for repeated names accidentally meant that if a scene item in a scene was meant to show another scene that was lower in the list, it would fail to create the item, and wouldn't make it into the imported collection. This fix makes sure that scenes as sources still works properly in that situation. --- UI/importers/sl.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/UI/importers/sl.cpp b/UI/importers/sl.cpp index c2c921bf6..c1b98b24b 100644 --- a/UI/importers/sl.cpp +++ b/UI/importers/sl.cpp @@ -120,7 +120,8 @@ static bool source_name_exists(const Json::array &sources, const string &name) return false; } -static string get_source_name_from_id(const Json::array &sources, +static string get_source_name_from_id(const Json &root, + const Json::array &sources, const string &id) { for (size_t i = 0; i < sources.size(); i++) { @@ -131,6 +132,25 @@ static string get_source_name_from_id(const Json::array &sources, return item["name"].string_value(); } + Json::array scene_arr = root["scenes"]["items"].array_items(); + + for (size_t i = 0; i < scene_arr.size(); i++) { + Json item = scene_arr[i]; + string source_id = item["id"].string_value(); + + if (source_id == id) { + string name = item["name"].string_value(); + + int copy = 1; + string out_name = name; + + while (source_name_exists(sources, out_name)) + out_name = name + "(" + to_string(copy++) + ")"; + + return out_name; + } + } + return ""; } @@ -164,8 +184,8 @@ static void get_hotkey_bindings(Json::object &out_hotkeys, } } -static void get_scene_items(const Json::array &out_sources, Json::object &scene, - const Json::array &in) +static void get_scene_items(const Json &root, const Json::array &out_sources, + Json::object &scene, const Json::array &in) { int length = 0; @@ -177,7 +197,7 @@ static void get_scene_items(const Json::array &out_sources, Json::object &scene, Json in_crop = item["crop"]; string id = item["sourceId"].string_value(); - string name = get_source_name_from_id(out_sources, id); + string name = get_source_name_from_id(root, out_sources, id); Json::array hotkey_items = item["hotkeys"]["items"].array_items(); @@ -326,7 +346,7 @@ static int attempt_import(const Json &root, const string &name, Json &res) Json in_items = scene["sceneItems"]; Json::array items_arr = in_items["items"].array_items(); - get_scene_items(out_sources, out, items_arr); + get_scene_items(root, out_sources, out, items_arr); out_sources.push_back(out); }