Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CharacterQuickBarSerializer.c
Go to the documentation of this file.
2{
3 int m_iIndex;
4 UUID m_sEntityId;
5}
6
7class SCR_CharacterQuickBarSerializer : BaseInventoryStorageComponentSerializer
8{
9 [Attribute(desc: "Filter to only handle specific quick slots. e.g. 0-3 are fixed through weapon slots and must not be saved.")]
10 ref array<int> m_aSlotIndexFilter;
12 //------------------------------------------------------------------------------------------------
13 override static typename GetTargetType()
14 {
16 }
17
18 //------------------------------------------------------------------------------------------------
19 override protected ESerializeResult Serialize(notnull IEntity owner, notnull GenericComponent component, notnull SaveContext context)
20 {
22
23 array<ref SCR_PersistentQuickSlotItem> slots();
24 foreach (int idx, auto quickslot : charStorage.GetQuickSlotItems())
25 {
26 if (!m_aSlotIndexFilter.IsEmpty() && !m_aSlotIndexFilter.Contains(idx))
27 continue;
28
29 auto container = SCR_QuickslotEntityContainer.Cast(quickslot);
30 if (!container)
31 continue;
32
33 const UUID id = GetSystem().GetId(container.GetEntity());
34 if (id.IsNull())
35 continue;
36
38 slot.m_iIndex = idx;
39 slot.m_sEntityId = id;
40 slots.Insert(slot);
41 }
42
43 context.StartObject("base");
44 const ESerializeResult baseResult = super.Serialize(owner, component, context);
45 context.EndObject();
46 if (baseResult == ESerializeResult.ERROR)
47 return baseResult;
48
49 if (baseResult == ESerializeResult.DEFAULT && slots.IsEmpty())
50 return baseResult;
51
52 context.WriteValue("version", 1);
53 const bool prev = context.EnableTypeDiscriminator(false);
54 context.WriteValue("quickSlots", slots);
55 context.EnableTypeDiscriminator(prev);
56 return ESerializeResult.OK;
57 }
58
59 //------------------------------------------------------------------------------------------------
60 override protected bool Deserialize(notnull IEntity owner, notnull GenericComponent component, notnull LoadContext context)
61 {
62 auto charStorage = SCR_CharacterInventoryStorageComponent.Cast(component);
63
64 if (context.DoesObjectExist("base"))
65 {
66 if (!context.StartObject("base") ||
67 !super.Deserialize(owner, component, context) ||
68 !context.EndObject())
69 {
70 return false;
71 }
72 }
73
74 int version;
75 context.Read(version);
76
77 array<ref SCR_PersistentQuickSlotItem> slots();
78 const bool prev = context.EnableTypeDiscriminator(false);
79 context.ReadValue("quickSlots", slots);
80 context.EnableTypeDiscriminator(prev);
81
82 array<int> allSlots();
83 allSlots.Copy(m_aSlotIndexFilter);
84
85 foreach (auto quickSlot : slots)
86 {
87 // We are on the storage that must have held the items, and do direct lookup, so any deferred deserialize is not relevant here
88 const IEntity entity = IEntity.Cast(GetSystem().FindById(quickSlot.m_sEntityId));
89 if (!entity)
90 continue;
91
92 charStorage.StoreItemToQuickSlot(entity, quickSlot.m_iIndex, true);
93 charStorage.SetQuickSlotInitialized(quickSlot.m_iIndex);
94 allSlots.RemoveItem(quickSlot.m_iIndex);
95 }
96
97 foreach (int noDataSlotIdx : allSlots)
98 {
99 charStorage.SetQuickSlotInitialized(noDataSlotIdx);
100 }
101
102 return true;
103 }
104}
class SCR_PersistentThreatSector GetTargetType()
AddonBuildInfoTool id
void SCR_QuickslotEntityContainer(IEntity entity)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
array< ref SCR_QuickslotBaseContainer > GetQuickSlotItems()
ESerializeResult Serialize(notnull IEntity owner, notnull GenericComponent component, notnull SaveContext context)
bool Deserialize(notnull IEntity owner, notnull GenericComponent component, notnull LoadContext context)
Definition UUID.c:28
SCR_FieldOfViewSettings Attribute
ESerializeResult