// Check if an import is required public bool NeedImport() { // Read the import log logFile = Path.Combine(contentPath, "import.ini"); IniData log = IniRead.ReadFromIni(logFile); // If no import log, import is required if (log == null) { return(true); } bool appVersionOK = false; bool valkVersionOK = false; // Check that the FFG app version in import is new enough string lastImport = log.Get("Import", "FFG"); appVersionOK = VersionNewerOrEqual(finder.RequiredFFGVersion(), lastImport); // Check that the Valkyrie version in import is new enough int lastValkVersion = 0; int.TryParse(log.Get("Import", "Valkyrie"), out lastValkVersion); valkVersionOK = (FFGImport.version == lastValkVersion); return(!appVersionOK || !valkVersionOK); }
// Check if an import is required public bool NeedImport() { // Read the import log logFile = ContentData.ContentPath() + gameType + "/ffg/import.ini"; IniData log = IniRead.ReadFromIni(logFile); // If no import log, import is required if (log == null) { return(true); } bool appVersionOK = false; bool valkVersionOK = false; // Check that the FFG app version in import is new enough string lastImport = log.Get("Import", "FFG"); appVersionOK = VersionNewerOrEqual(finder.RequiredFFGVersion(), lastImport); // Check that the Valkyrie version in import is new enough lastImport = log.Get("Import", "Valkyrie"); valkVersionOK = VersionNewerOrEqual(requiredValkyrieVersion, lastImport); return(!appVersionOK || !valkVersionOK); }
// Populate data public void LoadQuestData() { ValkyrieDebug.Log("Loading quest from: \"" + questPath + "\"" + System.Environment.NewLine); game = Game.Get(); components = new Dictionary <string, QuestComponent>(); questActivations = new Dictionary <string, ActivationData>(); // Read the main quest file IniData questIniData = IniRead.ReadFromIni(questPath); // Failure to read quest is fatal if (questIniData == null) { ValkyrieDebug.Log("Failed to load quest from: \"" + questPath + "\""); Application.Quit(); } // List of data files files = new List <string>(); // The main data file is included files.Add(questPath); // Find others (no addition files is not fatal) if (questIniData.Get("QuestData") != null) { foreach (string file in questIniData.Get("QuestData").Keys) { // path is relative to the main file (absolute not supported) files.Add(Path.GetDirectoryName(questPath) + "/" + file); } } foreach (string f in files) { // Read each file questIniData = IniRead.ReadFromIni(f); // Failure to read a file is fatal if (questIniData == null) { ValkyrieDebug.Log("Unable to read quest file: \"" + f + "\""); Application.Quit(); } // Loop through all ini sections foreach (KeyValuePair <string, Dictionary <string, string> > section in questIniData.data) { // Add the section to our quest data AddData(section.Key, section.Value, Path.GetDirectoryName(f)); } } }
public void LoadQuestData() { Debug.Log("Loading quest from: \"" + questPath + "\""); game = Game.Get(); components = new Dictionary <string, QuestComponent>(); flags = new List <string>(); heroSelection = new Dictionary <string, List <Game.Hero> >(); // Read the main quest file IniData d = IniRead.ReadFromIni(questPath); // Failure to read quest is fatal if (d == null) { Debug.Log("Failed to load quest from: \"" + questPath + "\""); Application.Quit(); } // List of data files files = new List <string>(); // The main data file is included files.Add(questPath); // Find others (no addition files is not fatal) if (d.Get("QuestData") != null) { foreach (string file in d.Get("QuestData").Keys) { // path is relative to the main file (absolute not supported) files.Add(Path.GetDirectoryName(questPath) + "/" + file); } } foreach (string f in files) { // Read each file d = IniRead.ReadFromIni(f); // Failure to read a file is fatal if (d == null) { Debug.Log("Unable to read quest file: \"" + f + "\""); Application.Quit(); } foreach (KeyValuePair <string, Dictionary <string, string> > section in d.data) { // Add the section to our quest data AddData(section.Key, section.Value, Path.GetDirectoryName(f)); } } }
public void DrawList() { localManifest = IniRead.ReadFromString(""); if (File.Exists(saveLocation() + "/manifest.ini")) { localManifest = IniRead.ReadFromIni(saveLocation() + "/manifest.ini"); } // Heading DialogBox db = new DialogBox(new Vector2(2, 1), new Vector2(UIScaler.GetWidthUnits() - 4, 3), "Download " + game.gameType.QuestName()); db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetLargeFont(); db.SetFont(game.gameType.GetHeaderFont()); TextButton tb; // Start here int offset = 5; // Loop through all available quests // FIXME: this isn't paged Dictionary<string, Dictionary<string, string>> data; foreach (KeyValuePair <string, Dictionary <string, string> > kv in remoteManifest.data) { string file = kv.Key + ".valkyrie"; // Size is 1.2 to be clear of characters with tails if (File.Exists(saveLocation() + "/" + file)) { int localVersion = 0; int remoteVersion = 0; int.TryParse(localManifest.Get(kv.Key, "version"), out localVersion); int.TryParse(remoteManifest.Get(kv.Key, "version"), out remoteVersion); if (localVersion < remoteVersion) { tb = new TextButton(new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 4, 1.2f), " [Update] " + kv.Value["name"], delegate { Selection(file); }, Color.blue, offset); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb.button.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0, 0, 0.1f); } else { db = new DialogBox(new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 4, 1.2f), " " + kv.Value["name"], Color.grey); db.AddBorder(); db.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.05f, 0.05f, 0.05f); db.textObj.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; } } else { tb = new TextButton(new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 4, 1.2f), " " + kv.Value["name"], delegate { Selection(file); }, Color.white, offset); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb.button.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0, 0, 0.1f); } offset += 2; } tb = new TextButton(new Vector2(1, UIScaler.GetBottom(-3)), new Vector2(8, 2), "Back", delegate { Cancel(); }, Color.red); tb.SetFont(game.gameType.GetHeaderFont()); }
public static void Load() { Game game = Game.Get(); try { if (File.Exists(SaveFile())) { string data = File.ReadAllText(SaveFile()); IniData saveData = IniRead.ReadFromString(data); Destroyer.Dialog(); game.cd = new ContentData(game.gameType.DataDirectory()); // Check if we found anything if (game.cd.GetPacks().Count == 0) { Debug.Log("Error: Failed to find any content packs, please check that you have them present in: " + game.gameType.DataDirectory() + System.Environment.NewLine); Application.Quit(); } game.cd.LoadContentID(""); Dictionary <string, string> packs = saveData.Get("Packs"); foreach (KeyValuePair <string, string> kv in packs) { game.cd.LoadContentID(""); game.cd.LoadContentID(kv.Key); } new Quest(saveData); game.heroCanvas.SetupUI(); game.heroCanvas.UpdateImages(); game.heroCanvas.UpdateStatus(); if (game.gameType.DisplayMorale()) { game.moraleDisplay = new MoraleDisplay(); } if (!game.gameType.DisplayHeroes()) { game.heroCanvas.Clean(); } // Create the menu button new MenuButton(); new NextStageButton(); } } catch (System.Exception) { Debug.Log("Error: Unable to open save file: " + SaveFile()); Application.Quit(); } }
public bool NeedImport() { logFile = ContentData.ContentPath() + gameType + "/ffg/import.ini"; IniData log = IniRead.ReadFromIni(logFile); if (log == null) { return(true); } bool appVersionOK = false; bool valkVersionOK = false; string lastImport = log.Get("Import", "FFG"); appVersionOK = VersionNewerOrEqual(finder.RequiredFFGVersion(), lastImport); lastImport = log.Get("Import", "Valkyrie"); valkVersionOK = VersionNewerOrEqual(requiredValkyrieVersion, lastImport); return(!appVersionOK || !valkVersionOK); }
public Quest(string p) { path = p; IniData d = IniRead.ReadFromIni(p + "/quest.ini"); if (d == null) { Debug.Log("Warning: Invalid quest:" + p + "/quest.ini!"); return; } name = d.Get("Quest", "name"); if (name.Equals("")) { Debug.Log("Warning: Failed to get name data out of " + p + "/content_pack.ini!"); return; } // Missing description is OK description = d.Get("Quest", "description"); }
public void DownloadImages(Stack <string> images = null) { string remoteDict = serverLocation + game.gameType.TypeName() + "/Localization.txt"; if (images == null) { remoteManifest = IniRead.ReadFromString(download.text); images = new Stack <string>(); foreach (KeyValuePair <string, Dictionary <string, string> > kv in remoteManifest.data) { if (remoteManifest.Get(kv.Key, "image").Length > 0) { images.Push(remoteManifest.Get(kv.Key, "image")); } } if (images.Count == 0) { StartCoroutine(Download(remoteDict, delegate { ReadManifest(); })); return; } StartCoroutine(Download(serverLocation + game.gameType.TypeName() + "/" + images.Peek(), delegate { DownloadImages(images); })); return; } if (download.error == null) { textures.Add(images.Pop(), download.texture); } else { images.Pop(); } if (images.Count > 0) { StartCoroutine(Download(serverLocation + game.gameType.TypeName() + "/" + images.Peek(), delegate { DownloadImages(images); })); return; } StartCoroutine(Download(remoteDict, delegate { ReadManifest(); })); }
/// <summary> /// Parse downloaded ini data /// </summary> /// <param name="download">download object</param> /// <param name="call">Function to call after parse</param> public void IniFetched(WWW download, UnityEngine.Events.UnityAction call) { if (download.error == null) { IniData remoteManifest = IniRead.ReadFromString(download.text); data = remoteManifest.Get("Quest"); } else { iniError = true; } call(); }
public Quest(string p) { path = p; IniData d = IniRead.ReadFromIni(p + "/quest.ini"); if (d == null) { Debug.Log("Warning: Invalid quest:" + p + "/quest.ini!"); return; } type = d.Get("Quest", "type"); if (type.Length == 0) { // Default to D2E to support historical quests type = "D2E"; } name = d.Get("Quest", "name"); if (name.Equals("")) { Debug.Log("Warning: Failed to get name data out of " + p + "/content_pack.ini!"); return; } if (d.Get("Quest", "packs").Length > 0) { packs = d.Get("Quest", "packs").Split(' '); } else { packs = new string[0]; } // Missing description is OK description = d.Get("Quest", "description"); }
// Read a content pack for list of files and meta data public void PopulatePackList(string path) { // All packs must have a content_pack.ini, otherwise ignore if (File.Exists(path + "/content_pack.ini")) { ContentPack pack = new ContentPack(); // Get all data from the file IniData d = IniRead.ReadFromIni(path + "/content_pack.ini"); // Todo: better error handling if (d == null) { Debug.Log("Failed to get any data out of " + path + "/content_pack.ini!"); Application.Quit(); } pack.name = d.Get("ContentPack", "name"); if (pack.name.Equals("")) { Debug.Log("Failed to get name data out of " + path + "/content_pack.ini!"); Application.Quit(); } // id can be empty/missing pack.id = d.Get("ContentPack", "id"); // If this is invalid we will just handle it later, not fatal pack.image = path + "/" + d.Get("ContentPack", "image"); // Black description isn't fatal pack.description = d.Get("ContentPack", "description"); // Get all the other ini files in the pack List <string> files = new List <string>(); // content_pack file is included files.Add(path + "/content_pack.ini"); // No extra files is valid if (d.Get("ContentPackData") != null) { foreach (string file in d.Get("ContentPackData").Keys) { files.Add(path + "/" + file); } } // Save list of files pack.iniFiles = files; // Add content pack allPacks.Add(pack); // We finish without actually loading the content, this is done later (content optional) } }
public void SetQuestAvailability(string key, bool isAvailable) { // update list of local quest IniData localManifest = IniRead.ReadFromString(""); string saveLocation = ContentData.DownloadPath(); if (File.Exists(saveLocation + "/manifest.ini")) { localManifest = IniRead.ReadFromIni(saveLocation + "/manifest.ini"); } if (isAvailable) { IniData downloaded_quest = IniRead.ReadFromString(remote_quests_data[key].ToString()); localManifest.Remove(key); localManifest.Add(key, downloaded_quest.data["Quest"]); } else { if (localManifest.Get(key) != null) { localManifest.Remove(key); } // we need to delete /temp and reload list UnloadLocalQuests(); } if (File.Exists(saveLocation + "/manifest.ini")) { File.Delete(saveLocation + "/manifest.ini"); } File.WriteAllText(saveLocation + "/manifest.ini", localManifest.ToString()); // update status quest remote_quests_data[key].downloaded = isAvailable; remote_quests_data[key].update_available = false; }
public void DrawList() { localManifest = IniRead.ReadFromString(""); if (File.Exists(saveLocation() + "/manifest.ini")) { localManifest = IniRead.ReadFromIni(saveLocation() + "/manifest.ini"); } // Heading DialogBox db = new DialogBox( new Vector2(2, 1), new Vector2(UIScaler.GetWidthUnits() - 4, 3), new StringKey("val", "QUEST_NAME_DOWNLOAD", game.gameType.QuestName()) ); db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetLargeFont(); db.SetFont(game.gameType.GetHeaderFont()); db = new DialogBox(new Vector2(1, 5f), new Vector2(UIScaler.GetWidthUnits() - 2f, 21f), StringKey.NULL); db.AddBorder(); db.background.AddComponent <UnityEngine.UI.Mask>(); UnityEngine.UI.ScrollRect scrollRect = db.background.AddComponent <UnityEngine.UI.ScrollRect>(); GameObject scrollArea = new GameObject("scroll"); RectTransform scrollInnerRect = scrollArea.AddComponent <RectTransform>(); scrollArea.transform.parent = db.background.transform; scrollInnerRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, (UIScaler.GetWidthUnits() - 3f) * UIScaler.GetPixelsPerUnit()); scrollInnerRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 1); GameObject scrollBarObj = new GameObject("scrollbar"); scrollBarObj.transform.parent = db.background.transform; RectTransform scrollBarRect = scrollBarObj.AddComponent <RectTransform>(); scrollBarRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 21 * UIScaler.GetPixelsPerUnit()); scrollBarRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, (UIScaler.GetWidthUnits() - 3f) * UIScaler.GetPixelsPerUnit(), 1 * UIScaler.GetPixelsPerUnit()); UnityEngine.UI.Scrollbar scrollBar = scrollBarObj.AddComponent <UnityEngine.UI.Scrollbar>(); scrollBar.direction = UnityEngine.UI.Scrollbar.Direction.BottomToTop; scrollRect.verticalScrollbar = scrollBar; GameObject scrollBarHandle = new GameObject("scrollbarhandle"); scrollBarHandle.transform.parent = scrollBarObj.transform; //RectTransform scrollBarHandleRect = scrollBarHandle.AddComponent<RectTransform>(); scrollBarHandle.AddComponent <UnityEngine.UI.Image>(); scrollBarHandle.GetComponent <UnityEngine.UI.Image>().color = new Color(0.7f, 0.7f, 0.7f); scrollBar.handleRect = scrollBarHandle.GetComponent <RectTransform>(); scrollBar.handleRect.offsetMin = Vector2.zero; scrollBar.handleRect.offsetMax = Vector2.zero; scrollRect.content = scrollInnerRect; scrollRect.horizontal = false; TextButton tb; // Start here int offset = 5; // Loop through all available quests foreach (KeyValuePair <string, Dictionary <string, string> > kv in remoteManifest.data) { string file = kv.Key + ".valkyrie"; LocalizationRead.scenarioDict = localizationDict; string questName = new StringKey("qst", kv.Key + ".name").Translate(); int remoteFormat = 0; int.TryParse(remoteManifest.Get(kv.Key, "format"), out remoteFormat); bool formatOK = (remoteFormat >= QuestData.Quest.minumumFormat) && (remoteFormat <= QuestData.Quest.currentFormat); if (!formatOK) { continue; } // Size is 1.2 to be clear of characters with tails if (File.Exists(saveLocation() + "/" + file)) { string localHash = localManifest.Get(kv.Key, "version"); string remoteHash = remoteManifest.Get(kv.Key, "version"); if (!localHash.Equals(remoteHash)) { tb = new TextButton( new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 8, 1.2f), //TODO: the name should be another key in near future. now is a nonLookup key new StringKey("val", "QUEST_NAME_UPDATE", questName), delegate { Selection(file); }, Color.black, offset); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb.button.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); tb.button.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.7f, 0.7f, 1f); tb.background.transform.parent = scrollArea.transform; tb = new TextButton( new Vector2(UIScaler.GetWidthUnits() - 6, offset), new Vector2(3, 1.2f), new StringKey("val", "DELETE"), delegate { Delete(file); }, Color.black, offset); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb.button.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); tb.background.GetComponent <UnityEngine.UI.Image>().color = Color.red; tb.background.transform.parent = scrollArea.transform; } else { db = new DialogBox( new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 8, 1.2f), new StringKey("val", "INDENT", questName), Color.black); db.AddBorder(); db.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.07f, 0.07f, 0.07f); db.background.transform.parent = scrollArea.transform; db.textObj.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; db.textObj.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); tb = new TextButton( new Vector2(UIScaler.GetWidthUnits() - 6, offset), new Vector2(3, 1.2f), new StringKey("val", "DELETE"), delegate { Delete(file); }, Color.black, offset); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb.button.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); tb.background.GetComponent <UnityEngine.UI.Image>().color = Color.red; tb.background.transform.parent = scrollArea.transform; } } else { tb = new TextButton( new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 5, 1.2f), new StringKey("val", "INDENT", questName), delegate { Selection(file); }, Color.black, offset); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb.button.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); tb.button.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; tb.background.GetComponent <UnityEngine.UI.Image>().color = Color.white; tb.background.transform.parent = scrollArea.transform; } offset += 2; } foreach (KeyValuePair <string, Dictionary <string, string> > kv in localManifest.data) { // Only looking for files missing from remote if (remoteManifest.data.ContainsKey(kv.Key)) { continue; } string type = localManifest.Get(kv.Key, "type"); // Only looking for packages of this game type if (!game.gameType.TypeName().Equals(type)) { continue; } string file = kv.Key + ".valkyrie"; // Size is 1.2 to be clear of characters with tails if (File.Exists(saveLocation() + "/" + file)) { db = new DialogBox( new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 8, 1.2f), new StringKey("val", "INDENT", file), Color.black); db.AddBorder(); db.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.07f, 0.07f, 0.07f); db.background.transform.parent = scrollArea.transform; db.textObj.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; db.textObj.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); tb = new TextButton( new Vector2(UIScaler.GetWidthUnits() - 6, offset), new Vector2(3, 1.2f), new StringKey("val", "DELETE"), delegate { Delete(file); }, Color.black, offset); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb.button.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); tb.background.GetComponent <UnityEngine.UI.Image>().color = Color.red; tb.background.transform.parent = scrollArea.transform; } } scrollInnerRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, (offset - 5) * UIScaler.GetPixelsPerUnit()); tb = new TextButton( new Vector2(1, UIScaler.GetBottom(-3)), new Vector2(8, 2), CommonStringKeys.BACK, delegate { Cancel(); }, Color.red); tb.SetFont(game.gameType.GetHeaderFont()); }
// Constructor takes a path in which to look for content public ContentData(string path) { // This is all of the available sides of tiles (not currently tracking physical tiles) tileSides = new Dictionary <string, TileSideData>(); // Available heros heros = new Dictionary <string, HeroData>(); // Available monsters monsters = new Dictionary <string, MonsterData>(); //This has the game game and all expansions, general info allPacks = new List <ContentPack>(); // This has all monster activations activations = new Dictionary <string, ActivationData>(); // This has all available tokens tokens = new Dictionary <string, TokenData>(); // This has all avilable perils perils = new Dictionary <string, PerilData>(); // Search each directory in the path (one should be base game, others expansion. Names don't matter string[] contentDirectories = Directory.GetDirectories(path); foreach (string p in contentDirectories) { // All packs must have a content_pack.ini, otherwise ignore if (File.Exists(p + "/content_pack.ini")) { ContentPack pack = new ContentPack(); // Get all data from the file IniData d = IniRead.ReadFromIni(p + "/content_pack.ini"); // Todo: better error handling if (d == null) { Debug.Log("Failed to get any data out of " + p + "/content_pack.ini!"); Application.Quit(); } pack.name = d.Get("ContentPack", "name"); if (pack.name.Equals("")) { Debug.Log("Failed to get name data out of " + p + "/content_pack.ini!"); Application.Quit(); } // id can be empty/missing pack.id = d.Get("ContentPack", "id"); // If this is invalid we will just handle it later, not fatal pack.image = p + "/" + d.Get("ContentPack", "image"); // Black description isn't fatal pack.description = d.Get("ContentPack", "description"); // Get all the other ini files in the pack List <string> files = new List <string>(); // content_pack file is included files.Add(p + "/content_pack.ini"); // No extra files is valid if (d.Get("ContentPackData") != null) { foreach (string file in d.Get("ContentPackData").Keys) { files.Add(p + "/" + file); } } // Save list of files pack.iniFiles = files; // Add content pack allPacks.Add(pack); // We finish without actually loading the content, this is done later (content optional) } } }
// Read a content pack for list of files and meta data public void PopulatePackList(string path) { // All packs must have a content_pack.ini, otherwise ignore if (File.Exists(path + "/content_pack.ini")) { ContentPack pack = new ContentPack(); // Get all data from the file IniData d = IniRead.ReadFromIni(path + "/content_pack.ini"); // Todo: better error handling if (d == null) { ValkyrieDebug.Log("Failed to get any data out of " + path + "/content_pack.ini!"); Application.Quit(); } pack.name = d.Get("ContentPack", "name"); if (pack.name.Equals("")) { ValkyrieDebug.Log("Failed to get name data out of " + path + "/content_pack.ini!"); Application.Quit(); } // id can be empty/missing pack.id = d.Get("ContentPack", "id"); // If this is invalid we will just handle it later, not fatal if (d.Get("ContentPack", "image").IndexOf("{import}") == 0) { pack.image = ContentData.ImportPath() + d.Get("ContentPack", "image").Substring(8); } else { pack.image = path + "/" + d.Get("ContentPack", "image"); } // Black description isn't fatal pack.description = d.Get("ContentPack", "description"); // Some packs have a type pack.type = d.Get("ContentPack", "type"); // Get cloned packs string cloneString = d.Get("ContentPack", "clone"); pack.clone = new List <string>(); foreach (string s in cloneString.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries)) { pack.clone.Add(s); } // Get all the other ini files in the pack List <string> files = new List <string>(); // content_pack file is included files.Add(path + "/content_pack.ini"); // No extra files is valid if (d.Get("ContentPackData") != null) { foreach (string file in d.Get("ContentPackData").Keys) { files.Add(path + "/" + file); } } // Save list of files pack.iniFiles = files; // Get all the other ini files in the pack Dictionary <string, List <string> > dictFiles = new Dictionary <string, List <string> >(); // No extra files is valid if (d.Get("LanguageData") != null) { foreach (string s in d.Get("LanguageData").Keys) { int firstSpace = s.IndexOf(' '); string id = s.Substring(0, firstSpace); string file = s.Substring(firstSpace + 1); if (!dictFiles.ContainsKey(id)) { dictFiles.Add(id, new List <string>()); } dictFiles[id].Add(path + "/" + file); } } // Save list of files pack.localizationFiles = dictFiles; // Add content pack allPacks.Add(pack); // We finish without actually loading the content, this is done later (content optional) } }
public SaveData(int num = 0) { Game game = Game.Get(); if (!File.Exists(SaveFile(num))) { return; } try { if (!Directory.Exists(Path.GetTempPath() + "/Valkyrie")) { Directory.CreateDirectory(Path.GetTempPath() + "/Valkyrie"); } if (!Directory.Exists(Path.GetTempPath() + "/Valkyrie/Load")) { Directory.CreateDirectory(Path.GetTempPath() + "/Valkyrie/Load"); } Directory.Delete(Path.GetTempPath() + "/Valkyrie/Load", true); ZipFile zip = ZipFile.Read(SaveFile(num)); zip.ExtractAll(Path.GetTempPath() + "/Valkyrie/Load"); zip.Dispose(); image = ContentData.FileToTexture(Path.GetTempPath() + "/Valkyrie/Load/image.png"); // Check that quest in save is valid QuestData.Quest q = new QuestData.Quest(Path.GetTempPath() + "/Valkyrie/Load/quest"); if (!q.valid) { ValkyrieDebug.Log("Warning: Save " + num + " contains unsupported quest version." + System.Environment.NewLine); return; } DictionaryI18n tmpDict = LocalizationRead.selectDictionary("qst"); LocalizationRead.AddDictionary("qst", q.localizationDict); quest = q.name.Translate(); LocalizationRead.AddDictionary("qst", tmpDict); string data = File.ReadAllText(Path.GetTempPath() + "/Valkyrie/Load/save.ini"); IniData saveData = IniRead.ReadFromString(data); saveData.Get("Quest", "valkyrie"); if (VersionNewer(game.version, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Warning: Save " + num + " is from a future version." + System.Environment.NewLine); return; } if (!VersionNewerOrEqual(minValkyieVersion, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Warning: Save " + num + " is from an old unsupported version." + System.Environment.NewLine); return; } saveTime = System.DateTime.Parse(saveData.Get("Quest", "time")); valid = true; } catch (System.Exception e) { ValkyrieDebug.Log("Warning: Unable to open save file: " + SaveFile(num) + " " + e.Message); } }
// Load a saved game, does nothing if file does not exist public static void Load(int num = 0) { Game game = Game.Get(); try { if (File.Exists(SaveFile(num))) { if (!Directory.Exists(Path.GetTempPath() + "/Valkyrie")) { Directory.CreateDirectory(Path.GetTempPath() + "/Valkyrie"); } if (!Directory.Exists(Path.GetTempPath() + "/Valkyrie/Load")) { Directory.CreateDirectory(Path.GetTempPath() + "/Valkyrie/Load"); } Directory.Delete(Path.GetTempPath() + "/Valkyrie/Load", true); ZipFile zip = ZipFile.Read(SaveFile(num)); zip.ExtractAll(Path.GetTempPath() + "/Valkyrie/Load"); zip.Dispose(); // Check that quest in save is valid QuestData.Quest q = new QuestData.Quest(Path.GetTempPath() + "/Valkyrie/Load/quest"); if (!q.valid) { ValkyrieDebug.Log("Error: save contains unsupported quest version." + System.Environment.NewLine); Destroyer.MainMenu(); return; } string data = File.ReadAllText(Path.GetTempPath() + "/Valkyrie/Load/save.ini"); IniData saveData = IniRead.ReadFromString(data); saveData.data["Quest"]["path"] = Path.GetTempPath() + "/Valkyrie/Load/quest/quest.ini"; saveData.Get("Quest", "valkyrie"); if (VersionNewer(game.version, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Error: save is from a future version." + System.Environment.NewLine); Destroyer.MainMenu(); return; } if (!VersionNewerOrEqual(minValkyieVersion, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Error: save is from an old unsupported version." + System.Environment.NewLine); Destroyer.MainMenu(); return; } Destroyer.Dialog(); // Restart contend data so we can select from save game.cd = new ContentData(game.gameType.DataDirectory()); // Check if we found anything if (game.cd.GetPacks().Count == 0) { ValkyrieDebug.Log("Error: Failed to find any content packs, please check that you have them present in: " + game.gameType.DataDirectory() + System.Environment.NewLine); Application.Quit(); } game.cd.LoadContentID(""); // Load the base content // Load content that the save game uses Dictionary <string, string> packs = saveData.Get("Packs"); foreach (KeyValuePair <string, string> kv in packs) { game.cd.LoadContentID(""); // Support for save games from 1.2 and older if (kv.Key.Equals("FA")) { game.cd.LoadContentID("FAI"); game.cd.LoadContentID("FAM"); game.cd.LoadContentID("FAT"); } if (kv.Key.Equals("CotW")) { game.cd.LoadContentID("CotWI"); game.cd.LoadContentID("CotWM"); game.cd.LoadContentID("CotWT"); } if (kv.Key.Equals("MoM1E")) { game.cd.LoadContentID("MoM1EI"); game.cd.LoadContentID("MoM1EM"); game.cd.LoadContentID("MoM1ET"); } else { game.cd.LoadContentID(kv.Key); } } // This loads the game new Quest(saveData); // Draw things on the screen game.heroCanvas.SetupUI(); game.heroCanvas.UpdateImages(); game.heroCanvas.UpdateStatus(); if (game.gameType.DisplayMorale()) { game.moraleDisplay = new MoraleDisplay(); } if (!game.gameType.DisplayHeroes()) { game.heroCanvas.Clean(); } // Create the menu button new MenuButton(); new LogButton(); new SkillButton(); new InventoryButton(); game.stageUI = new NextStageButton(); } } catch (System.Exception e) { ValkyrieDebug.Log("Error: Unable to open save file: " + SaveFile(num) + " " + e.Message); Application.Quit(); } }
public void DrawList() { localManifest = IniRead.ReadFromString(""); if (File.Exists(saveLocation() + "/manifest.ini")) { localManifest = IniRead.ReadFromIni(saveLocation() + "/manifest.ini"); } // Heading DialogBox db = new DialogBox(new Vector2(2, 1), new Vector2(UIScaler.GetWidthUnits() - 4, 3), "Download " + game.gameType.QuestName()); db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetLargeFont(); db.SetFont(game.gameType.GetHeaderFont()); db = new DialogBox(new Vector2(1, 5f), new Vector2(UIScaler.GetWidthUnits() - 2f, 21f), ""); db.AddBorder(); db.background.AddComponent <UnityEngine.UI.Mask>(); UnityEngine.UI.ScrollRect scrollRect = db.background.AddComponent <UnityEngine.UI.ScrollRect>(); GameObject scrollArea = new GameObject("scroll"); RectTransform scrollInnerRect = scrollArea.AddComponent <RectTransform>(); scrollArea.transform.parent = db.background.transform; scrollInnerRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, (UIScaler.GetWidthUnits() - 3f) * UIScaler.GetPixelsPerUnit()); scrollInnerRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 1); scrollRect.content = scrollInnerRect; scrollRect.horizontal = false; TextButton tb; // Start here int offset = 5; // Loop through all available quests foreach (KeyValuePair <string, Dictionary <string, string> > kv in remoteManifest.data) { string file = kv.Key + ".valkyrie"; // Size is 1.2 to be clear of characters with tails if (File.Exists(saveLocation() + "/" + file)) { int localVersion = 0; int remoteVersion = 0; int.TryParse(localManifest.Get(kv.Key, "version"), out localVersion); int.TryParse(remoteManifest.Get(kv.Key, "version"), out remoteVersion); if (localVersion < remoteVersion) { tb = new TextButton(new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 5, 1.2f), " [Update] " + kv.Value["name"], delegate { Selection(file); }, Color.black, offset); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb.button.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); tb.button.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.7f, 0.7f, 1f); tb.background.transform.parent = scrollArea.transform; } else { db = new DialogBox(new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 5, 1.2f), " " + kv.Value["name"], Color.black); db.AddBorder(); db.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.07f, 0.07f, 0.07f); db.background.transform.parent = scrollArea.transform; db.textObj.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; db.textObj.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); } } else { tb = new TextButton(new Vector2(2, offset), new Vector2(UIScaler.GetWidthUnits() - 5, 1.2f), " " + kv.Value["name"], delegate { Selection(file); }, Color.black, offset); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb.button.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); tb.button.GetComponent <UnityEngine.UI.Text>().alignment = TextAnchor.MiddleLeft; tb.background.GetComponent <UnityEngine.UI.Image>().color = Color.white; tb.background.transform.parent = scrollArea.transform; } offset += 2; } scrollInnerRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, (offset - 5) * UIScaler.GetPixelsPerUnit()); tb = new TextButton(new Vector2(1, UIScaler.GetBottom(-3)), new Vector2(8, 2), "Back", delegate { Cancel(); }, Color.red); tb.SetFont(game.gameType.GetHeaderFont()); }
public void DrawList() { localManifest = IniRead.ReadFromString(""); if (File.Exists(saveLocation() + "/manifest.ini")) { localManifest = IniRead.ReadFromIni(saveLocation() + "/manifest.ini"); } // Heading UIElement ui = new UIElement(); ui.SetLocation(2, 1, UIScaler.GetWidthUnits() - 4, 3); ui.SetText(new StringKey("val", "QUEST_NAME_DOWNLOAD", game.gameType.QuestName())); ui.SetFont(game.gameType.GetHeaderFont()); ui.SetFontSize(UIScaler.GetLargeFont()); UIElementScrollVertical scrollArea = new UIElementScrollVertical(); scrollArea.SetLocation(1, 5, UIScaler.GetWidthUnits() - 2f, 21f); new UIElementBorder(scrollArea); // Start here float offset = 0; // Loop through all available quests foreach (KeyValuePair <string, Dictionary <string, string> > kv in remoteManifest.data) { string file = kv.Key + ".valkyrie"; LocalizationRead.scenarioDict = localizationDict; string questName = new StringKey("qst", kv.Key + ".name").Translate(); int remoteFormat = 0; int.TryParse(remoteManifest.Get(kv.Key, "format"), out remoteFormat); bool formatOK = (remoteFormat >= QuestData.Quest.minumumFormat) && (remoteFormat <= QuestData.Quest.currentFormat); if (!formatOK) { continue; } bool exists = File.Exists(saveLocation() + "/" + file); bool update = true; if (exists) { string localHash = localManifest.Get(kv.Key, "version"); string remoteHash = remoteManifest.Get(kv.Key, "version"); update = !localHash.Equals(remoteHash); } Color bg = Color.white; if (exists) { bg = new Color(0.7f, 0.7f, 1f); if (!update) { bg = new Color(0.1f, 0.1f, 0.1f); } } // Frame ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(0.95f, offset, UIScaler.GetWidthUnits() - 4.9f, 3.1f); ui.SetBGColor(bg); if (update) { ui.SetButton(delegate { Selection(file); }); } offset += 0.05f; // Draw Image ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(1, offset, 3, 3); ui.SetBGColor(bg); if (update) { ui.SetButton(delegate { Selection(file); }); } int.TryParse(remoteManifest.Get(kv.Key, "format"), out remoteFormat); if (textures.ContainsKey(remoteManifest.Get(kv.Key, "image"))) { ui.SetImage(textures[remoteManifest.Get(kv.Key, "image")]); } ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetBGColor(Color.clear); ui.SetLocation(4, offset, UIScaler.GetWidthUnits() - 8, 3f); ui.SetTextPadding(1.2f); if (update && exists) { ui.SetText(new StringKey("val", "QUEST_NAME_UPDATE", questName), Color.black); } else { ui.SetText(questName, Color.black); } if (update) { ui.SetButton(delegate { Selection(file); }); } ui.SetTextAlignment(TextAnchor.MiddleLeft); ui.SetFontSize(Mathf.RoundToInt(UIScaler.GetSmallFont() * 1.3f)); // Duration int lengthMax = 0; int.TryParse(remoteManifest.Get(kv.Key, "lengthmax"), out lengthMax); if (lengthMax > 0) { int lengthMin = 0; int.TryParse(remoteManifest.Get(kv.Key, "lengthmin"), out lengthMin); ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(UIScaler.GetRight(-11), offset, 2, 1); ui.SetText(lengthMin.ToString(), Color.black); ui.SetBGColor(Color.clear); ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(UIScaler.GetRight(-9), offset, 1, 1); ui.SetText("-", Color.black); ui.SetBGColor(Color.clear); ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(UIScaler.GetRight(-8), offset, 2, 1); ui.SetText(lengthMax.ToString(), Color.black); ui.SetBGColor(Color.clear); } // Difficulty float difficulty = 0; float.TryParse(remoteManifest.Get(kv.Key, "difficulty"), out difficulty); if (difficulty != 0) { string symbol = "π"; // will if (game.gameType is MoMGameType) { symbol = new StringKey("val", "ICON_SUCCESS_RESULT").Translate(); } ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(UIScaler.GetRight(-12), offset + 1, 7, 2); ui.SetText(symbol + symbol + symbol + symbol + symbol, Color.black); ui.SetBGColor(Color.clear); ui.SetFontSize(UIScaler.GetMediumFont()); ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(UIScaler.GetRight(-11.95f) + (difficulty * 6.9f), offset + 1, (1 - difficulty) * 6.9f, 2); Color filter = bg; filter.a = 0.7f; ui.SetBGColor(filter); } // Size is 1.2 to be clear of characters with tails if (exists) { ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(((UIScaler.GetWidthUnits() - 3) / 2) - 4, offset + 2.5f, 8, 1.2f); ui.SetBGColor(new Color(0.7f, 0, 0)); ui.SetText(CommonStringKeys.DELETE, Color.black); ui.SetButton(delegate { Delete(file); }); offset += 0.5f; } offset += 4; } foreach (KeyValuePair <string, Dictionary <string, string> > kv in localManifest.data) { // Only looking for files missing from remote if (remoteManifest.data.ContainsKey(kv.Key)) { continue; } string type = localManifest.Get(kv.Key, "type"); // Only looking for packages of this game type if (!game.gameType.TypeName().Equals(type)) { continue; } string file = kv.Key + ".valkyrie"; // Size is 1.2 to be clear of characters with tails if (File.Exists(saveLocation() + "/" + file)) { ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(1, offset, UIScaler.GetWidthUnits() - 8, 1.2f); ui.SetTextPadding(1.2f); ui.SetText(file, Color.black); ui.SetBGColor(new Color(0.1f, 0.1f, 0.1f)); ui.SetTextAlignment(TextAnchor.MiddleLeft); ui = new UIElement(scrollArea.GetScrollTransform()); ui.SetLocation(UIScaler.GetWidthUnits() - 12, offset, 8, 1.2f); ui.SetText(CommonStringKeys.DELETE, Color.black); ui.SetTextAlignment(TextAnchor.MiddleLeft); ui.SetButton(delegate { Delete(file); }); ui.SetBGColor(new Color(0.7f, 0, 0)); offset += 2; } } scrollArea.SetScrollSize(offset); ui = new UIElement(); ui.SetLocation(1, UIScaler.GetBottom(-3), 8, 2); ui.SetText(CommonStringKeys.BACK, Color.red); ui.SetButton(delegate { Cancel(); }); ui.SetFont(game.gameType.GetHeaderFont()); ui.SetFontSize(UIScaler.GetMediumFont()); new UIElementBorder(ui, Color.red); }
// Load a saved game, does nothing if file does not exist public static void Load(int num = 0) { Game game = Game.Get(); try { if (File.Exists(SaveFile(num))) { if (!Directory.Exists(ContentData.TempValyriePath)) { Directory.CreateDirectory(ContentData.TempValyriePath); } string valkyrieLoadPath = Path.Combine(ContentData.TempValyriePath, "Load"); if (!Directory.Exists(valkyrieLoadPath)) { Directory.CreateDirectory(valkyrieLoadPath); } Directory.Delete(valkyrieLoadPath, true); ZipManager.Extract(valkyrieLoadPath, SaveFile(num), ZipManager.Extract_mode.ZIPMANAGER_EXTRACT_FULL); string savefile_content = File.ReadAllText(Path.Combine(valkyrieLoadPath, "save.ini")); IniData saveData = IniRead.ReadFromString(savefile_content); // when loading a quest, path should always be $TMP/load/quest/$subquest/quest.ini // Make sure it is when loading a quest saved for the first time, as in that case it is the original load path string questLoadPath = Path.GetDirectoryName(saveData.Get("Quest", "path")); string questOriginalPath = saveData.Get("Quest", "originalpath"); // loading a quest saved for the first time if (questLoadPath.Contains(questOriginalPath)) { questLoadPath = questLoadPath.Replace(questOriginalPath, ContentData.ValkyrieLoadQuestPath); } // Check that quest in save is valid QuestData.Quest q = new QuestData.Quest(questLoadPath); if (!q.valid) { ValkyrieDebug.Log("Error: save contains unsupported quest version." + Environment.NewLine); GameStateManager.MainMenu(); return; } saveData.data["Quest"]["path"] = Path.Combine(questLoadPath, "quest.ini"); if (VersionManager.VersionNewer(game.version, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Error: save is from a future version." + Environment.NewLine); GameStateManager.MainMenu(); return; } if (!VersionManager.VersionNewerOrEqual(minValkyieVersion, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Error: save is from an old unsupported version." + Environment.NewLine); GameStateManager.MainMenu(); return; } Destroyer.Dialog(); // Load content that the save game uses Dictionary <string, string> packs = saveData.Get("Packs"); foreach (KeyValuePair <string, string> kv in packs) { // Support for save games from 1.2 and older if (kv.Key.Equals("FA")) { game.ContentLoader.LoadContentID("FAI"); game.ContentLoader.LoadContentID("FAM"); game.ContentLoader.LoadContentID("FAT"); } if (kv.Key.Equals("CotW")) { game.ContentLoader.LoadContentID("CotWI"); game.ContentLoader.LoadContentID("CotWM"); game.ContentLoader.LoadContentID("CotWT"); } if (kv.Key.Equals("MoM1E")) { game.ContentLoader.LoadContentID("MoM1EI"); game.ContentLoader.LoadContentID("MoM1EM"); game.ContentLoader.LoadContentID("MoM1ET"); } else { game.ContentLoader.LoadContentID(kv.Key); } } // This loads the game new Quest(saveData); // Draw things on the screen game.heroCanvas.SetupUI(); game.heroCanvas.UpdateImages(); game.heroCanvas.UpdateStatus(); if (game.gameType.DisplayMorale()) { game.moraleDisplay = new MoraleDisplay(); } if (!game.gameType.DisplayHeroes()) { game.heroCanvas.Clean(); } // Create the menu button new MenuButton(); new LogButton(); new SkillButton(); new InventoryButton(); game.stageUI = new NextStageButton(); } } catch (IOException e) { ValkyrieDebug.Log("Error: Unable to open save file: " + SaveFile(num) + " " + e.Message); Application.Quit(); } }
public SaveData(int num = 0) { Game game = Game.Get(); if (!File.Exists(SaveFile(num))) { return; } try { if (!Directory.Exists(ContentData.TempValyriePath)) { Directory.CreateDirectory(ContentData.TempValyriePath); } string valkyrieLoadPath = Path.Combine(ContentData.TempValyriePath, "Preload"); if (!Directory.Exists(valkyrieLoadPath)) { Directory.CreateDirectory(valkyrieLoadPath); } ZipManager.Extract(valkyrieLoadPath, SaveFile(num), ZipManager.Extract_mode.ZIPMANAGER_EXTRACT_SAVE_INI_PIC); image = ContentData.FileToTexture(Path.Combine(valkyrieLoadPath, "image.png")); string data = File.ReadAllText(Path.Combine(valkyrieLoadPath, "save.ini")); IniData saveData = IniRead.ReadFromString(data); // when loading a quest, path should always be $TMP/load/quest/$subquest/quest.ini // Make sure it is when loading a quest saved for the first time, as in that case it is the original load path string questLoadPath = Path.GetDirectoryName(saveData.Get("Quest", "path")); string questOriginalPath = saveData.Get("Quest", "originalpath"); // loading a quest saved for the first time if (questLoadPath.Contains(questOriginalPath)) { questLoadPath = questLoadPath.Replace(questOriginalPath, ContentData.ValkyrieLoadQuestPath); } // use preload path rather than load questLoadPath = questLoadPath.Replace(ContentData.ValkyrieLoadPath, ContentData.ValkyriePreloadPath); QuestData.Quest q = new QuestData.Quest(questLoadPath); if (!q.valid) { ValkyrieDebug.Log("Warning: Save " + num + " contains unsupported quest version." + Environment.NewLine); return; } quest_name = saveData.Get("Quest", "questname"); if (VersionManager.VersionNewer(game.version, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Warning: Save " + num + " is from a future version." + Environment.NewLine); return; } if (!VersionManager.VersionNewerOrEqual(minValkyieVersion, saveData.Get("Quest", "valkyrie"))) { ValkyrieDebug.Log("Warning: Save " + num + " is from an old unsupported version." + Environment.NewLine); return; } saveTime = DateTime.Parse(saveData.Get("Quest", "time")); valid = true; } catch (Exception e) { ValkyrieDebug.Log("Warning: Unable to open save file: " + SaveFile(num) + "\nException: " + e.ToString()); } }
// Read save data public void LoadQuest(IniData saveData) { game = Game.Get(); // This happens anyway but we need it to be here before the following code is executed (also needed for loading saves) game.quest = this; // Get state int.TryParse(saveData.Get("Quest", "round"), out round); int.TryParse(saveData.Get("Quest", "morale"), out morale); bool.TryParse(saveData.Get("Quest", "heroesSelected"), out heroesSelected); bool horror; bool.TryParse(saveData.Get("Quest", "horror"), out horror); if (horror) { phase = MoMPhase.horror; } bool.TryParse(saveData.Get("Quest", "minorPeril"), out minorPeril); bool.TryParse(saveData.Get("Quest", "majorPeril"), out majorPeril); bool.TryParse(saveData.Get("Quest", "deadlyPeril"), out deadlyPeril); // Populate DelayedEvents delayedEvents = new List <QuestData.Event.DelayedEvent>(); string[] saveDelayed = saveData.Get("Quest", "DelayedEvents").Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries); foreach (string de in saveDelayed) { delayedEvents.Add(new QuestData.Event.DelayedEvent(de)); } // Set static quest data string questPath = saveData.Get("Quest", "path"); qd = new QuestData(questPath); // Clear all tokens game.tokenBoard.Clear(); // Clean up everything marked as 'board' foreach (GameObject go in GameObject.FindGameObjectsWithTag("board")) { Object.Destroy(go); } // Repopulate items on the baord boardItems = new Dictionary <string, BoardComponent>(); Dictionary <string, string> saveBoard = saveData.Get("Board"); foreach (KeyValuePair <string, string> kv in saveBoard) { if (kv.Key.IndexOf("Door") == 0) { boardItems.Add(kv.Key, new Door(qd.components[kv.Key] as QuestData.Door, game)); } if (kv.Key.IndexOf("Token") == 0) { boardItems.Add(kv.Key, new Token(qd.components[kv.Key] as QuestData.Token, game)); } if (kv.Key.IndexOf("Tile") == 0) { boardItems.Add(kv.Key, new Tile(qd.components[kv.Key] as QuestData.Tile, game)); } } // Set flags flags = new HashSet <string>(); Dictionary <string, string> saveFlags = saveData.Get("Flags"); foreach (KeyValuePair <string, string> kv in saveFlags) { flags.Add(kv.Key); } // Restart event EventManager eManager = new EventManager(); // Clean undo stack (we don't save undo stack) // When performing undo this is replaced later undo = new Stack <string>(); // Fetch hero state heroes = new List <Hero>(); monsters = new List <Monster>(); foreach (KeyValuePair <string, Dictionary <string, string> > kv in saveData.data) { if (kv.Key.IndexOf("Hero") == 0 && kv.Key.IndexOf("HeroSelection") != 0) { heroes.Add(new Hero(kv.Value)); } } // Monsters must be after heros because some activations refer to heros foreach (KeyValuePair <string, Dictionary <string, string> > kv in saveData.data) { if (kv.Key.IndexOf("Monster") == 0) { monsters.Add(new Monster(kv.Value)); } } // Restore hero selections heroSelection = new Dictionary <string, List <Hero> >(); Dictionary <string, string> saveSelection = saveData.Get("HeroSelection"); foreach (KeyValuePair <string, string> kv in saveSelection) { // List of selected heroes string[] selectHeroes = kv.Value.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries); List <Hero> heroList = new List <Hero>(); foreach (string s in selectHeroes) { foreach (Hero h in heroes) { // Match hero id int id; int.TryParse(s, out id); if (id == h.id) { heroList.Add(h); } } } // Add this selection heroSelection.Add(kv.Key, heroList); } // Update the screen game.monsterCanvas.UpdateList(); game.heroCanvas.UpdateStatus(); }
public IEnumerable <string> GetPacks(string gameType) { return(data.Get(gameType + "Packs")?.Keys ?? Enumerable.Empty <string>()); }
// Read save data public void LoadQuest(IniData saveData) { game = Game.Get(); // This happens anyway but we need it to be here before the following code is executed (also needed for loading saves) game.quest = this; // Get state int.TryParse(saveData.Get("Quest", "round"), out round); int.TryParse(saveData.Get("Quest", "morale"), out morale); bool.TryParse(saveData.Get("Quest", "heroesSelected"), out heroesSelected); bool horror; bool.TryParse(saveData.Get("Quest", "horror"), out horror); if (horror) { phase = MoMPhase.horror; } // Set camera float camx, camy, camz; float.TryParse(saveData.Get("Quest", "camx"), out camx); float.TryParse(saveData.Get("Quest", "camy"), out camy); float.TryParse(saveData.Get("Quest", "camz"), out camz); game.cc.gameObject.transform.position = new Vector3(camx, camy, camz); game.cc.minLimit = false; if (saveData.Get("Quest", "camxmin").Length > 0) { game.cc.minLimit = true; int.TryParse(saveData.Get("Quest", "camxmin"), out game.cc.minPanX); int.TryParse(saveData.Get("Quest", "camymin"), out game.cc.minPanY); } game.cc.maxLimit = false; if (saveData.Get("Quest", "camxmax").Length > 0) { game.cc.maxLimit = true; int.TryParse(saveData.Get("Quest", "camxmax"), out game.cc.maxPanX); int.TryParse(saveData.Get("Quest", "camymax"), out game.cc.maxPanY); } // Populate DelayedEvents (depreciated) delayedEvents = new List <QuestData.Event.DelayedEvent>(); string[] saveDelayed = saveData.Get("Quest", "DelayedEvents").Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries); foreach (string de in saveDelayed) { delayedEvents.Add(new QuestData.Event.DelayedEvent(de)); } // Set static quest data string questPath = saveData.Get("Quest", "path"); qd = new QuestData(questPath); monsterSelect = saveData.Get("SelectMonster"); if (monsterSelect == null) { // Support old saves monsterSelect = new Dictionary <string, string>(); GenerateMonsterSelection(); } // Clear all tokens game.tokenBoard.Clear(); // Clean up everything marked as 'board' foreach (GameObject go in GameObject.FindGameObjectsWithTag("board")) { Object.Destroy(go); } // Repopulate items on the baord boardItems = new Dictionary <string, BoardComponent>(); Dictionary <string, string> saveBoard = saveData.Get("Board"); foreach (KeyValuePair <string, string> kv in saveBoard) { if (kv.Key.IndexOf("Door") == 0) { boardItems.Add(kv.Key, new Door(qd.components[kv.Key] as QuestData.Door, game)); } if (kv.Key.IndexOf("Token") == 0) { boardItems.Add(kv.Key, new Token(qd.components[kv.Key] as QuestData.Token, game)); } if (kv.Key.IndexOf("Tile") == 0) { boardItems.Add(kv.Key, new Tile(qd.components[kv.Key] as QuestData.Tile, game)); } } Dictionary <string, string> saveVars = saveData.Get("Vars"); vars = new VarManager(saveVars); // Set items items = new HashSet <string>(); Dictionary <string, string> saveItems = saveData.Get("Items"); foreach (KeyValuePair <string, string> kv in saveItems) { items.Add(kv.Key); } // Restart event EventManager eManager = new EventManager(); // Clean undo stack (we don't save undo stack) // When performing undo this is replaced later undo = new Stack <string>(); // Fetch hero state heroes = new List <Hero>(); monsters = new List <Monster>(); foreach (KeyValuePair <string, Dictionary <string, string> > kv in saveData.data) { if (kv.Key.IndexOf("Hero") == 0 && kv.Key.IndexOf("HeroSelection") != 0) { heroes.Add(new Hero(kv.Value)); } } // Monsters must be after heros because some activations refer to heros foreach (KeyValuePair <string, Dictionary <string, string> > kv in saveData.data) { if (kv.Key.IndexOf("Monster") == 0) { monsters.Add(new Monster(kv.Value)); } } // Restore hero selections heroSelection = new Dictionary <string, List <Hero> >(); Dictionary <string, string> saveSelection = saveData.Get("HeroSelection"); foreach (KeyValuePair <string, string> kv in saveSelection) { // List of selected heroes string[] selectHeroes = kv.Value.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries); List <Hero> heroList = new List <Hero>(); foreach (string s in selectHeroes) { foreach (Hero h in heroes) { // Match hero id int id; int.TryParse(s, out id); if (id == h.id) { heroList.Add(h); } } } // Add this selection heroSelection.Add(kv.Key, heroList); } puzzle = new Dictionary <string, Puzzle>(); foreach (KeyValuePair <string, Dictionary <string, string> > kv in saveData.data) { if (kv.Key.IndexOf("PuzzleSlide") == 0) { puzzle.Add(kv.Key.Substring("PuzzleSlide".Length, kv.Key.Length - "PuzzleSlide".Length), new PuzzleSlide(kv.Value)); } if (kv.Key.IndexOf("PuzzleCode") == 0) { puzzle.Add(kv.Key.Substring("PuzzleCode".Length, kv.Key.Length - "PuzzleCode".Length), new PuzzleCode(kv.Value)); } if (kv.Key.IndexOf("PuzzleImage") == 0) { puzzle.Add(kv.Key.Substring("PuzzleImage".Length, kv.Key.Length - "PuzzleImage".Length), new PuzzleImage(kv.Value)); } } // Restore event quotas eventQuota = new Dictionary <string, int>(); foreach (KeyValuePair <string, string> kv in saveData.Get("EventQuota")) { int value; int.TryParse(kv.Value, out value); eventQuota.Add(kv.Key, value); } // Restore event log log = new List <LogEntry>(); foreach (KeyValuePair <string, string> kv in saveData.Get("Log")) { log.Add(new LogEntry(kv.Key, kv.Value)); } // Update the screen game.monsterCanvas.UpdateList(); game.heroCanvas.UpdateStatus(); }