Ejemplo n.º 1
0
    public static void SaveDialogue()
    {
        DialogueSaver ds = new DialogueSaver();

        ds.SaveFromDialogBox();
        JsonData dialogueData = JsonMapper.ToJson(ds);

        File.WriteAllText(Application.dataPath + DialogueDataPath, dialogueData.ToString());
    }
Ejemplo n.º 2
0
    public void Awake()
    {
        foreach (SavedObjType type in Enum.GetValues(typeof(SavedObjType)))
        {
            savedObjLists[type] = new List <ObjectInfo>();
        }

        if (File.Exists(Application.dataPath + EnvironmentSaver.EnviromentDataPath))
        {
            savedObjLists[SavedObjType.EnvironmentObjects] = JsonMapper.ToObject <List <ObjectInfo> >(File.ReadAllText(Application.dataPath + EnvironmentSaver.EnviromentDataPath));
        }
        if (File.Exists(Application.dataPath + EnvironmentSaver.TileDataPath))
        {
            savedObjLists[SavedObjType.Tiles] = JsonMapper.ToObject <List <ObjectInfo> >(File.ReadAllText(Application.dataPath + EnvironmentSaver.TileDataPath));
        }
        if (File.Exists(Application.dataPath + EnvironmentSaver.NPCsDataPath))
        {
            savedObjLists[SavedObjType.NPCs] = JsonMapper.ToObject <List <ObjectInfo> >(File.ReadAllText(Application.dataPath + EnvironmentSaver.NPCsDataPath));
        }
        if (File.Exists(Application.dataPath + EnvironmentSaver.InitInventoryDataPath))
        {
            savedObjLists[SavedObjType.Inventory] = JsonMapper.ToObject <List <ObjectInfo> >(File.ReadAllText(Application.dataPath + EnvironmentSaver.InitInventoryDataPath));
        }
        // Player info
        if (File.Exists(Application.dataPath + SaveManager.PlayerDataPath))
        {
            savedPlayer = JsonMapper.ToObject <CharacterInfo>(File.ReadAllText(Application.dataPath + SaveManager.PlayerDataPath));
            LoadPlayerInfo();
        }
        // Quests
        if (File.Exists(Application.dataPath + SaveManager.QuestDataPath))
        {
            List <Quest> QuestData = JsonMapper.ToObject <List <Quest> >(File.ReadAllText(Application.dataPath + SaveManager.QuestDataPath));
            if (QuestData != null)
            {
                QuestManager.ListOfQuests = QuestData;
            }
            Quest q = QuestManager.GetQuestByID("ThorinIntroQuest");
            if (q.ID != null)
            {
                GameManager.InTutorial = !q.Completed;
            }
        }
        // Dialogue Variables
        if (File.Exists(Application.dataPath + SaveManager.DialogueDataPath))
        {
            DialogueSaver dialogueSaver = JsonMapper.ToObject <DialogueSaver>(File.ReadAllText(Application.dataPath + SaveManager.DialogueDataPath));
            if (dialogueSaver != null)
            {
                dialogueSaver.LoadToDialogBox();
            }
        }
        // Unlocked Spells
        // if (File.Exists(Application.dataPath + SpellManager.InitializedUnlockedSpellsPath) && !File.Exists(Application.dataPath + SpellManager.UnlockedSpellsPath))
        // {
        //     JsonData spellsData = JsonMapper.ToJson(JsonMapper.ToObject(File.ReadAllText(Application.dataPath + SpellManager.InitializedUnlockedSpellsPath)));
        //     File.WriteAllText(Application.dataPath + SpellManager.UnlockedSpellsPath, spellsData.ToString());
        // }

        if (ChunkManager.TileReference == null)
        {
            ChunkManager.TileReference = new Dictionary <string, TileBase>();
            // string[] allFiles = Directory.GetFiles("Assets/Resources/Tiles/WorldTiles");
            Dictionary <string, string> tileFileNames = new Dictionary <string, string>();
            if (Application.isEditor)
            {
                string[] allFiles = Directory.GetFiles(Application.dataPath + "/Resources/Tiles/WorldTiles");

                for (int i = 0; i < allFiles.Length; i++)
                {
                    if (allFiles[i].Contains(".meta"))
                    {
                        continue;
                    }
                    string prefabName = Path.GetFileNameWithoutExtension(allFiles[i]);
                    // Help.print(prefabName);
                    string tileFile = "Tiles/WorldTiles/" + prefabName;
                    tileFileNames.Add(tileFile, prefabName);
                }
                // Save the tileFileNames
                JsonData tileFileNameData = JsonMapper.ToJson(tileFileNames);
                File.WriteAllText(Application.dataPath + TileFileNameJsonPath, tileFileNameData.ToString());
            }
            else
            {
                // Read from json
                if (File.Exists(Application.dataPath + TileFileNameJsonPath))
                {
                    tileFileNames = JsonMapper.ToObject <Dictionary <string, string> >(File.ReadAllText(Application.dataPath + TileFileNameJsonPath));
                }
                else
                {
                    throw new FileNotFoundException("Streaming Assets " + TileFileNameJsonPath + " Path not found.");
                }
            }
            foreach (KeyValuePair <string, string> tileFileName in tileFileNames)
            {
                TileBase tile = Resources.Load <TileBase>(tileFileName.Key);
                ChunkManager.TileReference.Add(tileFileName.Value, tile);
            }
        }
        SpellManager.LoadSpells();
    }