void LoadOwnershipInfo() { var date = GameManager.Instance.CurrentDate; try { //need to handle if there is no data. CurrentStarOwnership = Star.Ownerships[date]; //no data on the system. if (string.IsNullOrWhiteSpace(CurrentStarOwnership.FactionCode)) { Sprite.color = Color.white; } else { //some form of independent polity. if (CurrentStarOwnership.FactionCode.Contains("I(")) { Faction = GameManager.Instance.Factions["I"]; } else if (CurrentStarOwnership.FactionCode.Contains("U (A)") || CurrentStarOwnership.FactionCode.Contains("U(A)")) //is this a faction missing from the list? { Faction = GameManager.Instance.Factions["U"]; } else if (CurrentStarOwnership.IsDisputed) { Faction = GameManager.Instance.Factions["D"]; } else { Faction = GameManager.Instance.Factions[CurrentStarOwnership.FactionCode]; } Sprite.color = Faction.UnityColour; } } catch (Exception e) { Debug.LogError(e); Sprite.color = Color.clear; } }
/// <summary> /// Loads all the star data from resources. /// </summary> /// <returns></returns> IEnumerator LoadSystemInformation() { var starText = Resources.Load <TextAsset>("Sarna Unified Cartography Kit - Systems"); yield return(null); var lines = Regex.Split(starText.text, "\n|\r|\r\n").Where(x => !string.IsNullOrWhiteSpace(x)).ToArray(); var titleLineel = lines[1].Split('\t'); int nonDateRows = 8; var dates = new string[titleLineel.Length - nonDateRows]; for (int idx = nonDateRows; idx < titleLineel.Length; idx++) { dates[idx - nonDateRows] = titleLineel[idx]; } Dates = dates.ToList(); CurrentDate = Dates[0]; yield return(null); int count = 0; for (int idx = 2; idx < lines.Length; idx++) { var linesplit = lines[idx].Split('\t'); if (linesplit.Length < titleLineel.Length)//need to have a value for each column. { continue; } var star = new Star() { ID = linesplit[0], SystemName = linesplit[1], AlternativeNames = linesplit[2].Split(',').ToList(), X = linesplit[3], Y = linesplit[4], size = linesplit[5], SarnaLink = linesplit[6], Ownerships = new Dictionary <string, StarOwnership>() }; for (int jdx = 0; jdx < dates.Length; jdx++) { var ownerInfo = linesplit[jdx + nonDateRows].Split(','); string faction = ownerInfo[0].Trim(); //handle the disputed systems. bool dispute = false; bool isHidden = false; if (ownerInfo[0].Contains("D(")) { faction = ownerInfo[0] + ", " + ownerInfo[1]; dispute = true; } else if (ownerInfo[0].Contains("(H)")) { faction = faction.Replace("(H)", ""); isHidden = true; } var ownership = new StarOwnership() { StarId = star.ID, Year = dates[jdx], FactionCode = faction, IsCapital = false, SubRegion = new List <string>(), IsDisputed = dispute, IsHidden = isHidden }; if (ownerInfo.Length > 1 && !dispute) { if (ownerInfo[1].Contains("Faction Capital")) { ownership.IsCapital = true; } else { ownership.Region = ownerInfo[1]; } for (int rdx = 2; rdx < ownerInfo.Length; rdx++) { if (ownerInfo[rdx].Contains("Faction Capital")) { ownership.IsCapital = true; } else { ownership.SubRegion.Add(ownerInfo[rdx]); } } } if (!star.Ownerships.ContainsKey(ownership.Year)) //why do we have duplicate years? //correction, duplicate years due to clan invasion. Look into method we can use this. { star.Ownerships.Add(ownership.Year, ownership); } } Stars.Add(star); count++; if (count > 100) { yield return(null); count = 0; } } }