public void TestLoadException()
        {
            Exception ex = null;

            //Invalid Data Exception when the path isn't valid
            try
            {
                SaveContainer.Load("thisfileDoesn'tExitstAndIfItDoesThenThisWillFailSoDon'tHaveFileWithThisName2232.yep");
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is InvalidDataException);
                ex = e;
            }

            Assert.IsTrue(ex != null);
            ex = null;

            //Other exception for when there is another issue
            try
            {
                SaveContainer.Load(@"C:\scanimage\adminOnly.txt");
            }
            catch (Exception e)
            {
                Assert.IsFalse(e is InvalidDataException);
                ex = e;
            }
            Assert.IsNotNull(ex);
        }
        public void InvalidLoad()
        {
            string save = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "testSave";

            SaveContainer.CustomSaveDirectory = save;
            try
            {
                if (File.Exists(save))
                {
                    File.Delete(save);
                }

                SaveContainer.Data config = SaveContainer.Load();
                Assert.True(config.Equals(new SaveContainer.Data().Default()));
            }
            catch (Exception)
            {
                Assert.Fail("Shouldn't throw an error");
            }
            finally
            {
                if (File.Exists(save))
                {
                    File.Delete(save);
                }
            }
        }
Beispiel #3
0
    // Applies all options from the saved file to the locally created variables.
    public static void Load()
    {
        // Make sure all the strings for conversations are loaded.
        ConversationsDB.LoadConversationsFromFiles();

        if (File.Exists(WhereIsData()))
        {
            // Prepare for data IO.
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(WhereIsData(), FileMode.Open);

            // Deserialize the data.
            SaveContainer data = (SaveContainer)bf.Deserialize(file);
            file.Close();

            //! Fields go here.
            ConversationTrigger.tokens = new HashSet <string>(data.tokens);

            // Read inventory-related tokens.
            InventoryController.ConvertTokensToInventory();
            BatterySystem.TokensToPower();

            Debug.Log("Loaded all options successfully.");
        }
        else
        {
            // No file exists? We should make the default one!
            Debug.Log("No save found, creating default file.");
            Save();
        }
    }
    private IEnumerator LoadCoroutine(SaveContainer data)
    {
        yield return(UI.instance.LoadScene(data.sceneName));

        foreach (var pair in data.saverDatas)
        {
            if (!currentSavers.ContainsKey(pair.Key))
            {
                Debug.LogWarningFormat("Load data for nonexistent object: {0}", pair.Key.ToString());
                continue;
            }
            Saver saver = currentSavers[pair.Key];
            if (saver == null)
            {
                Debug.LogError($"Saver of ID {pair.Key} is null");
                continue;
            }
            try {
                saver.OnLoad(pair.Value);
            }
            catch (Exception ex) {
                Debug.LogError($"Failed to load saver {saver.name} (ID: {saver.id}).\n{ex}");
            }
        }
    }
        public void SaveandLoadNormally()
        {
            SaveContainer.Data data         = CreateDummyData(12);
            string             fileLocation = @"C:\scanimage\testFile.test";

            //ensure that the file doesn't already exist
            if (File.Exists(fileLocation))
            {
                File.Delete(fileLocation);
            }

            SaveContainer.Conf = data;
            SaveContainer.Save(fileLocation);

            Assert.IsTrue(File.Exists(fileLocation));

            //check that the loaded file is identicle
            SaveContainer.Conf = new SaveContainer.Data().Default();
            SaveContainer.Data loadData = SaveContainer.Load(fileLocation);
            File.Delete(fileLocation);

            Assert.IsTrue(loadData.CameraCount == data.CameraCount);
            for (int i = 0; i < loadData.CameraCount; i++)
            {
                Assert.IsTrue(data.Cameras[i].Address == loadData.Cameras[i].Address);
                Assert.IsTrue(data.Cameras[i].Id == loadData.Cameras[i].Id);
                Assert.IsTrue(data.Cameras[i].Port == loadData.Cameras[i].Port);
                Assert.IsTrue(data.Cameras[i].CamFileIdentity == loadData.Cameras[i].CamFileIdentity);
            }
        }
    private void loadProgress()
    {
        SaveContainer data = SaveDataHelper.loadSaveFile();

        currentRound = data.currentRound;
        powerUps     = data.powerUps;
    }
    private void loadFromController()
    {
        SaveContainer data = GameObject.Find("Load Game Controller").GetComponent <LoadGameController>().saveData;

        currentRound = data.currentRound;
        powerUps     = data.powerUps;
    }
