User Tools

Site Tools


besiege:modding:example-guides:creatingmapper

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
besiege:modding:example-guides:creatingmapper [2018/06/18 16:54]
von
besiege:modding:example-guides:creatingmapper [2018/07/10 16:32] (current)
spaar
Line 33: Line 33:
 By convention, these are named ''​MSomething''​ (e.g. ''​MKey'',​ ''​MToggle'',​ etc.) but this is not required. In this document we'll call it ''​TMapper''​. By convention, these are named ''​MSomething''​ (e.g. ''​MKey'',​ ''​MToggle'',​ etc.) but this is not required. In this document we'll call it ''​TMapper''​.
  
-```c# public class TMapper : MCustom {+<code csharp>​ 
 +public class TMapper : MCustom {
  
-```+} 
 +</​code>​
  
   * Create a constructor   * Create a constructor
Line 41: Line 43:
 There must be a constructor that calls the base constructor. By convention it has the signature ''​string displayName,​ string key, T defaultValue''​ and calls the base constructor with the same arguments, but it is also possible to receive additional parameters or omit the default value to always pass the same one to the base constructor. There must be a constructor that calls the base constructor. By convention it has the signature ''​string displayName,​ string key, T defaultValue''​ and calls the base constructor with the same arguments, but it is also possible to receive additional parameters or omit the default value to always pass the same one to the base constructor.
  
-''​c# ​public TMapper(string displayName,​ string key, T defaultValue) : base(displayName,​ key, defaultValue) { }''​+<code csharp>​ 
 +public TMapper(string displayName,​ string key, T defaultValue) : base(displayName,​ key, defaultValue) { } 
 +</​code>​
  
   * Create (de)serialization methods   * Create (de)serialization methods
Line 51: Line 55:
 The ''​XData''​ object returned from ''​SerializeValue''​ should always have a key equivalent to the ''​SerializationKey''​ property. The ''​XData''​ object returned from ''​SerializeValue''​ should always have a key equivalent to the ''​SerializationKey''​ property.
  
-```c# public XData SerializeValue(T value) { return new XString(SerializationKey,​ value.ToString());​ }+<code csharp>​ 
 +public XData SerializeValue(T value) { 
 +    ​return new XString(SerializationKey,​ value.ToString());​ 
 +}
  
-public T DeSerializeValue(XData data) { return T.FromString%%((%%string) (XString) data); } ```+public T DeSerializeValue(XData data) { 
 +    ​return T.FromString((string) (XString) data); 
 +} 
 +</​code>​
  
 There are other methods that can be overridden if necessary, but these are the only ones that must always be specified. For more information see [[..:​MapperTypes#​required-overrides|the complete documentation]]. There are other methods that can be overridden if necessary, but these are the only ones that must always be specified. For more information see [[..:​MapperTypes#​required-overrides|the complete documentation]].
Line 61: Line 71:
   * Create a class extending ''​CustomSelector<​T,​ TMapper>''​   * Create a class extending ''​CustomSelector<​T,​ TMapper>''​
  
-```c# public class TSelector : CustomSelector<​T,​ TMapper>{+<code csharp>​ 
 +public class TSelector : CustomSelector<​T,​ TMapper> {
  
-```+ 
 +</​code>​
  
 The convention for naming these is ''<​name of TMapper without the "​M">​Selector'',​ e.g. a ''​ToggleSelector''​ for ''​MToggle''​ etc. There is again no hard requirement to follow this convention though. The convention for naming these is ''<​name of TMapper without the "​M">​Selector'',​ e.g. a ''​ToggleSelector''​ for ''​MToggle''​ etc. There is again no hard requirement to follow this convention though.
besiege/modding/example-guides/creatingmapper.txt · Last modified: 2018/07/10 16:32 by spaar