public void ShowResults(EndgameResults results) { gameObject.SetActive(true); foreach (TextMeshProUGUI text in new TextMeshProUGUI[] { resultsText, hintsText, learningText }) { if (text) { text.text = string.Empty; } } void AddStringToText(string str, TextMeshProUGUI text) { if (text && !string.IsNullOrEmpty(str)) { text.text += (string.IsNullOrEmpty(text.text) ? string.Empty : "\n") + str; } } foreach (var summaryHint in results.summaryHintMap) { AddStringToText(summaryHint.Key, resultsText); AddStringToText(summaryHint.Value, hintsText); } results.learning.ForEach(learning => AddStringToText(learning, learningText)); if (animator) { animator.SetTrigger(ANIM_TRIGGER_RESULT); } }
public EndgameResults GetResults() { EndgameResults retval = new EndgameResults(); List <Endgame> validEndgames = endgames.FindAll(eg => eg.StatConditionsMet && eg.UnlockPathComplete); int maxNumStats = 0; // Unlock Paths and Learning Outcomes are easy, just get all that apply validEndgames.ForEach(eg => { maxNumStats = Mathf.Max(maxNumStats, eg.statConditions.Count); if (eg.learning.Count > 0) { retval.learning.Add(RLUtilities.RandomFromList(eg.learning)); } }); // Stat-based endgames are a bit trickier though List <Endgame> finalStats = new List <Endgame>(); List <Endgame>[] statResults = new List <Endgame> [maxNumStats + 1]; for (int i = 0; i < statResults.Length; i++) { statResults[i] = new List <Endgame>(); } // Sort endgames in descending order of statConditions.Count, for an ordered comparison // Note: HORRIBLY INEFFICIENT! There's gotta be a better way... validEndgames.ForEach(eg => { statResults[eg.statConditions.Count].Add(eg); }); HashSet <Endgame> removeEGs = new HashSet <Endgame>(); for (int r = 2; r < statResults.Length; r++) { if (statResults[r].Count == 0 || statResults[r - 1].Count == 0) { continue; } List <Endgame> curStatResults = statResults[r], lesserStatResults = statResults[r - 1]; foreach (Endgame curEG in curStatResults) { removeEGs.Clear(); for (int lessR = r - 1; lessR >= 1; lessR--) { statResults[lessR].ForEach(lessEG => { if (lessEG.statConditions.TrueForAll(sc => curEG.statConditions.Contains(sc))) { removeEGs.Add(lessEG); } }); } foreach (Endgame eg in removeEGs) { statResults[r - 1].Remove(eg); } } statResults[r].Reverse(); // Put back in spreadsheet order (1) } foreach (var sr in statResults) { finalStats.AddRange(sr); } finalStats.Reverse(); // Put back in spreadsheet order (2) foreach (Endgame eg in finalStats) { if (eg.summaries.Count > 0) { string curSummary = RLUtilities.RandomFromList(eg.summaries), curHint = eg.hints.Count > 0 ? RLUtilities.RandomFromList(eg.hints) : null; retval.summaryHintMap[curSummary] = curHint; } } return(retval); }