Beispiel #8
0
    // Saves a file containing all game options which are in the above.
    public static void Save()
    {
        // Prepare for data IO.
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(WhereIsData());

        // Create and write to a new container.
        SaveContainer data = new SaveContainer();

        //! Fields go here.
        // Create and add inventory tokens.
        //InventoryController.ConvertInventoryToTokens();

        // Save all tokens!
        List <string> tokensTemp = new List <string>();

        foreach (string ii in ConversationTrigger.tokens)
        {
            tokensTemp.Add(ii);
        }
        data.tokens = new List <string>(tokensTemp);

        // Save and close safely.
        bf.Serialize(file, data);
        file.Close();

        Debug.Log("Saved all options successfully.");
    }
Beispiel #9
0
        /// <summary>
        /// Main runtime loop used to collect and send data off too the computer
        /// </summary>
        private void Start()
        {
            ThreadManager manager = new ThreadManager(SaveContainer.Load());

            Logger.Logger logs = new Logger.Logger();
            logs.RemoveOldLogs(DateTime.Today.AddMonths(-1));

            string command = "";

            while ((command = Console.ReadLine()) != "e")
            {
                if (command == "t")
                {
                    manager.CaptureImageSet(CameraRequest.SendTestImage);
                }
                else if (command == "s")
                {
                    Console.WriteLine(manager.SavePath);
                    Console.Write("new save path: ");
                    manager.SavePath = Console.ReadLine();
                }
                else
                {
                    manager.CaptureImageSet();
                }
            }
            Console.WriteLine("Quitting");
        }
    private void saveProgress()
    {
        SaveContainer data = new SaveContainer();

        data.currentRound = currentRound;
        data.powerUps     = powerUps;
        SaveDataHelper.saveFile(data);
    }
Beispiel #11
0
    public void SaveScores()
    {
        sc = new SaveContainer(currentScoreList);
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Open(Application.persistentDataPath + "/RoomBattle.sav", FileMode.OpenOrCreate);

        bf.Serialize(file, sc);
        file.Close();
        Debug.Log("Saved");
    }
Beispiel #12
0
        private void StandardXmlUnmarshal(string fileName)
        {
            Stream        sr        = new FileStream(fileName, FileMode.Open);
            XmlSerializer xmlSer    = new XmlSerializer(typeof(SaveContainer));
            SaveContainer container = (SaveContainer)xmlSer.Deserialize(sr);

            bs.DataSource        = words = container.Words;
            bsResults.DataSource = results = container.QuizResults;
            sr.Close();
        }
Beispiel #13
0
        private void BinDeser(string fileName)
        {
            Stream        stream    = new FileStream(fileName, FileMode.Open);
            IFormatter    fmt       = new BinaryFormatter();
            SaveContainer container = (SaveContainer)fmt.Deserialize(stream);

            bs.DataSource        = words = container.Words;
            bsResults.DataSource = results = container.QuizResults;
            stream.Close();
        }
Beispiel #14
0
    public void LoadPlayer(SaveContainer LoadedSaveContainer)
    {
        foreach (int ItemID in LoadedSaveContainer.playerData.ItemIDs)
        {
            GameObject ItemPrefab = Dictionary.GetItemObjects(ItemID);
            GameObject item       = Instantiate(ItemPrefab, new Vector3(0, 0, 100), Quaternion.identity);
            item.GetComponent <BaseItem>()?.PickupItem();
        }
        GameObject player = GameObject.FindGameObjectWithTag("Player");

        if (LoadedSaveContainer.playerData.currentweaponID < Dictionary.ItemObjects.Length)
        {
            GameObject CurrentWeapon = Dictionary.GetItemObjects(LoadedSaveContainer.playerData.currentweaponID);
            if (CurrentWeapon != null)
            {
                GameObject Weapon = Instantiate(CurrentWeapon, new Vector2(0, 0), Quaternion.identity);
                Debug.Log("Weapon instantiated");
                BaseWeapon weap = Weapon.GetComponentInChildren <BaseWeapon>();
                if (weap != null)
                {
                    weap.GetUITexts();
                    weap.ModId = LoadedSaveContainer.playerData.currentweaponModID;
                    weap.Start();
                    //Debug.Log("Weapon start called");
                    player.GetComponent <PlayerCombat>()?.ChangeWeapon(weap);
                    //Debug.Log("Weapon picked up");
                    EventController.instance.itemEvents.CallOnItemDied(weap);
                    //Debug.Log("called on weapon die");
                }
                else
                {
                    Debug.Log("weap was null");
                }
            }
            else
            {
                Debug.Log("weap was null");
            }
        }
        else
        {
            player.GetComponent <PlayerCombat>()?.currentWeapon?.DropWeapon();
            Debug.Log("Dropped weapon");
        }

        Vector3 pos = LoadedSaveContainer.playerData.PlayerPosition;

        GameController.instance.DataStorage.PlayerInfo.level = LoadedSaveContainer.playerData.level;
        Debug.Log("LoadedPosition was" + pos);
        GameController.instance.DataStorage.PlayerInfo.cocoa         = LoadedSaveContainer.playerData.cocoa;
        GameController.instance.DataStorage.PlayerInfo.blood         = LoadedSaveContainer.playerData.blood;
        GameController.instance.DataStorage.PlayerInfo.currenthealth = LoadedSaveContainer.playerData.currenthealth;
        player.transform.position = LoadedSaveContainer.playerData.PlayerPosition;
        GameController.instance.DataStorage.PlayerInfo.TimeInGame = LoadedSaveContainer.playerData.TimeInGame;
    }
