Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ConfigHelper.c
Go to the documentation of this file.
2{
3 //------------------------------------------------------------------------------------------------
12 static BaseContainer GetBaseContainerByPath(notnull Resource resource, string subChildPath = "", bool removeEntryPart = false)
13 {
14 if (!resource.IsValid())
15 return null;
16
17 if (subChildPath.IsEmpty())
18 return resource.GetResource().ToBaseContainer();
19
20 return GetChildBaseContainerByPath(resource.GetResource().ToBaseContainer(), subChildPath, removeEntryPart);
21 }
22
23 //------------------------------------------------------------------------------------------------
32 static BaseContainer GetChildBaseContainerByPath(BaseContainer container, string subChildPath, bool removeEntryPart = false)
33 {
34 if (!container)
35 return null;
36
37 array<string> paths = {};
38 SplitConfigPath(subChildPath, paths, removeEntryPart);
39 if (paths.IsEmpty())
40 return container;
41
42 return GetChildBaseContainerByPath(container, paths);
43 }
44
45 //------------------------------------------------------------------------------------------------
51 // to do: split in smaller methods?
52 protected static BaseContainer GetChildBaseContainerByPath(notnull BaseContainer container, array<string> paths)
53 {
54 if (!container)
55 return null;
56
57 if (!paths || paths.IsEmpty())
58 return container;
59
60 string path;
61 string nextPath;
62 BaseContainer prevChild = container;
63 BaseContainer child = container;
64 BaseContainerList containerList;
65 for (int i, cntMinus1 = paths.Count() - 1; i <= cntMinus1; i++)
66 {
67 path = paths[i];
68 if (i < cntMinus1)
69 nextPath = paths[i + 1];
70 else
71 nextPath = string.Empty;
72
73 prevChild = child;
74 child = prevChild.GetObject(path);
75 if (child)
76 continue; // child is found, we need to go deeper
77
78 if (nextPath.IsEmpty())
79 return null;
80
81 containerList = prevChild.GetObjectArray(path);
82 if (!containerList)
83 return null; // no child, no array of children, get out
84
85 child = GetChildFromList(containerList, nextPath);
86 if (!child)
87 return null;
88
89 i++; // moved one step ahead with list → child
90 }
91
92 return child;
93 }
94
95 //------------------------------------------------------------------------------------------------
100 protected static BaseContainer GetChildFromList(notnull BaseContainerList containerList, string childName)
101 {
102 if (childName.IsEmpty())
103 return null;
104
105 string arrayItemName;
106 BaseContainer containerListElement;
107 for (int i, cnt = containerList.Count(); i < cnt; i++)
108 {
109 containerListElement = containerList[i];
110 arrayItemName = containerListElement.GetName();
111
112 if (arrayItemName.IsEmpty())
113 arrayItemName = containerListElement.GetClassName(); // if .et
114
115 if (arrayItemName.IsEmpty())
116 continue;
117
118 arrayItemName.ToLower();
119 childName.ToLower();
120 if (arrayItemName == childName)
121 return containerListElement;
122 }
123
124 return null;
125 }
126
127 //------------------------------------------------------------------------------------------------
133 static string SplitConfigPath(string input, out array<string> output, bool removeLastPart = false)
134 {
135 input.Split("/", output, true);
136
137 string lastPart;
138 if (output.IsEmpty())
139 return lastPart;
140
141 int lastIndex = output.Count() -1;
142 lastPart = output[lastIndex].Trim();
143 if (removeLastPart)
144 output.Remove(lastIndex);
145
146 for (int i, cnt = output.Count(); i < cnt; i++)
147 {
148 output[i] = output[i].Trim();
149 }
150
151 return lastPart;
152 }
153
154 //------------------------------------------------------------------------------------------------
159 static string GetGUID(ResourceName resourceName, bool removeBrackets = false)
160 {
161 int guidIndex = resourceName.LastIndexOf("}");
162 if (guidIndex < 0)
163 return string.Empty;
164
165 if (removeBrackets)
166 return resourceName.Substring(1, guidIndex - 1);
167 else
168 return resourceName.Substring(0, guidIndex + 1);
169 }
170}
171
172class SCR_ConfigHelperT<Class T>
173{
174 //------------------------------------------------------------------------------------------------
179 static T GetConfigObject(ResourceName configPath)
180 {
181 if (configPath.IsEmpty())
182 return null;
183
184 Resource resource = BaseContainerTools.LoadContainer(configPath);
185 if (!resource || !resource.IsValid())
186 return null;
187
188 BaseContainer container = resource.GetResource().ToBaseContainer();
189 if (!container)
190 return null;
191
192 return T.Cast(BaseContainerTools.CreateInstanceFromContainer(container));
193 }
194}
string path
ResourceName resourceName
Definition SCR_AIGroup.c:66
class SCR_ConfigHelper GetConfigObject(ResourceName configPath)
class SCR_MapHelperT< Class T, Class U > T
Super root of all classes in Enforce script.
Definition Types.c:35
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
static BaseContainer GetChildBaseContainerByPath(notnull BaseContainer container, array< string > paths)
static string GetGUID(ResourceName resourceName, bool removeBrackets=false)
static BaseContainer GetChildFromList(notnull BaseContainerList containerList, string childName)
static string SplitConfigPath(string input, out array< string > output, bool removeLastPart=false)