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;
         }
     }
 }
Exemple #2
0
        private void initialize()
        {
            meshes = part.transform.FindChildren(decalMeshName);
            ConfigNode node = SSTUStockInterop.getPartModuleConfig(part, this);

            ConfigNode[] decalNodes = node.GetNodes("DECAL");
            int          len        = decalNodes.Length;

            possibleDecals = new SSTUDecal[len];
            for (int i = 0; i < len; i++)
            {
                possibleDecals[i] = new SSTUDecal(decalNodes[i]);
            }
            SSTUDecal currentDecalObj = Array.Find(possibleDecals, m => m.name == currentDecal);

            if (currentDecalObj == null && len > 0)
            {
                currentDecalObj = possibleDecals[0];
                currentDecal    = currentDecalObj.name;
            }
            else if (currentDecalObj == null)
            {
                MonoBehaviour.print("ERROR: NO decals found to load for part: " + part.name);
            }
            foreach (Transform mesh in meshes)
            {
                currentDecalObj.enable(mesh);
            }
        }
Exemple #3
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            mpf = part.GetComponent <ModuleProceduralFairing>();
            ConfigNode node = SSTUStockInterop.getPartModuleConfig(part, this);

            textureSets = TextureSet.loadTextureSets(node.GetNodes("TEXTURESET"));
            int len = textureSets.Length;

            string[] textureSetNames = new string[len];
            for (int i = 0; i < len; i++)
            {
                textureSetNames[i] = textureSets[i].setName;
            }
            this.updateUIChooseOptionControl("currentTextureSet", textureSetNames, textureSetNames, true, currentTextureSet);
            techLimitMaxDiameter = SSTUStockInterop.getTechLimit(techLimitSet);
            if (currentDiameter > techLimitMaxDiameter)
            {
                currentDiameter = techLimitMaxDiameter;
            }
            updateModelScale();
            updateTexture(currentTextureSet);
            updateNodePositions(false);
            float max = techLimitMaxDiameter < maxDiameter ? techLimitMaxDiameter : maxDiameter;

            this.updateUIFloatEditControl("currentDiameter", minDiameter, max, diameterIncrement * 2f, diameterIncrement, diameterIncrement * 0.05f, true, currentDiameter);
            Fields["currentDiameter"].uiControlEditor.onFieldChanged   = onDiameterUpdated;
            Fields["currentTextureSet"].uiControlEditor.onFieldChanged = onTextureUpdated;
            Fields["currentTextureSet"].guiActiveEditor = textureSets.Length > 1;
            updateEditorFields();
        }
        private void loadConfigData()
        {
            ConfigNode node = SSTUStockInterop.getPartModuleConfig(part, this);

            ConfigNode[] textureNodes = node.GetNodes("TEXTURESET");
            int          len          = textureNodes.Length;

            textureSetData = new TextureSet[len];
            for (int i = 0; i < len; i++)
            {
                textureSetData[i] = new TextureSet(textureNodes[i]);
            }
            currentTextureSetData = Array.Find(textureSetData, m => m.setName == currentTextureSet);
            if (currentTextureSetData == null)
            {
                currentTextureSetData = textureSetData[0];
                currentTextureSet     = currentTextureSetData.setName;
            }
            string[] textureSetNames = new string[len];
            for (int i = 0; i < len; i++)
            {
                textureSetNames[i] = textureSetData[i].setName;
            }
            this.updateUIChooseOptionControl("currentTextureSet", textureSetNames, textureSetNames, true, currentTextureSet);

            techLimitMaxDiameter = SSTUStockInterop.getTechLimit(techLimitSet);
            if (diameter > techLimitMaxDiameter)
            {
                diameter = techLimitMaxDiameter;
            }
        }
Exemple #5
0
 private void initialize()
 {
     if (initialized)
     {
         return;
     }
     initialized = true;
     loadConfigData(SSTUStockInterop.getPartModuleConfig(part, this));
     setState(state);
 }
Exemple #6
0
        private void initialize()
        {
            constraints.Clear();
            ConfigNode node = SSTUStockInterop.getPartModuleConfig(part, this);

            ConfigNode[] lookConstraintNodes = node.GetNodes("LOOK_CONST");
            foreach (ConfigNode lcn in lookConstraintNodes)
            {
                loadLookConstraint(lcn);
            }

            ConfigNode[] lockedConstraintNodes = node.GetNodes("LOCKED_CONST");
            foreach (ConfigNode lcn in lockedConstraintNodes)
            {
                loadLockedConstraint(lcn);
            }
            updateConstraints();
        }
