Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_EditorPreviewParams.c
Go to the documentation of this file.
1
2
5{
7 RplId m_ParentID = RplId.Invalid();
8 bool m_bParentChanged;
9
10 RplId m_TargetRplID = RplId.Invalid();
11 EntityID m_TargetStaticID;
13 EEditableEntityInteraction m_TargetInteraction;
14
15 vector m_vTransform[4];
16 vector m_Offset;
17 bool m_bIsUnderwater;
18 EEditorTransformVertical m_VerticalMode;
19 EEditorPlacingFlags m_PlacingFlags;
20 SCR_EditableEntityComponent m_CurrentLayer; //--- No replicated, used to extract data from SCR_PlacingEditorComponent.SpawnEntityResource()
22 int m_iActionInfo = -1;
25
26
27 //------------------------------------------------------------------------------------------------
28 static void Encode(SSnapSerializerBase snapshot, ScriptCtx hint, ScriptBitSerializer packet)
29 {
30 snapshot.Serialize(packet, 88);
31 }
32
33 //------------------------------------------------------------------------------------------------
34 static bool Decode(ScriptBitSerializer packet, ScriptCtx hint, SSnapSerializerBase snapshot)
35 {
36 return snapshot.Serialize(packet, 88);
37 }
38
39 //------------------------------------------------------------------------------------------------
41 {
42 return lhs.CompareSnapshots(rhs, 88);
43 }
44
45 //------------------------------------------------------------------------------------------------
47 {
48 return snapshot.Compare(prop.m_vTransform, 48)
49 && snapshot.Compare(prop.m_ParentID, 4)
50 && snapshot.Compare(prop.m_bParentChanged, 4)
51 && snapshot.Compare(prop.m_VerticalMode, 4)
52 && snapshot.Compare(prop.m_bIsUnderwater, 4)
53 && snapshot.Compare(prop.m_TargetRplID, 4)
54 && snapshot.Compare(prop.m_TargetStaticID, 8)
55 && snapshot.Compare(prop.m_TargetInteraction, 4)
56 && snapshot.Compare(prop.m_PlacingFlags, 4)
57 && snapshot.Compare(prop.m_iActionInfo, 4);
58 }
59
60 //------------------------------------------------------------------------------------------------
62 {
63 snapshot.SerializeBytes(prop.m_vTransform, 48);
64 snapshot.SerializeBytes(prop.m_ParentID, 4);
65 snapshot.SerializeBytes(prop.m_bParentChanged, 4);
66 snapshot.SerializeBytes(prop.m_VerticalMode, 4);
67 snapshot.SerializeBytes(prop.m_bIsUnderwater, 4);
68 snapshot.SerializeBytes(prop.m_TargetRplID, 4);
69 snapshot.SerializeBytes(prop.m_TargetStaticID, 8);
70 snapshot.SerializeBytes(prop.m_TargetInteraction, 4);
71 snapshot.SerializeBytes(prop.m_PlacingFlags, 4);
72 snapshot.SerializeBytes(prop.m_iActionInfo, 4);
73
74 return true;
75 }
76
77 //------------------------------------------------------------------------------------------------
79 {
80 snapshot.SerializeBytes(prop.m_vTransform, 48);
81 snapshot.SerializeBytes(prop.m_ParentID, 4);
82 snapshot.SerializeBytes(prop.m_bParentChanged, 4);
83 snapshot.SerializeBytes(prop.m_VerticalMode, 4);
84 snapshot.SerializeBytes(prop.m_bIsUnderwater, 4);
85 snapshot.SerializeBytes(prop.m_TargetRplID, 4);
86 snapshot.SerializeBytes(prop.m_TargetStaticID, 8);
87 snapshot.SerializeBytes(prop.m_TargetInteraction, 4);
88 snapshot.SerializeBytes(prop.m_PlacingFlags, 4);
89 snapshot.SerializeBytes(prop.m_iActionInfo, 4);
90
91 return true;
92 }
93
94 //------------------------------------------------------------------------------------------------
97 void GetWorldTransform(out vector outTransform[4])
98 {
99 if (m_Offset == vector.Zero)
100 {
101 //--- Exact position
102 //outTransform = m_vTransform; //--- Doesn't work, reference is lost
103 Math3D.MatrixCopy(m_vTransform, outTransform);
104 }
105 else
106 {
107 //--- Offset when multiple entities are being placed (e.g., waypoints for a group)
108 vector coefMatrix[4] = {m_vTransform[0], m_vTransform[1], m_vTransform[2], vector.Zero};
109 vector offsetMatrix[4] = { vector.Zero, vector.Zero, vector.Zero, m_Offset};
110 Math3D.MatrixMultiply4(coefMatrix, offsetMatrix, offsetMatrix);
111 outTransform = {m_vTransform[0], m_vTransform[1], m_vTransform[2], m_vTransform[3] + offsetMatrix[3]};
112 }
113 }
114
115 //------------------------------------------------------------------------------------------------
119 {
120 m_Parent = SCR_EditableEntityComponent.Cast(Replication.FindItem(m_ParentID));
121 if (!m_Parent && m_ParentID.IsValid())
122 {
123 Print(string.Format("Cannot deserialize entity, parent with RplId = %1 not found!", m_ParentID), LogLevel.ERROR);
124 return false;
125 }
126
127 m_Target = SCR_EditableEntityComponent.Cast(Replication.FindItem(m_TargetRplID));
128
129 if (!m_Target)
130 m_Target = SCR_EditableEntityComponent.GetEditableEntity(GetGame().GetWorld().FindEntityByID(m_TargetStaticID));
131
132 if (!m_Target && m_TargetRplID.IsValid())
133 {
134 Print(string.Format("Cannot deserialize entity, target neither with RplId = %1 nor with EntityID = %2 found!", m_TargetRplID, m_TargetStaticID), LogLevel.ERROR);
135 return false;
136 }
137
138 return true;
139 }
140
141 //------------------------------------------------------------------------------------------------
145 {
146 if (target && target.GetOwner())
147 {
148 m_TargetRplID = Replication.FindItemId(target);
149 if (!m_TargetRplID.IsValid())
150 m_TargetStaticID = target.GetOwner().GetID();
151 }
152 }
153
154 //------------------------------------------------------------------------------------------------
159 static int PackActionInfo(notnull SCR_BaseEditorAction action, notnull IEntity actionCompOwner)
160 {
162 array<Managed> actionProviders = {};
163 actionCompOwner.FindComponents(SCR_BaseActionsEditorComponent, actionProviders);
164 SCR_BaseActionsEditorComponent actionProvider;
165 int output = -1;
166 foreach (int i, Managed comp : actionProviders)
167 {
168 actionProvider = SCR_BaseActionsEditorComponent.Cast(comp);
169 if (!comp)
170 continue;
171
172 data = SCR_BaseActionsEditorComponentClass.Cast(actionProvider.GetComponentData(actionCompOwner));
173 output = data.FindAction(action);
174 if (output < 0)
175 continue;
176
177 if (output >= 1000)
178 {
179 Print("SCR_EditorPreviewParams.SetActionInfo: System supports only up to 999 actions per SCR_BaseActionsEditorComponent! Processing of action with ID = " + output + " from " + comp + " was aborted.", LogLevel.ERROR);
180 return -1;
181 }
182
183 output += i * 1000;
184 return output;
185 }
186
187 return output;
188 }
189
190 //------------------------------------------------------------------------------------------------
195 {
196 if (m_SourceAction)
197 return m_SourceAction;
198
199 array<Managed> actionProviders = {};
200 actionCompOwner.FindComponents(SCR_BaseActionsEditorComponent, actionProviders);
201 int componentId = Math.Floor(m_iActionInfo * 0.001);
202 if (!actionProviders.IsIndexValid(componentId))
203 return null;
204
205 SCR_BaseActionsEditorComponent actionProvider = SCR_BaseActionsEditorComponent.Cast(actionProviders[componentId]);
206 SCR_BaseActionsEditorComponentClass data = SCR_BaseActionsEditorComponentClass.Cast(actionProvider.GetComponentData(actionCompOwner));
207 m_SourceAction = data.GetAction(m_iActionInfo - componentId * 1000);
208 return m_SourceAction;
209 }
210
211 //------------------------------------------------------------------------------------------------
221 vector transform[4],
222 RplId parentID = Replication.INVALID_ID,
224 bool isUnderwater = false,
225 SCR_EditableEntityComponent target = null,
227 )
228 {
230 Math3D.MatrixCopy(transform, params.m_vTransform);
231 params.m_ParentID = parentID;
232 params.m_VerticalMode = verticalMode;
233 params.m_bIsUnderwater = isUnderwater;
234 params.m_TargetInteraction = targetInteraction;
235 params.SetTarget(target);
236 return params;
237 }
238
239 //------------------------------------------------------------------------------------------------
245 // TODO: notnull or nullcheck previewManager
247 {
248 //--- Check if target interaction is valid
249 if (previewManager.GetTarget() && previewManager.GetTargetInteraction() == EEditableEntityInteraction.NONE)
250 {
251 SCR_NotificationsComponent.SendLocal(ENotification.EDITOR_TRANSFORMING_INCORRECT_TARGET);
252 return null;
253 }
254
256
257 previewManager.GetPreviewTransform(params.m_vTransform);
258 params.m_VerticalMode = previewManager.GetVerticalModeReal();
259 params.m_bIsUnderwater = previewManager.IsUnderwater();
260 params.m_TargetInteraction = previewManager.GetTargetInteraction();
261 params.SetTarget(previewManager.GetTarget());
262 params.m_ParentID = Replication.FindItemId(parent);
263 params.m_bParentChanged = parentChanged;
264
265 return params;
266 }
267}
EEditorPlacingFlags
ENotification
ArmaReforgerScripted GetGame()
Definition game.c:1398
Get all prefabs that have the spawner data
Definition Math.c:13
Main replication API.
Definition Replication.c:14
Replication item identifier.
Definition RplId.c:14
static SCR_EditableEntityComponent GetEditableEntity(IEntity owner)
Network packet of variables for entity placing and transformation.
SCR_BaseEditorAction m_SourceAction
local cache of the action which was the reason for creation of this param
static void Encode(SSnapSerializerBase snapshot, ScriptCtx hint, ScriptBitSerializer packet)
static bool Extract(SCR_EditorPreviewParams prop, ScriptCtx hint, SSnapSerializerBase snapshot)
static bool SnapCompare(SSnapSerializerBase lhs, SSnapSerializerBase rhs, ScriptCtx hint)
static SCR_EditorPreviewParams CreateParamsFromPreview(SCR_PreviewEntityEditorComponent previewManager, SCR_EditableEntityComponent parent=null, bool parentChanged=false)
SCR_BaseEditorAction GetSourceAction(notnull IEntity actionCompOwner)
void SetTarget(SCR_EditableEntityComponent target)
static SCR_EditorPreviewParams CreateParams(vector transform[4], RplId parentID=Replication.INVALID_ID, EEditorTransformVertical verticalMode=EEditorTransformVertical.SEA, bool isUnderwater=false, SCR_EditableEntityComponent target=null, EEditableEntityInteraction targetInteraction=EEditableEntityInteraction.NONE)
static bool Inject(SSnapSerializerBase snapshot, ScriptCtx hint, SCR_EditorPreviewParams prop)
static bool PropCompare(SCR_EditorPreviewParams prop, SSnapSerializerBase snapshot, ScriptCtx hint)
void GetWorldTransform(out vector outTransform[4])
static bool Decode(ScriptBitSerializer packet, ScriptCtx hint, SSnapSerializerBase snapshot)
static int PackActionInfo(notnull SCR_BaseEditorAction action, notnull IEntity actionCompOwner)
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
EEditorTransformVertical
Vertical transformation mode.
EEditableEntityInteraction
Type of suggested interaction when hovering edited entity on top of another entity.