예제 #1
0
    private void OnLoadButtonPressed()
    {
        if (this.HasSaveData == false)
        {
            // Initialize new EncounterState, EncounterScene
            var scene    = _encounterPrefab.Instance() as EncounterScene;
            var newState = EncounterState.Create(this.SaveLocation);
            newState.SetStateForNewGame();
            scene.SetEncounterState(newState);

            // Save to slot
            newState.WriteToFile();

            var sceneManager = (SceneManager)GetNode("/root/SceneManager");
            sceneManager.ShowEncounterScene(scene);
        }
        else
        {
            var scene = _encounterPrefab.Instance() as EncounterScene;

            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            Godot.File file = new Godot.File();
            file.Open(this.SaveLocation, File.ModeFlags.Read);
            var saveData = file.GetAsText();
            saveData = StringCompression.DecompressString(saveData);
            file.Close();

            var oldState = EncounterState.FromSaveData(saveData);
            stopwatch.Stop();
            GD.Print("SaveSlotScene load completed, elapsed ms: ", stopwatch.ElapsedMilliseconds);
            scene.SetEncounterState(oldState);

            var sceneManager = (SceneManager)GetNode("/root/SceneManager");
            sceneManager.ShowEncounterScene(scene);
        }
    }