public SessionData() { //DataStore.InitData() has already been called at this point to load data difficulty = Difficulty.NotSet; threatLevel = addtlThreat = 0; allyRules = AllyRules.Normal; optionalDeployment = YesNo.No; allyThreatCost = YesNo.No; selectedMissionExpansion = Expansion.Core; selectedMissionID = "core1"; selectedMissionName = DataStore.missionCards["Core"][0].name; includeImperials = true; includeMercs = true; selectedDeploymentCards = new DeploymentCards[5]; for (int i = 0; i < 5; i++) { selectedDeploymentCards[i] = new DeploymentCards(); } selectedAlly = null; //ignore "Other" expansion enemy groups by default selectedDeploymentCards[3].cards.AddRange(DataStore.deploymentCards.cards.Where(x => x.expansion == "Other")); gameVars = new GameVars(); }
public static void LoadTranslatedData() { try { string[] expansions = Enum.GetNames(typeof(Expansion)); TextAsset json; missionCards = new Dictionary <string, List <MissionCard> >(); //load mission card DATA foreach (string expansion in expansions) { json = Resources.Load <TextAsset>($"MissionData/{expansion}"); if (json != null) { var cards = JsonConvert.DeserializeObject <List <MissionCard> >(json.text); missionCards.Add(expansion, cards); } } //load card DATA deploymentCards = LoadCards("enemies"); allyCards = LoadCards("allies"); villainCards = LoadCards("villains"); heroCards = LoadCards("heroes"); //events, activation instructions, bonus effects cardEvents = LoadEvents(); activationInstructions = LoadInstructions(); bonusEffects = LoadBonusEffects(); //ui uiLanguage = LoadUILanguage(); uiLanguage.uiDeploymentGroups = LoadDeploymentCardTranslations(); LoadMissionCardTranslations(); //assign translations to card data SetCardTranslations(deploymentCards.cards); SetCardTranslations(allyCards.cards); SetCardTranslations(villainCards.cards); SetCardTranslations(heroCards.cards); Debug.Log("Loaded Language: " + languageCodeList[languageCode]); } catch (Exception e) { Debug.Log($"LoadTranslatedData() ERROR:\r\nError parsing data"); Debug.Log(e); //default to English so app loads correctly next time languageCode = 0; PlayerPrefs.SetInt("language", 0); PlayerPrefs.Save(); } }
public void OnChangeExpansion(string expansion) { EventSystem.current.SetSelectedGameObject(null); Enum.TryParse(expansion, out selectedExpansion); cardPrefab.gameObject.SetActive(false); foreach (Transform c in transform) { c.gameObject.SetActive(false); c.GetComponent <Toggle>().isOn = false; c.GetComponent <Toggle>().interactable = true; } //0=starting, 1=reserved, 2=villains, 3=ignored if (groupIndex == 0 || groupIndex == 1) { deploymentCards = new DeploymentCards() { cards = DataStore.deploymentCards.cards.Concat(DataStore.villainCards.cards).ToList() }; } else if (groupIndex == 2) { deploymentCards = DataStore.villainCards; } else if (groupIndex == 3) { deploymentCards = DataStore.deploymentCards; } CardDescriptor custom = new CardDescriptor() { cost = 0, expansion = "Other", name = "Custom Group", faction = "None", id = "DG070", ignored = "", priority = 2, rcost = 0, size = 1, tier = 1 }; enemyCards = deploymentCards.cards.Where(x => x.expansion == expansion).ToList(); if (expansion == "Other") { enemyCards.Add(custom); } DeploymentCards prevSelected = DataStore.sessionData.selectedDeploymentCards[groupIndex]; Sprite thumbNail = null; for (int i = 0; i < enemyCards.Count; i++) { var child = transform.GetChild(i); //switch on if previously selected //do it while Toggle is INACTIVE so OnToggle code doesn't run if (prevSelected.cards.Contains(enemyCards[i])) { buttonToggles[i].isOn = true; } child.gameObject.SetActive(true); //re-enable the Toggle var id = int.Parse(enemyCards[i].id.Substring(2).TrimStart('0')); if (id <= 70) //groupIndex != 2 )//if NOT villains { thumbNail = Resources.Load <Sprite>($"Cards/Enemies/{selectedExpansion}/{enemyCards[i].id.Replace( "DG", "M" )}"); } else //villain thumb directory { thumbNail = Resources.Load <Sprite>($"Cards/Villains/{enemyCards[i].id.Replace( "DG", "M" )}"); } //set the thumbnail texture var thumb = child.Find("Image"); thumb.GetComponent <Image>().sprite = thumbNail; if (enemyCards[i].isElite || id > 70) { thumb.GetComponent <Image>().color = new Color(1, .5f, .5f, 1); } else { thumb.GetComponent <Image>().color = new Color(1, 1, 1, 1); } //if an enemy is already in another group index (Initial, Reserved, etc), disable the toggle so the enemy can't be added to 2 different groups //ie: can't put same enemy into both Initial and Reserved if (IsInGroup(enemyCards[i])) { buttonToggles[i].interactable = false; if (!enemyCards[i].isElite) { thumb.GetComponent <Image>().color = new Color(1, 1, 1, .35f); } else { thumb.GetComponent <Image>().color = new Color(1, .5f, .5f, .35f); } } } expansionController.UpdateText((int)selectedExpansion, buttonToggles.Count(x => x.isOn)); }
public void OnReturnTo() { EventSystem.current.SetSelectedGameObject(null); cg.DOFade(1, .5f); //if we just restored a saved default, make sure the expansion from the saved mission is still "owned" (excluding "Other" expansion) if (DataStore.sessionData.selectedMissionExpansion == Expansion.Other || DataStore.ownedExpansions.Contains(DataStore.sessionData.selectedMissionExpansion)) { //handle selected mission string n = DataStore.sessionData.selectedMissionID; //restoring defaults calls this method //langauge may have been changed since saving the defaults //instead of relying on the saved mission NAME (possibly wrong language), lookup current translated name using the saved id var c = DataStore.missionCards[DataStore.sessionData.selectedMissionExpansion.ToString()].Where(x => x.id.ToLower() == n.ToLower()).FirstOr(new MissionCard { name = "" }); selectedMissionText.text = c.name.ToLower(); } else { //loaded expansions is no longer in OWNED list, reset to core1, mission 1 DataStore.sessionData.selectedMissionID = "core1"; DataStore.sessionData.selectedMissionName = DataStore.missionCards["Core"][0].name; DataStore.sessionData.selectedMissionExpansion = Expansion.Core; var c = DataStore.missionCards["Core"][0]; selectedMissionText.text = c.name.ToLower(); } selectedMissionText.transform.Find("view Button").GetComponent <Button>().interactable = true; selectedMissionText.transform.Find("mission info button").GetComponent <Button>().interactable = true; //handle selected enemy groups for (int i = 0; i < 4; i++) { //only the first 4 DeploymentCards //index 4 contains heroes DeploymentCards selectedCards = DataStore.sessionData.selectedDeploymentCards[i]; if (selectedCards.cards.Count > 0) { enemyGroupText[i].text = selectedCards.cards.Count + " " + DataStore.uiLanguage.uiSetup.selected; } else { enemyGroupText[i].text = DataStore.uiLanguage.uiSetup.choose; } } //handle selected heroes for (int i = 0; i < 4; i++) { heroMetas[i].gameObject.SetActive(false); } addHeroButton.interactable = DataStore.sessionData.MissionHeroes.Count < 4; int idx = 0; foreach (CardDescriptor dc in DataStore.sessionData.MissionHeroes) { //add thumbnail heroMetas[idx].gameObject.SetActive(true); heroMetas[idx].allyName = dc.name; heroMetas[idx].id = dc.id; heroMetas[idx].allySprite.sprite = Resources.Load <Sprite>($"Cards/Heroes/{dc.id}"); idx++; } ColorBlock cb = addHeroButton.colors; if (DataStore.sessionData.MissionHeroes.Count > 0) { cb.normalColor = new Color(0, 0.6440244f, 1, 1); } else { cb.normalColor = new Color(1, 0.1568628f, 0, 1); } addHeroButton.colors = cb; //handle selected ally if (DataStore.sessionData.selectedAlly != null) { addAllyButton.SetActive(false); allyImage.gameObject.SetActive(true); allyImage.sprite = Resources.Load <Sprite>($"Cards/Allies/{DataStore.sessionData.selectedAlly.id.Replace( "A", "M" )}"); } else { addAllyButton.SetActive(true); allyImage.gameObject.SetActive(false); } }