Class MCustom<T>
Base class for all custom mod-added mapper types.
Namespace: Modding.Mapper
Assembly: Assembly-CSharp.dll
Syntax
public abstract class MCustom<T> : MapperType
Type Parameters
Name | Description |
---|---|
T |
Constructors
MCustom(String, String, T)
Declaration
protected MCustom(string displayName, string key, T defaultValue)
Parameters
Type | Name | Description |
---|---|---|
String | displayName | |
String | key | |
T | defaultValue |
Fields
defaultValue
The default value this mapper type was created with.
Declaration
protected T defaultValue
Field Value
Type | Description |
---|---|
T |
loadValue
Load value of the mapper type. This is used for the undo system, and is normally handled completely automatically.
Declaration
protected T loadValue
Field Value
Type | Description |
---|---|
T |
value
Current value of the mapper type.
Declaration
protected T value
Field Value
Type | Description |
---|---|
T |
Properties
isDefaultValue
Default implementation compares value and defaultValue using .Equals(). If this is not suitable or ideal for type T, override this.
Declaration
public override bool isDefaultValue { get; }
Property Value
Type | Description |
---|---|
Boolean |
Overrides
SerializationKey
This key should be used for all serialization of the mapper type.
Declaration
protected string SerializationKey { get; }
Property Value
Type | Description |
---|---|
String |
Value
Provides public access to the underlying value. Setting this automatically invokes the Changed event.
Declaration
public virtual T Value { get; set; }
Property Value
Type | Description |
---|---|
T |
Methods
ApplyValue()
Applies the load value to the value and invokes the Changed event.
Declaration
public override void ApplyValue()
Overrides
DeSerialize(XData)
Deserializes the given data into both value and load value.
Declaration
public override void DeSerialize(XData raw)
Parameters
Type | Name | Description |
---|---|---|
XData | raw |
Overrides
DeSerializeValue(XData)
Override to specify how to deserialize from XData to a T.
Declaration
public abstract T DeSerializeValue(XData data)
Parameters
Type | Name | Description |
---|---|---|
XData | data |
Returns
Type | Description |
---|---|
T |
Remarks
This is used to provide default implementations for the other DeSerialize* methods.
InvokeChanged(T)
Be careful if you override this, it is called from the base constructor.
Declaration
public virtual void InvokeChanged(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value |
ResetDefaults()
Resets the mapper type's value back to the default value.
Declaration
public override void ResetDefaults()
Overrides
ResetValue()
Resets the value back to the load value. Used for undo.
Declaration
public override void ResetValue()
Overrides
Serialize()
Serializes the current value.
Declaration
public override XData Serialize()
Returns
Type | Description |
---|---|
XData |
Overrides
SerializeDefault()
Serializes the default value.
Declaration
public override XData SerializeDefault()
Returns
Type | Description |
---|---|
XData |
Overrides
SerializeLoadValue()
Serializes the load value.
Declaration
public override XData SerializeLoadValue()
Returns
Type | Description |
---|---|
XData |
Overrides
SerializeValue(T)
Override to specify how to serialize a T into an XData. Be careful: This is called from the MCustom constructor, which means it is called before the derived class' constructor is called! Use SerializationKey as the key for the XData object!
Declaration
public abstract XData SerializeValue(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value |
Returns
Type | Description |
---|---|
XData |
Remarks
This is used to provide default implementations for the other Serialize* methods.
Events
Changed
Invoked whenever the underlying value of the mapper type is changed.
Declaration
public event Action<T> Changed
Event Type
Type | Description |
---|---|
Action<T> |