Beispiel #15
0
    public void WipeSave()
    {
        runtime.inventory.Clear();
        runtime.loadedOnce = false;
        SaveContainer newContainer = GetNewSaveContainer();

        runtime.save            = newContainer.GetSave();
        this.startingGameStates = newContainer.startingGameStates;
        this.startingItems      = newContainer.startingItems;
        runtime.save.Initialize();
    }
 public static void saveFile(SaveContainer data)
 {
     if (saveFileExists())
     {
         updateSaveFile(data);
     }
     else
     {
         createSaveFile(data);
     }
 }
    /**
     * Saves the save data to the disk
     */
    public static void createSaveFile(SaveContainer data)
    {
        string savePath = Application.persistentDataPath + "/" + "CurrentSave.gd";

        Debug.Log("Saving file to disk " + savePath);
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(savePath);

        bf.Serialize(file, data);
        file.Close();
    }
Beispiel #18
0
    /*
     * public void LoadWeapons(SaveContainer LoadedSaveContainer)
     * {
     *  foreach (WeaponData loadedWeapon in LoadedSaveContainer.levelData.weaponData)
     *  {
     *      Debug.Log("Weapons id was "+loadedWeapon.id);
     *      GameObject WeaponPrefab = Dictionary.GetWeaponObjects(loadedWeapon.id);
     *      if (WeaponPrefab != null)
     *      {
     *          GameObject weapon = Instantiate(WeaponPrefab, loadedWeapon.position, Quaternion.identity);
     *          weapon.transform.parent = LoadedObjectHolder.transform;
     *      }
     *  }
     * }
     *
     */

    public void LoadEnvironment(SaveContainer LoadedSaveContainer)
    {
        foreach (EnviroData loadedEnvironment in LoadedSaveContainer.levelData.enviromentData)
        {
            GameObject EnviroPrefab = Dictionary.GetEnviroObjects(loadedEnvironment.id);
            if (EnviroPrefab != null)
            {
                GameObject enviro = Instantiate(EnviroPrefab, loadedEnvironment.position, Quaternion.identity);
                enviro.transform.parent = RoomsByNumbers[loadedEnvironment.roomNumber].transform /*.Find("Podłoga")*/;
            }
        }
    }
