示例#1
0
 /// <summary>
 /// Updates the current fuel type from user input
 /// </summary>
 /// <param name="newFuelType"></param>
 private void updateFuelTypeFromEditor(FuelTypeData newFuelType)
 {
     currentFuelTypeData = newFuelType;
     currentFuelType = newFuelType.name;
     updateTankStats();
     updatePartResources();
     updateGuiState();
 }
示例#2
0
 private void setFuelTypeFromEditor(FuelTypeData newFuelType, bool updateSymmetry)
 {
     if (!canChangeFuelType()) { return; }
     currentFuelTypeData = newFuelType;
     currentFuelType = currentFuelTypeData.name;
     updateTankStats();
     updatePartResources();
     if (updateSymmetry)
     {
         SSTUModularFuelTank tank = null;
         foreach (Part p in part.symmetryCounterparts)
         {
             tank = p.GetComponent<SSTUModularFuelTank>();
             if (tank == null) { continue; }
             tank.setFuelTypeFromEditor(Array.Find(tank.fuelTypes, m => m.name==currentFuelType), false);
         }
     }
 }
示例#3
0
        /// <summary>
        /// Loads all of the part definitions and values from the stashed config node data
        /// </summary>
        private void loadConfigData()
        {
            ConfigNode node = SSTUConfigNodeUtils.parseConfigNode(configNodeData);

            fuelTypes = FuelTypeData.parseFuelTypeData(node.GetNodes("FUELTYPE"));
            currentFuelTypeData = Array.Find(fuelTypes, l => l.name == currentFuelType);
            if (currentFuelTypeData == null)
            {
                MonoBehaviour.print("ERROR: Could not locate fuel type for: " + currentFuelType + ". reverting to default fuel type of: " + defaultFuelType);
                currentFuelType = defaultFuelType;
                currentFuelTypeData = Array.Find(fuelTypes, l => l.name == currentFuelType);
                initializedResources = false;
            }
            reserveFuelTypeData = FuelTypes.INSTANCE.getFuelTypeData(reserveFuelType);

            //mandatory nodes, -all- tank types must have these
            ConfigNode tankUpperNode = node.GetNode("TANKUPPER");
            ConfigNode upperTopCapNode = node.GetNode("TANKUPPERTOPCAP");
            ConfigNode upperBottomCapNode = node.GetNode("TANKUPPERBOTTOMCAP");
            ConfigNode[] limitNodes = node.GetNodes("TECHLIMIT");

            ConfigNode rcsNode = node.GetNode("RCS");
            ConfigNode[] mountNodes = node.GetNodes("MOUNT");

            upperModule = new SingleModelData(tankUpperNode);
            upperTopCapModule = new SingleModelData(upperTopCapNode);
            upperBottomCapModule = new SingleModelData(upperBottomCapNode);
            rcsModule = new SSTUCustomUpperStageRCS(rcsNode);

            //load mount configs
            int len = mountNodes.Length;
            mountModules = new MountModelData[len];
            for (int i = 0; i < len; i++)
            {
                mountModules[i] = new MountModelData(mountNodes[i]);
            }
            currentMountModule = Array.Find(mountModules, l => l.name == currentMount);

            if (splitTank)
            {
                //fields that are only populated by split-tank type upper-stages
                ConfigNode tankLowerNode = node.GetNode("TANKLOWER");
                ConfigNode lowerBottomCapNode = node.GetNode("TANKLOWERBOTTOMCAP");
                ConfigNode[] intertankNodes = node.GetNodes("INTERTANK");
                lowerModule = new SingleModelData(tankLowerNode);
                lowerBottomCapModule = new SingleModelData(lowerBottomCapNode);
                //load intertank configs
                len = intertankNodes.Length;
                intertankModules = new SingleModelData[len];
                for (int i = 0; i < len; i++)
                {
                    intertankModules[i] = new SingleModelData(intertankNodes[i]);
                }
                currentIntertankModule = Array.Find(intertankModules, l => l.name == currentIntertank);
            }

            len = limitNodes.Length;
            techLimits = new TechLimitHeightDiameter[len];
            for (int i = 0; i < len; i++) { techLimits[i] = new TechLimitHeightDiameter(limitNodes[i]); }
        }
