12 static BaseContainer GetBaseContainerByPath(notnull Resource resource,
string subChildPath =
"",
bool removeEntryPart =
false)
14 if (!resource.IsValid())
17 if (subChildPath.IsEmpty())
18 return resource.GetResource().ToBaseContainer();
20 return GetChildBaseContainerByPath(resource.GetResource().ToBaseContainer(), subChildPath, removeEntryPart);
32 protected static BaseContainer GetChildBaseContainerByPath(BaseContainer container,
string subChildPath,
bool removeEntryPart =
false)
37 array<string> paths = {};
38 SplitConfigPath(subChildPath, paths, removeEntryPart);
42 return GetChildBaseContainerByPath(container, paths);
52 protected static BaseContainer GetChildBaseContainerByPath(notnull BaseContainer container, array<string> paths)
57 if (!paths || paths.IsEmpty())
62 BaseContainer prevChild = container;
63 BaseContainer child = container;
64 BaseContainerList containerList;
65 for (
int i, cntMinus1 = paths.Count() - 1; i <= cntMinus1; i++)
69 nextPath = paths[i + 1];
71 nextPath =
string.Empty;
74 child = prevChild.GetObject(path);
78 if (nextPath.IsEmpty())
81 containerList = prevChild.GetObjectArray(path);
85 child = GetChildFromList(containerList, nextPath);
100 protected static BaseContainer GetChildFromList(notnull BaseContainerList containerList,
string childName)
102 if (childName.IsEmpty())
105 string arrayItemName;
106 BaseContainer containerListElement;
107 for (
int i, cnt = containerList.Count(); i < cnt; i++)
109 containerListElement = containerList[i];
110 arrayItemName = containerListElement.GetName();
112 if (arrayItemName.IsEmpty())
113 arrayItemName = containerListElement.GetClassName();
115 if (arrayItemName.IsEmpty())
118 arrayItemName.ToLower();
120 if (arrayItemName == childName)
121 return containerListElement;
133 static string SplitConfigPath(
string input, out array<string> output,
bool removeLastPart =
false)
135 input.Split(
"/", output,
true);
138 if (output.IsEmpty())
141 int lastIndex = output.Count() -1;
142 lastPart = output[lastIndex].Trim();
144 output.Remove(lastIndex);
146 for (
int i, cnt = output.Count(); i < cnt; i++)
148 output[i] = output[i].Trim();
159 static string GetGUID(ResourceName resourceName,
bool removeBrackets =
false)
161 int guidIndex = resourceName.LastIndexOf(
"}");
166 return resourceName.Substring(1, guidIndex - 1);
168 return resourceName.Substring(0, guidIndex + 1);
172 class SCR_ConfigHelperT<Class T>
181 if (configPath.IsEmpty())
184 Resource resource = BaseContainerTools.LoadContainer(configPath);
185 if (!resource || !resource.IsValid())
188 BaseContainer container = resource.GetResource().ToBaseContainer();
192 return T.Cast(BaseContainerTools.CreateInstanceFromContainer(container));