Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DamageAreaShapesPlugin.c
Go to the documentation of this file.
1#ifdef WORKBENCH
2[WorkbenchPluginAttribute(name: "Optimize Damage Area Shapes", description: "Attempts to adjust shapes of the selected damage area entities.", wbModules: { "WorldEditor" }, awesomeFontCode: 0xf714)]
3class SCR_DamageAreaShapesPlugin : WorldEditorPlugin
4{
5 protected const string PROPERTY_COORDS = "coords";
6 protected const string PROPERTY_SHAPE = "Area shape";
7 protected const string PROPERTY_AREA = "DamageAreas";
8 protected const string PROPERTY_COMPONENTS = "components";
9
10 //------------------------------------------------------------------------------------------------
11 override void Run()
12 {
13 WorldEditorAPI api = SCR_WorldEditorToolHelper.GetWorldEditorAPI();
14 if (!api)
15 return;
16
17 if (api.GetSelectedEntity() == null)
18 {
19 SCR_WorkbenchHelper.PrintDialog("Select entities for optimization!", level: LogLevel.ERROR);
20 return;
21 }
22
23 IEntity ent;
24 IEntitySource entSrc;
25 SCR_DamageAreaComponent dmgAreaComp;
26 array<ref DamageArea> damageAreas = {};
27
28 api.BeginEntityAction();
29
30 bool anythingChanged;
31 for (int i, count = api.GetSelectedEntitiesCount(); i < count; i++)
32 {
33 entSrc = api.GetSelectedEntity(i);
34 if (!entSrc)
35 continue;
36
37 ent = api.SourceToEntity(entSrc);
38 if (!ent)
39 continue;
40
41 dmgAreaComp = SCR_DamageAreaComponent.Cast(ent.FindComponent(SCR_DamageAreaComponent));
42 if (!dmgAreaComp)
43 continue;
44
45 int componentIndex = SCR_BaseContainerTools.FindComponentIndex(entSrc, SCR_DamageAreaComponent);
46 ContainerIdPathEntry componentPath = new ContainerIdPathEntry(PROPERTY_COMPONENTS, componentIndex);
47 ContainerIdPathEntry areaPath = new ContainerIdPathEntry(PROPERTY_AREA);
48 ContainerIdPathEntry shapePath = new ContainerIdPathEntry(PROPERTY_SHAPE);
49 array<ref ContainerIdPathEntry> finalPath;
50
52 dmgAreaComp.GetDamageAreas(damageAreas);
53 foreach (int areaId, DamageArea dmgArea : damageAreas)
54 {
55 if (!dmgArea)
56 continue;
57
58 shape = SCR_BaseDamageAreaShape.Cast(dmgArea.GetShape());
59 if (!shape)
60 continue;
61
62 vector offset;
63 areaPath.Index = areaId;
64 finalPath = {componentPath, areaPath, shapePath};
65 if (!shape.OptimizeShape(entSrc, api, finalPath, offset))
66 continue; // it did nothing so we can skip
67
68 anythingChanged = true;
69 // Move the entity to such position that its moddified area is in the same place
70 vector newEntPos;
71 entSrc.Get(PROPERTY_COORDS, newEntPos);
72 newEntPos += offset;
73 api.SetVariableValue(entSrc, null, PROPERTY_COORDS, newEntPos.ToString(false));
74 }
75 }
76
77 api.EndEntityAction();
78 if (anythingChanged)
79 SCR_WorkbenchHelper.PrintDialog("Recentering has been finished. Dont forget to save the changes!", level: LogLevel.WARNING);
80 }
81}
82#endif
void ContainerIdPathEntry(string propertyName, int index=-1)
Definition worldEditor.c:30
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
override void Run()
proto external Managed FindComponent(typename typeName)
static void PrintDialog(string message, string caption="", LogLevel level=LogLevel.WARNING)
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14