Manager Pattern depracated

Jan 14, 2013 at 3:40 AM
Edited Jan 14, 2013 at 3:44 AM

For those grabbing the latest source I have settled on using JSON.Net serialization patterns and converters to populate higher level classes. This allows both custom properties in classes with special handling while not losing any properties that are not serialized into a strict property or object type.


Code usage is extremely simplified. This example is from a basic test that runs some simple functionality:



// Open a save file
var sf = SaveFile.CreateFromKspFile(@"Data\Saves\KspPersistentSfswMods.sfs");

// Fill all resource tanks (electric, fuel etc) Methods exsit on individual objects as well

// Change the title
sf.Game.Title = "HELLO WORLD!";

// Clear all debris

// Getting a vessel by name
var sat = sf.Game.FlightState.Vessels.Where(v => v["name"].ToString().Contains("Beta Geo-Sat")).FirstOrDefault();

// Changing the vessel's orbit using the Body enum. Method currently sets a default orbit ~100km above targe.

// Saves file, automatically creates a backup of the orignal file



This implementation does not have the top level class for loading from a KSP install location yet. I will be adding that with a later check in. 


All object types Game and lower are implemented as IDictionary<string, JToken>. The data found in the object's dictionary represents any properties found in the KSP data file that are not mapped to a typed property on the model. This allows the system to gracefully handle new fields added by Squad and mod authors while allowing end users/developers access to this data. Any changed made to this data will be reflected in the data file. Key names are case sensitive.