Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_EditableEntityComponentSerializer.c
Go to the documentation of this file.
2{
3 //------------------------------------------------------------------------------------------------
4 override static typename GetTargetType()
5 {
7 }
8
9 //------------------------------------------------------------------------------------------------
10 override protected ESerializeResult Serialize(notnull IEntity owner, notnull GenericComponent component, notnull SaveContext context)
11 {
12 const SCR_EditableEntityComponent editable = SCR_EditableEntityComponent.Cast(component);
13
14 if (editable.HasEntityFlag(EEditableEntityFlag.NON_SERIALIZABLE))
15 return ESerializeResult.DEFAULT;
16
17 IEntity parentEntity;
18 const SCR_EditableEntityComponent parent = editable.GetParentEntity();
19 if (parent)
20 {
21 parentEntity = parent.GetOwner();
22
23 // For linked component it would be unnecessary so save the parent id as that is implictly known
24 const SCR_EditorLinkComponent editorLink = SCR_EditorLinkComponent.Cast(parentEntity.FindComponent(SCR_EditorLinkComponent));
25 if (editorLink && editorLink.HasChild(owner))
26 parentEntity = null;
27 }
28
29 const UUID parentId = GetSystem().GetId(parentEntity);
30
31 auto slotManager = SCR_CompositionSlotManagerComponent.GetInstance();
32 const bool slotted = slotManager && slotManager.IsInSlot(owner);
33
34 const UUID author = editable.GetAuthorUID();
35 const int lastUpdated = editable.GetAuthorLastUpdated();
36
37 if (parentId.IsNull() && !slotted && author.IsNull())
38 return ESerializeResult.DEFAULT;
39
40 context.WriteValue("version", 1);
41 context.WriteDefault(parentId, UUID.NULL_UUID);
42 context.WriteDefault(slotted, false);
43 context.WriteDefault(author, UUID.NULL_UUID);
44 if (!author.IsNull())
45 context.WriteDefault(lastUpdated, 0);
46
47 return ESerializeResult.OK;
48 }
49
50 //------------------------------------------------------------------------------------------------
51 override protected bool Deserialize(notnull IEntity owner, notnull GenericComponent component, notnull LoadContext context)
52 {
54
55 int version;
56 context.Read(version);
57
58 UUID parentId;
59 context.ReadDefault(parentId, UUID.NULL_UUID);
60 if (!parentId.IsNull())
61 {
62 Tuple1<SCR_EditableEntityComponent> parentContext(editable);
63 PersistenceWhenAvailableTask parentTask(OnParentAvailable, parentContext);
64 GetSystem().WhenAvailable(parentId, parentTask);
65 }
66
67 bool slotted;
68 context.ReadDefault(slotted, false);
69 if (slotted)
70 {
71 auto slotManager = SCR_CompositionSlotManagerComponent.GetInstance();
72 if (slotManager)
73 slotManager.SetOccupant(owner.GetOrigin(), owner);
74 }
75
76 UUID author;
77 context.ReadDefault(author, UUID.NULL_UUID);
78 if (!author.IsNull())
79 {
80 int lastUpdated;
81 context.ReadDefault(lastUpdated, 0);
82
84 if (core)
85 {
86 SCR_EditableEntityAuthor data = core.FindAuthorByIdentity(author);
87 if (data)
88 {
89 data.m_iEntityCount++;
90 editable.SetAuthor(data);
91 editable.SetAuthorUpdatedTime(lastUpdated);
92 }
93 }
94 }
95
96 return true;
97 }
98
99 //------------------------------------------------------------------------------------------------
100 protected static void OnParentAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
101 {
102 auto parentEntity = IEntity.Cast(instance);
103 if (!parentEntity)
104 return;
105
106 SCR_EditableEntityComponent parentEditable = SCR_EditableEntityComponent.Cast(parentEntity.FindComponent(SCR_EditableEntityComponent));
107 if (!parentEditable)
108 return;
109
110 auto parentContext = Tuple1<SCR_EditableEntityComponent>.Cast(context);
111 if (parentContext.param1)
112 parentEditable.SetParentEntity(parentContext.param1);
113 }
114}
class SCR_PersistentThreatSector GetTargetType()
Get all prefabs that have the spawner data
proto external Managed FindComponent(typename typeName)
bool HasEntityFlag(EEditableEntityFlag flag)
SCR_EditableEntityComponent SetParentEntity(SCR_EditableEntityComponent parentEntity, bool changedByUser=false)
SCR_EditableEntityComponent GetParentEntity()
bool Deserialize(notnull IEntity owner, notnull GenericComponent component, notnull LoadContext context)
static void OnParentAvailable(Managed instance, PersistenceDeferredDeserializeTask task, bool expired, Managed context)
ESerializeResult Serialize(notnull IEntity owner, notnull GenericComponent component, notnull SaveContext context)
SCR_EditableEntityAuthor FindAuthorByIdentity(UUID authorIdentity)
Definition UUID.c:28
EEditableEntityFlag
Unique flags of the entity.
ESerializeResult
void Tuple1(T1 p1)
Definition tuple.c:37