public static bool isValidMount(string name, string variantName, TankVariant[] variantData) { TankVariant v = Array.Find(variantData, m => m.name == variantName); if (v != null) { return(v.isValidMount(name)); } return(true); }
public static TankVariant[] parseVariants(ConfigNode[] nodes) { int len = nodes.Length; TankVariant[] vs = new TankVariant[len]; for (int i = 0; i < len; i++) { vs[i] = new TankVariant(nodes[i]); } return(vs); }
/// <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(); }