105 lines
3.2 KiB
C#
105 lines
3.2 KiB
C#
using Invector;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Beyond
|
|
{
|
|
/// <summary>
|
|
/// Attribute of the item including the value (int)
|
|
/// </summary>
|
|
[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();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get attribute text
|
|
/// </summary>
|
|
/// <param name="format">custom format, if null, the format will be <seealso cref=" displayFormat"/></param>
|
|
/// <returns>Formated attribute text</returns>
|
|
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<bItemAttribute> attributes, bItemAttributes name)
|
|
{
|
|
var attribute = attributes.Find(at => at.name == name);
|
|
return attribute != null;
|
|
}
|
|
|
|
public static bItemAttribute GetAttributeByType(this List<bItemAttribute> 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<bItemAttribute> CopyAsNew(this List<bItemAttribute> copy)
|
|
{
|
|
var target = new List<bItemAttribute>();
|
|
|
|
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;
|
|
}
|
|
}
|
|
} |