Beispiel #19
0
    IEnumerator WaitForVideoThenSave()
    {
        yield return(new WaitUntil(() => videoPlayer.isPlaying));

        yield return(new WaitUntil(() => !videoPlayer.isPlaying));

        inputTutorial.TriggerTutorial();
        MusicController.CurrentTrack = startTrack;
        SaveContainer.AutoSave();
        wall.SetBool("drop", true);
        Destroy(gameObject);
    }
    public void endRound()
    {
        currentRound++;
        SaveContainer data = new SaveContainer();

        data.currentRound = currentRound;
        data.powerUps     = powerUps;
        persistence.GetComponent <LoadGameController>().saveData = data;
        saveProgress(data);
        SceneManager.LoadScene("Tavern", LoadSceneMode.Additive);
        SceneManager.UnloadSceneAsync("Main Game");
    }
        public void SaveException()
        {
            Exception ex = null;

            SaveContainer.Conf = new SaveContainer.Data()
            {
                Cameras = new CameraConfiguration[0]
            };

            //No camera Exception
            try
            {
                SaveContainer.Save("nope");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                ex = e;
            }

            Assert.IsTrue(ex != null);
            ex = null;

            //Invlid path exception
            SaveContainer.Conf = new SaveContainer.Data().Default();
            try
            {
                SaveContainer.Save(null);
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is NullReferenceException);
                ex = e;
            }

            Assert.IsTrue(ex != null);
            ex = null;

            //Other exception for when there is another issue
            try
            {
                SaveContainer.Save(@"C:\foob.test");

                //wow, ok that should't work so let's delete that file
                File.Delete(@"C:\foob.test");
            }
            catch (Exception e)
            {
                Assert.IsFalse(e is NullReferenceException);
                ex = e;
            }
            Assert.IsNotNull(ex);
        }
    /**
     * Saves the save data to the disk
     */
    public static void updateSaveFile(SaveContainer data)
    {
        string savePath = Application.persistentDataPath + "/" + "CurrentSave.gd";

        Debug.Log("Saving file to disk " + savePath);
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = new FileStream(savePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);

        file.SetLength(0);
        bf.Serialize(file, data);
        file.Close();
    }
Beispiel #23
0
        // Request is sent by the Save System
        public void OnLoadRequest(SaveGame saveGame)
        {
            if (cachedSaveGame != saveGame)
            {
                cachedSaveGame = saveGame;
            }

            if (saveGame == null)
            {
                Debug.Log("Invalid save game request");
                return;
            }

            if (loadOnce && hasLoaded)
            {
                return;
            }

            if (string.IsNullOrEmpty(saveIdentification.Value))
            {
                Debug.Log($"Save identification is empty on {this.gameObject.name}");
                return;
            }

            iSaveableData = JsonUtility.FromJson <SaveContainer>(saveGame.Get(saveIdentification.Value));

            if (iSaveableData != null)
            {
                for (int i = 0; i < iSaveableData.saveStructures.Count; i++)
                {
                    // Try to get a saveable component by it's unique identifier.
                    ISaveable getSaveable;
                    saveableComponentDictionary.TryGetValue(iSaveableData.saveStructures[i].identifier, out getSaveable);

                    if (getSaveable != null)
                    {
                        getSaveable.OnLoad(iSaveableData.saveStructures[i].data);

                        if (!iSaveableDataIdentifiers.ContainsKey(iSaveableData.saveStructures[i].identifier))
                        {
                            iSaveableDataIdentifiers.Add(iSaveableData.saveStructures[i].identifier, i);
                        }
                    }
                }
            }
            else
            {
                iSaveableData = new SaveContainer();
            }

            hasLoaded = true;
        }
Beispiel #24
0
 public void LoadItems(SaveContainer LoadedSaveContainer)
 {
     foreach (ItemData loadedItem in LoadedSaveContainer.levelData.itemData)
     {
         GameObject ItemPrefab = Dictionary.GetItemObjects(loadedItem.id);
         if (ItemPrefab != null)
         {
             GameObject item = Instantiate(ItemPrefab, loadedItem.position, Quaternion.identity);
             item.GetComponentInChildren <BaseItem>().ModId = loadedItem.ModId;
             item.transform.parent = RoomsByNumbers[loadedItem.roomNumber].transform /*.Find("Items")*/;
         }
     }
 }
 private void OnTriggerEnter(Collider other)
 {
     if (charged)
     {
         SaveContainer.Save("autosave.save");
         if (once)
         {
             Destroy(gameObject);
         }
         charged   = false;
         coroutine = StartCoroutine("Recharge");
     }
 }
Beispiel #26
0
 public void LoadOldPlayerData(SaveContainer LoadedSaveContainer)
 {
     if (LoadedSaveContainer.oldPlayerData != null)
     {
         saveContainer.oldPlayerData = LoadedSaveContainer.oldPlayerData;
         GameController.instance.DataStorage.EvilPlayerInfo.currentweaponID    = LoadedSaveContainer.oldPlayerData.currentweaponID;
         GameController.instance.DataStorage.EvilPlayerInfo.currentweaponModID = LoadedSaveContainer.oldPlayerData.currentweaponModID;
         GameController.instance.DataStorage.EvilPlayerInfo.ItemIDs            = LoadedSaveContainer.oldPlayerData.ItemIDs;
         GameController.instance.DataStorage.EvilPlayerInfo.level   = LoadedSaveContainer.oldPlayerData.level;
         GameController.instance.DataStorage.EvilPlayerInfo.IsAlive = false;
         //EvilPlayer.GetComponent<EvilPlayerLoader>().LoadEvilPlayer();
         //Debug.LogFormat("Maxhealth value in oldPlayerData was {0}", LoadedSaveContainer.oldPlayerData.maxhealth);
     }
 }
