Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_LatestSaveDSSessionCallback.c
Go to the documentation of this file.
2 class SCR_LatestSaveDSSessionCallback: DSSessionCallback
3 {
4  [Attribute(".LatestSave")]
5  protected string m_sFileName;
6 
7  protected bool m_bIsLoaded;
8  protected bool m_bWriteToFile;
9 
10  protected ref SCR_LatestSaveStruct m_Struct = new SCR_LatestSaveStruct();
11 
12 
13  //----------------------------------------------------------------------------------------
19  void SetFileName(string missionFileName, string saveFileName)
20  {
21  m_Struct.SetFileName(missionFileName, saveFileName);
22  WriteToFile();
23 
24  Print(string.Format("SCR_LatestSaveDSSessionCallback: Latest save for %1 is now %2", missionFileName, saveFileName), LogLevel.VERBOSE);
25  }
26 
27  //----------------------------------------------------------------------------------------
32  void RemoveFileName(string missionFileName)
33  {
34  m_Struct.RemoveFileName(missionFileName);
35  WriteToFile();
36  }
37 
38  //----------------------------------------------------------------------------------------
45  bool FindFileName(string missionFileName, out string outSaveFileName)
46  {
47  return m_Struct.FindFileName(missionFileName, outSaveFileName);
48  }
53  //----------------------------------------------------------------------------------------
54  void Log()
55  {
56  m_Struct.Log();
57  }
58 
59  //----------------------------------------------------------------------------------------
63  void WriteToFile()
64  {
65  SessionStorage storage = GetGame().GetBackendApi().GetStorage();
66  storage.AssignFileIDCallback(m_sFileName, this);
67  if (GetGame().GetSaveManager().CanSaveToCloud())
68  {
69  Print(string.Format("SCR_LatestSaveDSSessionCallback: RequestSave: %1", m_sFileName), LogLevel.VERBOSE);
70  storage.RequestSave(m_sFileName);
71  }
72  else
73  {
74  PrintFormat(string.Format("SCR_LatestSaveDSSessionCallback: LocalSave: %1", m_sFileName), LogLevel.VERBOSE);
75  storage.LocalSave(m_sFileName);
76  }
77  m_bWriteToFile = true;
78  }
79 
80  //----------------------------------------------------------------------------------------
84  void ReadFromFile()
85  {
86  //--- Latest saves were already loaded, don't do it again and use what's already in the memory.
87  if (m_bIsLoaded)
88  {
89  //--- File is already loaded, proceed straight to init
90  GetGame().GetSaveManager().LoadOnInit();
91  return;
92  }
93 
94  SessionStorage storage = GetGame().GetBackendApi().GetStorage();
95  if (!storage.CheckFileID(m_sFileName))
96  {
97  //--- File does not exist, proceed straight to init
98  Print(string.Format("SCR_LatestSaveDSSessionCallback: Unable to load %1, it does not exist!", m_sFileName), LogLevel.VERBOSE);
99  GetGame().GetSaveManager().LoadOnInit();
100  return;
101  }
102 
103  m_bIsLoaded = true;
104 
105  //--- Load latest saves from save file
106  storage.AssignFileIDCallback(m_sFileName, this);
107  if (GetGame().GetSaveManager().CanSaveToCloud())
108  {
109  Print(string.Format("SCR_LatestSaveDSSessionCallback: RequestLoad: %1", m_sFileName), LogLevel.VERBOSE);
110  storage.RequestLoad(m_sFileName);
111  }
112  else
113  {
114  Print(string.Format("SCR_LatestSaveDSSessionCallback: LocalLoad: %1", m_sFileName), LogLevel.VERBOSE);
115  storage.LocalLoad(m_sFileName);
116  }
117  }
118 
119  //----------------------------------------------------------------------------------------
120  override void OnSaving(string fileName)
121  {
122  GetGame().GetBackendApi().GetStorage().ProcessSave(m_Struct, fileName);
123  }
124 
125  //----------------------------------------------------------------------------------------
126  override void OnLoaded(string fileName)
127  {
128  GetGame().GetBackendApi().GetStorage().ProcessLoad(m_Struct, fileName);
129  Print(string.Format("SCR_LatestSaveDSSessionCallback: Loading file '%1' succeeded!", fileName), LogLevel.VERBOSE);
130 
131  GetGame().GetSaveManager().LoadOnInit();
132  }
133 
134  //----------------------------------------------------------------------------------------
135  override void OnLoadFailed(string fileName)
136  {
137  Print(string.Format("SCR_LatestSaveDSSessionCallback: Loading file '%1' failed!", fileName), LogLevel.WARNING);
138  }
139 
140  //----------------------------------------------------------------------------------------
141  override void OnSaveSuccess(string fileName)
142  {
143  m_bWriteToFile = false;
144  GetGame().GetSaveManager().GetOnLatestSave().Invoke(fileName);
145  }
146 
147  //----------------------------------------------------------------------------------------
148  bool IsLoaded()
149  {
150  return m_bIsLoaded;
151  }
152 }
SCR_LatestSaveDSSessionCallback
Definition: SCR_LatestSaveDSSessionCallback.c:2
m_sFileName
protected string m_sFileName
Definition: ServerHostingUI.c:188
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
Attribute
typedef Attribute
Post-process effect of scripted camera.
GetSaveManager
SCR_SaveManagerCore GetSaveManager()
Definition: game.c:211
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468
SCR_LatestSaveStruct
Definition: SCR_LatestSaveStruct.c:1