Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_RegisterPlaceableEntitiesPlugin.c
Go to the documentation of this file.
1#ifdef WORKBENCH
2[WorkbenchPluginAttribute(name: "Register Placeable Entities...", category: SCR_PluginCategory.EDITOR, wbModules: { "ResourceManager" })]
3class SCR_RegisterPlaceableEntitiesPlugin : WorkbenchPlugin
4{
5 [Attribute(desc: "File to which the resulting list will be saved.", params: "class=SCR_PlaceableEntitiesRegistry conf")]
6 protected ResourceName m_sConfig;
7
8 //------------------------------------------------------------------------------------------------
9 protected void Scan()
10 {
11 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
12 WBProgressDialog progress = new WBProgressDialog("Scanning...", resourceManager);
13
14 //--- Open config
15 if (m_sConfig.IsEmpty())
16 {
17 Print("Config file not found!", LogLevel.ERROR);
18 return;
19 }
20
21 Resource configContainer = BaseContainerTools.LoadContainer(m_sConfig);
22 if (!configContainer)
23 return;
24
25 SCR_PlaceableEntitiesRegistry registry = SCR_PlaceableEntitiesRegistry.Cast(BaseContainerTools.CreateInstanceFromContainer(configContainer.GetResource().ToBaseContainer()));
26 if (!registry)
27 {
28 Print(string.Format("SCR_PlaceableEntitiesRegistry class not found in '%1'!", m_sConfig), LogLevel.ERROR);
29 return;
30 }
31
32 string filesystem = SCR_AddonTool.ToFileSystem(registry.GetAddon());
33 string directory = registry.GetSourceDirectory().GetPath();
34
35 //--- Get all prefabs
36 array<ResourceName> resources = {};
37
38 SearchResourcesFilter filter = new SearchResourcesFilter();
39 filter.fileExtensions = { "et" };
40 filter.rootPath = filesystem + directory;
41 ResourceDatabase.SearchResources(filter, resources.Insert);
42
43 array<ResourceName> prefabs = {};
44
45 //--- Iterate through all prefabs and their components
46 Resource container;
47 BaseResourceObject object;
48 IEntitySource entity;
49 IEntityComponentSource editableEntityComponent;
50 IEntityComponentSource component;
51 int resourcesCount = resources.Count();
52 float prevProgress, currProgress;
53 foreach (int i, ResourceName prefab : resources)
54 {
55 container = BaseContainerTools.LoadContainer(prefab);
56 if (!container)
57 continue;
58
59 object = container.GetResource();
60 entity = object.ToEntitySource();
61
62 //--- Find required components
63 int componentCount = entity.GetComponentCount();
64 editableEntityComponent = null;
65 for (int c = 0; c < componentCount; c++)
66 {
67 component = entity.GetComponent(c);
68
69 if (component.GetClassName().ToType().IsInherited(SCR_EditableEntityComponent))
70 editableEntityComponent = component;
71 }
72
73 //--- Register
74 if (editableEntityComponent)
75 {
76 //--- Check if it's marked as PLACEABLE
77 if (!SCR_EditableEntityComponentClass.HasFlag(editableEntityComponent, EEditableEntityFlag.PLACEABLE))
78 continue;
79
80 Print(string.Format("Registered '%1'", prefab), LogLevel.DEBUG);
81 prefabs.Insert(prefab);
82 }
83
84 currProgress = i / resourcesCount;
85 if (currProgress - prevProgress >= 0.01) // min 1%
86 {
87 progress.SetProgress(currProgress); // expensive
88 prevProgress = currProgress;
89 }
90 }
91
92 resources.Clear();
93
94 //--- Save config to the file
95 registry.SetPrefabs(prefabs);
96 container = BaseContainerTools.CreateContainerFromInstance(registry);
97 if (container)
98 {
99 BaseContainerTools.SaveContainer(container.GetResource().ToBaseContainer(), m_sConfig);
100 resourceManager.SetOpenedResource(m_sConfig);
101 resourceManager.Save();
102 Print(string.Format("Entities from '%1' saved to '%2'", directory, m_sConfig.GetPath()), LogLevel.DEBUG);
103 }
104 }
105
106 //------------------------------------------------------------------------------------------------
107 override void Run()
108 {
109 if (Workbench.ScriptDialog("Register Placeable Entities", "Register all entity prefabs that have SCR_EditableEntityComponent\nwith PLACEABLE flag into target config.\nThe game uses it to get the list of all entities available for placing.\n\nMake sure you don't have the target config open!", this))
110 Scan();
111 }
112
113 //------------------------------------------------------------------------------------------------
114 override void RunCommandline()
115 {
116 Scan();
117 Workbench.Exit(0);
118 }
119
120 //------------------------------------------------------------------------------------------------
121 [ButtonAttribute("Run")]
122 protected bool OK()
123 {
124 return true;
125 }
126
127 //------------------------------------------------------------------------------------------------
128 [ButtonAttribute("Cancel")]
129 protected bool Cancel()
130 {
131 return false;
132 }
133}
134#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
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)
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
EEditableEntityFlag
Unique flags of the entity.
SCR_FieldOfViewSettings Attribute