private void loadConfigNodeData()
{
ConfigNode node = SSTUConfigNodeUtils.parseConfigNode(configNodeData);
//load all main tank model datas
mainModules = SRBModelData.parseSRBModels(node.GetNodes("MAINMODEL"));
currentMainModule = Array.Find(mainModules, m => m.name == currentMainName);
if (currentMainModule == null)
{
currentMainModule = mainModules[0];
currentMainName = currentMainModule.name;
}
if (!currentMainModule.isValidTextureSet(currentMainTexture))
{
currentMainTexture = currentMainModule.getDefaultTextureSet();
}
//load nose modules from NOSE nodes
ConfigNode[] noseNodes = node.GetNodes("NOSE");
ConfigNode noseNode;
int length = noseNodes.Length;
List<SingleModelData> noseModulesTemp = new List<SingleModelData>();
for (int i = 0; i < length; i++)
{
noseNode = noseNodes[i];
noseModulesTemp.Add(new SingleModelData(noseNode));
}
this.noseModules = noseModulesTemp.ToArray();
currentNoseModule = Array.Find(this.noseModules, m => m.name == currentNoseName);
if (currentNoseModule == null)
{
currentNoseModule = this.noseModules[0];//not having a mount defined is an error, at least one mount must be defined, crashing at this point is acceptable
currentNoseName = currentNoseModule.name;
}
if (!currentNoseModule.isValidTextureSet(currentNoseTexture))
{
currentNoseTexture = currentNoseModule.getDefaultTextureSet();
}
//load nose modules from NOZZLE nodes
ConfigNode[] nozzleNodes = node.GetNodes("NOZZLE");
ConfigNode nozzleNode;
length = nozzleNodes.Length;
List<SRBNozzleData> nozzleModulesTemp = new List<SRBNozzleData>();
for (int i = 0; i < length; i++)
{
nozzleNode = nozzleNodes[i];
nozzleModulesTemp.Add(new SRBNozzleData(nozzleNode));
}
this.nozzleModules = nozzleModulesTemp.ToArray();
currentNozzleModule = Array.Find(this.nozzleModules, m => m.name == currentNozzleName);
if (currentNozzleModule == null)
{
currentNozzleModule = this.nozzleModules[0];//not having a mount defined is an error, at least one mount must be defined, crashing at this point is acceptable
currentNozzleName = currentNozzleModule.name;
}
if (!currentNozzleModule.isValidTextureSet(currentNozzleTexture))
{
currentNozzleTexture = currentNozzleModule.getDefaultTextureSet();
}
//reset existing gimbal/thrust transforms, remove them from the model hierarchy
resetTransformParents();//this resets the thrust transform parent in case it was changed during prefab; we don't want to delete the thrust transform
Transform parentTransform = part.transform.FindRecursive("model").FindOrCreate(baseTransformName);
//finally, clear any existing models from prefab, and initialize the currently configured models
SSTUUtils.destroyChildren(parentTransform);
currentNoseModule.setupModel(parentTransform, ModelOrientation.TOP);
currentNozzleModule.setupModel(parentTransform, ModelOrientation.BOTTOM);
currentMainModule.setupModel(parentTransform, ModelOrientation.CENTRAL);
//lastly, re-insert gimbal and thrust transforms into model hierarchy and reset default gimbal rotation offset
currentNozzleModule.setupTransformDefaults(part.transform.FindRecursive(thrustTransformName), part.transform.FindRecursive(gimbalTransformName));
//if had custom thrust curve data, reload it now (else it will default to whatever is on the engine)
if (!string.IsNullOrEmpty(thrustCurveData))
{
thrustCurveCache = new FloatCurve();
string[] keySplits = thrustCurveData.Split(':');
string[] valSplits;
int len = keySplits.Length;
float key, value, inTan, outTan;
for (int i = 0; i < len; i++)
{
valSplits = keySplits[i].Split(',');
key = float.Parse(valSplits[0]);
value = float.Parse(valSplits[1]);
inTan = float.Parse(valSplits[2]);
outTan = float.Parse(valSplits[3]);
thrustCurveCache.Add(key, value, inTan, outTan);
}
}
if (!string.IsNullOrEmpty(presetCurveName))
{
ConfigNode[] presetNodes = GameDatabase.Instance.GetConfigNodes("SSTU_THRUSTCURVE");
int len = presetNodes.Length;
for (int i = 0; i < len; i++)
{
if (presetNodes[i].GetStringValue("name") == presetCurveName)
{
thrustCurveCache = presetNodes[i].GetFloatCurve("curve");
break;
}
}
}
}