private void initialize() { //MonoBehaviour.print("NodeFairingInit: "+fairingCreated+ " :: " +fairingForceDisabled+ " :: "+fairingJettisoned + " :: " +fairingEnabled); if (rendersToRemove != null && rendersToRemove.Length > 0) { SSTUUtils.removeTransforms(part, SSTUUtils.parseCSV(rendersToRemove)); } loadFairingData(SSTUConfigNodeUtils.parseConfigNode(configNodeData)); if (externalUpdateData != null) { updateFromExternalData(externalUpdateData); } if (fairingCreated || (fairingEnabled && !fairingJettisoned && !fairingForceDisabled && string.IsNullOrEmpty(nodeName)))//previously existed, recreate it, or should exist by default values in the config { buildFairing(); if (!string.IsNullOrEmpty(nodeName)) { AttachNode n = part.FindAttachNode(nodeName); if (n != null && n.attachedPart != null) { prevAttachedPart = n.attachedPart; //MonoBehaviour.print("Setting initial attached part to: " + prevAttachedPart); } } } else if (!fairingJettisoned && !fairingForceDisabled && !string.IsNullOrEmpty(nodeName))//else could potentially be activated by a node...check for activation { needsStatusUpdate = true; } updateTextureSet(false); needsGuiUpdate = true; //MonoBehaviour.print("NodeFairingInit End: " + fairingCreated + " :: " + fairingForceDisabled + " :: " + fairingJettisoned + " :: " + fairingEnabled); }
private void initialize() { if (rendersToRemove != null && rendersToRemove.Length > 0) { SSTUUtils.removeTransforms(part, SSTUUtils.parseCSV(rendersToRemove)); } loadFairingData(SSTUStockInterop.getPartModuleConfig(part, this)); if (externalUpdateData != null) { updateFromExternalData(externalUpdateData); } updateEditorFields(false); //update cached editor gui field values for diameter, sections, etc. buildFairing(); //construct fairing from cached/persistent/default data needsStatusUpdate = true; if (textureSets != null) { if (textureSets.Length <= 1)//only a single, (or no) texture set selected/avaialable { Events["nextTextureEvent"].active = false; } if (textureSets.Length > 0 && String.IsNullOrEmpty(currentTextureSet)) { TextureSet s = textureSets[0]; currentTextureSet = textureSets[0].setName; } } }
//creates/recreates FairingData instances from data from config node and any persistent node (if applicable) private void loadFairingData(ConfigNode node) { ConfigNode[] fairingNodes = node.GetNodes("FAIRING"); fairingParts = new SSTUNodeFairingData[fairingNodes.Length]; Transform modelBase = part.transform.FindRecursive("model"); Transform parent; SSTUNodeFairing[] cs = part.GetComponents <SSTUNodeFairing>(); int l = Array.IndexOf(cs, this); int moduleIndex = l; for (int i = 0; i < fairingNodes.Length; i++) { parent = modelBase.FindOrCreate(fairingName + "-" + moduleIndex + "-" + i); fairingParts[i] = new SSTUNodeFairingData(); fairingParts[i].load(fairingNodes[i], parent.gameObject); if (fairingParts[i].canAdjustTop) { enableTopDiameterControls = true; } if (fairingParts[i].canAdjustBottom) { enableBottomDiameterControls = true; } } if (!String.IsNullOrEmpty(persistentDataString)) { String[] datas = SSTUUtils.parseCSV(persistentDataString, ":"); int length = datas.Length; for (int i = 0; i < length; i++) { fairingParts[i].loadPersistence(datas[i]); } } textureSets = TextureSet.loadTextureSets(node.GetNodes("TEXTURESET")); if (fairingMaterial != null) { Material.Destroy(fairingMaterial); fairingMaterial = null; } if (textureSets != null && !String.IsNullOrEmpty(currentTextureSet)) { TextureSet t = Array.Find(textureSets, m => m.setName == currentTextureSet); if (t != null) { TextureData d = t.textureDatas[0]; if (d != null) { diffuseTextureName = d.diffuseTextureName; normalTextureName = d.normalTextureName; } } } fairingMaterial = SSTUUtils.loadMaterial(diffuseTextureName, normalTextureName, "KSP/Bumped Specular"); }
public void loadPersistence(String data) { String[] csv = SSTUUtils.parseCSV(data); topY = SSTUUtils.safeParseFloat(csv[0]); bottomY = SSTUUtils.safeParseFloat(csv[1]); topRadius = SSTUUtils.safeParseFloat(csv[2]); bottomRadius = SSTUUtils.safeParseFloat(csv[3]); }
/// <summary> /// Restores ModelData instances from config node data, and populates the 'currentModule' instances with the currently enabled modules. /// </summary> private void loadConfigData() { ConfigNode node = SSTUStockInterop.getPartModuleConfig(part, this); ConfigNode[] tankNodes = node.GetNodes("TANK"); ConfigNode[] mountNodes = node.GetNodes("CAP"); ConfigNode[] fuelNodes = node.GetNodes("FUELTYPE"); ConfigNode[] limitNodes = node.GetNodes("TECHLIMIT"); mainTankModules = SingleModelData.parseModels(tankNodes); int len = mountNodes.Length; ConfigNode mountNode; List <MountModelData> noses = new List <MountModelData>(); List <MountModelData> mounts = new List <MountModelData>(); for (int i = 0; i < len; i++) { mountNode = mountNodes[i]; if (mountNode.GetBoolValue("useForNose", true)) { mountNode.SetValue("nose", "true"); noses.Add(new MountModelData(mountNode)); } if (mountNode.GetBoolValue("useForMount", true)) { mountNode.SetValue("nose", "false"); mounts.Add(new MountModelData(mountNode)); } } mountModules = mounts.ToArray(); noseModules = noses.ToArray(); topNodeNames = SSTUUtils.parseCSV(topManagedNodeNames); bottomNodeNames = SSTUUtils.parseCSV(bottomManagedNodeNames); currentMainTankModule = Array.Find(mainTankModules, m => m.name == currentTankType); if (currentMainTankModule == null) { MonoBehaviour.print("ERROR: Could not locate tank type for: " + currentTankType + ". reverting to first available tank type."); currentMainTankModule = mainTankModules[0]; currentTankType = currentMainTankModule.name; } currentNoseModule = Array.Find(noseModules, m => m.name == currentNoseType); if (currentNoseModule == null) { MonoBehaviour.print("ERROR: Could not locate nose type for: " + currentNoseType + ". reverting to first available nose type."); currentNoseModule = noseModules[0]; currentNoseType = currentNoseModule.name; } currentMountModule = Array.Find(mountModules, m => m.name == currentMountType); if (currentMountModule == null) { MonoBehaviour.print("ERROR: Could not locate mount type for: " + currentMountType + ". reverting to first available mount type."); currentMountModule = mountModules[0]; currentMountType = currentMountModule.name; } if (!currentMainTankModule.isValidTextureSet(currentTankTexture)) { currentTankTexture = currentMainTankModule.getDefaultTextureSet(); } if (!currentNoseModule.isValidTextureSet(currentNoseTexture)) { currentNoseTexture = currentNoseModule.getDefaultTextureSet(); } if (!currentMountModule.isValidTextureSet(currentMountTexture)) { currentMountTexture = currentMountModule.getDefaultTextureSet(); } currentNoseModule.updateTextureUIControl(this, "currentNoseTexture", currentNoseTexture); currentMainTankModule.updateTextureUIControl(this, "currentTankTexture", currentTankTexture); currentMountModule.updateTextureUIControl(this, "currentMountTexture", currentMountTexture); }
/// <summary> /// Restores ModelData instances from config node data, and populates the 'currentModule' instances with the currently enabled modules. /// </summary> private void loadConfigData() { ConfigNode node = SSTUConfigNodeUtils.parseConfigNode(configNodeData); ConfigNode[] tankSetsNodes = node.GetNodes("TANKSET"); ConfigNode[] tankNodes = node.GetNodes("TANK"); ConfigNode[] mountNodes = node.GetNodes("CAP"); ConfigNode[] limitNodes = node.GetNodes("TECHLIMIT"); tankSets = TankSet.parseSets(tankSetsNodes); //if no sets exist, initialize a default set to add all models to if (tankSets.Length == 0) { tankSets = new TankSet[1]; ConfigNode defaultSetNode = new ConfigNode("TANKSET"); defaultSetNode.AddValue("name", "default"); tankSets[0] = new TankSet(defaultSetNode); } mainTankModules = ModelData.parseModels <TankModelData>(tankNodes, m => new TankModelData(m)); int len = mainTankModules.Length; TankSet set; for (int i = 0; i < len; i++) { set = Array.Find(tankSets, m => m.name == mainTankModules[i].setName); //if set is not found by name, add it to the first set which is guaranteed to exist due to the default-set-adding code above. if (set == null) { set = tankSets[0]; } set.addModel(mainTankModules[i]); } len = mountNodes.Length; ConfigNode mountNode; List <SingleModelData> noses = new List <SingleModelData>(); List <SingleModelData> mounts = new List <SingleModelData>(); for (int i = 0; i < len; i++) { mountNode = mountNodes[i]; if (mountNode.GetBoolValue("useForNose", true)) { mountNode.SetValue("nose", "true"); noses.Add(new SingleModelData(mountNode)); } if (mountNode.GetBoolValue("useForMount", true)) { mountNode.SetValue("nose", "false"); mounts.Add(new SingleModelData(mountNode)); } } mountModules = mounts.ToArray(); noseModules = noses.ToArray(); topNodeNames = SSTUUtils.parseCSV(topManagedNodeNames); bottomNodeNames = SSTUUtils.parseCSV(bottomManagedNodeNames); currentMainTankModule = Array.Find(mainTankModules, m => m.name == currentTankType); if (currentMainTankModule == null) { MonoBehaviour.print("ERROR: Could not locate tank type for: " + currentTankType + ". reverting to first available tank type."); currentMainTankModule = mainTankModules[0]; currentTankType = currentMainTankModule.name; } currentTankSetModule = Array.Find(tankSets, m => m.name == currentMainTankModule.setName); currentTankSet = currentTankSetModule.name; lastSelectedVariant = currentMainTankModule.variantName; currentNoseModule = Array.Find(noseModules, m => m.name == currentNoseType); if (currentNoseModule == null) { MonoBehaviour.print("ERROR: Could not locate nose type for: " + currentNoseType + ". reverting to first available nose type."); currentNoseModule = noseModules[0]; currentNoseType = currentNoseModule.name; } currentMountModule = Array.Find(mountModules, m => m.name == currentMountType); if (currentMountModule == null) { MonoBehaviour.print("ERROR: Could not locate mount type for: " + currentMountType + ". reverting to first available mount type."); currentMountModule = mountModules[0]; currentMountType = currentMountModule.name; } if (!currentMainTankModule.isValidTextureSet(currentTankTexture)) { currentTankTexture = currentMainTankModule.getDefaultTextureSet(); } if (!currentNoseModule.isValidTextureSet(currentNoseTexture)) { currentNoseTexture = currentNoseModule.getDefaultTextureSet(); } if (!currentMountModule.isValidTextureSet(currentMountTexture)) { currentMountTexture = currentMountModule.getDefaultTextureSet(); } }
private void findTransforms() { String[] suncatcherNames = SSTUUtils.parseCSV(rayTransforms); String[] pivotNames = SSTUUtils.parseCSV(pivotTransforms); PivotData pd; SuncatcherData sd; int len2; Transform[] trs; String name; List <PivotData> tempPivotData = new List <PivotData>(); int len = pivotNames.Length; for (int i = 0; i < len; i++) { name = pivotNames[i]; if (String.IsNullOrEmpty(name)) { MonoBehaviour.print("ERROR: Empty name for solar pivot for part: " + part); } trs = part.transform.FindChildren(name); len2 = trs.Length; if (len2 == 0) { MonoBehaviour.print("ERROR: Could not locate solar pivot transforms for name: " + name + " for part: " + part); } for (int k = 0; k < len2; k++) { pd = new PivotData(); pd.pivotTransform = trs[k]; pd.defaultOrientation = pd.pivotTransform.localRotation; tempPivotData.Add(pd); } } pivotData = tempPivotData.ToArray(); tempPivotData.Clear(); List <SuncatcherData> tempSunData = new List <SuncatcherData>(); len = suncatcherNames.Length; for (int i = 0; i < len; i++) { name = suncatcherNames[i]; if (String.IsNullOrEmpty(name)) { MonoBehaviour.print("ERROR: Empty name for suncatcher for part: " + part); } trs = part.transform.FindChildren(name); len2 = trs.Length; if (len2 == 0) { MonoBehaviour.print("ERROR: Could not locate suncatcher transforms for name: " + name + " for part: " + part); } for (int k = 0; k < len2; k++) { sd = new SuncatcherData(); sd.suncatcherTransform = trs[k]; tempSunData.Add(sd); } } suncatcherData = tempSunData.ToArray(); Transform t1; if (windBreakTransformName != null && windBreakTransformName.Length > 0) { t1 = part.FindModelTransform(windBreakTransformName); if (t1 != null) { windBreakTransform = t1; } } if (windBreakTransform == null && pivotData.Length > 0) { windBreakTransform = pivotData[0].pivotTransform; }//else it will use default vessel transform }
private void initialize() { if (heatCurve == null) { heatCurve = new FloatCurve(); heatCurve.Add(0, 0.00002f); //very minimal initial ablation factor heatCurve.Add(50, 0.00005f); //ramp it up fairly quickly though heatCurve.Add(150, 0.00015f); heatCurve.Add(500, 0.00050f); heatCurve.Add(750, 0.00075f); heatCurve.Add(1000, 0.00100f); heatCurve.Add(2000, 0.00400f); heatCurve.Add(3000, 0.00800f); //generally, things will explode before this point heatCurve.Add(10000, 0.05000f); //but just in case, continue the curve up to insane levels } double hsp = 1; double dens = 1; if (heatSoak) { PartResourceDefinition resource = PartResourceLibrary.Instance.GetDefinition(resourceName); hsp = resource.specificHeatCapacity; dens = resource.density; } else { resource = part.Resources[resourceName]; if (resource != null) { hsp = resource.info.specificHeatCapacity; dens = resource.info.density; } else { hsp = PhysicsGlobals.StandardSpecificHeatCapacity; dens = 0.005f; } } useToFluxMultiplier = hsp * ablationEfficiency * dens * ablationMult; baseSkinIntMult = part.skinInternalConductionMult; //stand-alone modular heat-shield setup if (standAlonePart) { if (string.IsNullOrEmpty(modelName)) { MonoBehaviour.print("SEVERE ERROR: SSTUModularHeatShield could has no model specified for part: " + part.name); } if (!String.IsNullOrEmpty(transformsToRemove)) { SSTUUtils.removeTransforms(part, SSTUUtils.parseCSV(transformsToRemove)); } shieldTypeNames = SSTUDatabase.getHeatShieldNames(); ConfigNode modelNode = new ConfigNode("MODEL"); modelNode.AddValue("name", modelName); mainModelData = new SingleModelData(modelNode); mainModelData.setupModel(part.transform.FindRecursive("model"), ModelOrientation.CENTRAL, true); setModelDiameter(currentDiameter); updateAttachNodes(false); updateDragCube(); updateEditorFields(); } ConfigNode node = SSTUConfigNodeUtils.parseConfigNode(configNodeData); ConfigNode[] typeNodes = node.GetNodes("SHIELDTYPE"); int len = typeNodes.Length; shieldTypeNames = new string[len]; for (int i = 0; i < len; i++) { shieldTypeNames[i] = typeNodes[i].GetStringValue("name"); } if (shieldTypeNames.Length == 0) { shieldTypeNames = new string[] { "Medium" }; } currentShieldTypeData = SSTUDatabase.getHeatShieldType(currentShieldType); heatCurve = currentShieldTypeData.heatCurve; updatePartCost(); if (!initializedResources && (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight)) { updatePartResources(); initializedResources = true; } }
private void init(bool start) { if (initialized) { return; } initialized = true; topNodeNames = SSTUUtils.parseCSV(topManagedNodes); bottomNodeNames = SSTUUtils.parseCSV(bottomManagedNodes); ConfigNode node = SSTUConfigNodeUtils.parseConfigNode(configNodeData); coreModules = SingleModelData.parseModels(node.GetNodes("CORE")); List <ConfigNode> tops = new List <ConfigNode>(); List <ConfigNode> bottoms = new List <ConfigNode>(); ConfigNode[] mNodes = node.GetNodes("CAP"); ConfigNode mNode; int len = mNodes.Length; for (int i = 0; i < len; i++) { mNode = mNodes[i]; if (mNode.GetBoolValue("useForTop", true)) { tops.Add(mNode); } if (mNode.GetBoolValue("useForBottom", true)) { bottoms.Add(mNode); } } topModules = SingleModelData.parseModels(tops.ToArray()); bottomModules = SingleModelData.parseModels(bottoms.ToArray()); tops.Clear(); bottoms.Clear(); mNodes = node.GetNodes("DOCK"); len = mNodes.Length; for (int i = 0; i < len; i++) { mNode = mNodes[i]; if (mNode.GetBoolValue("useForTop", true)) { tops.Add(mNode); } if (mNode.GetBoolValue("useForBottom", true)) { bottoms.Add(mNode); } } topDockModules = SingleModelData.parseModels(tops.ToArray()); bottomDockModules = SingleModelData.parseModels(bottoms.ToArray()); tops.Clear(); bottoms.Clear(); mNodes = node.GetNodes("SOLAR"); len = mNodes.Length; solarModules = new SolarData[len]; for (int i = 0; i < len; i++) { mNode = mNodes[i]; solarModules[i] = new SolarData(mNode); } topDockModule = SingleModelData.findModel(topDockModules, currentTopDock); topModule = SingleModelData.findModel(topModules, currentTop); coreModule = SingleModelData.findModel(coreModules, currentCore); bottomModule = SingleModelData.findModel(bottomModules, currentBottom); bottomDockModule = SingleModelData.findModel(bottomDockModules, currentBottomDock); solarModule = Array.Find(solarModules, m => m.name == currentSolar);//TODO cleanup //validate selections for sub-modules that may require unlocks if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight) { if (!topDockModule.isAvailable(upgradesApplied)) { topDockModule = Array.Find(topDockModules, m => m.isAvailable(upgradesApplied)); } if (!bottomDockModule.isAvailable(upgradesApplied)) { bottomDockModule = Array.Find(bottomDockModules, m => m.isAvailable(upgradesApplied)); } if (!solarModule.isAvailable(this)) { solarModule = Array.Find(solarModules, m => m.isAvailable(this)); } currentTopDock = topDockModule.name; currentBottomDock = bottomDockModule.name; currentSolar = solarModule.name; } if (!topModule.isValidTextureSet(currentTopTexture)) { currentTopTexture = topModule.getDefaultTextureSet(); } if (!coreModule.isValidTextureSet(currentCoreTexture)) { currentCoreTexture = coreModule.getDefaultTextureSet(); } if (!bottomModule.isValidTextureSet(currentBottomTexture)) { currentBottomTexture = bottomModule.getDefaultTextureSet(); } restoreModels(); updateModulePositions(); updateMass(); updateCost(); updateAttachNodes(false); if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight) { ModuleDockingNode[] mdns = part.GetComponents <ModuleDockingNode>(); if (mdns.Length > 0) { if (topDockModule.model != null) { topDockPartModule = mdns[0]; } if (bottomDockModule.model != null) { bottomDockPartModule = mdns.Length > 1 ? mdns[1] : mdns[0]; } } updateDockingModules(start); } //resources are updated in Start(), to ensure that the dependent modules have loaded }
//creates/recreates FairingData instances from data from config node and any persistent node (if applicable) private void loadFairingData(ConfigNode node) { recolorHandler = new RecoloringHandler(Fields[nameof(customColorData)]); ConfigNode[] fairingNodes = node.GetNodes("FAIRING"); fairingParts = new SSTUNodeFairingData[fairingNodes.Length]; Transform modelBase = part.transform.FindRecursive("model"); Transform parent; SSTUNodeFairing[] cs = part.GetComponents <SSTUNodeFairing>(); int l = Array.IndexOf(cs, this); int moduleIndex = l; for (int i = 0; i < fairingNodes.Length; i++) { parent = modelBase.FindOrCreate(fairingName + "-" + moduleIndex + "-" + i); fairingParts[i] = new SSTUNodeFairingData(); fairingParts[i].load(fairingNodes[i], parent.gameObject); if (fairingParts[i].canAdjustTop) { enableTopDiameterControls = true; if (guiTopDiameter < 0) { guiTopDiameter = fairingParts[i].topRadius * 2f; } else { fairingParts[i].topRadius = guiTopDiameter * 0.5f; } } if (fairingParts[i].canAdjustBottom) { enableBottomDiameterControls = true; if (guiBottomDiameter < 0) { guiBottomDiameter = fairingParts[i].bottomRadius * 2f; } else { fairingParts[i].bottomRadius = guiBottomDiameter * 0.5f; } } } //reload fairing data from persistence; //it -should- already match the guiTopDiameter/guiBottomDiameter (or else was already corrupted/invalid when saved out). if (!String.IsNullOrEmpty(persistentDataString)) { String[] datas = SSTUUtils.parseCSV(persistentDataString, ":"); int length = datas.Length; for (int i = 0; i < length; i++) { fairingParts[i].loadPersistence(datas[i]); } } ConfigNode[] textureNodes = node.GetNodes("TEXTURESET"); string[] names = TextureSet.getTextureSetNames(textureNodes); string[] titles = TextureSet.getTextureSetTitles(textureNodes); TextureSet t = KSPShaderLoader.getTextureSet(currentTextureSet); if (t == null) { currentTextureSet = names[0]; t = KSPShaderLoader.getTextureSet(currentTextureSet); initializedColors = false; } if (!initializedColors) { initializedColors = true; recolorHandler.setColorData(t.maskColors); } this.updateUIChooseOptionControl(nameof(currentTextureSet), names, titles, true, currentTextureSet); fairingMaterial = t.textureData[0].createMaterial("SSTUFairingMaterial"); }
private void initialize(bool start) { if (initialized) { return; } initialized = true; topNodeNames = SSTUUtils.parseCSV(topManagedNodes); bottomNodeNames = SSTUUtils.parseCSV(bottomManagedNodes); ConfigNode node = SSTUConfigNodeUtils.parseConfigNode(configNodeData); coreModule = new ModelModule <ServiceModuleCoreModel, SSTUModularServiceModule>(part, this, getRootTransform("MSC-CORE", true), ModelOrientation.TOP, nameof(coreModulePersistentData), nameof(currentCore), nameof(currentCoreTexture)); coreModule.getSymmetryModule = m => m.coreModule; coreModule.setupModelList(ModelData.parseModels(node.GetNodes("CORE"), m => new ServiceModuleCoreModel(m))); topModule = new ModelModule <SingleModelData, SSTUModularServiceModule>(part, this, getRootTransform("MSC-TOP", true), ModelOrientation.TOP, nameof(topModulePersistentData), nameof(currentTop), nameof(currentTopTexture)); topModule.getSymmetryModule = m => m.topModule; topModule.getValidSelections = m => topModule.models.FindAll(s => s.canSwitchTo(part, topNodeNames)); bottomModule = new ModelModule <SingleModelData, SSTUModularServiceModule>(part, this, getRootTransform("MSC-BOTTOM", true), ModelOrientation.BOTTOM, nameof(bottomModulePersistentData), nameof(currentBottom), nameof(currentBottomTexture)); bottomModule.getSymmetryModule = m => m.bottomModule; bottomModule.getValidSelections = m => bottomModule.models.FindAll(s => s.canSwitchTo(part, bottomNodeNames)); solarModule = new ModelModule <SolarData, SSTUModularServiceModule>(part, this, getRootTransform("MSC-Solar", true), ModelOrientation.CENTRAL, null, nameof(currentSolar), null); solarModule.getSymmetryModule = m => m.solarModule; solarModule.setupModelList(ModelData.parseModels(node.GetNodes("SOLAR"), m => new SolarData(m))); solarModule.getValidSelections = delegate(IEnumerable <SolarData> all) { //System.Linq.Enumerable.Where(all, s => s.isAvailable(upgradesApplied)); float scale = coreModule.model.currentDiameterScale; //find all solar panels that are unlocked via upgrades/tech-tree List <SolarData> unlocked = solarModule.models.FindAll(s => s.isAvailable(upgradesApplied)); //filter those to find only the ones available for the current List <SolarData> availableByScale = unlocked.FindAll(s => coreModule.model.isValidSolarOption(s.name, scale)); return(availableByScale); }; solarModule.preModelSetup = delegate(SolarData d) { d.positions = coreModule.model.getPanelConfiguration(d.name).getScaledPositions(coreModule.model.currentDiameterScale); }; rcsModule = new ModelModule <ServiceModuleRCSModelData, SSTUModularServiceModule>(part, this, getRootTransform("MSC-Rcs", true), ModelOrientation.CENTRAL, null, nameof(currentRCS), null); rcsModule.getSymmetryModule = m => m.rcsModule; rcsModule.setupModelList(ModelData.parseModels(node.GetNodes("RCS"), m => new ServiceModuleRCSModelData(m))); rcsModule.getValidSelections = m => rcsModule.models.FindAll(s => s.isAvailable(upgradesApplied)); List <ConfigNode> tops = new List <ConfigNode>(); List <ConfigNode> bottoms = new List <ConfigNode>(); ConfigNode[] mNodes = node.GetNodes("CAP"); ConfigNode mNode; int len = mNodes.Length; for (int i = 0; i < len; i++) { mNode = mNodes[i]; if (mNode.GetBoolValue("useForTop", true)) { tops.Add(mNode); } if (mNode.GetBoolValue("useForBottom", true)) { bottoms.Add(mNode); } } topModule.setupModelList(SingleModelData.parseModels(tops.ToArray())); bottomModule.setupModelList(SingleModelData.parseModels(bottoms.ToArray())); tops.Clear(); bottoms.Clear(); topModule.setupModel(); coreModule.setupModel(); coreModule.model.updateScaleForDiameter(currentDiameter); bottomModule.setupModel(); solarModule.setupModel(); rcsModule.setupModel(); rcsModule.model.renameThrustTransforms(rcsThrustTransformName); updateModulePositions(); updateMassAndCost(); updateAttachNodes(false); SSTUStockInterop.updatePartHighlighting(part); }
/// <summary> /// Restores ModelData instances from config node data, and populates the 'currentModule' instances with the currently enabled modules. /// </summary> private void loadConfigData() { ConfigNode node = SSTUConfigNodeUtils.parseConfigNode(configNodeData); ConfigNode[] tankSetsNodes = node.GetNodes("TANKSET"); ConfigNode[] tankNodes = node.GetNodes("TANK"); ConfigNode[] mountNodes = node.GetNodes("CAP"); variantData = TankVariant.parseVariants(node.GetNodes("VARIANT")); tankSets = TankSet.parseSets(tankSetsNodes); //if no sets exist, initialize a default set to add all models to if (tankSets.Length == 0) { tankSets = new TankSet[1]; ConfigNode defaultSetNode = new ConfigNode("TANKSET"); defaultSetNode.AddValue("name", "default"); tankSets[0] = new TankSet(defaultSetNode); } TankModelData[] mainTankModules = ModelData.parseModels <TankModelData>(tankNodes, m => new TankModelData(m)); int len = mainTankModules.Length; TankSet set; for (int i = 0; i < len; i++) { set = Array.Find(tankSets, m => m.name == mainTankModules[i].setName); //if set is not found by name, add it to the first set which is guaranteed to exist due to the default-set-adding code above. if (set == null) { set = tankSets[0]; } set.addModel(mainTankModules[i]); } topNodeNames = SSTUUtils.parseCSV(topManagedNodeNames); bottomNodeNames = SSTUUtils.parseCSV(bottomManagedNodeNames); tankModule = new ModelModule <TankModelData, SSTUModularFuelTank>(part, this, getRootTransform(rootTransformName, true), ModelOrientation.CENTRAL, nameof(bodyModuleData), nameof(currentTankType), nameof(currentTankTexture)); tankModule.getSymmetryModule = m => m.tankModule; tankModule.getDisplayNames = m => SSTUUtils.getNames(m, s => s.variantName); tankModule.setupModelList(mainTankModules); currentTankSetModule = Array.Find(tankSets, m => m.name == tankModule.model.setName); currentTankSet = currentTankSetModule.name; lastSelectedVariant = tankModule.model.variantName; tankModule.getValidSelections = delegate(IEnumerable <TankModelData> data) { return(System.Linq.Enumerable.Where(data, s => s.setName == currentTankSet)); }; tankModule.updateSelections(); tankModule.setupModel(); len = mountNodes.Length; ConfigNode mountNode; List <SingleModelData> noses = new List <SingleModelData>(); List <SingleModelData> mounts = new List <SingleModelData>(); for (int i = 0; i < len; i++) { mountNode = mountNodes[i]; if (mountNode.GetBoolValue("useForNose", true)) { mountNode.SetValue("nose", "true"); noses.Add(new SingleModelData(mountNode)); } if (mountNode.GetBoolValue("useForMount", true)) { mountNode.SetValue("nose", "false"); mounts.Add(new SingleModelData(mountNode)); } } noseModule = new ModelModule <SingleModelData, SSTUModularFuelTank>(part, this, getRootTransform(rootNoseTransformName, true), ModelOrientation.TOP, nameof(noseModuleData), nameof(currentNoseType), nameof(currentNoseTexture)); noseModule.getSymmetryModule = m => m.noseModule; noseModule.getValidSelections = delegate(IEnumerable <SingleModelData> data) { return(System.Linq.Enumerable.Where(data, m => m.canSwitchTo(part, topNodeNames) && TankVariant.isValidNose(m.name, tankModule.model.variantName, variantData))); }; noseModule.setupModelList(noses); noseModule.setupModel(); mountModule = new ModelModule <SingleModelData, SSTUModularFuelTank>(part, this, getRootTransform(rootMountTransformName, true), ModelOrientation.BOTTOM, nameof(mountModuleData), nameof(currentMountType), nameof(currentMountTexture)); mountModule.getSymmetryModule = m => m.mountModule; mountModule.getValidSelections = delegate(IEnumerable <SingleModelData> data) { return(System.Linq.Enumerable.Where(data, m => m.canSwitchTo(part, bottomNodeNames) && TankVariant.isValidMount(m.name, tankModule.model.variantName, variantData))); }; mountModule.setupModelList(mounts); mountModule.setupModel(); }
private void initialize(bool start) { if (initialized) { return; } initialized = true; topNodeNames = SSTUUtils.parseCSV(topManagedNodes); bottomNodeNames = SSTUUtils.parseCSV(bottomManagedNodes); ConfigNode node = SSTUConfigNodeUtils.parseConfigNode(configNodeData); coreModule = new ModelModule <SingleModelData, SSTUModularStationCore>(part, this, getRootTransform("MSC-CORE", true), ModelOrientation.TOP, nameof(coreModulePersistentData), nameof(currentCore), nameof(currentCoreTexture)); coreModule.getSymmetryModule = m => m.coreModule; coreModule.setupModelList(SingleModelData.parseModels(node.GetNodes("CORE"))); topModule = new ModelModule <SingleModelData, SSTUModularStationCore>(part, this, getRootTransform("MSC-TOP", true), ModelOrientation.TOP, nameof(topModulePersistentData), nameof(currentTop), nameof(currentTopTexture)); topModule.getSymmetryModule = m => m.topModule; topModule.getValidSelections = m => topModule.models.FindAll(s => s.canSwitchTo(part, topNodeNames)); bottomModule = new ModelModule <SingleModelData, SSTUModularStationCore>(part, this, getRootTransform("MSC-BOTTOM", true), ModelOrientation.BOTTOM, nameof(bottomModulePersistentData), nameof(currentBottom), nameof(currentBottomTexture)); bottomModule.getSymmetryModule = m => m.bottomModule; bottomModule.getValidSelections = m => bottomModule.models.FindAll(s => s.canSwitchTo(part, bottomNodeNames)); solarModule = new ModelModule <SolarData, SSTUModularStationCore>(part, this, getRootTransform("MSC-Solar", true), ModelOrientation.CENTRAL, null, nameof(currentSolar), null); solarModule.getSymmetryModule = m => m.solarModule; solarModule.setupModelList(SingleModelData.parseModels(node.GetNodes("SOLAR"), m => new SolarData(m))); solarModule.getValidSelections = m => solarModule.models.FindAll(s => s.isAvailable(upgradesApplied)); List <ConfigNode> tops = new List <ConfigNode>(); List <ConfigNode> bottoms = new List <ConfigNode>(); ConfigNode[] mNodes = node.GetNodes("CAP"); ConfigNode mNode; int len = mNodes.Length; for (int i = 0; i < len; i++) { mNode = mNodes[i]; if (mNode.GetBoolValue("useForTop", true)) { tops.Add(mNode); } if (mNode.GetBoolValue("useForBottom", true)) { bottoms.Add(mNode); } } topModule.setupModelList(SingleModelData.parseModels(tops.ToArray())); bottomModule.setupModelList(SingleModelData.parseModels(bottoms.ToArray())); tops.Clear(); bottoms.Clear(); topModule.setupModel(); coreModule.setupModel();//TODO -- only setup core module if not the prefab part -- else need to add transform updating/fx-updating for RCS and engine modules, as they lack proper handling for transform swapping at runtime bottomModule.setupModel(); solarModule.setupModel(); updateModulePositions(); updateMassAndCost(); updateAttachNodes(false); SSTUStockInterop.updatePartHighlighting(part); }