KSP API
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
Public Member Functions | Static Public Member Functions | Protected Member Functions | Properties | List of all members
KSP.IO.PluginConfiguration Class Reference

From N3X15: PluginConfiguration was something I threw together a while ago to try and improve settings serialization. The INI files we were using just couldn't cope with newlines and had all sorts of horrible workarounds. Instead of INI files, it writes structured XML files that look like this: More...

Public Member Functions

GetValue< T > (string key)
 Get a typed value from the root node. More...
 
GetValue< T > (string key, T _default)
 Get a typed value from the root node, and set to a default if it doesn't exist. More...
 
void load ()
 Load from disk More...
 
void save ()
 Commit changes to disk More...
 
void SetValue (string key, object value)
 Set a configuration key's value More...
 

Static Public Member Functions

static PluginConfiguration CreateForType< T > (Vessel flight=null)
 Initialize the configuration object More...
 

Protected Member Functions

 PluginConfiguration (string pathToFile)
 

Properties

object this[string key] [get, set]
 Return configuration key from the root node More...
 

Detailed Description

From N3X15: PluginConfiguration was something I threw together a while ago to try and improve settings serialization. The INI files we were using just couldn't cope with newlines and had all sorts of horrible workarounds. Instead of INI files, it writes structured XML files that look like this:

<config> <int name="int"&gt;4</int> <long name="long">45</long> <short name="short">4</short> <byte name="byte">255</byte> <bool name="bool">1</bool> <vector3 name="vector3"> <x>0</x> <y>1</y> <z>2</z> </vector3> <vector3d name="vector3d"> <x>0</x> <y>1</y> <z>2.05</z> </vector3d> <string name="string">string</string> </config>

Despite looking a bit messy, it's actually a lot easier to use and doesn't have as many drawbacks as INI files. Newlines are preserved, and most importantly, types are also preserved. Oh, and it's UTF-8 encoded, so internationalization won't be as much as a problem, theoretically. Here's how to use it:

PluginConfiguration cfg = PluginConfiguration.CreateForType<MyCoolModule>(); cfg["a string"] = "I love KSP!"; cfg["another setting"] = new Vector3d(0,1,2); cfg.save(); // Later... cfg.load(); settingAString = cfg.GetValue<string>("a string"); settingAVector = cfg.GetValue<Vector3d>("another setting");

Constructor & Destructor Documentation

KSP.IO.PluginConfiguration.PluginConfiguration ( string  pathToFile)
protected

Member Function Documentation

static PluginConfiguration KSP.IO.PluginConfiguration.CreateForType< T > ( Vessel  flight = null)
static

Initialize the configuration object

Template Parameters
T
Parameters
flight
Returns
T KSP.IO.PluginConfiguration.GetValue< T > ( string  key)

Get a typed value from the root node.

Template Parameters
T
Parameters
key
Returns
T KSP.IO.PluginConfiguration.GetValue< T > ( string  key,
_default 
)

Get a typed value from the root node, and set to a default if it doesn't exist.

Template Parameters
T
Parameters
key
_default
Returns
void KSP.IO.PluginConfiguration.load ( )

Load from disk

void KSP.IO.PluginConfiguration.save ( )

Commit changes to disk

void KSP.IO.PluginConfiguration.SetValue ( string  key,
object  value 
)

Set a configuration key's value

Parameters
key
value

Property Documentation

object KSP.IO.PluginConfiguration.this[string key]
getset

Return configuration key from the root node

Parameters
key
Returns

The documentation for this class was generated from the following file: