Jump to content

[1.0.4] VesselModule class data persistence


Diazo

Recommended Posts

Vessel Module Save/Load Framework

This framework adds the familiar Save/Load logic we are use to in a partModule to the new VesselModule class.

This mod is a .dll release that you create a dependancy on in your mod to use, similar to Firespitter or the Toolbar mod.

License: Released into the public domain, mainly to ensure that it can be distributed with other mods that use it.

Source

Download here.

Caution: While I am not aware of any issues and this has full functionality to the best of my knowledge, please make sure to test it with your implementation before using to make sure there are no bugs that will trip you up. I want more people then just me to give it a clean bill of health before I do an official release.

Install: Merge the GameData folder inside the .zip file with your GameData folder. Note that the 000 prefix is important as this mod has to load before yours to handle dependency correctly. There is only a single .dll file, do not move it's location if you distribute with your own mod. Multiple copies of the VesselModuleSave.dll file in a players GameData folder will cause issues.

Use (dependancy):

If this mod is used, it's absence will break the mod that uses it so I expect a hard dependancy to be used. Add a reference to the VesselModuleSave.dll file the same as you do the UnityEngine.dll file.

Use (example .cs file):


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using VesselModuleSaveFramework; //the reference to the VesselModuleSave.dll file.

namespace VMSTest //change to namespace of your mod
{
public class VMSTest1 : VesselModuleSave //change VMSTest1 to the name of your VesselModule class, note you inherit VesselModuleSave, not VesselModule
{
public override void VSMStart() //this replaces your Start() and OnStart() methods, this runs when a vessel loads and it's VesselModules are initialized
{
//your code here
}

public override ConfigNode VSMSave(ConfigNode node) //this replaces the OnSave() method from a partModule.
{
return node; //note that unlike a partModule (which uses reflection), you must return the ConfigNode you wish to save
}

public override void VSMLoad(ConfigNode node) //this replaces OnLoad(), note this method runs automatically after VSMStart() when initializing to load your data
{
//your code here
}

public override void VSMDestroy() //this replaces OnDestroy(), runs when a vessel unloads and it's VesselModules are destroyed.
{
//your code here
}

public void Update() //no change, this is the default UnityEngine Update() method we all know
{
}

public void FixedUpdate() //no change, this is the default UnityEngine FixedUpdate() method we all know
{
}

public void OnGUI() //no change, this is the default UnityEngine OnGUI() method we all know
{
}
}

Note the name changes on the Start and Destroy methods, I need to run code in the background in those methods to make this work, use the VSMStart and VSMDestroy methods instead.

There is also no equivalent of the KSPField, you must use AddValue/AddNode and GetValue/GetNode to save/load data.

The last caution is that there is no provisions for undocking, you must do that yourself in your code. This mod saves data based on the Vessel.id property, you must move data between different Vessel.id's yourself.

Let me know how this works for you all,

D.

Edited by Diazo
Link to comment
Share on other sites

  • 1 year later...

I just discovered VesselModules and am trying to convert my part module and would very much like to use this. I have gotten a few steps in and wanted to see if this was still a valid approach as I try and roll it into my mod. 

I really only have a 3 or 4 values I need to persist. Do you have some examples of Saving and Loading using this method. I am a bit confused on how this will deal with data types, my values are boolean and Vector3 coordinates.

Regards

Edited by gomker
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...