using Invector; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Beyond { /// /// Attribute of the item including the value (int) /// [System.Serializable] public class bItemAttribute { public bItemAttributes name = 0; public int value = 0; public bool isOpen; public bool isBool; public string displayFormat { get { return name.DisplayFormat(); } } /// /// Get attribute text /// /// custom format, if null, the format will be /// Formated attribute text public string GetDisplayText(string format = null) { { var _text = string.IsNullOrEmpty(format) ? displayFormat : format; if (string.IsNullOrEmpty(_text)) { _text = name.ToString().InsertSpaceBeforeUpperCase().RemoveUnderline(); _text += " : " + value.ToString(); } else { if (_text.Contains("(NAME)")) { _text = _text.Replace("(NAME)", name.ToString().InsertSpaceBeforeUpperCase().RemoveUnderline()); } if (_text.Contains("(VALUE)")) { _text = _text.Replace("(VALUE)", value.ToString()); } } return _text; } } public bItemAttribute(bItemAttributes name, int value) { this.name = name; this.value = value; } } public static class vItemAttributeHelper { public static void CopyTo(this bItemAttribute itemAttribute, bItemAttribute to) { to.isBool = itemAttribute.isBool; to.name = itemAttribute.name; to.value = itemAttribute.value; } public static bool Contains(this List attributes, bItemAttributes name) { var attribute = attributes.Find(at => at.name == name); return attribute != null; } public static bItemAttribute GetAttributeByType(this List attributes, bItemAttributes name) { var attribute = attributes.Find(at => at.name == name); return attribute; } public static bool Equals(this bItemAttribute attributeA, bItemAttribute attributeB) { return attributeA.name == attributeB.name; } public static List CopyAsNew(this List copy) { var target = new List(); if (copy != null) { for (int i = 0; i < copy.Count; i++) { bItemAttribute attribute = new bItemAttribute(copy[i].name, copy[i].value); target.Add(attribute); } } return target; } } }