From d5b1de016d1afc145a3f3b5e55d6f78df475932b Mon Sep 17 00:00:00 2001 From: cooolbros Date: Mon, 11 Dec 2023 21:07:10 +1100 Subject: [PATCH] Remove LoadControls --- src/HUDMerger/Utilities.cs | 173 ------------------------------------- 1 file changed, 173 deletions(-) diff --git a/src/HUDMerger/Utilities.cs b/src/HUDMerger/Utilities.cs index 20dd167..eed8a80 100644 --- a/src/HUDMerger/Utilities.cs +++ b/src/HUDMerger/Utilities.cs @@ -11,179 +11,6 @@ namespace HUDMerger; public static class Utilities { - /// - /// Loads controls from a file the same way TF2 does. - /// - public static Dictionary LoadControls(string hudRoot, string relativeFilePath) - { - // #base files get loaded in order, with keys from the topmost files being used, - // then the keyvalues from the original file get applied over everything. - - // values that are strings in base files will get overrided by objects - // loaded in a higher priority file - - // values that are objects in base files will get overrided by string - // loaded in a higher priority file - - // multiple objects in the same #base file will not override previous properties set, - // but multiple objects in the same origin file will overrie previous properties set. - // - // file1.res: - // Container - // { - // Element - // { - // "xpos" "10" - // "bgcolor_override" "0 255 0 255" - // } - // Element1 StringValue - // } - // - // file2.res: - // Container - // { - // Element - // { - // "xpos" "20" - // } - // } - // - // Origin file: - // #base file1.res - // #base file2.res - // Container - // { - // Element - // { - // "bgcolor_override" "255 0 0 255" - // } - // Element1 - // { - // "ControlName" "EditablePanel" - // "fieldName" "Element1" - // "xpos" "0" - // "ypos" "0" - // "zpos" "10" - // "wide" "100" - // "tall" "100" - // "visible" "1" - // "enabled" "1" - // "bgcolor_override" "255 100 0 255" - // } - // } - // - // The origin file will be loaded as: - // Container - // { - // Element - // { - // "xpos" "20" - // "bgcolor_override" "255 0 0 255" - // } - // Element1 - // { - // "ControlName" "EditablePanel" - // "fieldName" "Element1" - // "xpos" "0" - // "ypos" "0" - // "zpos" "10" - // "wide" "100" - // "tall" "100" - // "visible" "1" - // "enabled" "1" - // "bgcolor_override" "255 100 0 255" - // } - // } - // - - Dictionary origin = new(); - - void AddControls(string _folderPath, string _fileName, bool overrideKeys) - { - string _filePath = Path.Join(_folderPath, _fileName); - Dictionary obj; - if (File.Exists(_filePath)) - { - obj = VDFTryParse(_filePath); - } - else if (File.Exists(Path.Join("Resources\\HUD", _filePath))) - { - obj = VDFTryParse(Path.Join("Resources\\HUD", _filePath)); - } - else - { - obj = new(); - } - - if (obj.ContainsKey("#base")) - { - List baseFiles = new(); - - if (obj["#base"].GetType() == typeof(List)) - { - foreach (dynamic baseFile in obj["#base"]) - { - baseFiles.Add(baseFile); - } - } - else - { - baseFiles.Add(obj["#base"]); - } - - string folderName = Path.GetDirectoryName(_filePath); - - foreach (string baseFile in baseFiles) - { - AddControls(folderName, baseFile, false); - } - - obj.Remove("#base"); - } - - Merge(origin, obj, overrideKeys); - } - - Dictionary Merge(Dictionary obj1, Dictionary obj2, bool overrideKeys) - { - foreach (string i in obj2.Keys) - { - if (obj1.ContainsKey(i)) - { - if (obj1[i].GetType() == typeof(Dictionary) && obj2[i].GetType() == typeof(Dictionary)) - { - Merge(obj1[i], obj2[i], overrideKeys); - } - else - { - if (overrideKeys) - { - obj1[i] = obj2[i]; - } - } - } - else - { - if (obj2[i] is List items) - { - obj1[i] = items.Aggregate((a, b) => a.GetType() == typeof(Dictionary) ? Merge(obj1[i], obj2[i], overrideKeys) : b); - } - else - { - // We dont need overrideKeys to write to object - obj1[i] = obj2[i]; - } - } - } - - return obj1; - } - - FileInfo fileInfo = new FileInfo(Path.Join(hudRoot, relativeFilePath)); - AddControls(fileInfo.Directory.FullName, fileInfo.Name, true); - return origin; - } - /// /// Determines whether the specified file exists. Does not throw an error if any folder in the path doesn't exist. ///