Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CampaignBuildingCompositionComponentSerializer.c
Go to the documentation of this file.
2{
3 //------------------------------------------------------------------------------------------------
4 override static typename GetTargetType()
5 {
6 return SCR_CampaignBuildingCompositionComponent;
7 }
8
9 //------------------------------------------------------------------------------------------------
10 override protected ESerializeResult Serialize(notnull IEntity owner, notnull GenericComponent component, notnull SaveContext context)
11 {
12 const SCR_CampaignBuildingCompositionComponent buildableCompostion = SCR_CampaignBuildingCompositionComponent.Cast(component);
13
14 // If we do not find a layout anymore it was already fully built
15 float current = 1.0;
16 int max = 1;
17 const SCR_CampaignBuildingLayoutComponent layout = buildableCompostion.GetCompositionLayout();
18 if (layout)
19 {
20 current = layout.GetCurrentBuildValue();
21 max = layout.GetToBuildValue();
22 }
23
24 // It will spawn by with no progress due to BuildableEntitySerializer.DeserializeSpawnData(), so we can abort if that is the desired outcome.
25 if (float.AlmostEqual(current, 0.0))
26 return ESerializeResult.DEFAULT;
27
28 const float progress = current / max;
29
30 context.WriteValue("version", 1);
31 context.Write(progress);
32 return ESerializeResult.OK;
33 }
34
35 //------------------------------------------------------------------------------------------------
36 override protected bool Deserialize(notnull IEntity owner, notnull GenericComponent component, notnull LoadContext context)
37 {
38 SCR_CampaignBuildingCompositionComponent buildableCompostion = SCR_CampaignBuildingCompositionComponent.Cast(component);
39
40 int version;
41 context.Read(version);
42
43 float progress;
44 context.Read(progress);
45
46 SCR_CampaignBuildingLayoutComponent layout = buildableCompostion.GetCompositionLayout();
47 if (layout)
48 {
49 layout.SetBuildingValue(layout.GetToBuildValue() * progress);
50 }
51 else if (float.AlmostEqual(progress, 1.0))
52 {
53 // If no layout exists, its not buildable in phases and we want to construct it instantly via link component
54 SCR_EditorLinkComponent linkComponent = SCR_EditorLinkComponent.Cast(owner.FindComponent(SCR_EditorLinkComponent));
55 if (linkComponent)
56 linkComponent.SpawnComposition();
57 }
58
59 return true;
60 }
61}
class SCR_PersistentThreatSector GetTargetType()
UI layouts Menus CleanSweep CleanSweepAreaSelection layout
ESerializeResult Serialize(notnull IEntity owner, notnull GenericComponent component, notnull SaveContext context)
bool Deserialize(notnull IEntity owner, notnull GenericComponent component, notnull LoadContext context)
ESerializeResult