Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_PrefabEditingPluginBase.c
Go to the documentation of this file.
1#ifdef WORKBENCH
2class SCR_PrefabEditingPluginBase : WorkbenchPlugin
3{
4 //------------------------------------------------------------------------------------------------
5 protected WBProgressDialog StartProgressWorldEditor()
6 {
7 return new WBProgressDialog("Processing Prefabs...", Workbench.GetModule(WorldEditor));
8 }
9
10 //------------------------------------------------------------------------------------------------
11 protected WBProgressDialog StartProgress()
12 {
13 return StartProgressWorldEditor();
14 }
15
16 //------------------------------------------------------------------------------------------------
17 protected void GetSelectedWorldEditor(out array<ResourceName> selection)
18 {
19 WorldEditor worldEditor = Workbench.GetModule(WorldEditor);
20 worldEditor.GetResourceBrowserSelection(selection.Insert, true);
21 }
22
23 //------------------------------------------------------------------------------------------------
24 protected void GetSelectedResourceBrowser(out array<ResourceName> selection)
25 {
26 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
27 resourceManager.GetResourceBrowserSelection(selection.Insert, true);
28 }
29
30 //------------------------------------------------------------------------------------------------
31 protected void GetSelected(out array<ResourceName> selection)
32 {
33 GetSelectedWorldEditor(selection);
34 }
35
36 //------------------------------------------------------------------------------------------------
37 protected bool GetPrefabs(out notnull array<ResourceName> compatiblePrefabs, bool includeComponentPrefabs = false)
38 {
39 //--- Get selected prefabs
40 array<ResourceName> selectedPrefabs = {};
41 GetSelected(selectedPrefabs);
42 if (selectedPrefabs.IsEmpty())
43 {
44 Print("No prefab selected!", LogLevel.ERROR);
45 return false;
46 }
47
48 //--- Evaluate selected prefabs
49 string extension;
50 Resource prefabResource;
51 BaseResourceObject prefabBase;
52 BaseContainer prefabContainer;
53 typename prefabType;
54 foreach (ResourceName prefab : selectedPrefabs)
55 {
56 FilePath.StripExtension(prefab, extension);
57 if (includeComponentPrefabs)
58 {
59 if (extension != "et" && extension != "ct")
60 {
61 Print(string.Format("Cannot load prefab '%1', it's not a prefab! Only .et and .ct files can be loaded.", prefab), LogLevel.ERROR);
62 continue;
63 }
64 }
65 else
66 {
67 if (extension != "et")
68 {
69 Print(string.Format("Cannot load prefab '%1', it's not a prefab! Only .et files can be loaded.", prefab), LogLevel.ERROR);
70 continue;
71 }
72 }
73
74 prefabResource = Resource.Load(prefab);
75 if (!prefabResource.IsValid())
76 {
77 Print(string.Format("Cannot load prefab '%1'!", prefab), LogLevel.ERROR);
78 continue;
79 }
80
81 prefabBase = prefabResource.GetResource();
82 if (!prefabBase)
83 {
84 Print(string.Format("Cannot load prefab '%1'!", prefab), LogLevel.ERROR);
85 continue;
86 }
87
88 prefabContainer = prefabBase.ToBaseContainer();
89 if (!prefabContainer)
90 {
91 Print(string.Format("Cannot load prefab '%1'!", prefab), LogLevel.ERROR);
92 continue;
93 }
94
95 prefabType = prefabContainer.GetClassName().ToType();
96 if (includeComponentPrefabs)
97 {
98 if (!prefabType.IsInherited(IEntity) && !prefabType.IsInherited(GenericComponent))
99 {
100 Print(string.Format("Cannot load prefab '%1', it's neither an entity nor a component!", prefab), LogLevel.ERROR);
101 continue;
102 }
103 }
104 else
105 {
106 if (!prefabType.IsInherited(IEntity))
107 {
108 Print(string.Format("Cannot load prefab '%1', it's not an entity!", prefab), LogLevel.ERROR);
109 continue;
110 }
111 }
112
113 compatiblePrefabs.Insert(prefab);
114 }
115
116 return !compatiblePrefabs.IsEmpty();
117 }
118}
119#endif
enum EVehicleType IEntity
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 external int GetSelected(out notnull array< MapItem > outItems)
Get all selected entities.