public void SetCard(AbstractCard card) { if (card.GetType() == typeof(SupportCard)) { isDraggable = false; } this.card = card; fieldName.SetText(card.name); }
private string ParseText(string s) { MatchCollection matches = new Regex(@"\[[^\]]*\]").Matches(s); for (int i = 0; i < matches.Count; i++) { Match match = matches[i]; try{ if (match.Value == "[S]" || match.Value == "[s]") // Argument stack parsing { int stacks = (int)reference.GetType().GetField("STACKS").GetValue(reference); s = s.Replace(match.Value, stacks.ToString()); } else if (match.Value == "[D]") // Damage parsing { int min = (int)reference.GetType().GetField("MIN_DAMAGE").GetValue(reference); int max = (int)reference.GetType().GetField("MAX_DAMAGE").GetValue(reference); if (min == max) { s = s.Replace(match.Value, min.ToString()); } else { s = s.Replace(match.Value, min.ToString() + "-" + max.ToString()); } } else if (match.Value == "[P]") // Poise parsing { int poise = (int)reference.GetType().GetField("POISE").GetValue(reference); s = s.Replace(match.Value, poise.ToString()); } else if (match.Value == "[N]") // Draw parsing { int poise = (int)reference.GetType().GetField("DRAW").GetValue(reference); s = s.Replace(match.Value, poise.ToString()); } else // Custom parsing (e.g. if we do [ABC], searches for an 'ABC' field in the card) { string parsed = match.Value.Substring(1, match.Value.Length - 2); // Remove [ and ] characters int customValue = (int)reference.GetType().GetField(parsed).GetValue(reference); s = s.Replace(match.Value, customValue.ToString()); } } catch { Debug.Log("Unable to parse " + match.Value + " for " + reference.NAME + ": check .json and .cs files to make sure right field names are used!"); continue; } } return(s); }