Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SearchXOBPlugin.c
Go to the documentation of this file.
1#ifdef WORKBENCH
2enum SCR_ESearchXOBPluginSearchType
3{
4 ListAllXOBs,
5 LoadAllXOBs,
6 InvalidMask,
7 LayerPreset,
8 LayerMask,
9}
10
11enum SCR_ESearchXOBPluginLayerFilter
12{
13 ANY,
14 ALL,
15 EXACT,
16 NONE,
17}
18
19class SCR_SearchXOBFunctor
20{
21 protected ref array<ResourceName> m_aFiles;
22 protected int m_iCounter;
23 protected bool m_bPrintFiles;
24 protected bool m_bIgnoreNoColliders;
25 protected ResourceName m_sSearchedDirectory;
26 protected int m_iAddon;
27
28 //------------------------------------------------------------------------------------------------
30 void Search()
31 {
32 WBProgressDialog progress = new WBProgressDialog("Searching...", null);
33
34 PrintHeader();
35
36 string addon = SCR_AddonTool.ToFileSystem(SCR_AddonTool.GetAddonID(m_iAddon));
37
38 m_aFiles = SCR_WorkbenchHelper.SearchWorkbenchResources({ "xob" }, null, addon + m_sSearchedDirectory.GetPath());
39 int count = m_aFiles.Count();
40 int updateMask = SCR_Math.IntegerMask(count * 0.1);
41
42 foreach (int i, ResourceName file : m_aFiles)
43 {
44 ProcessFile(file);
45
46 if ((i & updateMask) == updateMask)
47 progress.SetProgress(i / count);
48 }
49
50 PrintResults();
51 m_aFiles.Clear();
52 }
53
54 // methods to be overridden
55 protected void PrintHeader();
56 protected void ProcessFile(ResourceName file);
57 protected void PrintResults();
58
59 //------------------------------------------------------------------------------------------------
60 // constructor
65 void SCR_SearchXOBFunctor(bool printFiles, bool ignoreNoColliders, ResourceName searchedDir, int searchedAddon)
66 {
67 m_aFiles = {};
68 m_bPrintFiles = printFiles;
69 m_bIgnoreNoColliders = ignoreNoColliders;
70 m_sSearchedDirectory = searchedDir;
71 m_iAddon = searchedAddon;
72 }
73}
74
75class SCR_SearchXOBListAllFunctor : SCR_SearchXOBFunctor
76{
77 //------------------------------------------------------------------------------------------------
78 override void PrintHeader()
79 {
80 Print("--- List All XOBs --------------------------------------------------------------", LogLevel.NORMAL);
81 }
82
83 //------------------------------------------------------------------------------------------------
84 override void ProcessFile(ResourceName file)
85 {
86 if (m_bPrintFiles)
87 Print(file, LogLevel.NORMAL);
88 }
89
90 //------------------------------------------------------------------------------------------------
91 override void PrintResults()
92 {
93 Print("Total: " + m_aFiles.Count(), LogLevel.NORMAL);
94 }
95}
96
97class SCR_SearchXOBLoadAllFunctor : SCR_SearchXOBFunctor
98{
99 //------------------------------------------------------------------------------------------------
100 override void PrintHeader()
101 {
102 Print("--- Load All XOBs --------------------------------------------------------------", LogLevel.NORMAL);
103 }
104
105 //------------------------------------------------------------------------------------------------
106 override void ProcessFile(ResourceName file)
107 {
108 Resource res = Resource.Load(file);
109 MeshObject mesh = res.GetResource().ToMeshObject();
110 if (mesh)
111 m_iCounter++;
112 }
113
114 //------------------------------------------------------------------------------------------------
115 override void PrintResults()
116 {
117 Print("Loaded: " + m_iCounter, LogLevel.NORMAL);
118 Print("Total: " + m_aFiles.Count(), LogLevel.NORMAL);
119 }
120}
121
122class SCR_SearchXOBInvalidMaskFunctor : SCR_SearchXOBFunctor
123{
124 //------------------------------------------------------------------------------------------------
125 override void PrintHeader()
126 {
127 Print("--- Find Invalid Mask ----------------------------------------------------------", LogLevel.NORMAL);
128 }
129
130 //------------------------------------------------------------------------------------------------
131 override void ProcessFile(ResourceName file)
132 {
133 Resource res = Resource.Load(file);
134 MeshObject mesh = res.GetResource().ToMeshObject();
135 if (m_bIgnoreNoColliders && mesh.GetNumGeoms() == 0)
136 return;
137
138 if (mesh.HasValidMask())
139 return;
140
141 m_iCounter++;
142 if (m_bPrintFiles)
143 Print(string.Format("@\"%1\"", file.GetPath()), LogLevel.NORMAL);
144 }
145
146 //------------------------------------------------------------------------------------------------
147 override void PrintResults()
148 {
149 Print("Found: " + m_iCounter, LogLevel.NORMAL);
150 Print("Total: " + m_aFiles.Count(), LogLevel.NORMAL);
151 }
152}
153
154class SCR_SearchXOBLayerMaskFunctor : SCR_SearchXOBFunctor
155{
156 protected int m_iLayerMask;
157 protected SCR_ESearchXOBPluginLayerFilter m_eLayerFilter = SCR_ESearchXOBPluginLayerFilter.ANY;
158
159 //------------------------------------------------------------------------------------------------
160 override void PrintHeader()
161 {
162 Print("--- Find Layer Mask ------------------------------------------------------------", LogLevel.NORMAL);
163 }
164
165 //------------------------------------------------------------------------------------------------
166 override void ProcessFile(ResourceName file)
167 {
168 Resource res = Resource.Load(file);
169 MeshObject mesh = res.GetResource().ToMeshObject();
170 if (m_bIgnoreNoColliders && mesh.GetNumGeoms() == 0)
171 return;
172
173 if (!mesh.HasLayerMask(m_iLayerMask, m_eLayerFilter))
174 return;
175
176 m_iCounter++;
177 if (m_bPrintFiles)
178 Print(string.Format("@\"%1\"", file.GetPath()), LogLevel.NORMAL);
179 }
180
181 //------------------------------------------------------------------------------------------------
182 override void PrintResults()
183 {
184 Print("Found: " + m_iCounter, LogLevel.NORMAL);
185 Print("Total: " + m_aFiles.Count(), LogLevel.NORMAL);
186 }
187
188 //------------------------------------------------------------------------------------------------
189 // constructor
190 void SCR_SearchXOBLayerMaskFunctor(bool printFiles, bool ignoreNoColliders, ResourceName searchedDir, int searchedAddon, int layerMask, SCR_ESearchXOBPluginLayerFilter layerFilter)
191 {
192 m_iLayerMask = layerMask;
193 m_eLayerFilter = layerFilter;
194 }
195}
196
197[WorkbenchPluginAttribute(name: "Search Tool (XOBs)", description: "Searches XOB files", wbModules: { "ResourceManager" }, awesomeFontCode: 0xF002)]
198class SearchXOBPlugin : WorkbenchPlugin // TODO: SCR_
199{
200 [Attribute("0", UIWidgets.ComboBox, "Type of search", "", enumType: SCR_ESearchXOBPluginSearchType)]
201 protected SCR_ESearchXOBPluginSearchType m_eSearchType;
202
203 [Attribute("1", UIWidgets.ComboBox, "In which addon should be search performed", "", SCR_ParamEnumArray.FromAddons())]
204 protected int m_iAddon;
205
206 [Attribute(defvalue: "", desc: "Folder where to perform search. If empty, search is performed everywhere", params: "unregFolders")]
207 protected ResourceName m_sSearchedDirectory;
208
209 [Attribute("0", UIWidgets.ComboBox, "LayerPreset search parameter", "", enumType: EPhysicsLayerPresets)]
210 protected EPhysicsLayerPresets m_eLayerPreset;
211
212 [Attribute("0", UIWidgets.ComboBox, "LayerMask search parameter", "", enumType: EPhysicsLayerDefs)]
213 protected ref array<EPhysicsLayerDefs> m_aLayerDefinitions;
214
215 [Attribute("0", UIWidgets.ComboBox, "Filter applied to layer mask", "", enumType: SCR_ESearchXOBPluginLayerFilter)]
216 protected SCR_ESearchXOBPluginLayerFilter m_eLayerFilter;
217
218 [Attribute(defvalue: "0", desc: "Print all found files")]
219 protected bool m_bPrintFiles;
220
221 [Attribute(defvalue: "0", desc: "Ignore files with no physics geometry")]
222 protected bool m_bIgnoreNoColliders;
223
224 //------------------------------------------------------------------------------------------------
225 override void Run()
226 {
227 if (!Workbench.ScriptDialog("Search XOBs", "Choose search type, set search parameters ...", this))
228 return;
229
230 SCR_SearchXOBFunctor functor = CreateFunctor();
231 functor.Search();
232 }
233
234 //------------------------------------------------------------------------------------------------
235 override void RunCommandline()
236 {
237 // ResourceManager module = Workbench.GetModule(ResourceManager);
238 // module = Workbench.GetModule(ResourceManager);
239
240 Print("Command-line functionality not implemented", LogLevel.WARNING);
241
242 //SCR_SearchXOBFunctor functor = CreateFunctor();
243 //functor.Search();
244
245 Workbench.Exit(0);
246 }
247
248 //------------------------------------------------------------------------------------------------
249 [ButtonAttribute("Run")]
250 protected bool OK()
251 {
252 return true;
253 }
254
255 //------------------------------------------------------------------------------------------------
256 [ButtonAttribute("Cancel")]
257 protected bool Cancel()
258 {
259 return false;
260 }
261
262 //------------------------------------------------------------------------------------------------
263 protected int GetLayerMask()
264 {
265 int mask = 0;
266 foreach (int layer : m_aLayerDefinitions)
267 {
268 mask |= layer;
269 }
270 return mask;
271 }
272
273 //------------------------------------------------------------------------------------------------
274 protected SCR_SearchXOBFunctor CreateFunctor()
275 {
276 switch (m_eSearchType)
277 {
278 case SCR_ESearchXOBPluginSearchType.ListAllXOBs: return new SCR_SearchXOBListAllFunctor(m_bPrintFiles, m_bIgnoreNoColliders, m_sSearchedDirectory, m_iAddon);
279 case SCR_ESearchXOBPluginSearchType.LoadAllXOBs: return new SCR_SearchXOBLoadAllFunctor(m_bPrintFiles, m_bIgnoreNoColliders, m_sSearchedDirectory, m_iAddon);
280 case SCR_ESearchXOBPluginSearchType.InvalidMask: return new SCR_SearchXOBInvalidMaskFunctor(m_bPrintFiles, m_bIgnoreNoColliders, m_sSearchedDirectory, m_iAddon);
281 case SCR_ESearchXOBPluginSearchType.LayerPreset: return new SCR_SearchXOBLayerMaskFunctor(m_bPrintFiles, m_bIgnoreNoColliders, m_sSearchedDirectory, m_iAddon, m_eLayerPreset, m_eLayerFilter);
282 case SCR_ESearchXOBPluginSearchType.LayerMask: return new SCR_SearchXOBLayerMaskFunctor(m_bPrintFiles, m_bIgnoreNoColliders, m_sSearchedDirectory, m_iAddon, GetLayerMask(), m_eLayerFilter);
283 }
284
285 return new SCR_SearchXOBFunctor(m_bPrintFiles, m_bIgnoreNoColliders, m_sSearchedDirectory, m_iAddon);
286 }
287}
288#endif // WORKBENCH
override void RunCommandline()
Definition FlowmapTool.c:60
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
LayerPresets layer
override void Run()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_RespawnComponentClass OK
Result code for request/assign response.
Definition EMoveError.c:14
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
static ParamEnumArray FromAddons(int titleFormat=2, int hideCoreModules=0)
EPhysicsLayerPresets
Enum is filled by C++ by data in project config PhysicsSettings.LayerPresets.
Definition gameLib.c:19
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
@ NONE
When Shape is created and not initialized yet.
Definition ShapeType.c:15
SCR_FieldOfViewSettings Attribute
@ ANY
Will list all servers regardless platform compatibility.
Definition EnScript.c:8
@ ALL
Everything except general switch.
Definition EntityEvent.c:37
@ EXACT
set exact value