Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_RestoreEditorModesComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/GameMode/Components", description: "Restore editor modes when world changes in multiplayer.")]
3 {
4 }
5 
6 class SCR_RestoreEditorModesComponent : SCR_BaseGameModeComponent
7 {
8  [Attribute(desc: "When enabled, the system will remember and restore also modes of limited editor managers (e.g., those with only PHOTO mode, not EDIT).")]
9  protected bool m_bRestoreLimitedEditors;
10 
11  protected static const string GAME_SESSION_STORAGE_MODES = "SCR_RestoreEditorModesComponent_ModesMap";
12  protected static const string DELIMITER_PLAYERS = " ";
13  protected static const string DELIMITER_VALUES = ":";
14 
15  protected ref map<string, EEditorMode> m_mModes = new map<string, EEditorMode>();
16 
17  //------------------------------------------------------------------------------------------------
19  {
20  int playerID = editorManager.GetPlayerID();
21  string playerUID = GetGame().GetBackendApi().GetPlayerIdentityId(playerID);
22  EEditorMode modes;
23  if (m_mModes.Find(playerUID, modes))
24  {
25  Print(string.Format("SCR_RestoreEditorModesComponent: Restoring editor modes %1 for playerId=%2 ('%3')", SCR_Enum.FlagsToString(EEditorMode, modes), playerID, GetGame().GetPlayerManager().GetPlayerName(playerID)), LogLevel.NORMAL);
26  editorManager.AddEditorModes(EEditorModeAccess.BASE, modes);
27  }
28  }
29 
30  //------------------------------------------------------------------------------------------------
31  override void OnGameEnd()
32  {
33  if (!Replication.IsRunning() || !Replication.IsServer())
34  return;
35 
37  if (!core)
38  return;
39 
40  BackendApi backendApi = GetGame().GetBackendApi();
41 
42  string modes;
43  array<SCR_EditorManagerEntity> managers = {};
44  core.GetEditorEntities(managers);
45  foreach (SCR_EditorManagerEntity editorManager: managers)
46  {
47  if (m_bRestoreLimitedEditors || !editorManager.IsLimited())
48  modes += backendApi.GetPlayerIdentityId(editorManager.GetPlayerID()) + DELIMITER_VALUES + editorManager.GetEditorModes() + DELIMITER_PLAYERS;
49  }
50 
51  GameSessionStorage.s_Data.Insert(GAME_SESSION_STORAGE_MODES, modes);
52 
53  core.Event_OnEditorManagerCreatedServer.Remove(OnEditorManagerCreatedServer);
54  }
55 
56  //------------------------------------------------------------------------------------------------
57  override void OnPostInit(IEntity owner)
58  {
59  if (!Replication.IsRunning() || !Replication.IsServer())
60  return;
61 
62  string modesMap;
63  if (!GameSessionStorage.s_Data.Find(GAME_SESSION_STORAGE_MODES, modesMap))
64  return;
65 
67  if (!core)
68  return;
69 
70  array<string> players = {};
71  array<string> values = {};
72  modesMap.Split(DELIMITER_PLAYERS, players, true);
73  for (int i = 0, count = players.Count(); i < count; i++)
74  {
75  players[i].Split(DELIMITER_VALUES, values, false);
76  m_mModes.Insert(values[0], values[1].ToInt());
77  }
78 
79  GameSessionStorage.s_Data.Remove(GAME_SESSION_STORAGE_MODES);
80 
81  core.Event_OnEditorManagerCreatedServer.Insert(OnEditorManagerCreatedServer);
82  }
83 }
m_mModes
protected ref map< string, EEditorMode > m_mModes
Definition: SCR_RestoreEditorModesComponent.c:15
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
SCR_Enum
Definition: SCR_Enum.c:1
Attribute
SCR_RestoreEditorModesComponentClass SCR_BaseGameModeComponentClass Attribute(desc:"When enabled, the system will remember and restore also modes of limited editor managers (e.g., those with only PHOTO mode, not EDIT).")] protected bool m_bRestoreLimitedEditors
EEditorModeAccess
EEditorModeAccess
Definition: EEditorModeAccess.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_EditorManagerCore
Core component to manage SCR_EditorManagerEntity.
Definition: SCR_EditorManagerCore.c:5
OnPostInit
override void OnPostInit(IEntity owner)
Editable Mine.
Definition: SCR_RestoreEditorModesComponent.c:57
OnGameEnd
override void OnGameEnd()
Called on all machines when the world ends.
Definition: SCR_RestoreEditorModesComponent.c:31
EEditorMode
EEditorMode
Editor mode that defines overall functionality.
Definition: EEditorMode.c:5
OnEditorManagerCreatedServer
protected void OnEditorManagerCreatedServer(SCR_EditorManagerEntity editorManager)
Definition: SCR_RestoreEditorModesComponent.c:18
SCR_RestoreEditorModesComponentClass
Definition: SCR_RestoreEditorModesComponent.c:2
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
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26