Ejemplo n.º 1
0
 //called from the ModuleManagerPostLoad() callback for KSPShaderTools
 public void KSPShaderToolsPostLoad()
 {
     MonoBehaviour.print("Reloading config databases (fuel types, model data, etc...)");
     //FuelTypes.INSTANCE.loadConfigData();
     //VolumeContainerLoader.loadConfigData();//needs to be loaded after fuel types
     ROLModelLayout.load();
     ROLModelData.loadConfigData();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a group of model definition layout sets.  Loads the model definitions + their supported layout configurations.
        /// </summary>
        /// <param name="nodes"></param>
        /// <returns></returns>
        public static ModelDefinitionLayoutOptions[] getModelDefinitions(ConfigNode[] nodes)
        {
            int len = nodes.Length;

            List <ModelDefinitionLayoutOptions> options = new List <ModelDefinitionLayoutOptions>();
            List <ModelLayoutData> layoutDataList       = new List <ModelLayoutData>();
            ROLModelDefinition     def;

            string[] groupedNames;
            string[] groupedLayouts;
            int      len2;

            for (int i = 0; i < len; i++)
            {
                //because configNode.ToString() reverses the order of values, and model def layouts are always loaded from string-cached config nodes
                //we need to reverse the order of the model and layout names during parsing
                groupedNames   = nodes[i].ROLGetStringValues("model");
                groupedLayouts = nodes[i].ROLGetStringValues("layout", new string[] { "default" });
                len2           = groupedNames.Length;
                for (int k = 0; k < len2; k++)
                {
                    def = ROLModelData.getModelDefinition(groupedNames[k]);
                    layoutDataList.AddRange(ROLModelLayout.findLayouts(groupedLayouts));
                    if (nodes[i].HasValue("position") || nodes[i].HasValue("rotation") || nodes[i].HasValue("scale"))
                    {
                        Vector3           pos    = nodes[i].ROLGetVector3("position", Vector3.zero);
                        Vector3           scale  = nodes[i].ROLGetVector3("scale", Vector3.one);
                        Vector3           rot    = nodes[i].ROLGetVector3("rotation", Vector3.zero);
                        ModelPositionData mpd    = new ModelPositionData(pos, scale, rot);
                        ModelLayoutData   custom = new ModelLayoutData("default", new ModelPositionData[] { mpd });
                        if (layoutDataList.Exists(m => m.name == "default"))
                        {
                            ModelLayoutData del = layoutDataList.Find(m => m.name == "default");
                            layoutDataList.Remove(del);
                        }
                        layoutDataList.Add(custom);
                    }
                    if (def == null)
                    {
                        ROLLog.error("Model definition was null for name: " + groupedNames[k] + ". Skipping definition during loading of part");
                    }
                    else
                    {
                        options.Add(new ModelDefinitionLayoutOptions(def, layoutDataList.ToArray()));
                    }
                    layoutDataList.Clear();
                }
            }
            return(options.ToArray());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initialization method.  Sets up model modules, loads their configs from the input config node.  Does all initial linking of part-modules.<para/>
        /// Does NOT set up their UI interaction -- that is all handled during OnStart()
        /// </summary>
        private void Initialize()
        {
            if (initialized)
            {
                return;
            }
            initialized = true;

            prevLength = panelLength;
            prevWidth  = panelWidth;
            prevScale  = panelScale;

            coreNodeNames = ROLUtils.parseCSV(coreManagedNodes);

            // Model-Module Setup / Initialization
            ConfigNode node = ROLConfigNodeUtils.parseConfigNode(configNodeData);

            // List of CORE model nodes from config
            // each one may contain multiple 'model=modelDefinitionName' entries
            // but must contain no more than a single 'variant' entry.
            // If no variant is specified, they are added to the 'Default' variant.
            ConfigNode[] coreDefNodes = node.GetNodes("CORE");

            List <ModelDefinitionLayoutOptions> coreDefList = new List <ModelDefinitionLayoutOptions>();

            foreach (ConfigNode cn in coreDefNodes)
            {
                string variantName = cn.ROLGetStringValue("variant", "Default");
                coreDefs = ROLModelData.getModelDefinitionLayouts(cn.ROLGetStringValues("model"));
                coreDefList.AddUniqueRange(coreDefs);
                ModelDefinitionVariantSet mdvs = GetVariantSet(variantName);
                mdvs.AddModels(coreDefs);
            }
            coreDefs = coreDefList.ToArray();

            coreModule      = new ROLModelModule <ModuleROSolar>(part, this, ROLUtils.GetRootTransform(part, "ModuleROSolar-CORE"), ModelOrientation.CENTRAL, nameof(currentCore), null, null, null);
            coreModule.name = "ModuleROSolar-Core";
            coreModule.getSymmetryModule = m => m.coreModule;
            coreModule.getValidOptions   = () => GetVariantSet(currentVariant).definitions;

            coreModule.setupModelList(coreDefs);
            coreModule.setupModel();

            UpdateModulePositions();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initialization method.  Sets up model modules, loads their configs from the input config node.  Does all initial linking of part-modules.<para/>
        /// Does NOT set up their UI interaction -- that is all handled during OnStart()
        /// </summary>
        private void Initialize()
        {
            if (initialized)
            {
                return;
            }
            ROLLog.debug($"{modName}: Initialize Starting");
            initialized = true;

            prevLength = panelLength;
            prevWidth  = panelWidth;
            prevScale  = panelScale;

            ROLLog.debug($"{modName}: Initialize() parseCSV");
            coreNodeNames = ROLUtils.parseCSV(coreManagedNodes);

            ROLLog.debug($"{modName}: Initialize() Model-Module Initialization");
            // Model-Module Setup / Initialization
            ConfigNode node = ROLConfigNodeUtils.parseConfigNode(configNodeData);

            ROLLog.debug($"{modName}: Initialize() Core Model Nodes");
            // List of CORE model nodes from config
            // each one may contain multiple 'model=modelDefinitionName' entries
            // but must contain no more than a single 'variant' entry.
            // If no variant is specified, they are added to the 'Default' variant.
            ConfigNode[] coreDefNodes = node.GetNodes("CORE");

            ROLLog.debug($"{modName}: Initialize() MDLO");
            List <ModelDefinitionLayoutOptions> coreDefList = new List <ModelDefinitionLayoutOptions>();
            int coreDefLen = coreDefNodes.Length;

            for (int i = 0; i < coreDefLen; i++)
            {
                string variantName = coreDefNodes[i].ROLGetStringValue("variant", "Default");
                coreDefs = ROLModelData.getModelDefinitionLayouts(coreDefNodes[i].ROLGetStringValues("model"));
                coreDefList.AddUniqueRange(coreDefs);
                ModelDefinitionVariantSet mdvs = getVariantSet(variantName);
                mdvs.addModels(coreDefs);
            }
            coreDefs = coreDefList.ToArray();

            coreModule      = new ROLModelModule <ModuleROSolar>(part, this, getRootTransform("ModuleROSolar-CORE"), ModelOrientation.CENTRAL, nameof(currentCore), null, null, null);
            coreModule.name = "ModuleROSolar-Core";
            coreModule.getSymmetryModule = m => m.coreModule;
            coreModule.getValidOptions   = () => getVariantSet(currentVariant).definitions;

            coreModule.setupModelList(coreDefs);
            coreModule.setupModel();

            if (GameDatabase.Instance.GetConfigNode("ROSolar/TechLimits/ROSOLAR_CONFIG") is ConfigNode ROSconfig)
            {
                SolarTechLimit.Init(ROSconfig);
            }

            stl = SolarTechLimit.GetTechLevel(techLevel);

            UpdateModulePositions();
            UpdateAttachNodes(false);
            UpdateAvailableVariants();
            UpdateMassAndCost();
            RecalculateStats();
            ROLStockInterop.updatePartHighlighting(part);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initialization method.  Sets up model modules, loads their configs from the input config node.  Does all initial linking of part-modules.<para/>
        /// Does NOT set up their UI interaction -- that is all handled during OnStart()
        /// </summary>
        private void initialize()
        {
            if (initialized)
            {
                return;
            }
            initialized = true;

            prevDiameter = currentDiameter;
            if (lengthWidth)
            {
                prevLength = currentLength;
            }

            noseNodeNames  = ROLUtils.parseCSV(noseManagedNodes);
            coreNodeNames  = ROLUtils.parseCSV(coreManagedNodes);
            mountNodeNames = ROLUtils.parseCSV(mountManagedNodes);

            //model-module setup/initialization
            ConfigNode node = ROLConfigNodeUtils.parseConfigNode(configNodeData);

            //list of CORE model nodes from config
            //each one may contain multiple 'model=modelDefinitionName' entries
            //but must contain no more than a single 'variant' entry.
            //if no variant is specified, they are added to the 'Default' variant.
            ConfigNode[] coreDefNodes = node.GetNodes("CORE");

            List <ModelDefinitionLayoutOptions> coreDefList = new List <ModelDefinitionLayoutOptions>();
            int coreDefLen = coreDefNodes.Length;

            for (int i = 0; i < coreDefLen; i++)
            {
                string variantName = coreDefNodes[i].ROLGetStringValue("variant", "Default");
                coreDefs = ROLModelData.getModelDefinitionLayouts(coreDefNodes[i].ROLGetStringValues("model"));
                coreDefList.AddUniqueRange(coreDefs);
                ModelDefinitionVariantSet mdvs = getVariantSet(variantName);
                mdvs.addModels(coreDefs);
            }
            coreDefs = coreDefList.ToArray();

            //model defs - brought here so we can capture the array rather than the config node+method call
            noseDefs  = ROLModelData.getModelDefinitions(node.GetNodes("NOSE"));
            mountDefs = ROLModelData.getModelDefinitions(node.GetNodes("MOUNT"));

            noseModule      = new ROLModelModule <ModuleROTank>(part, this, getRootTransform("ModularPart-NOSE"), ModelOrientation.TOP, nameof(currentNose), null, nameof(currentNoseTexture), nameof(noseModulePersistentData));
            noseModule.name = "ModuleROTank-Nose";
            noseModule.getSymmetryModule = m => m.noseModule;
            noseModule.getValidOptions   = () => noseDefs;

            coreModule      = new ROLModelModule <ModuleROTank>(part, this, getRootTransform("ModularPart-CORE"), ModelOrientation.CENTRAL, nameof(currentCore), null, nameof(currentCoreTexture), nameof(coreModulePersistentData));
            coreModule.name = "ModuleROTank-Core";
            coreModule.getSymmetryModule = m => m.coreModule;
            coreModule.getValidOptions   = () => getVariantSet(currentVariant).definitions;

            mountModule      = new ROLModelModule <ModuleROTank>(part, this, getRootTransform("ModularPart-MOUNT"), ModelOrientation.BOTTOM, nameof(currentMount), null, nameof(currentMountTexture), nameof(mountModulePersistentData));
            mountModule.name = "ModuleROTank-Mount";
            mountModule.getSymmetryModule = m => m.mountModule;
            mountModule.getValidOptions   = () => mountDefs;

            noseModule.volumeScalar  = volumeScalingPower;
            coreModule.volumeScalar  = volumeScalingPower;
            mountModule.volumeScalar = volumeScalingPower;

            //set up the model lists and load the currently selected model
            noseModule.setupModelList(noseDefs);
            coreModule.setupModelList(coreDefs);
            mountModule.setupModelList(mountDefs);
            coreModule.setupModel();
            noseModule.setupModel();
            mountModule.setupModel();

            updateModulePositions();
            updateDimensions();
            updateAttachNodes(false);
            updateAvailableVariants();
            if (scaleMass)
            {
                updateMass();
            }
            if (scaleCost)
            {
                updateCost();
            }
            ROLStockInterop.updatePartHighlighting(part);
            UpdateTankVolume(lengthWidth);
        }