Exemplo n.º 1
0
        public void initializeData()
        {
            if (!initialized)
            {
                debug = new InterstellarDebugMessages(debugMode, "InterstellarMeshSwitch");
                // you can't have fuel switching without symmetry, it breaks the editor GUI.
                if (useFuelSwitchModule)
                {
                    updateSymmetry = true;
                }

                parseObjectNames();
                fuelTankSetupList = ParseTools.ParseIntegers(fuelTankSetups);
                objectDisplayList = ParseTools.ParseNames(objectDisplayNames);

                if (useFuelSwitchModule)
                {
                    fuelSwitch = part.GetComponent <InterstellarFuelSwitch>();
                    if (fuelSwitch == null)
                    {
                        useFuelSwitchModule = false;
                        debug.debugMessage("no FSfuelSwitch module found, despite useFuelSwitchModule being true");
                    }
                }
                initialized = true;
            }
        }
Exemplo n.º 2
0
        // runs the kind of commands that would normally be in OnStart, if they have not already been run. In case a method is called upon externally, but values have not been set up yet
        private void initializeData()
        {
            if (initialized)
            {
                return;
            }

            debug = new InterstellarDebugMessages(debugMode, "InterstellarTextureSwitch2");
            // you can't have fuel switching without symmetry, it breaks the editor GUI.
            if (useFuelSwitchModule)
            {
                updateSymmetry = true;
            }

            objectList         = ParseTools.ParseNames(objectNames, true);
            texList            = ParseTools.ParseNames(textureNames, true, true, textureRootFolder);
            mapList            = ParseTools.ParseNames(mapNames, true, true, textureRootFolder);
            textureDisplayList = ParseTools.ParseNames(textureDisplayNames);
            fuelTankSetupList  = ParseTools.ParseIntegers(fuelTankSetups);

            debug.debugMessage("found " + texList.Count + " textures, using number " + selectedTexture + ", found " + objectList.Count + " objects, " + mapList.Count + " maps");

            foreach (String targetObjectName in objectList)
            {
                Transform[]     targetObjectTransformArray = part.FindModelTransforms(targetObjectName);
                List <Material> matList = new List <Material>();
                foreach (Transform t in targetObjectTransformArray)
                {
                    if (t != null)
                    {
                        var renderer = t.gameObject.GetComponent <Renderer>();

                        // check for if the object even has a mesh. otherwise part list loading crashes
                        if (renderer != null)
                        {
                            Material targetMat = renderer.material;
                            if (targetMat != null && !matList.Contains(targetMat))
                            {
                                matList.Add(targetMat);
                            }
                        }
                    }
                }
                targetMats.Add(matList);
            }

            if (useFuelSwitchModule)
            {
                fuelSwitch = part.GetComponent <InterstellarFuelSwitch>(); // only looking for first, not supporting multiple fuel switchers
                if (fuelSwitch == null)
                {
                    useFuelSwitchModule = false;
                    debug.debugMessage("no InterstellarFuelSwitch module found, despite useFuelSwitchModule being true");
                }
            }
            initialized = true;
        }
