Terraria ModLoader  0.11.7.7
A mod to make and play Terraria mods
Terraria.ModLoader.Config.ConfigManager Class Reference
+ Collaboration diagram for Terraria.ModLoader.Config.ConfigManager:

Static Public Member Functions

static object AlternateCreateInstance (Type type)
 
static bool EnumerableEquals (IEnumerable a, IEnumerable b)
 
static ModConfig GeneratePopulatedClone (ModConfig original)
 
static T GetCustomAttribute< T > (PropertyFieldWrapper memberInfo, object item, object array)
 
static T GetCustomAttribute< T > (PropertyFieldWrapper memberInfo, Type type)
 
static IEnumerable< PropertyFieldWrapper > GetFieldsAndProperties (object item)
 
static bool ObjectEquals (object a, object b)
 
static void SetPendingChanges (bool changes=true)
 
static Tuple< UIElement, UIElement > WrapIt (UIElement parent, ref int top, PropertyFieldWrapper memberInfo, object item, int order, object list=null, Type arrayType=null, int index=-1)
 

Static Public Attributes

static readonly string ModConfigPath = Path.Combine(Main.SavePath, "Mod Configs")
 
static readonly JsonSerializerSettings serializerSettings
 
static readonly string ServerModConfigPath = Path.Combine(Main.SavePath, "Mod Configs", "Server")
 

Static Private Attributes

static readonly IList< JsonConverter > converters
 
static readonly IDictionary< Mod, List< ModConfig > > LoadTimeConfigs = new Dictionary<Mod, List<ModConfig>>()
 

Detailed Description

Definition at line 18 of file ConfigManager.cs.

Member Function Documentation

static object Terraria.ModLoader.Config.ConfigManager.AlternateCreateInstance ( Type  type)
static

Definition at line 300 of file ConfigManager.cs.

301  {
302  if (type == typeof(string))
303  return "";
304  return Activator.CreateInstance(type);
305  }
static bool Terraria.ModLoader.Config.ConfigManager.EnumerableEquals ( IEnumerable  a,
IEnumerable  b 
)
static

Definition at line 354 of file ConfigManager.cs.

354  {
355  IEnumerator enumeratorA = a.GetEnumerator();
356  IEnumerator enumeratorB = b.GetEnumerator();
357  bool hasNextA = enumeratorA.MoveNext();
358  bool hasNextB = enumeratorB.MoveNext();
359  while (hasNextA && hasNextB) {
360  if (!ObjectEquals(enumeratorA.Current, enumeratorB.Current)) return false;
361  hasNextA = enumeratorA.MoveNext();
362  hasNextB = enumeratorB.MoveNext();
363  }
364  return !hasNextA && !hasNextB;
365  }
static bool ObjectEquals(object a, object b)
static ModConfig Terraria.ModLoader.Config.ConfigManager.GeneratePopulatedClone ( ModConfig  original)
static

Definition at line 293 of file ConfigManager.cs.

References Terraria.ModLoader.Config.ModConfig.Clone(), and Terraria.ModLoader.Config.ConfigManager.serializerSettings.

293  {
294  string json = JsonConvert.SerializeObject(original, ConfigManager.serializerSettings);
295  ModConfig properClone = original.Clone();
296  JsonConvert.PopulateObject(json, properClone, ConfigManager.serializerSettings);
297  return properClone;
298  }

+ Here is the call graph for this function:

static T Terraria.ModLoader.Config.ConfigManager.GetCustomAttribute< T > ( PropertyFieldWrapper  memberInfo,
object  item,
object  array 
)
static
Type Constraints
T :Attribute 

Definition at line 309 of file ConfigManager.cs.

309  : Attribute {
310  // Class
311  T attribute = (T)Attribute.GetCustomAttribute(memberInfo.Type, typeof(T), true);
312  if (array != null)
313  {
314  // item null?
315  // attribute = (T)Attribute.GetCustomAttribute(item.GetType(), typeof(T), true) ?? attribute; // TODO: is this wrong?
316  }
317  // Member
318  attribute = (T)Attribute.GetCustomAttribute(memberInfo.MemberInfo, typeof(T)) ?? attribute;
319  return attribute;
320  // TODO: allow for inheriting from parent's parent? (could get attribute from parent ConfigElement)
321  }
static T Terraria.ModLoader.Config.ConfigManager.GetCustomAttribute< T > ( PropertyFieldWrapper  memberInfo,
Type  type 
)
static
Type Constraints
T :Attribute 

