Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_EditorLinkComponentSerializer.c
Go to the documentation of this file.
2{
3 string StoreName;
4 ref BufferSaveContext Context;
5}
6
7class SCR_EditorLinkComponentSerializer : ScriptedComponentSerializer
8{
9 //------------------------------------------------------------------------------------------------
10 override static typename GetTargetType()
11 {
12 return SCR_EditorLinkComponent;
13 }
14
15 //------------------------------------------------------------------------------------------------
16 override protected ESerializeResult Serialize(notnull IEntity owner, notnull GenericComponent component, notnull SaveContext context)
17 {
18 const SCR_EditorLinkComponent editorLink = SCR_EditorLinkComponent.Cast(component);
19 const array<IEntity> children = editorLink.GetLinkedChildren();
20 if (!children)
21 return ESerializeResult.DEFAULT;
22
23 auto entriesContainer = editorLink.GetComponentSource(owner).GetObjectArray("m_aEntries");
24 if (children.Count() != entriesContainer.Count())
25 return ESerializeResult.ERROR;
26
27 array<ref PersistentEntityLinkItem> changed();
28 array<string> removed();
29
30 foreach (int idx, auto child : children)
31 {
32 if (child && !GetSystem().IsTracked(child))
33 continue;
34
35 const BaseContainer container = entriesContainer.Get(idx);
36 const string storeName = SCR_ResourceNameUtils.GetPrefabGUID(container.GetResourceName());
37
38 if (!child)
39 {
40 removed.Insert(storeName);
41 continue;
42 }
43
45 item.StoreName = storeName;
46 item.Context = BufferSaveContext.Create(context);
47 item.Context.StartObject();
48
49 // Ignore default data from prefab
50 ResourceName prefab;
51 container.Get("m_Prefab", prefab);
52
53 vector prefabPos;
54 container.Get("m_vPosition", prefabPos);
55
56 vector prefabAngles;
57 container.Get("m_vAngles", prefabAngles);
58
59 // Pitch Yaw Roll from prefab to Yaw Pitch Roll used at runtime
60 float yaw = prefabAngles[1];
61 prefabAngles[1] = prefabAngles[0];
62 prefabAngles[0] = yaw;
63
64 float scale;
65 container.Get("m_fScale", scale);
66
68 defaults.Prefab = prefab;
69 Math3D.AnglesToMatrix(prefabAngles, defaults.Transform);
70 Math3D.MatrixScale(defaults.Transform, scale);
71 defaults.Transform[3] = prefabPos;
72
73 const ESerializeResult result = GetSystem().SerializeEntity(child, item.Context, defaults);
74 if (result == ESerializeResult.ERROR)
75 return ESerializeResult.ERROR;
76
77 if (result == ESerializeResult.DEFAULT)
78 continue;
79
80 item.Context.EndObject();
81 changed.Insert(item);
82 }
83
84 if (changed.IsEmpty() && removed.IsEmpty())
85 return ESerializeResult.DEFAULT;
86
87 context.WriteValue("version", 1);
88
89 if (!changed.IsEmpty() || !context.CanSeekMembers())
90 {
91 int count = changed.Count();
92 context.StartMap("changed", count);
93 foreach (PersistentEntityLinkItem item : changed)
94 {
95 context.WriteMapKey(item.StoreName);
96 item.Context.Apply(context);
97 }
98 context.EndMap();
99 }
100
101 if (!removed.IsEmpty() || !context.CanSeekMembers())
102 context.Write(removed);
103
104 return ESerializeResult.OK;
105 }
106
107 //------------------------------------------------------------------------------------------------
108 override protected bool Deserialize(notnull IEntity owner, notnull GenericComponent component, notnull LoadContext context)
109 {
110 SCR_EditorLinkComponent editorLink = SCR_EditorLinkComponent.Cast(component);
111
112 int version;
113 context.ReadValue("version", version);
114
115 map<string, IEntity> linkedChildrenLookup();
116 const array<IEntity> children = editorLink.GetLinkedChildren();
117 if (!children)
118 return false;
119
120 auto entriesContainer = editorLink.GetComponentSource(owner).GetObjectArray("m_aEntries");
121 if (children.Count() != entriesContainer.Count())
122 return false;
123
124 foreach (int idx, auto child : children)
125 {
126 const string storeName = SCR_ResourceNameUtils.GetPrefabGUID(entriesContainer.Get(idx).GetResourceName());
127 linkedChildrenLookup.Insert(storeName, child);
128 }
129
130 int changedCount = 0;
131 if (context.StartMap("changed", changedCount))
132 {
133 string keyBuffer;
134 for (int i = 0; i < changedCount; ++i)
135 {
136 context.ReadMapKey(i, keyBuffer);
137 context.StartObject(keyBuffer);
138 IEntity changeEntitiy = linkedChildrenLookup.Get(keyBuffer);
139 if (changeEntitiy)
140 {
141 const IEntity resultEnt = GetSystem().DeserializeLoadEntity(changeEntitiy, context, false);
142 if (resultEnt != changeEntitiy)
143 return false;
144 }
145 context.EndObject();
146 }
147 context.EndMap();
148 }
149
150 array<string> removed();
151 context.Read(removed);
152 foreach (auto removeStoreName : removed)
153 {
154 IEntity removeEntity = linkedChildrenLookup.Get(removeStoreName);
155 SCR_EntityHelper.DeleteEntityAndChildren(removeEntity);
156 }
157
158 return true;
159 }
160}
class SCR_PersistentThreatSector GetTargetType()
vector scale
ESerializeResult Serialize(notnull IEntity owner, notnull GenericComponent component, notnull SaveContext context)
bool Deserialize(notnull IEntity owner, notnull GenericComponent component, notnull LoadContext context)
Collection of data to avoid writing known defaults during serialization.
Definition Types.c:486
ESerializeResult