Skip to content

Commit

Permalink
Fix bug where difficulty doesn't set when starting a new game after h…
Browse files Browse the repository at this point in the history
…aving quit a game to the menu
  • Loading branch information
JosiahJack committed Dec 22, 2023
1 parent 1dbf9a8 commit 4cf932b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
32 changes: 30 additions & 2 deletions Assets/Scripts/Const.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,10 @@ public void NewGame() {
SceneTransitionHandler sth =
newGameIndicator.AddComponent<SceneTransitionHandler>();
sth.saveGameIndex = -1;
sth.diffCombatCarryover = Const.a.difficultyCombat;
sth.diffCyberCarryover = Const.a.difficultyCyber;
sth.diffPuzzleCarryover = Const.a.difficultyPuzzle;
sth.diffMissionCarryover = Const.a.difficultyMission;
Cursor.lockState = CursorLockMode.None;
DontDestroyOnLoad(newGameIndicator); // 4b.2.
loadingScreen.SetActive(true);
Expand All @@ -1322,9 +1326,33 @@ public void GoIntoGame(Stopwatch loadTimer) {
GameObject freshGame = GameObject.Find("GameNotYetStarted");
if (freshGame != null) Utils.SafeDestroy(freshGame);
GameObject saveIndicator = GameObject.Find("NewGameIndicator");
if (saveIndicator != null) Utils.SafeDestroy(saveIndicator);
if (saveIndicator != null) {
SceneTransitionHandler sth = saveIndicator.GetComponent<SceneTransitionHandler>();
UnityEngine.Debug.Log("Acquiring sth data");
if (sth != null) {
if (sth.setActiveAtNext) {
Const.a.difficultyCombat = sth.diffCombatCarryover;
Const.a.difficultyMission = sth.diffMissionCarryover;
Const.a.difficultyPuzzle = sth.diffPuzzleCarryover;
Const.a.difficultyCyber = sth.diffCyberCarryover;
}
}
Utils.SafeDestroy(saveIndicator);
}
GameObject loadIndicator = GameObject.Find("LoadGameIndicator");
if (loadIndicator != null) Utils.SafeDestroy(loadIndicator);
if (loadIndicator != null) {
SceneTransitionHandler sth = loadIndicator.GetComponent<SceneTransitionHandler>();
UnityEngine.Debug.Log("Acquiring sth data");
if (sth != null) {
if (sth.setActiveAtNext) {
Const.a.difficultyCombat = sth.diffCombatCarryover;
Const.a.difficultyMission = sth.diffMissionCarryover;
Const.a.difficultyPuzzle = sth.diffPuzzleCarryover;
Const.a.difficultyCyber = sth.diffCyberCarryover;
}
}
Utils.SafeDestroy(loadIndicator);
}
Cursor.visible = true;
Utils.Deactivate(loadingScreen);
Utils.Deactivate(MainMenuHandler.a.IntroVideo);
Expand Down
18 changes: 14 additions & 4 deletions Assets/Scripts/SceneTransitionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,29 @@

public class SceneTransitionHandler : MonoBehaviour {
private bool transitionActive;
private bool setActiveAtNext;
public bool setActiveAtNext;
private bool loadActive;
public int saveGameIndex;
private AsyncOperation unloaderStatus;
private int sceneIndexToLoad;
private float loadDelayFinished;
public int diffCombatCarryover;
public int diffCyberCarryover;
public int diffPuzzleCarryover;
public int diffMissionCarryover;

void Update() {
if (setActiveAtNext) {
setActiveAtNext = false;
Const.a.Awake();
Scene mainScene = SceneManager.GetSceneByName("CitadelScene");
if (mainScene != null) SceneManager.SetActiveScene(mainScene); // Must delay by 1 frame.
if (mainScene != null) SceneManager.SetActiveScene(mainScene);
Const.a.Awake();
Const.a.difficultyCombat = diffCombatCarryover;
Const.a.difficultyMission = diffMissionCarryover;
Const.a.difficultyPuzzle = diffPuzzleCarryover;
Const.a.difficultyCyber = diffCyberCarryover;
Debug.Log("Const.a.difficultyCombat " + Const.a.difficultyCombat.ToString());
// Must delay by 1 frame.
Scene loadScene = SceneManager.GetSceneByName("LoadScene");
Debug.Log("Unloading LoadScene");
//if (loadScene != null) SceneManager.UnloadSceneAsync(loadScene);
Expand Down Expand Up @@ -51,4 +61,4 @@ public void Reload(int scenedex, ref AsyncOperation aso) {
transitionActive = true;
setActiveAtNext = false;
}
}
}

0 comments on commit 4cf932b

Please sign in to comment.