Definition at line 323 of file ConfigManager.cs.

323  : Attribute {
324  // Class
325  T attribute = (T)Attribute.GetCustomAttribute(memberInfo.Type, typeof(T), true);
326 
327  attribute = (T)Attribute.GetCustomAttribute(type, typeof(T), true) ?? attribute;
328 
329  // Member
330  attribute = (T)Attribute.GetCustomAttribute(memberInfo.MemberInfo, typeof(T)) ?? attribute;
331  return attribute;
332  }
static IEnumerable<PropertyFieldWrapper> Terraria.ModLoader.Config.ConfigManager.GetFieldsAndProperties ( object  item)
static

Definition at line 278 of file ConfigManager.cs.

Referenced by Terraria.ModLoader.Config.ModConfig.NeedsReload().

279  {
280  PropertyInfo[] properties = item.GetType().GetProperties(
281  //BindingFlags.DeclaredOnly |
282  BindingFlags.Public |
283  BindingFlags.Instance);
284 
285  FieldInfo[] fields = item.GetType().GetFields(
286  //BindingFlags.DeclaredOnly |
287  BindingFlags.Public |
288  BindingFlags.Instance);
289 
290  return fields.Select(x => new PropertyFieldWrapper(x)).Concat(properties.Select(x => new PropertyFieldWrapper(x)));
291  }

+ Here is the caller graph for this function:

static bool Terraria.ModLoader.Config.ConfigManager.ObjectEquals ( object  a,
object  b 
)
static

Definition at line 346 of file ConfigManager.cs.

Referenced by Terraria.ModLoader.Config.ReferenceDefaultsPreservingResolver.CreateProperties(), and Terraria.ModLoader.Config.ModConfig.NeedsReload().

346  {
347  if (ReferenceEquals(a, b)) return true;
348  if (a == null || b == null) return false;
349  if (a is IEnumerable && b is IEnumerable && !(a is string) && !(b is string))
350  return EnumerableEquals((IEnumerable)a, (IEnumerable)b);
351  return a.Equals(b);
352  }
static bool EnumerableEquals(IEnumerable a, IEnumerable b)

+ Here is the caller graph for this function:

static void Terraria.ModLoader.Config.ConfigManager.SetPendingChanges ( bool  changes = true)
static

Definition at line 340 of file ConfigManager.cs.

340  {
341  // public api for modders.
342  Interface.modConfig.SetPendingChanges(changes);
343  }
static Tuple<UIElement, UIElement> Terraria.ModLoader.Config.ConfigManager.WrapIt ( UIElement  parent,
ref int  top,
PropertyFieldWrapper  memberInfo,
object  item,
int  order,
object  list = null,
Type  arrayType = null,
int  index = -1 
)
static

Definition at line 334 of file ConfigManager.cs.

335  {
336  // public api for modders.
337  return UIModConfig.WrapIt(parent, ref top, memberInfo, item, order, list, arrayType, index);
338  }

Member Data Documentation

readonly IList<JsonConverter> Terraria.ModLoader.Config.ConfigManager.converters
staticprivate
Initial value:
= new List<JsonConverter>() {
new Newtonsoft.Json.Converters.VersionConverter(),
}

Definition at line 48 of file ConfigManager.cs.

readonly IDictionary<Mod, List<ModConfig> > Terraria.ModLoader.Config.ConfigManager.LoadTimeConfigs = new Dictionary<Mod, List<ModConfig>>()
staticprivate

Definition at line 26 of file ConfigManager.cs.

readonly string Terraria.ModLoader.Config.ConfigManager.ModConfigPath = Path.Combine(Main.SavePath, "Mod Configs")
static

Definition at line 53 of file ConfigManager.cs.

readonly JsonSerializerSettings Terraria.ModLoader.Config.ConfigManager.serializerSettings
static
Initial value:
= new JsonSerializerSettings
{
Formatting = Formatting.Indented,
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate,
ObjectCreationHandling = ObjectCreationHandling.Replace,
NullValueHandling = NullValueHandling.Ignore,
Converters = converters,
ContractResolver = new ReferenceDefaultsPreservingResolver()
}

Definition at line 28 of file ConfigManager.cs.

Referenced by Terraria.ModLoader.Config.ConfigManager.GeneratePopulatedClone().

readonly string Terraria.ModLoader.Config.ConfigManager.ServerModConfigPath = Path.Combine(Main.SavePath, "Mod Configs", "Server")
static

Definition at line 54 of file ConfigManager.cs.