tModLoader v0.11.8.9
A mod to make and play Terraria mods
ModConfig.cs
Go to the documentation of this file.
1using Newtonsoft.Json;
2using System;
3using System.Collections;
4using System.Collections.Generic;
5using System.Linq;
6using Terraria.ModLoader.Config.UI;
7
9{
10 // TODO: Enforce no statics allowed.
11
18 public abstract class ModConfig
19 {
20 [JsonIgnore]
21 public Mod mod { get; internal set; }
22
23 [JsonIgnore]
24 public string Name { get; internal set; }
25
26 [JsonIgnore]
27 public abstract ConfigScope Mode { get; }
28
29 // TODO: Does non-autoloaded ModConfigs have a use-case?
30 public virtual bool Autoload(ref string name) => mod.Properties.Autoload;
31
36 public virtual void OnLoaded()
37 {
38 }
39
43 public virtual void OnChanged()
44 {
45 }
46
54 public virtual bool AcceptClientChanges(ModConfig pendingConfig, int whoAmI, ref string message)
55 {
56 return true;
57 }
58
59 // TODO: Can we get rid of Clone and just load from disk? Don't think so yet.
64 public virtual ModConfig Clone() => (ModConfig)MemberwiseClone();
65
71 public virtual bool NeedsReload(ModConfig pendingConfig)
72 {
73 foreach (PropertyFieldWrapper variable in ConfigManager.GetFieldsAndProperties(this))
74 {
75 ReloadRequiredAttribute reloadRequired = ConfigManager.GetCustomAttribute<ReloadRequiredAttribute>(variable, this, null);
76 if (reloadRequired != null)
77 {
78 // Do we need to implement nested ReloadRequired? Right now only top level fields will trigger it.
79 if (!ConfigManager.ObjectEquals(variable.GetValue(this), variable.GetValue(pendingConfig))) {
80 return true;
81 }
82 }
83 }
84 return false;
85 }
86 }
87
91 public enum ConfigScope
92 {
101 // PlayerSpecific,
102 // WorldSpecific
103 }
104}
static bool ObjectEquals(object a, object b)
static IEnumerable< PropertyFieldWrapper > GetFieldsAndProperties(object item)
ModConfig provides a way for mods to be configurable. ModConfigs can either be Client specific or Ser...
Definition: ModConfig.cs:19
abstract ConfigScope Mode
Definition: ModConfig.cs:27
virtual bool Autoload(ref string name)
virtual ModConfig Clone()
tModLoader will call Clone on ModConfig to facilitate proper implementation of the ModConfig user int...
virtual bool NeedsReload(ModConfig pendingConfig)
Whether or not a reload is required. The default implementation compares properties and fields annota...
Definition: ModConfig.cs:71
virtual void OnChanged()
This hook is called anytime new config values have been set and are ready to take effect....
Definition: ModConfig.cs:43
virtual bool AcceptClientChanges(ModConfig pendingConfig, int whoAmI, ref string message)
Called on the Server for ServerSide configs to determine if the changes asked for by the Client will ...
Definition: ModConfig.cs:54
virtual void OnLoaded()
This method is called when the ModConfig has been loaded for the first time. This happens before regu...
Definition: ModConfig.cs:36
This attribute hints that changing the value of the annotated property or field will put the config i...
Mod is an abstract class that you will override. It serves as a central place from which the mod's co...
Definition: Mod.cs:25
ModProperties Properties
Definition: Mod.cs:52
ConfigScope
Each ModConfig class has a different scope. Failure to use the correct mode will lead to bugs.
Definition: ModConfig.cs:92
@ ClientSide
This config is specific to the client. Use this for personalization options.
@ ServerSide
This config is shared between all clients and maintained by the server. Use this for game-play change...
bool Autoload
Whether or not this mod will autoload content by default. Autoloading content means you do not need t...