3using System.ComponentModel;
4using System.Globalization;
5using System.Reflection;
16 [DefaultValue(
"Terraria")]
18 [DefaultValue(
"None")]
34 string[] parts = key.Split(
new char[] {
' ' }, 2);
35 if (parts.Length == 2) {
41 public override bool Equals(
object obj) {
49 public override string ToString() => $
"{mod} {name}";
52 return new {
mod,
name }.GetHashCode();
58 public abstract int Type {
get; }
72 [
TypeConverter(typeof(ToFromStringConverter<ItemDefinition>))]
85 public override int Type => ItemID.TypeFromUniqueKey(base.mod, base.name);
101 public override int Type => ProjectileID.TypeFromUniqueKey(
mod,
name);
133 public override int Type => PrefixID.TypeFromUniqueKey(
mod,
name);
147 public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) {
148 return destinationType != typeof(
string);
151 public override bool CanConvertFrom(ITypeDescriptorContext context, System.Type sourceType) {
152 if (sourceType == typeof(
string)) {
155 return base.CanConvertFrom(context, sourceType);
157 public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture,
object value) {
158 if (value is
string) {
159 MethodInfo parse = typeof(T).GetMethod(
"FromString",
new Type[] { typeof(
string) });
160 if (parse !=
null && parse.IsStatic && parse.ReturnType == typeof(T)) {
161 return parse.Invoke(
null,
new object[] { value });
164 throw new JsonException(
string.Format(
165 "The {0} type does not have a public static FromString(string) method that returns a {0}.",
168 return base.ConvertFrom(context, culture, value);
Classes implementing EntityDefinition serve to function as a way to save and load the identities of v...
override int GetHashCode()
EntityDefinition(string mod, string name)
override bool Equals(object obj)
TagCompound SerializeData()
override string ToString()
EntityDefinition(string key)
ItemDefinition represents an Item identity. A typical use for this class is usage in ModConfig,...
static readonly Func< TagCompound, ItemDefinition > DESERIALIZER
ItemDefinition(string mod, string name)
static ItemDefinition FromString(string s)
static ItemDefinition Load(TagCompound tag)
ItemDefinition(string key)
static NPCDefinition FromString(string s)
NPCDefinition(string mod, string name)
static readonly Func< TagCompound, NPCDefinition > DESERIALIZER
static NPCDefinition Load(TagCompound tag)
NPCDefinition(string key)
static PrefixDefinition Load(TagCompound tag)
PrefixDefinition(int type)
static readonly Func< TagCompound, PrefixDefinition > DESERIALIZER
PrefixDefinition(string mod, string name)
static PrefixDefinition FromString(string s)
PrefixDefinition(string key)
ProjectileDefinition(int type)
static ProjectileDefinition Load(TagCompound tag)
ProjectileDefinition(string key)
ProjectileDefinition(string mod, string name)
static ProjectileDefinition FromString(string s)
static readonly Func< TagCompound, ProjectileDefinition > DESERIALIZER
This TypeConverter facilitates converting to and from the string Type. This is necessary for Objects ...
override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
override bool CanConvertFrom(ITypeDescriptorContext context, System.Type sourceType)