Exemple #7
0
        private void initialize()
        {
            ConfigNode node = SSTUStockInterop.getPartModuleConfig(part, this);

            ConfigNode[] animNodes = node.GetNodes("ANIMATION");
            int          len       = animNodes.Length;

            ConfigNode[] allNodes = null;
            if (!String.IsNullOrEmpty(animationName))
            {
                allNodes = new ConfigNode[len + 1];
                for (int i = 0; i < len; i++)
                {
                    allNodes[i] = animNodes[i];
                }
                ConfigNode legacyNode = new ConfigNode("ANIMATION");
                legacyNode.AddValue("name", animationName);
                legacyNode.AddValue("speed", animationSpeed);
                legacyNode.AddValue("layer", animationLayer);
                allNodes[len] = legacyNode;
            }
            else
            {
                allNodes = animNodes;
            }

            controller = new AnimationController();
            SSTUAnimData animationData;

            len = allNodes.Length;
            for (int i = 0; i < len; i++)
            {
                animationData = new SSTUAnimData(allNodes[i], part.gameObject.transform);
                controller.addAnimationData(animationData);
            }
            AnimState prevState = (AnimState)Enum.Parse(typeof(AnimState), persistentState);

            controller.restorePreviousAnimationState(prevState);
            controller.setStateChangeCallback(onAnimationStateChange);
        }
        private void loadConfigData()
        {
            ConfigNode node = SSTUStockInterop.getPartModuleConfig(this);

            ConfigNode[] containerNodes = node.GetNodes("CONTAINER");
            int          len            = containerNodes.Length;

            containers = new ContainerDefinition[len];
            for (int i = 0; i < len; i++)
            {
                containers[i] = new ContainerDefinition(containerNodes[i], volume);
            }
            if (!string.IsNullOrEmpty(persistentData))
            {
                string[] splits = persistentData.Split(':');
                len = containers.Length;
                for (int i = 0; i < len && i < splits.Length; i++)
                {
                    containers[i].loadPersistenData(splits[i]);
                }
            }
            prevFuelType = getBaseContainer().fuelPreset;
        }
Exemple #9
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 = 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);
        }
        private void loadRecipeFromSavedConfigString()
        {
            ConfigNode moduleNode = SSTUStockInterop.getPartModuleConfig(part, this);

            loadRecipeFromNode(moduleNode);
        }
Exemple #11
0
        /// <summary>
        /// Initialize this module - load config data, restore persistent data, setup gui fields
        /// </summary>
        private void initialize()
        {
            ConfigNode node = SSTUStockInterop.getPartModuleConfig(this);

            if (node.HasValue("controlledNode"))
            {
                controlledNodes = node.GetStringValues("controlledNode");
            }
            //load model groups, initializing a default 'Main' group if none are defined
            ConfigNode[] groupNodes = node.GetNodes("GROUP");
            int          len        = groupNodes.Length;

            if (len == 0)//create default group
            {
                len           = 1;
                groupNodes    = new ConfigNode[1];
                groupNodes[0] = new ConfigNode("GROUP");
                groupNodes[0].AddValue("name", "Main");
            }
            modelGroups = new ModelSwitchGroup[len];
            ModelSwitchGroup group;

            for (int i = 0; i < len; i++)
            {
                group          = new ModelSwitchGroup(groupNodes[i], this);
                modelGroups[i] = group;
                groupsByName.Add(group.name, group);
            }

            //load model definitions, initializing them with the model group
            ConfigNode[] modelNodes = node.GetNodes("MODEL");
            len       = modelNodes.Length;
            modelData = new ModelSwitchData[len];
            string groupName;

            for (int i = 0; i < len; i++)
            {
                groupName    = modelNodes[i].GetStringValue("group", "Main");
                modelData[i] = new ModelSwitchData(modelNodes[i], part, groupsByName[groupName]);
            }

            //pre-initialize model groups; this sets up their parent/children relations and loads default enabled/disabled status into the model definitions
            len = modelGroups.Length;
            for (int i = 0; i < len; i++)
            {
                modelGroups[i].preInitialize();
            }

            //load persistent data for groups; this will restore the settings for enabled/disabled for each model definition
            string data = persistentConfigData;

            if (!string.IsNullOrEmpty(data))
            {
                string[] split = data.Split(':');
                len = split.Length;
                for (int i = 0; i < len; i++)
                {
                    modelGroups[i].load(split[i]);
                }
            }

            //initialize root model groups; they will recursively enable children if they should be enabled
            len = modelGroups.Length;
            for (int i = 0; i < len; i++)
            {
                modelGroups[i].initializeRoot();
            }

            //update persistent data to the currently setup state; this updates the persistent data for a freshly-initialized part
            updatePersistentData();

            //mass, attach node, and drag cube updating
            updateMassAndCost();
            updateAttachNodes(false);
            updateDragCube();

            //initialize gui selection field to the first available group
            guiGroupSelection = Array.Find(modelGroups, m => m.isAvailable()).name;

            //update ui option arrays for the given group and its current model
            updateGui();

            //setup ui callbacks for group/model changed
            Fields["guiGroupSelection"].uiControlEditor.onFieldChanged = onGroupUpdated;
            Fields["guiModelSelection"].uiControlEditor.onFieldChanged = onModelUpdated;
        }
