Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CheckRuinModelsAndUsagePlugin.c
Go to the documentation of this file.
1#ifdef WORKBENCH
3 name: "Check Ruin Models and Usage",
4// category: "Building Destruction",
5 description: "Destruction configuration plugin to:\n- Find .xob _Ruin files that do not have an associated Prefab\n- Find house_base Prefabs that do not have the _Ruin Prefab associated",
6 wbModules: { "ResourceManager" },
7 awesomeFontCode: 0xE4D4)]
8class SCR_CheckRuinModelsAndUsagePlugin : WorkbenchPlugin
9{
10 [Attribute(defvalue: "1", desc: "Print Resource Names")]
11 protected bool m_bPrintResourceNames;
12
13 [Attribute(defvalue: "1", desc: "Search in all addons - if unchecked, search only in " + BASE_PREFIX + " and " + ADDON_PREFIX)]
14 protected bool m_bSearchInAllAddons;
15
16 protected static const string BASE_PREFIX = "$ArmaReforger:";
17 protected static const string ADDON_PREFIX = "$BuildingDestruction:";
18 protected static const string XOBS_DIR = "Assets";
19 protected static const string PREFABS_DIR = "Prefabs";
20
21 //------------------------------------------------------------------------------------------------
22 protected override void Run()
23 {
24 // - Find all _Ruin Prefabs
25 array<ResourceName> ruinPrefabs = GetRuinPrefabs();
26 int ruinPrefabsCount = ruinPrefabs.Count();
27
28 array<ResourceName> prefablessRuinModels = GetRuinModelsWithoutPrefabs(ruinPrefabs);
29 array<ResourceName> unassignedRuinPrefabs = GetUnassignedRuinPrefabs(ruinPrefabs);
30
31 if (m_bPrintResourceNames)
32 {
33 foreach (ResourceName resourceName : prefablessRuinModels)
34 {
35 Print("No Prefab found for Ruin " + resourceName, LogLevel.NORMAL);
36 }
37
38 foreach (ResourceName resourceName : unassignedRuinPrefabs)
39 {
40 Print("No Prefab using Ruin " + resourceName, LogLevel.NORMAL);
41 }
42 }
43
44 // always print that
45 Print("Total _Ruin Prefabs: " + ruinPrefabs.Count(), LogLevel.NORMAL);
46 Print("Ruin XOBs without Prefab: " + prefablessRuinModels.Count(), LogLevel.NORMAL);
47 Print("Unused Ruin Prefabs: " + unassignedRuinPrefabs.Count(), LogLevel.NORMAL);
48 }
49
50 //------------------------------------------------------------------------------------------------
53 protected array<ResourceName> GetRuinModelsWithoutPrefabs(notnull array<ResourceName> ruinPrefabs)
54 {
55 // - Find .xob _Ruin files that do not have an associated _Ruin Prefab
56
57 Resource resource;
58 BaseResourceObject baseResourceObject;
59 IEntitySource entitySource;
60 set<ResourceName> ruinXobSet = new set<ResourceName>(); // found xob set
61 foreach (ResourceName ruinPrefab : ruinPrefabs)
62 {
63 resource = Resource.Load(ruinPrefab);
64 if (!resource.IsValid())
65 {
66 Print("Invalid Ruin Prefab (invalid resource) " + ruinPrefab, LogLevel.WARNING);
67 continue;
68 }
69
70 baseResourceObject = resource.GetResource();
71 if (!baseResourceObject)
72 {
73 Print("Invalid Ruin Prefab (no baseResourceObject) " + ruinPrefab, LogLevel.WARNING);
74 continue;
75 }
76
77 entitySource = baseResourceObject.ToEntitySource();
78 if (!entitySource)
79 {
80 Print("Invalid Ruin Prefab (no entitySource) " + ruinPrefab, LogLevel.WARNING);
81 continue;
82 }
83
84 ResourceName ruinXOB = GetModelFromPrefab(entitySource);
85 if (!ruinXOB)
86 {
87 Print("Invalid Ruin Prefab (no model) " + ruinPrefab, LogLevel.NORMAL);
88 continue;
89 }
90
91 ruinXobSet.Insert(ruinXOB);
92 }
93
94 array<ResourceName> result = {};
95 array<ResourceName> ruinXOBs = GetRuinXOBs();
96 foreach (ResourceName ruinXOB : ruinXOBs)
97 {
98 if (!ruinXobSet.Contains(ruinXOB))
99 result.Insert(ruinXOB);
100 }
101
102 return result;
103 }
104
105 //------------------------------------------------------------------------------------------------
106 protected static ResourceName GetModelFromPrefab(notnull IEntitySource entitySource)
107 {
108 IEntityComponentSource meshComp = SCR_BaseContainerTools.FindComponentSource(entitySource, MeshObject);
109 if (!meshComp)
110 return ResourceName.Empty;
111
112 ResourceName result;
113 meshComp.Get("Object", result);
114 return result;
115 }
116
117 //------------------------------------------------------------------------------------------------
119 protected array<ResourceName> GetUnassignedRuinPrefabs(notnull array<ResourceName> ruinPrefabs)
120 {
121 // - Check that all _Ruin Prefabs have an associated building _base Prefab
122
123 array<ResourceName> houseBases = GetHouseBasePrefabs();
124
125 Resource resource;
126 BaseResourceObject baseResourceObject;
127 IEntitySource entitySource;
128 typename type;
129 set<ResourceName> usedRuinPrefabSet = new set<ResourceName>(); // found Ruin set
130 foreach (ResourceName houseBase : houseBases)
131 {
132 resource = Resource.Load(houseBase);
133 if (!resource.IsValid())
134 {
135 Print("Invalid building Prefab (invalid resource) " + houseBase, LogLevel.WARNING);
136 continue;
137 }
138
139 baseResourceObject = resource.GetResource();
140 if (!baseResourceObject)
141 {
142 Print("Invalid building Prefab (no baseResourceObject) " + houseBase, LogLevel.WARNING);
143 continue;
144 }
145
146 entitySource = baseResourceObject.ToEntitySource();
147 if (!entitySource)
148 {
149 Print("Invalid building Prefab (no entitySource) " + houseBase, LogLevel.WARNING);
150 continue;
151 }
152
153 type = entitySource.GetClassName().ToType();
154 if (!type || !type.IsInherited(SCR_DestructibleBuildingEntity))
155 continue;
156
157 ResourceName ruinPrefab = GetRuinFromBaseBuildingPrefab(entitySource);
158 if (!ruinPrefab)
159 {
160 // Print("Invalid building Prefab (no ruin) " + houseBase, LogLevel.NORMAL);
161 continue;
162 }
163
164 usedRuinPrefabSet.Insert(ruinPrefab);
165 }
166
167 array<ResourceName> result = {};
168 foreach (ResourceName ruinPrefab : ruinPrefabs)
169 {
170 if (!usedRuinPrefabSet.Contains(ruinPrefab))
171 result.Insert(ruinPrefab);
172 }
173
174 return result;
175 }
176
177 //------------------------------------------------------------------------------------------------
178 protected static ResourceName GetRuinFromBaseBuildingPrefab(notnull IEntitySource entitySource)
179 {
180 IEntityComponentSource destrComp = SCR_BaseContainerTools.FindComponentSource(entitySource, SCR_DestructibleBuildingComponent);
181 if (!destrComp)
182 return ResourceName.Empty;
183
184 BaseContainerList effects = destrComp.GetObjectArray("m_aEffects");
185 if (!effects)
186 return ResourceName.Empty;
187
188 BaseContainer effect;
189 ResourceName result;
190 typename type;
191 for (int i, count = effects.Count(); i < count; ++i)
192 {
193 effect = effects.Get(i);
194 type = effect.GetClassName().ToType();
195 if (!type || !type.IsInherited(SCR_TimedPrefab))
196 continue;
197
198 if (effect.Get("m_sRuinsPrefab", result) && result)
199 return result;
200 }
201
202 return ResourceName.Empty;
203 }
204
205 //------------------------------------------------------------------------------------------------
206 protected array<ResourceName> GetRuinPrefabs()
207 {
208 if (m_bSearchInAllAddons)
209 return SCR_WorkbenchHelper.SearchWorkbenchResources({ "et" }, { "_Ruin" });
210
211 array<ResourceName> result = {};
212 result.InsertAll(SCR_WorkbenchHelper.SearchWorkbenchResources({ "et" }, { "_Ruin" }, BASE_PREFIX + PREFABS_DIR));
213 result.InsertAll(SCR_WorkbenchHelper.SearchWorkbenchResources({ "et" }, { "_Ruin" }, ADDON_PREFIX + PREFABS_DIR));
214 return result;
215 }
216
217 //------------------------------------------------------------------------------------------------
218 protected array<ResourceName> GetRuinXOBs()
219 {
220 if (m_bSearchInAllAddons)
221 return SCR_WorkbenchHelper.SearchWorkbenchResources({ "xob" }, { "_ruin" });
222
223 array<ResourceName> result = {};
224 result.InsertAll(SCR_WorkbenchHelper.SearchWorkbenchResources({ "xob" }, { "_ruin" }, BASE_PREFIX + XOBS_DIR));
225 result.InsertAll(SCR_WorkbenchHelper.SearchWorkbenchResources({ "xob" }, { "_ruin" }, ADDON_PREFIX + XOBS_DIR));
226 return result;
227 }
228
229 //------------------------------------------------------------------------------------------------
230 protected array<ResourceName> GetHouseBasePrefabs()
231 {
232 if (m_bSearchInAllAddons)
233 return SCR_WorkbenchHelper.SearchWorkbenchResources({ "et" }, { "_base" });
234
235 array<ResourceName> result = {};
236 result.InsertAll(SCR_WorkbenchHelper.SearchWorkbenchResources({ "et" }, { "_base" }, BASE_PREFIX + PREFABS_DIR));
237 result.InsertAll(SCR_WorkbenchHelper.SearchWorkbenchResources({ "et" }, { "_base" }, ADDON_PREFIX + PREFABS_DIR));
238 return result;
239 }
240
241 //------------------------------------------------------------------------------------------------
242 protected override void Configure()
243 {
244 Workbench.ScriptDialog("Check Ruin Models and Usage", "", this);
245 }
246
247 //------------------------------------------------------------------------------------------------
248 [ButtonAttribute("Close", true)]
249 protected int CloseButton()
250 {
251 return 1;
252 }
253}
254#endif
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
ResourceName resourceName
Definition SCR_AIGroup.c:66
EDamageType type
override void Run()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
override void Configure()
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
MeshObject.
Definition MeshObject.c:34
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
static array< ResourceName > SearchWorkbenchResources(array< string > fileExtensions=null, array< string > searchStrArray=null, string rootPath="", bool recursive=true)
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
SCR_FieldOfViewSettings Attribute