Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SaveLoadComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/GameMode/Components", description: "")]
3 {
4 }
5 
7 class SCR_SaveLoadComponent : SCR_BaseGameModeComponent
8 {
9  [Attribute(desc: "Struct object which manages saved data. Must be defined, without it saving won't work.")]
10  protected ref SCR_MissionStruct m_Struct;
11 
12  [Attribute(defvalue: "1", desc: "When enabled, save the state when exiting the world.")]
13  protected bool m_SaveOnExit;
14 
15  [Attribute(defvalue: "0", desc: "0 = disabled. 60 seconds is the lowest accepted value otherwise.")]
16  protected int m_iAutosavePeriod;
17 
18  [Attribute(uiwidget: UIWidgets.ResourceNamePicker, params: "conf class=SCR_MissionHeader", desc: "Mission header used for saving/loading in Workbench (where standard mission header is not loaded)")]
19  protected ResourceName m_DebugHeaderResourceName;
20 
21  protected static const int MINIMUM_AUTOSAVE_PERIOD = 60;
22 
24  // Public
26 
27  //------------------------------------------------------------------------------------------------
29  static SCR_SaveLoadComponent GetInstance()
30  {
31  BaseGameMode gameMode = GetGame().GetGameMode();
32  if (gameMode)
33  return SCR_SaveLoadComponent.Cast(gameMode.FindComponent(SCR_SaveLoadComponent));
34  else
35  return null;
36  }
37 
38  //------------------------------------------------------------------------------------------------
41  {
42  return m_SaveOnExit;
43  }
44 
45  //------------------------------------------------------------------------------------------------
48  {
50  }
51 
52  //------------------------------------------------------------------------------------------------
56  bool ContainsStruct(typename structType)
57  {
58  return m_Struct && m_Struct.ContainsStruct(structType);
59  }
60 
62  // Protected
64 
65  //------------------------------------------------------------------------------------------------
66  protected void Autosave()
67  {
68  GetGame().GetSaveManager().Save(ESaveType.AUTO);
69  }
70 
72  // Overrides
74 
75  //------------------------------------------------------------------------------------------------
77  {
78  GetGame().GetSaveManager().RemoveCurrentMissionLatestSave();
79  }
80 
81  //------------------------------------------------------------------------------------------------
82  override void OnPostInit(IEntity owner)
83  {
84  if (owner.GetWorld().IsEditMode())
85  return;
86 
87  //--- Assign structs (must be on client as well, it's used to correctly read meta header from save files)
88  SCR_SaveManagerCore saveManager = GetGame().GetSaveManager();
89  saveManager.SetStruct(ESaveType.USER, m_Struct);
90  saveManager.SetStruct(ESaveType.AUTO, m_Struct);
91  saveManager.SetStruct(ESaveType.EDITOR, m_Struct);
92 
93  //--- Initialise autosave on server
94  if (Replication.IsServer())
95  {
96  if (m_iAutosavePeriod == 0)
97  {
98  Print("SCR_SaveLoadComponent: Periodical autosave is disabled.", LogLevel.WARNING);
99  return;
100  }
101 
102  if (m_iAutosavePeriod > 0 && m_iAutosavePeriod < MINIMUM_AUTOSAVE_PERIOD)
103  {
104  Print("SCR_SaveLoadComponent: Autosave period set too low (" + m_iAutosavePeriod + "), setting to " + MINIMUM_AUTOSAVE_PERIOD, LogLevel.WARNING);
105  m_iAutosavePeriod = MINIMUM_AUTOSAVE_PERIOD;
106  }
107 
108  //--- Use call queue, because frame event is not called when the game is paused
109  GetGame().GetCallqueue().CallLater(Autosave, m_iAutosavePeriod * 1000, true);
110  }
111  }
112 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
SCR_SaveLoadComponentClass
Definition: SCR_SaveLoadComponent.c:2
m_iAutosavePeriod
protected int m_iAutosavePeriod
Definition: SCR_SaveLoadComponent.c:16
Autosave
protected void Autosave()
Definition: SCR_SaveLoadComponent.c:66
CanSaveOnExit
bool CanSaveOnExit()
Definition: SCR_SaveLoadComponent.c:40
GetInstance
SCR_TextsTaskManagerComponentClass ScriptComponentClass GetInstance()
Definition: SCR_TextsTaskManagerComponent.c:50
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
ContainsStruct
bool ContainsStruct(typename structType)
Definition: SCR_SaveLoadComponent.c:56
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
ESaveType
ESaveType
Definition: ESaveType.c:1
SCR_GameModeEndData
Definition: SCR_GameModeEndData.c:4
SCR_SaveManagerCore
Definition: SCR_SaveManagerCore.c:9
OnPostInit
override void OnPostInit(IEntity owner)
Editable Mine.
Definition: SCR_SaveLoadComponent.c:82
OnGameModeEnd
override void OnGameModeEnd(SCR_GameModeEndData data)
Definition: SCR_SaveLoadComponent.c:76
SCR_MissionStruct
Definition: SCR_MissionStruct.c:7
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
m_DebugHeaderResourceName
protected ResourceName m_DebugHeaderResourceName
Definition: SCR_SaveLoadComponent.c:19
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
Attribute
SCR_SaveLoadComponentClass SCR_BaseGameModeComponentClass Attribute(desc:"Struct object which manages saved data. Must be defined, without it saving won't work.")] protected ref SCR_MissionStruct m_Struct
Game mode-specific settings for session saving.
GetDebugHeaderResourceName
ResourceName GetDebugHeaderResourceName()
Definition: SCR_SaveLoadComponent.c:47
m_SaveOnExit
protected bool m_SaveOnExit
Definition: SCR_SaveLoadComponent.c:13
SCR_BaseGameModeComponentClass
Definition: SCR_BaseGameModeComponent.c:2
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_BaseGameModeComponent
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_BaseGameModeComponent.c:199