Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_EditableEntityMaintenancePlugin.c
Go to the documentation of this file.
1#ifdef WORKBENCH
2[WorkbenchPluginAttribute(name: "Maintain Editable Entities", category: SCR_PluginCategory.EDITOR, wbModules: { "WorldEditor", "ResourceManager" }, awesomeFontCode: 0xF0AD)]
3class SCR_EditableEntityMaintenancePlugin : WorkbenchPlugin
4{
5 [Attribute("ArmaReforger")]
6 protected string m_sAddon;
7
8 [Attribute("PrefabsEditable/Auto", params: "unregFolders")]
9 protected ResourceName m_sDirectory;
10
11 //[Attribute("MeshObject RigidBody RplComponent Hierarchy SCR_DestructionMultiPhaseComponent")]
12 //private ref array<string> m_aCheckedComponents;
13
14 protected static const ref array<string> UNIQUE_COMPONENTS = { "MeshObject", "RigidBody", "RplComponent", "Hierarchy", "SCR_DestructionMultiPhaseComponent" };
15
16 //------------------------------------------------------------------------------------------------
17 override void Run()
18 {
19 string uniqueComponentClasses;
20 foreach (int i, string uniqueComponent : UNIQUE_COMPONENTS)
21 {
22 if (i > 0)
23 uniqueComponentClasses += "\n";
24 uniqueComponentClasses += " - " + uniqueComponent;
25 }
26
27 if (!Workbench.ScriptDialog("Maintain Editable Entities", string.Format("Go through all entity prefabs in the folder and remove duplicate components of following types:\n%1", uniqueComponentClasses), this))
28 return;
29
30 array<ResourceName> resources = {};
31 string path = SCR_AddonTool.ToFileSystem(m_sAddon) + m_sDirectory.GetPath();
32 SearchResourcesFilter filter = new SearchResourcesFilter();
33 filter.fileExtensions = { "et" };
34 filter.rootPath = path;
35 ResourceDatabase.SearchResources(filter, resources.Insert);
36
37 int repairedCount;
38 Resource resource;
39 IEntitySource entitySource, ancestorSource;
40 BaseContainerList componentsArray, ancestorComponentsArray;
41 array<BaseContainer> ancestorComponents = {};
42 array<BaseContainer> componentsToRemove = {};
43 array<string> componentClasses = {};
44 string componentClass;
45 IEntityComponentSource component;
46 foreach (ResourceName prefab : resources)
47 {
48 resource = Resource.Load(prefab);
49 if (!resource.IsValid())
50 {
51 PrintFormat("Cannot load %1 | %2:%3", prefab + FilePath.StripPath(__FILE__), __LINE__, level: LogLevel.WARNING);
52 return;
53 }
54
55 entitySource = resource.GetResource().ToEntitySource();
56
57 componentsToRemove.Clear();
58 componentClasses.Clear();
59
60 //--- Get ancestor components
61 ancestorSource = entitySource.GetAncestor();
62 if (ancestorSource)
63 {
64 ancestorComponentsArray = ancestorSource.GetObjectArray("components");
65 for (int i = 0, count = ancestorComponentsArray.Count(); i < count; i++)
66 {
67 ancestorComponents.Insert(ancestorComponentsArray.Get(i));
68 }
69 }
70
71 //--- Get prefab's components
72 componentsArray = entitySource.SetObjectArray("components");
73 int componentCount = componentsArray.Count();
74 for (int i = 0; i < componentCount; i++)
75 {
76 component = componentsArray.Get(i);
77 componentClass = component.GetClassName();
78
79 if (componentClasses.Contains(componentClass) && UNIQUE_COMPONENTS.Contains(componentClass) && !ancestorComponents.Contains(component))
80 {
81 //--- Duplicate component which is on the list of checked components, and is also defined in this prefab and not in ancestor
82 componentsToRemove.Insert(component);
83 }
84 else
85 {
86 //--- Not duplicate
87 componentClasses.Insert(componentClass);
88 }
89 }
90
91 if (!componentsToRemove.IsEmpty())
92 {
93 foreach (BaseContainer componentToRemove : componentsToRemove)
94 {
95 Print(string.Format("@\"%1\": Removed duplicate component %2", entitySource.GetResourceName().GetPath(), componentToRemove.GetClassName()), LogLevel.WARNING);
96 componentsArray.Remove(componentToRemove);
97 }
98
99 BaseContainerTools.SaveContainer(entitySource, prefab);
100 repairedCount++;
101 }
102 }
103
104 Print(string.Format("%1 prefabs checked, %2 repaired.", resources.Count(), repairedCount), LogLevel.NORMAL);
105 }
106
107 //------------------------------------------------------------------------------------------------
108 [ButtonAttribute("Run")]
109 protected bool ButtonRun()
110 {
111 return true;
112 }
113
114 //------------------------------------------------------------------------------------------------
115 [ButtonAttribute("Close")]
116 protected bool ButtonClose()
117 {
118 return false;
119 }
120}
121#endif // WORKBENCH
string path
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
override void Run()
string m_sDirectory
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", 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
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
SCR_FieldOfViewSettings Attribute