Exemple #12
0
        private void initialize()
        {
            if (initialized)
            {
                return;
            }
            initialized = true;
            ConfigNode node = SSTUStockInterop.getPartModuleConfig(part, this);

            ConfigNode[] textureNodes = node.GetNodes("TEXTURESET");
            textureSetData        = TextureSet.loadTextureSets(textureNodes);
            currentTextureSetData = Array.Find(textureSetData, m => m.setName == currentTextureSet);
            if (currentTextureSetData == null)
            {
                currentTextureSetData = textureSetData[0];
                currentTextureSet     = currentTextureSetData.setName;
            }

            int len = textureSetData.Length;

            string[] textureSetNames = new string[len];
            for (int i = 0; i < len; i++)
            {
                textureSetNames[i] = textureSetData[i].setName;
            }
            this.updateUIChooseOptionControl("currentTextureSet", textureSetNames, textureSetNames, true, currentTextureSet);

            TextureData data = currentTextureSetData.textureDatas[0];

            fairingMaterial = SSTUUtils.loadMaterial(data.diffuseTextureName, null, "KSP/Specular");

            loadMaterial();

            techLimitMaxDiameter = SSTUStockInterop.getTechLimit(techLimitSet);
            if (topDiameter > techLimitMaxDiameter)
            {
                topDiameter = techLimitMaxDiameter;
            }
            if (bottomDiameter > techLimitMaxDiameter)
            {
                bottomDiameter = techLimitMaxDiameter;
            }

            Transform tr = part.transform.FindRecursive("model").FindOrCreate("PetalAdapterRoot");

            fairingBase = new InterstageFairingContainer(tr.gameObject, cylinderSides, numberOfPanels, wallThickness);
            UVMap uvs = UVMap.GetUVMapGlobal(uvMap);

            fairingBase.outsideUV = uvs.getArea("outside");
            fairingBase.insideUV  = uvs.getArea("inside");
            fairingBase.edgesUV   = uvs.getArea("edges");

            rebuildFairing(false);//will create fairing using default / previously saved fairing configuration
            restoreEditorFields();
            setPanelRotations(currentRotation);
            if (panelsJettisoned)
            {
                fairingBase.destroyExistingPanels();
            }
            updateGuiState();
        }
        private void loadConfigData()
        {
            ConfigNode node = SSTUStockInterop.getPartModuleConfig(part, this);

            textureSets = TextureSet.loadTextureSets(node.GetNodes("TEXTURESET"));
        }
Exemple #14
0
        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));
                }

                techLimitMaxDiameter = SSTUStockInterop.getTechLimit(techLimitSet);
                if (currentDiameter > techLimitMaxDiameter)
                {
                    currentDiameter = techLimitMaxDiameter;
                }
                shieldTypeNames = SSTUDatabase.getHeatShieldNames();

                ConfigNode modelNode = new ConfigNode("MODEL");
                modelNode.AddValue("name", modelName);
                mainModelData = new SingleModelData(modelNode);
                mainModelData.setupModel(part, part.transform.FindRecursive("model"), ModelOrientation.CENTRAL, true);
                setModelDiameter(currentDiameter);
                updateAttachNodes(false);
                updateDragCube();
                updateEditorFields();
            }

            ConfigNode node = SSTUStockInterop.getPartModuleConfig(this);

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