Exemplo n.º 3
0
        public void InitializeData(bool forced = false)
        {
            if (initialized && !forced)
            {
                return;
            }

            // you can't have fuel switching without symmetry, it breaks the editor GUI.
            if (useFuelSwitchModule)
            {
                updateSymmetry = true;
            }

            objectTransforms = ParseObjectNames();
            var fuelTankSetupList   = ParseTools.ParseNames(fuelTankSetups);
            var objectDisplayList   = ParseTools.ParseNames(objectDisplayNames);
            var indexNamesList      = ParseTools.ParseNames(indexNames);
            var tankSwitchNamesList = ParseTools.ParseNames(tankSwitchNames);

            // we need to clear the list because InitializeData might be called multiple times
            meshConfigurationList.Clear();

            for (var i = 0; i < objectDisplayList.Count; i++)
            {
                meshConfigurationList.Add(new MeshConfiguration()
                {
                    objectDisplay    = objectDisplayList[i],
                    tankSwitchName   = Localizer.Format(i < tankSwitchNamesList.Count ? tankSwitchNamesList[i] : objectDisplayList[i]),
                    indexName        = i < indexNamesList.Count ? indexNamesList[i] : objectDisplayList[i],
                    fuelTankSetup    = i < fuelTankSetupList.Count ? fuelTankSetupList[i] : objectDisplayList[i],
                    objectTransforms = i < objectTransforms.Count ? objectTransforms[i] : new List <Transform>()
                });
            }

            if (orderByIndexNames)
            {
                if (debugMode)
                {
                    Debug.Log("[IFS] - InterstellarMeshSwitch " + part.GetInstanceID() + " order meshConfigurationList on indexName");
                }
                meshConfigurationList.Sort((a, b) => string.Compare(a.indexName, b.indexName, StringComparison.Ordinal));
            }

            if (debugMode)
            {
                foreach (var config in meshConfigurationList)
                {
                    Debug.Log("fuelTankSetup:" + config.fuelTankSetup + " indexName:" + config.indexName +
                              " objectDisplay: " + config.objectDisplay + " tankSwitchName:" + config.tankSwitchName);
                }
            }

            if (useFuelSwitchModule)
            {
                var fuelSwitches = part.FindModulesImplementing <InterstellarFuelSwitch>();

                if (fuelSwitches.Any() && !string.IsNullOrEmpty(searchTankId))
                {
                    fuelSwitch = fuelSwitches.FirstOrDefault(m => m.tankId == searchTankId);
                }

                if (fuelSwitch == null)
                {
                    fuelSwitch = fuelSwitches.FirstOrDefault();
                }

                if (fuelSwitch == null)
                {
                    useFuelSwitchModule = false;
                }
                else
                {
                    var matchingObject = fuelSwitch.FindMatchingConfig(this);

                    var matchingArray = matchingObject.Split(',');

                    var matchingIndexName = matchingArray[0];

                    var matchingMesh = meshConfigurationList.FirstOrDefault(m => m.indexName == matchingIndexName);

                    if (matchingMesh != null)
                    {
                        selectedObject = meshConfigurationList.IndexOf(matchingMesh);
                    }
                    else
                    {
                        var matchingIndex = int.Parse(matchingObject.Split(',')[1]);

                        if (HighLogic.LoadedSceneIsFlight || matchingIndex >= 0)
                        {
                            if (debugMode)
                            {
                                Debug.Log("[IFS] - InterstellarMeshSwitch " + part.GetInstanceID() +
                                          " sets selectedObject to matching object " + matchingObject);
                            }
                            selectedObject = matchingIndex;
                        }
                    }
                }
            }
            initialized = true;
        }
        // runs the kind of commands that would normally be in OnStart, if they have not already been run. In case a method is called upon externally, but values have not been set up yet
        private void InitializeData()
        {
            if (initialized)
            {
                return;
            }

            debug = new InterstellarDebugMessages(debugMode, "InterstellarTextureSwitch2");

            // you can't have fuel switching without symmetry, it breaks the editor GUI.
            if (useFuelSwitchModule)
            {
                updateSymmetry = true;
            }

            objectList         = ParseTools.ParseNames(objectNames, true);
            mapList            = ParseTools.ParseNames(mapNames, true, true, textureRootFolder);
            textureDisplayList = ParseTools.ParseNames(textureDisplayNames);
            fuelTankSetupList  = ParseTools.ParseNames(fuelTankSetups);

            var textureNameGroups = textureNames.Split(';').ToArray();

            for (var i = 0; i < textureNameGroups.Count(); i++)
            {
                var texListGroup = ParseTools.ParseNames(textureNameGroups[i], true, true, textureRootFolder);

                texList.Add(texListGroup);
            }

            debug.debugMessage("found " + texList.Count + " textures, using number " + selectedTexture + ", found " + objectList.Count + " objects, " + mapList.Count + " maps");

            for (var i = 0; i < objectList.Count(); i++)
            {
                Transform[] targetObjectTransformArray = part.FindModelTransforms(objectList[i]);

                var matList = new List <Material>();

                foreach (Transform t in targetObjectTransformArray)
                {
                    if (t == null)
                    {
                        continue;
                    }

                    var renderer = t.gameObject.GetComponent <Renderer>();

                    // check for if the object even has a mesh. otherwise part list loading crashes
                    if (renderer == null)
                    {
                        continue;
                    }

                    Material targetMat = renderer.material;
                    if (targetMat != null && !matList.Contains(targetMat))
                    {
                        matList.Add(targetMat);
                    }
                }

                targetMats.Add(matList);
            }

            if (useFuelSwitchModule)
            {
                fuelSwitch = part.GetComponent <InterstellarFuelSwitch>(); // only looking for first, not supporting multiple fuel switchers
                if (fuelSwitch == null)
                {
                    useFuelSwitchModule = false;
                    debug.debugMessage("no InterstellarFuelSwitch module found, despite useFuelSwitchModule being true");
                }
                else
                {
                    var matchingObject = fuelSwitch.FindMatchingConfig(this);
                    var matchingIndex  = int.Parse(matchingObject.Split(',')[1]);

                    if (matchingIndex >= 0)
                    {
                        selectedTexture = matchingIndex;
                    }
                }
            }
            initialized = true;
        }
