Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AddonPatchSizeLoader.c
Go to the documentation of this file.
1 
4 //------------------------------------------------------------------------------------------------
7 
8 //------------------------------------------------------------------------------------------------
10 {
11  protected ref array<SCR_WorkshopItem> m_aItems = {};
12  protected ref array<SCR_WorkshopItem> m_aItemsFailed = {};
13  protected int m_iLoadedPatches;
14 
15  protected ref ScriptInvokerBase<ScriptInvoker_AddonPatchSizeLoad> m_OnAllPatchSizeLoaded;
16 
17  //------------------------------------------------------------------------------------------------
18  // Public
19  //------------------------------------------------------------------------------------------------
20 
21  //------------------------------------------------------------------------------------------------
22  void InsertItem(SCR_WorkshopItem item)
23  {
24  m_aItems.Insert(item);
25  }
26 
27  //------------------------------------------------------------------------------------------------
28  void RemoveItem(SCR_WorkshopItem item)
29  {
30  m_aItems.RemoveItem(item);
31  }
32 
33  //------------------------------------------------------------------------------------------------
34  void ClearItems()
35  {
36  m_aItems.Clear();
37  }
38 
39  protected ref array<ref SCR_BackendCallback> m_aCallbacks = {};
40 
41  //------------------------------------------------------------------------------------------------
43  void LoadPatchSizes()
44  {
45  foreach (SCR_WorkshopItem item : m_aItems)
46  {
47  Revision revision = item.GetCurrentLocalRevision();
48  Revision target = item.GetItemTargetRevision();
49 
50  // Is matching
51  if (Revision.AreEqual(revision, target))
52  {
53  m_iLoadedPatches++;
54  continue;
55  }
56 
57  // Compute patch size
59  callback.GetEventOnResponse().Insert(OnPatchSizeLoadResponse);
60  m_aCallbacks.Insert(callback);
61 
62  target.ComputePatchSize(callback);
63  }
64  }
65 
66  //------------------------------------------------------------------------------------------------
67  // Protected
68  //------------------------------------------------------------------------------------------------
69 
70  //------------------------------------------------------------------------------------------------
71  protected void OnPatchSizeLoadResponse(SCR_BackendCallbackWorkshopItem callback)
72  {
73  SCR_WorkshopItem item = callback.GetItem();
74 
75  if (callback.GetResponseType() == EBackendCallbackResponse.SUCCESS)
76  {
77  float size;
78  if (item.GetItemTargetRevision().GetPatchSize(size))
79  {
80  // Setup size
81  item.SetTargetRevisionPatchSize(size);
82  m_iLoadedPatches++;
83  }
84  else
85  {
86  // Patch size not loaded
87  m_aItemsFailed.Insert(item);
88  }
89  }
90  else
91  {
92  // Fail or timeout
93  m_aItemsFailed.Insert(item);
94  }
95 
96  // All loaded
97  if (m_iLoadedPatches + m_aItemsFailed.Count() == m_aItems.Count())
98  {
99  bool allLoaded = m_aItemsFailed.IsEmpty();
100 
101  if (m_OnAllPatchSizeLoaded)
102  m_OnAllPatchSizeLoaded.Invoke(this, allLoaded);
103  }
104 
105  callback.GetEventOnResponse().Remove(OnPatchSizeLoadResponse);
106  m_aCallbacks.RemoveItem(callback);
107  }
108 
109  //------------------------------------------------------------------------------------------------
110  // Get set
111  //------------------------------------------------------------------------------------------------
112 
113  //------------------------------------------------------------------------------------------------
114  ScriptInvokerBase<ScriptInvoker_AddonPatchSizeLoad> GetOnAllPatchSizeLoaded()
115  {
116  if (!m_OnAllPatchSizeLoaded)
117  m_OnAllPatchSizeLoaded = new ScriptInvokerBase<ScriptInvoker_AddonPatchSizeLoad>();
118 
119  return m_OnAllPatchSizeLoaded;
120  }
121 
122  //------------------------------------------------------------------------------------------------
123  // Construct
124  //------------------------------------------------------------------------------------------------
125 
126  //------------------------------------------------------------------------------------------------
128  {
129  m_aItems.Clear();
130  m_aItemsFailed.Clear();
131 
132  if (m_OnAllPatchSizeLoaded)
133  m_OnAllPatchSizeLoaded.Clear();
134  }
135 }
136 
137 //------------------------------------------------------------------------------------------------
139 {
140  protected ref SCR_WorkshopItem m_Item;
141 
142  //------------------------------------------------------------------------------------------------
144  {
145  return m_Item;
146  }
147 
148  //------------------------------------------------------------------------------------------------
150  {
151  m_Item = item;
152  }
153 }
SCR_AddonPatchSizeLoader
Definition: SCR_AddonPatchSizeLoader.c:9
SCR_BackendCallbackWorkshopItem
void SCR_BackendCallbackWorkshopItem(SCR_WorkshopItem item)
Definition: SCR_AddonPatchSizeLoader.c:149
func
func
Definition: SCR_AIThreatSystem.c:5
SCR_WorkshopItem
Definition: SCR_WorkshopItem.c:21
SCR_BackendCallback
Scripted backend callback class unifying backend response.
Definition: SCR_BackendCallback.c:21
ScriptInvoker_AddonPatchSizeLoad
func ScriptInvoker_AddonPatchSizeLoad
Definition: SCR_AddonPatchSizeLoader.c:6
GetItem
SCR_WorkshopItem GetItem()
Definition: SCR_AddonPatchSizeLoader.c:143
EBackendCallbackResponse
EBackendCallbackResponse
Basic callback responses.
Definition: SCR_BackendCallback.c:12
callback
DownloadConfigCallback callback
m_Item
class SCR_AddonPatchSizeLoader m_Item