Ejemplo n.º 1
0
        public static void CreateJsonVaultFiles(string path)
        {
            try
            {
                path = path + "/VaultFiles";

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                string[] vaultFiles = ES2.GetFiles(string.Empty, "*.txt");
                List <SavedGunSerializable> savedGuns = new List <SavedGunSerializable>();
                foreach (string name in vaultFiles)
                {
                    try
                    {
                        if (name.Contains("DONTREMOVETHISPARTOFFILENAMEV02a"))
                        {
                            if (ES2.Exists(name))
                            {
                                using (ES2Reader reader = ES2Reader.Create(name))
                                {
                                    savedGuns.Add(new SavedGunSerializable(reader.Read <SavedGun>("SavedGun")));
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        TNHTweakerLogger.LogError("Vault File could not be loaded");
                    }
                }

                foreach (SavedGunSerializable savedGun in savedGuns)
                {
                    if (File.Exists(path + "/" + savedGun.FileName + ".json"))
                    {
                        File.Delete(path + "/" + savedGun.FileName + ".json");
                    }

                    // Create a new file
                    using (StreamWriter sw = File.CreateText(path + "/" + savedGun.FileName + ".json"))
                    {
                        string characterString = JsonConvert.SerializeObject(savedGun, Formatting.Indented, new StringEnumConverter());
                        sw.WriteLine(characterString);
                        sw.Close();
                    }
                }
            }

            catch (Exception ex)
            {
                TNHTweakerLogger.LogError(ex.ToString());
            }
        }
    /**
     * Look in the default search folder for all the saves
     * then add them to the saveList array.
     */
    public static void LoadInitialSavedGames()
    {
        // don't forget to update assets
        //AssetDatabase.Refresh();

        string[] filesInFolder = ES2.GetFiles("");

        for (int i = 0; i < filesInFolder.Length; i++)
        {
            saveList.Add(new SaveGame(filesInFolder[i]));

            print(saveList[i].saveName + "|       |" + saveList[i].saveTimeString);
        }

        print(System.DateTime.Now);
    }
Ejemplo n.º 3
0
    public void GetAllSavedCharacters()
    {
        foreach (GameObject go in loadButtons)
        {
            Destroy(go.gameObject);
        }

        loadButtons.Clear();

        if (!ES2.Exists("characterSaves/"))
        {
            Debug.Log("characterSaves Not Found");
            ES2.Save <int>(0, "characterSaves/init/fin.dat");
        }

        string[] filesInFolder = ES2.GetFiles("characterSaves/");

        if (filesInFolder == null)
        {
            Debug.Log("No saved characters.");
            return;
        }

        foreach (string file in filesInFolder)
        {
            string fileExt = file.Substring(file.Length - 4, 4);
            if (fileExt == ".txt")
            {
                GameObject newButton = Instantiate(cSaveButtonPrefab);
                newButton.transform.SetParent(cSaveButtonPrefab.transform.parent, false);
                newButton.name = "LOAD-BUTTON-" + file;

                newButton.GetComponent <CharacterLoadButton>().SetupButton(Path.GetFileNameWithoutExtension(Application.persistentDataPath + "/characterSaves/" + file));

                loadButtons.Add(newButton);
                newButton.SetActive(true);
            }
        }
    }