Skip to content

Commit

Permalink
Improve save synchronisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Extremelyd1 committed Jul 27, 2024
1 parent 0e7d956 commit e6eaa71
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
7 changes: 7 additions & 0 deletions HKMP/Game/Client/Save/SaveChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ internal class SaveChanges {
/// <param name="name">The name of the PlayerData entry.</param>
public void ApplyPlayerDataSaveChange(string name) {
Logger.Debug($"ApplyPlayerData for name: {name}");

// If we receive the dash from a save update, we need to also set the 'canDash' boolean to ensure that
// the input for dashing is accepted
if (name == "hasDash") {
PlayerData.instance.SetBool("canDash", true);
return;
}

var currentScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;

Expand Down
14 changes: 7 additions & 7 deletions HKMP/Game/Client/Save/SaveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,15 @@ public void Initialize() {
On.GameManager.StartNewGame += (orig, self, mode, rushMode) => {
orig(self, mode, rushMode);
ResetLastPlayerData();
MonoBehaviourUtil.Instance.OnUpdateEvent += OnUpdatePlayerData;
};
On.GameManager.ContinueGame += (orig, self) => {
orig(self);
ResetLastPlayerData();
MonoBehaviourUtil.Instance.OnUpdateEvent += OnUpdatePlayerData;
};
On.UIManager.GoToMainMenu += (orig, self) => {
MonoBehaviourUtil.Instance.OnUpdateEvent -= OnUpdatePlayerData;
return orig(self);
};


UnityEngine.SceneManagement.SceneManager.activeSceneChanged += OnSceneChanged;

MonoBehaviourUtil.Instance.OnUpdateEvent += OnUpdatePlayerData;
MonoBehaviourUtil.Instance.OnUpdateEvent += OnUpdatePersistents;
MonoBehaviourUtil.Instance.OnUpdateEvent += OnUpdateCompounds;

Expand Down Expand Up @@ -159,6 +154,11 @@ private void OnUpdatePlayerData() {
if (_lastPlayerData == null) {
return;
}

var gm = global::GameManager.instance;
if (gm.gameState == GameState.MAIN_MENU) {
return;
}

foreach (var field in _playerDataSyncFields) {
var currentValue = field.GetValue(pd);
Expand Down
7 changes: 6 additions & 1 deletion HKMP/Resource/save-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,17 @@
"SyncType": "Player",
"IgnoreSceneHost": true
},
"mapZone": {
"Sync": true,
"SyncType": "Player",
"IgnoreSceneHost": true
},
"respawnMarkerName": {
"Sync": true,
"SyncType": "Player",
"IgnoreSceneHost": true
},
"mapZone": {
"respawnType": {
"Sync": true,
"SyncType": "Player",
"IgnoreSceneHost": true
Expand Down

0 comments on commit e6eaa71

Please sign in to comment.