示例#4
0
        /// <summary>
        /// Restores SSTUCustomFuelTankPart instances from config node data, and populates the 'currentModule' instances with the currently selected module.
        /// </summary>
        private void loadConfigData()
        {
            ConfigNode node = SSTUNodeUtils.parseConfigNode(configNodeData);
            ConfigNode[] tankNodes = node.GetNodes("TANK");
            ConfigNode[] mountNodes = node.GetNodes("CAP");
            ConfigNode[] fuelNodes = node.GetNodes("FUELTYPE");
            ConfigNode[] limitNodes = node.GetNodes("TECHLIMIT");
            ConfigNode[] textureNodes = node.GetNodes("TEXTURESET");

            int len = tankNodes.Length;
            mainTankModules = new SingleModelData[len];
            for (int i = 0; i < len; i++) { mainTankModules[i] = new SingleModelData(tankNodes[i]); }
            
            len = mountNodes.Length;
            ConfigNode mountNode;
            List<CustomFuelTankMount> noses = new List<CustomFuelTankMount>();
            List<CustomFuelTankMount> mounts = new List<CustomFuelTankMount>();
            for (int i = 0; i < len; i++)
            {
                mountNode = mountNodes[i];
                if (mountNode.GetBoolValue("useForNose", true))
                {
                    noses.Add(new CustomFuelTankMount(mountNode, true));
                }
                if (mountNode.GetBoolValue("useForMount", true))
                {
                    mounts.Add(new CustomFuelTankMount(mountNode, false));
                }
            }
            mountModules = mounts.ToArray();
            noseModules = noses.ToArray();

            len = fuelNodes.Length;
            fuelTypes = new FuelTypeData[len];
            for (int i = 0; i < len; i++) { fuelTypes[i] = new FuelTypeData(fuelNodes[i]); }

            len = limitNodes.Length;
            techLimits = new TechLimitHeightDiameter[len];
            for (int i = 0; i < len; i++) { techLimits[i] = new TechLimitHeightDiameter(limitNodes[i]); }

            len = textureNodes.Length;
            textureSets = new TextureSet[len];
            for (int i = 0; i < len; i++)
            {
                textureSets[i] = TextureSets.INSTANCE.getTextureSet(textureNodes[i].GetStringValue("name"));
            }

            topNodeNames = SSTUUtils.parseCSV(topManagedNodeNames);
            bottomNodeNames = SSTUUtils.parseCSV(bottomManagedNodeNames);
        }
示例#5
0
 /// <summary>
 /// If tank is uninitialized (no current tank type), will load the default values for tank type/diameter/nose/mount/fuel type into the 'current' slots.
 /// Will populate the 'currentModuleX' slot with the module for the loaded current-name
 /// </summary>
 private void loadTankModules()
 {
     currentMainTankModule = Array.Find(mainTankModules, m => m.name == currentTankType);
     currentNoseModule = Array.Find(noseModules, m => m.name == currentNoseType);
     currentMountModule = Array.Find(mountModules, m => m.name == currentMountType);
     currentFuelTypeData = Array.Find(fuelTypes, m => m.name == currentFuelType);
     if (currentFuelTypeData == null)
     {
         MonoBehaviour.print("ERROR: Could not locate fuel type for: " + currentFuelType + ". reverting to default fuel type of: " + defaultFuelType);
         currentFuelType = defaultFuelType;
         currentFuelTypeData = Array.Find(fuelTypes, m => m.name == currentFuelType);
         initializedResources = false;
     }
 }
示例#6
0
        /// <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[] 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();

            fuelTypes = FuelTypeData.parseFuelTypeData(fuelNodes);

            len = limitNodes.Length;
            techLimits = TechLimitHeightDiameter.loadTechLimits(limitNodes);

            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;
            }

            currentFuelTypeData = Array.Find(fuelTypes, m => m.name == currentFuelType);
            if (currentFuelTypeData == null)
            {
                MonoBehaviour.print("ERROR: Could not locate fuel type for: " + currentFuelType + ". reverting to first available fuel type.");
                FuelTypeData d = fuelTypes[0];
                currentFuelType = d.name;
                currentFuelTypeData = d;
                initializedResources = false;
            }
            if (!currentMainTankModule.isValidTextureSet(currentTankTexture))
            {
                currentTankTexture = currentMainTankModule.modelDefinition.defaultTextureSet;
            }
            if (!currentNoseModule.isValidTextureSet(currentNoseTexture))
            {
                currentNoseTexture = currentNoseModule.modelDefinition.defaultTextureSet;
            }
            if (!currentMountModule.isValidTextureSet(currentMountTexture))
            {
                currentMountTexture = currentMountModule.modelDefinition.defaultTextureSet;
            }
        }
示例#7
0
 public static FuelTypeData[] parseFuelTypeData(ConfigNode[] nodes)
 {
     int len = nodes.Length;
     FuelTypeData[] array = new FuelTypeData[len];
     for (int i = 0; i < len; i++)
     {
         array[i] = new FuelTypeData(nodes[i]);
     }
     return array;
 }
示例#8
0
        /// <summary>
        /// Loads the current configuration from the cached persistent config node data
        /// </summary>
        private void loadConfigNodeData()
        {
            ConfigNode node = SSTUConfigNodeUtils.parseConfigNode(configNodeData);

            //load singular fuel type data from config node;
            //using a node so that it may have the custom fields defined for mass fraction/etc on a per-part basis
            fuelTypeData = new FuelTypeData(node.GetNode("FUELTYPE"));

            //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.modelDefinition.defaultTextureSet; }

            //load nose modules from NOSE nodes
            ConfigNode[] noseNodes = node.GetNodes("NOSE");
            ConfigNode noseNode;
            int length = noseNodes.Length;
            List<MountModelData> noseModulesTemp = new List<MountModelData>();
            for (int i = 0; i < length; i++)
            {
                noseNode = noseNodes[i];
                noseModulesTemp.Add(new MountModelData(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.modelDefinition.defaultTextureSet; }

            //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.modelDefinition.defaultTextureSet; }

            //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(part, parentTransform, ModelOrientation.TOP);
            currentNozzleModule.setupModel(part, parentTransform, ModelOrientation.BOTTOM);
            currentMainModule.setupModel(part, 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));
        }