Exemplo n.º 5
0
        public void InitializeData()
        {
            try
            {
                if (!initialized)
                {
                    debug = new InterstellarDebugMessages(debugMode, "InterstellarMeshSwitch");
                    // you can't have fuel switching without symmetry, it breaks the editor GUI.
                    if (useFuelSwitchModule)
                    {
                        updateSymmetry = true;
                    }

                    parseObjectNames();
                    fuelTankSetupList = ParseTools.ParseIntegers(fuelTankSetups);
                    objectDisplayList = ParseTools.ParseNames(objectDisplayNames);

                    tankSwitchNamesList = new List <string>();

                    // add any missing names
                    var tankSwitchNamesListTmp = ParseTools.ParseNames(tankSwitchNames);
                    for (int i = 0; i < objectDisplayList.Count; i++)
                    {
                        if (i < tankSwitchNamesListTmp.Count)
                        {
                            tankSwitchNamesList.Add(tankSwitchNamesListTmp[i]);
                        }
                        else
                        {
                            tankSwitchNamesList.Add(objectDisplayList[i]);
                        }
                    }

                    if (useFuelSwitchModule)
                    {
                        var fuelSwitches = part.FindModulesImplementing <InterstellarFuelSwitch>();

                        if (!String.IsNullOrEmpty(searchTankId))
                        {
                            fuelSwitch = fuelSwitches.FirstOrDefault(m => m.tankId == searchTankId);
                        }

                        if (fuelSwitch == null)
                        {
                            fuelSwitch = fuelSwitches.FirstOrDefault();
                        }

                        //searchTankId
                        if (fuelSwitch == null)
                        {
                            useFuelSwitchModule = false;
                            debug.debugMessage("no FSfuelSwitch module found, despite useFuelSwitchModule being true");
                        }
                    }
                    initialized = true;
                }
            }
            catch (Exception e)
            {
                Debug.LogError("[IFS] - InterstellarMeshSwitch.InitializeData Error: " + e.Message);
                throw;
            }
        }
        public void InitializeData()
        {
            try
            {
                if (initialized)
                {
                    return;
                }

                // you can't have fuel switching without symmetry, it breaks the editor GUI.
                if (useFuelSwitchModule)
                {
                    updateSymmetry = true;
                }

                objectTransforms = ParseObjectNames();
                var fuelTankSetupList   = ParseTools.ParseNames(fuelTankSetups);
                var objectDisplayList   = ParseTools.ParseNames(objectDisplayNames);
                var indexNamesList      = ParseTools.ParseNames(indexNames);
                var tankSwitchNamesList = ParseTools.ParseNames(tankSwitchNames);

                for (var i = 0; i < objectDisplayList.Count; i++)
                {
                    meshConfigurationList.Add(new meshConfiguration()
                    {
                        objectDisplay    = objectDisplayList[i],
                        tankSwitchName   = Localizer.Format(i < tankSwitchNamesList.Count ? tankSwitchNamesList[i] : objectDisplayList[i]),
                        indexName        = i < indexNamesList.Count ? indexNamesList[i] : objectDisplayList[i],
                        fuelTankSetup    = i < fuelTankSetupList.Count ? fuelTankSetupList[i] : objectDisplayList[i],
                        objectTransforms = i < objectTransforms.Count ? objectTransforms[i] : new List <Transform>()
                    });
                }

                if (orderByIndexNames)
                {
                    meshConfigurationList = meshConfigurationList.OrderBy(m => m.indexName).ToList();
                }

                if (useFuelSwitchModule)
                {
                    var fuelSwitches = part.FindModulesImplementing <InterstellarFuelSwitch>();

                    if (fuelSwitches.Any() && !string.IsNullOrEmpty(searchTankId))
                    {
                        fuelSwitch = fuelSwitches.FirstOrDefault(m => m.tankId == searchTankId);
                    }

                    if (fuelSwitch == null)
                    {
                        fuelSwitch = fuelSwitches.FirstOrDefault();
                    }

                    if (fuelSwitch == null)
                    {
                        useFuelSwitchModule = false;
                    }
                    else
                    {
                        var matchingObject = fuelSwitch.FindMatchingConfig();

                        if (HighLogic.LoadedSceneIsFlight || matchingObject >= 0)
                        {
                            selectedObject = matchingObject;
                        }
                    }
                }
                initialized = true;
            }
            catch (Exception e)
            {
                Debug.LogError("[IFS] - InterstellarMeshSwitch.InitializeData Error: " + e.Message);
                throw;
            }
        }