示例#1
0
    public void SavePlayerData(Model_SaveData data)
    {
        game.UpdatePlayerStateToCurrent();
        Model_PlayerState p = game.GetPlayerState();

        data.playerData = new Model_PlayerState(
            p.spawnX,
            p.spawnY,
            p.spawnZ,
            p.faceDirection
            );
    }
示例#2
0
    public void LoadPlayerData(Model_SaveData data)
    {
        Model_PlayerState p = new Model_PlayerState(
            data.playerData.spawnX,
            data.playerData.spawnY,
            data.playerData.spawnZ,
            data.playerData.faceDirection
            );

        game.SetPlayerState(p);

        Debug.Log($"-------- LOADED {name} --------");
        Script_Utils.DebugToConsole(p);
    }
    /// <param name="type">SavePoint saves within Kelsingor</param>
    /// <param name="playerStateOverride">Option to override player state</param>
    public void Save(
        Model_PlayerState playerStateOverride = null,
        Model_GameData gameDataOverride       = null
        )
    {
        SetPath();

        try
        {
            /// Update total play time
            game.OnSaveTasks();

            BinaryFormatter bf = new BinaryFormatter();

            /// Main data to pass around and modify
            Model_SaveData saveData = new Model_SaveData();

            SaveGame(saveData);
            OverridePlayerData(saveData, playerStateOverride);
            HandleSaveRun(saveData);
            WriteSaveDataFile(bf, saveFilePath, saveData);

            /// Create SavedGameTitleData
            FileStream titleFile = File.Create(savedGameTitleDataPath);
            Model_SavedGameTitleData savedGameTitleData = savedGameTitleDataHandler.Create();
            bf.Serialize(titleFile, savedGameTitleData);
            titleFile.Close();

            if (Debug.isDebugBuild)
            {
                Debug.Log("Save successful at: " + saveFilePath);
            }
        }
        catch (System.Exception e)
        {
            Debug.LogError("Failed Save with exception: " + e.ToString());
        }

        void SaveGame(Model_SaveData data)
        {
            gameHandler.SaveGameData(data, gameDataOverride);
            playerHandler.SavePlayerData(data);
            entriesHandler.SaveEntries(data);
            inventoryHandler.SaveInventory(data);
            equipmentHandler.SaveEquipment(data);
            dropsHandler.SaveDrops(data);
            namesHandler.SaveNames(data);
            scarletCipherHandler.SaveScarletCipher(data);
            eventCycleHandler.SaveEventCycle(data);
            mynesMirrorHandler.SaveMynesMirror(data);
            pianosHandler.SavePianos(data);
        }

        void WriteSaveDataFile(BinaryFormatter bf, string filePath, Model_SaveData data)
        {
            // will overwrite existing file
            FileStream gameFile = File.Create(filePath);

            bf.Serialize(gameFile, data);
            gameFile.Close();
        }

        void OverridePlayerData(Model_SaveData data, Model_PlayerState playerState)
        {
            data.playerData = playerState ?? data.playerData;
        }

        void HandleSaveRun(Model_SaveData data)
        {
            levelsHandler.SaveLevels(data);
        }
    }