Beispiel #27
0
 public void LoadEnemies(SaveContainer LoadedSaveContainer)
 {
     foreach (EnemyData loadedEnemy in LoadedSaveContainer.levelData.enemiesData)
     {
         GameObject EnemyPrefab = Dictionary.GetEnemyObjects(loadedEnemy.id);
         if (EnemyPrefab != null)
         {
             GameObject enemy = Instantiate(EnemyPrefab, loadedEnemy.position, Quaternion.identity);
             //Debug.LogFormat("LoadedEnemies roomNumber was {0}", loadedEnemy.roomNumber);
             enemy.transform.parent = RoomsByNumbers[loadedEnemy.roomNumber].transform /*.Find("Enemies")*/;
         }
     }
     EvilPlayer.GetComponent <EvilPlayerLoader>().LoadEvilPlayer();
 }
Beispiel #28
0
 public void LoadScores()
 {
     if (File.Exists(Application.persistentDataPath + "/RoomBattle.sav"))
     {
         Stream          stream     = File.Open(Application.persistentDataPath + "/RoomBattle.sav", FileMode.Open);
         BinaryFormatter bformatter = new BinaryFormatter();
         sc = (SaveContainer)bformatter.Deserialize(stream);
         stream.Close();
         currentScoreList = sc.highScores;
         PersistantHighScoreList.scoreList = currentScoreList;
         UpdateLeaderboard();
         Debug.Log("Loaded");
     }
 }
        public void AlternateSave()
        {
            #region initialise
            SaveContainer.CustomSaveDirectory = SaveContainer.DefaultSaveDirectory;
            SaveContainer.Data testCase = new SaveContainer.Data
            {
                Cameras = new[]
                {
                    new CameraConfiguration()
                    {
                        Address         = 3556734,
                        CamFileIdentity = "test1",
                        Id   = 67,
                        Port = 3165
                    },
                    new CameraConfiguration()
                    {
                        Address         = 7489,
                        CamFileIdentity = "test1WE",
                        Id   = 562,
                        Port = 673
                    }
                }
            };
            #endregion

            try
            {
                SaveContainer.Conf = testCase;
                SaveContainer.Save();
                Assert.IsTrue(File.Exists(SaveContainer.CustomSaveDirectory));

                SaveContainer.Load();
                File.Delete(SaveContainer.CustomSaveDirectory);

                Assert.IsTrue(SaveContainer.Conf.Equals(testCase));
            }
            catch (Exception e)
            {
                Assert.Fail("Shouldn't throw an error, " + e.Message);
            }
            finally
            {
                if (File.Exists(SaveContainer.DefaultSaveDirectory))
                {
                    File.Delete(SaveContainer.DefaultSaveDirectory);
                }
            }
        }
Beispiel #30
0
    public void LoadGlobalStats(SaveContainer LoadedSaveContainer)
    {
        GlobalStatistics.instance.enemiesKilled     = LoadedSaveContainer.globalStatistics.enemiesKilled;
        GlobalStatistics.instance.timePassed        = LoadedSaveContainer.globalStatistics.timePassed;
        GlobalStatistics.instance.bleedDamageDealt  = LoadedSaveContainer.globalStatistics.bleedDamageDealt;
        GlobalStatistics.instance.doubleKills       = LoadedSaveContainer.globalStatistics.doubleKills;
        GlobalStatistics.instance.fireDamageDealt   = LoadedSaveContainer.globalStatistics.fireDamageDealt;
        GlobalStatistics.instance.playerDeaths      = LoadedSaveContainer.globalStatistics.playerDeaths;
        GlobalStatistics.instance.poisonDamageDealt = LoadedSaveContainer.globalStatistics.poisonDamageDealt;



        //GlobalStatistics.instance.enemiesKilled = LoadedSaveContainer.globalStatsData.enemiesKilled;
        //GlobalStatistics.instance.timePassed = LoadedSaveContainer.globalStatsData.timePassed;
    }