1 [
ComponentEditorProps(
category:
"GameScripted/GameMode/Components", description:
"Restore editor modes when world changes in multiplayer.")]
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;
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 =
":";
15 protected ref map<string, EEditorMode>
m_mModes =
new map<string, EEditorMode>();
20 int playerID = editorManager.GetPlayerID();
21 string playerUID =
GetGame().GetBackendApi().GetPlayerIdentityId(playerID);
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);
33 if (!Replication.IsRunning() || !Replication.IsServer())
40 BackendApi backendApi =
GetGame().GetBackendApi();
43 array<SCR_EditorManagerEntity> managers = {};
44 core.GetEditorEntities(managers);
47 if (m_bRestoreLimitedEditors || !editorManager.IsLimited())
48 modes += backendApi.GetPlayerIdentityId(editorManager.GetPlayerID()) + DELIMITER_VALUES + editorManager.GetEditorModes() + DELIMITER_PLAYERS;
51 GameSessionStorage.s_Data.Insert(GAME_SESSION_STORAGE_MODES, modes);
59 if (!Replication.IsRunning() || !Replication.IsServer())
63 if (!GameSessionStorage.s_Data.Find(GAME_SESSION_STORAGE_MODES, modesMap))
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++)
75 players[i].Split(DELIMITER_VALUES, values,
false);
76 m_mModes.Insert(values[0], values[1].ToInt());
79 GameSessionStorage.s_Data.Remove(GAME_SESSION_STORAGE_MODES);