Esempio 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;
            }
        }
Esempio n. 2
0
        //public float GetModuleCost()
        //{
        //    return moduleCost;
        //}

        public override string GetInfo()
        {
            if (showInfo)
            {
                List <string> variantList;
                if (objectDisplayNames.Length > 0)
                {
                    variantList = ParseTools.ParseNames(objectDisplayNames);
                }
                else
                {
                    variantList = ParseTools.ParseNames(objects);
                }

                StringBuilder info = new StringBuilder();
                info.AppendLine("Part variants available:");
                for (int i = 0; i < variantList.Count; i++)
                {
                    info.AppendLine(variantList[i]);
                }
                return(info.ToString());
            }
            else
            {
                return(string.Empty);
            }
        }
        public override string GetInfo()
        {
            if (showInfo)
            {
                var variantList = ParseTools.ParseNames(textureNames.Length > 0 ? textureNames : mapNames);
                textureDisplayList = ParseTools.ParseNames(textureDisplayNames);

                var info = StringBuilderCache.Acquire();
                info.AppendLine(Localizer.Format("#LOC_IFS_TextureSwitch_GetInfo"));//"Alternate textures available:"
                if (variantList.Count == 0)
                {
                    if (variantList.Count == 0)
                    {
                        info.AppendLine(Localizer.Format("#LOC_IFS_TextureSwitch_GetInfoNone"));//"None"
                    }
                }

                for (var i = 0; i < variantList.Count; i++)
                {
                    info.AppendLine(i > textureDisplayList.Count - 1 ?
                                    getTextureDisplayName(variantList[i]) : textureDisplayList[i]);
                }

                info.AppendLine().AppendLine().Append(Localizer.Format("#LOC_IFS_TextureSwitch_GetInfoNext"));//Use the Next Texture button on the right click menu.
                return(info.ToStringAndRelease());
            }
            else
            {
                return(string.Empty);
            }
        }
Esempio n. 4
0
        public override string GetInfo()
        {
            if (showInfo)
            {
                var variantList = ParseTools.ParseNames(textureNames.Length > 0 ? textureNames : mapNames);

                textureDisplayList = ParseTools.ParseNames(textureDisplayNames);
                var info = new StringBuilder();
                info.AppendLine("Alternate textures available:");
                if (variantList.Count == 0)
                {
                    if (variantList.Count == 0)
                    {
                        info.AppendLine("None");
                    }
                }
                for (var i = 0; i < variantList.Count; i++)
                {
                    info.AppendLine(i > textureDisplayList.Count - 1
                        ? getTextureDisplayName(variantList[i])
                        : textureDisplayList[i]);
                }
                info.AppendLine("\nUse the Next Texture button on the right click menu.");
                return(info.ToString());
            }
            else
            {
                return(string.Empty);
            }
        }
        public override string GetInfo()
        {
            try
            {
                if (!showInfo)
                {
                    return(string.Empty);
                }

                var resourceList = ParseTools.ParseNames(resourceNames);
                var info         = new StringBuilder();

                info.AppendLine("Fuel tank setups available:");

                foreach (string t in resourceList)
                {
                    info.AppendLine(t.Replace(",", ", "));
                }
                return(info.ToString());
            }
            catch (Exception e)
            {
                Debug.LogError("InsterstellarFuelSwitch GetInfo Error " + e.Message);
                throw;
            }
        }
Esempio n. 6
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;
        }
        private void InitializeData()
        {
            try
            {
                if (initialized)
                {
                    return;
                }

                SetupTankList(false);

                weightList   = ParseTools.ParseDoubles(tankMass, () => weightList);
                tankCostList = ParseTools.ParseDoubles(tankCost, () => tankCost);

                if (hasGUI)
                {
                    var nextEvent = Events["nextTankSetupEvent"];
                    nextEvent.guiActive       = availableInFlight;
                    nextEvent.guiActiveEditor = availableInEditor;
                    nextEvent.guiName         = nextTankSetupText;

                    var previousEvent = Events["previousTankSetupEvent"];
                    previousEvent.guiActive       = availableInFlight;
                    previousEvent.guiActiveEditor = availableInEditor;
                    previousEvent.guiName         = previousTankSetupText;
                }
                else
                {
                    Events["nextTankSetupEvent"].guiActive           = false;
                    Events["nextTankSetupEvent"].guiActiveEditor     = false;
                    Events["previousTankSetupEvent"].guiActive       = false;
                    Events["previousTankSetupEvent"].guiActiveEditor = false;
                }

                Fields["addedCost"].guiActiveEditor = displayCurrentTankCost && HighLogic.LoadedSceneIsEditor;

                initialized = true;
            }
            catch (Exception e)
            {
                Debug.LogError("InsterstellarFuelSwitch InitializeData Error");
                throw;
            }
        }
Esempio n. 8
0
        public override string GetInfo()
        {
            if (showInfo)
            {
                List <string> variantList = ParseTools.ParseNames(objectDisplayNames.Length > 0 ? objectDisplayNames : objects);

                var info = new StringBuilder();
                info.AppendLine(Localizer.Format("#LOC_IFS_MeshSwitch_GetInfo") + ":");
                for (int i = 0; i < variantList.Count; i++)
                {
                    info.AppendLine(variantList[i]);
                }
                return(info.ToString());
            }
            else
            {
                return(string.Empty);
            }
        }
Esempio n. 9
0
        public override string GetInfo()
        {
            if (showInfo)
            {
                var variantList = ParseTools.ParseNames(objectDisplayNames.Length > 0 ? objectDisplayNames : objects);

                var info = StringBuilderCache.Acquire();
                info.Append(Localizer.Format("#LOC_IFS_MeshSwitch_GetInfo")).AppendLine(":");

                foreach (var t in variantList)
                {
                    info.AppendLine(t);
                }
                return(info.ToStringAndRelease());
            }
            else
            {
                return(string.Empty);
            }
        }
Esempio n. 10
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;
        }
Esempio n. 12
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;
            }
        }
        private void SetupTankList(bool calledByPlayer)
        {
            try
            {
                tankList = new List <IFSmodularTank>();

                // toDo: move to tankList
                weightList         = new List <double>();
                tankCostList       = new List <double>();
                activeResourceList = new HashSet <string>();

                // First find the amounts each tank type is filled with
                List <List <double> > resourceList             = new List <List <double> >();
                List <List <double> > initialResourceList      = new List <List <double> >();
                List <List <double> > boilOffTempList          = new List <List <double> >();
                List <List <double> > latendHeatVaporationList = new List <List <double> >();

                string[] resourceTankAmountArray   = resourceAmounts.Split(';');
                string[] initialResourceTankArray  = initialResourceAmounts.Split(';');
                string[] tankGuiNameTankArray      = resourceGui.Split(';');
                string[] boilOffTempTankArray      = boilOffTemp.Split(';');
                string[] latendHeatVaporationArray = latendHeatVaporation.Split(';');
                string[] tankNameArray             = resourceNames.Split(';');

                int tankGuiNameArrayCount = tankGuiNameTankArray.Count();

                // if missing or not complete, use full amount
                if (initialResourceAmounts.Equals(String.Empty) ||
                    initialResourceTankArray.Length != resourceTankAmountArray.Length)
                {
                    initialResourceTankArray = resourceTankAmountArray;
                }

                for (int tankCounter = 0; tankCounter < resourceTankAmountArray.Length; tankCounter++)
                {
                    resourceList.Add(new List <double>());
                    initialResourceList.Add(new List <double>());
                    boilOffTempList.Add(new List <double>());
                    latendHeatVaporationList.Add(new List <double>());

                    string[] resourceAmountArray             = resourceTankAmountArray[tankCounter].Trim().Split(',');
                    string[] initialResourceAmountArray      = initialResourceTankArray[tankCounter].Trim().Split(',');
                    string[] boilOffTempAmountArray          = boilOffTempTankArray.Count() > tankCounter ? boilOffTempTankArray[tankCounter].Trim().Split(',') : new string[0];
                    string[] latendHeatVaporationAmountArray = latendHeatVaporationArray.Count() > tankCounter ? latendHeatVaporationArray[tankCounter].Trim().Split(',') : new string[0];

                    // if missing or not complete, use full amount
                    if (initialResourceAmounts.Equals(String.Empty) ||
                        initialResourceAmountArray.Length != resourceAmountArray.Length)
                    {
                        initialResourceAmountArray = resourceAmountArray;
                    }

                    for (var amountCounter = 0; amountCounter < resourceAmountArray.Length; amountCounter++)
                    {
                        try
                        {
                            if (tankCounter >= resourceList.Count || amountCounter >= resourceAmountArray.Count())
                            {
                                continue;
                            }

                            resourceList[tankCounter].Add(double.Parse(resourceAmountArray[amountCounter].Trim()));
                        }
                        catch (Exception exception)
                        {
                            Debug.LogWarning("InsterstellarFuelSwitch: error parsing resourceTankAmountArray amount " + tankCounter + "/" + amountCounter +
                                             ": '" + resourceTankAmountArray[tankCounter] + "': '" + resourceAmountArray[amountCounter].Trim() + "' with error: " + exception.Message);
                        }

                        try
                        {
                            if (tankCounter < initialResourceList.Count && amountCounter < initialResourceAmountArray.Count())
                            {
                                initialResourceList[tankCounter].Add(ParseTools.ParseDouble(initialResourceAmountArray[amountCounter]));
                            }
                        }
                        catch (Exception exception)
                        {
                            Debug.LogWarning("InsterstellarFuelSwitch: error parsing initialResourceList amount " + tankCounter + "/" + amountCounter +
                                             ": '" + initialResourceList[tankCounter] + "': '" + initialResourceAmountArray[amountCounter].Trim() + "' with error: " + exception.Message);
                        }

                        try
                        {
                            if (tankCounter < boilOffTempList.Count && amountCounter < boilOffTempAmountArray.Length)
                            {
                                boilOffTempList[tankCounter].Add(ParseTools.ParseDouble(boilOffTempAmountArray[amountCounter]));
                            }
                        }
                        catch (Exception exception)
                        {
                            Debug.LogWarning("InsterstellarFuelSwitch: error parsing boilOffTempList amount " + tankCounter + "/" + amountCounter +
                                             ": '" + boilOffTempList[tankCounter] + "': '" + boilOffTempAmountArray[amountCounter].Trim() + "' with error: " + exception.Message);
                        }

                        try
                        {
                            if (tankCounter < latendHeatVaporationList.Count && amountCounter < latendHeatVaporationAmountArray.Length)
                            {
                                latendHeatVaporationList[tankCounter].Add(ParseTools.ParseDouble(latendHeatVaporationAmountArray[amountCounter].Trim()));
                            }
                        }
                        catch (Exception exception)
                        {
                            Debug.LogWarning("InsterstellarFuelSwitch: error parsing latendHeatVaporation amount " + tankCounter + "/" + amountCounter +
                                             ": '" + latendHeatVaporationList[tankCounter] + "': '" + latendHeatVaporationAmountArray[amountCounter].Trim() + "' with error: " + exception.Message);
                        }
                    }
                }

                // Then find the kinds of resources each tank holds, and fill them with the amounts found previously, or the amount hey held last (values kept in save persistence/craft)
                for (int currentResourceCounter = 0; currentResourceCounter < tankNameArray.Length; currentResourceCounter++)
                {
                    var newTank = new IFSmodularTank();

                    if (currentResourceCounter < tankGuiNameArrayCount)
                    {
                        newTank.GuiName = tankGuiNameTankArray[currentResourceCounter];
                    }

                    tankList.Add(newTank);
                    string[] resourceNameArray = tankNameArray[currentResourceCounter].Split(',');
                    for (var nameCounter = 0; nameCounter < resourceNameArray.Length; nameCounter++)
                    {
                        var resourceName = resourceNameArray[nameCounter].Trim(' ');

                        if (!activeResourceList.Contains(resourceName))
                        {
                            activeResourceList.Add(resourceName);
                        }

                        var newResource = new IFSresource(resourceName);
                        if (resourceList[currentResourceCounter] != null && nameCounter < resourceList[currentResourceCounter].Count)
                        {
                            newResource.maxAmount = resourceList[currentResourceCounter][nameCounter];
                            newResource.amount    = initialResourceList[currentResourceCounter][nameCounter];
                        }

                        // add boiloff data
                        if (currentResourceCounter < boilOffTempList.Count && boilOffTempList[currentResourceCounter] != null &&
                            boilOffTempList[currentResourceCounter].Count > nameCounter)
                        {
                            newResource.boiloffTemp = boilOffTempList[currentResourceCounter][nameCounter];
                        }

                        if (currentResourceCounter < latendHeatVaporationList.Count && latendHeatVaporationList[currentResourceCounter] != null &&
                            latendHeatVaporationList[currentResourceCounter].Count > nameCounter)
                        {
                            newResource.latendHeatVaporation = latendHeatVaporationList[currentResourceCounter][nameCounter];
                        }

                        //newTank.Contents += newResource.name + ",";
                        newTank.Resources.Add(newResource);
                    }
                }

                var maxNrTanks = tankList.Max(t => t.Resources.Count);

                Fields["resourceAmountStr0"].guiActive = maxNrTanks > 0;
                Fields["resourceAmountStr1"].guiActive = maxNrTanks > 1;
                Fields["resourceAmountStr2"].guiActive = maxNrTanks > 2;

                Fields["resourceAmountStr0"].guiActiveEditor = maxNrTanks > 0;
                Fields["resourceAmountStr1"].guiActiveEditor = maxNrTanks > 1;
                Fields["resourceAmountStr2"].guiActiveEditor = maxNrTanks > 2;
            }
            catch (Exception e)
            {
                Debug.LogError("InsterstellarFuelSwitch SetupTankList Error");
                throw;
            }
        }
        private List <string> SetupTankInPart(Part currentPart, bool calledByPlayer)
        {
            try
            {
                // find selected tank
                var selectedTank = calledByPlayer || String.IsNullOrEmpty(selectedTankSetupTxt)
                    ? selectedTankSetup < tankList.Count ? tankList[selectedTankSetup] : tankList[0]
                    : tankList.FirstOrDefault(t => t.GuiName == selectedTankSetupTxt) ?? (selectedTankSetup < tankList.Count ? tankList[selectedTankSetup] : tankList[0]);

                // update txt and index for future
                selectedTankSetupTxt = selectedTank.GuiName;
                selectedTankSetup    = tankList.IndexOf(selectedTank);

                // check if we need to change anything
                //if (!HighLogic.LoadedSceneIsEditor && gameLoaded && !calledByPlayer)
                //{
                //    Debug.Log("InsterstellarFuelSwitch assignResourcesToPart, no change required");
                //    return part.Resources.list.Select(r => r.resourceName).ToList();
                //}

                // create new ResourceNode
                var newResources       = new List <string>();
                var newResourceNodes   = new List <ConfigNode>();
                var parsedConfigAmount = new List <float>();

                // parse configured amounts
                if (configuredAmounts.Length > 0)
                {
                    // empty configuration if switched by user
                    if (calledByPlayer)
                    {
                        configuredAmounts = String.Empty;
                        //Debug.Log("InsterstellarFuelSwitch assignResourcesToPart calledByPlayer reset configuredAmounts");
                    }

                    //Debug.Log("InsterstellarFuelSwitch assignResourcesToPart parsing configuredAmounts = " + configuredAmounts);
                    string[] configAmount = configuredAmounts.Split(',');
                    foreach (string item in configAmount)
                    {
                        float value;
                        if (float.TryParse(item, out value))
                        {
                            parsedConfigAmount.Add(value);
                        }
                    }

                    // empty configuration if in flight
                    if (!HighLogic.LoadedSceneIsEditor)
                    {
                        configuredAmounts = String.Empty;
                        //Debug.Log("InsterstellarFuelSwitch assignResourcesToPart not HighLogic.LoadedSceneIsEditor reset configuredAmounts");
                    }
                }

                // imitialise minimum boiloff temperature at current part temperature
                double minimumBoiloffTemerature = -1;

                for (int resourceId = 0; resourceId < selectedTank.Resources.Count; resourceId++)
                {
                    var selectedTankResource = selectedTank.Resources[resourceId];

                    if (minimumBoiloffTemerature == -1 || (selectedTankResource.boiloffTemp > 0 && selectedTankResource.boiloffTemp < minimumBoiloffTemerature))
                    {
                        minimumBoiloffTemerature = selectedTankResource.boiloffTemp;
                    }

                    if (selectedTankResource.name == "Structural")
                    {
                        continue;
                    }

                    newResources.Add(selectedTankResource.name);

                    ConfigNode newResourceNode = new ConfigNode("RESOURCE");
                    double     maxAmount       = selectedTankResource.maxAmount * currentVolumeMultiplier;

                    newResourceNode.AddValue("name", selectedTankResource.name);
                    newResourceNode.AddValue("maxAmount", maxAmount);

                    PartResource existingResource = null;
                    if (!HighLogic.LoadedSceneIsEditor || (HighLogic.LoadedSceneIsEditor && !calledByPlayer))
                    {
                        foreach (PartResource partResource in currentPart.Resources)
                        {
                            if (partResource.resourceName.Equals(selectedTankResource.name))
                            {
                                existingResource = partResource;
                                break;
                            }
                        }
                    }

                    double resourceNodeAmount;
                    if (existingResource != null)
                    {
                        resourceNodeAmount = Math.Min(existingResource.amount, maxAmount);
                    }
                    else if (!HighLogic.LoadedSceneIsEditor && resourceId < parsedConfigAmount.Count)
                    {
                        resourceNodeAmount = parsedConfigAmount[resourceId];
                    }
                    else if (!HighLogic.LoadedSceneIsEditor && calledByPlayer)
                    {
                        resourceNodeAmount = 0.0;
                    }
                    else
                    {
                        resourceNodeAmount = selectedTank.Resources[resourceId].amount * currentVolumeMultiplier;
                    }

                    newResourceNode.AddValue("amount", resourceNodeAmount);
                    newResourceNodes.Add(newResourceNode);
                }


                //// prepare part to initialise temerature
                //if (minimumBoiloffTemerature != -1)
                //{
                //    var currentFuelswitch = part.FindModuleImplementing<InterstellarFuelSwitch>();
                //    if (currentFuelswitch != null)
                //    {
                //        Debug.Log("InsterstellarFuelSwitch SetupTankInPart prepared to initialise part temperature at " + minimumBoiloffTemerature);
                //        currentFuelswitch.initializePartTemperature = minimumBoiloffTemerature;
                //    }
                //}

                var finalResourceNodes = new List <ConfigNode>();

                // remove all resources except those we ignore
                PartResource[] partResources = currentPart.GetComponents <PartResource>();
                foreach (PartResource resource in partResources)
                {
                    if (activeResourceList.Contains(resource.resourceName))
                    {
                        if (newResourceNodes.Count > 0)
                        {
                            finalResourceNodes.AddRange(newResourceNodes);
                            newResourceNodes.Clear();
                        }

                        currentPart.Resources.list.Remove(resource);
                        DestroyImmediate(resource);
                    }
                    else
                    {
                        ConfigNode newResourceNode = new ConfigNode("RESOURCE");
                        newResourceNode.AddValue("name", resource.resourceName);
                        newResourceNode.AddValue("maxAmount", resource.maxAmount);
                        newResourceNode.AddValue("amount", resource.amount);

                        finalResourceNodes.Add(newResourceNode);
                        Debug.Log("InsterstellarFuelSwitch SetupTankInPart created confignode for: " + resource.resourceName);

                        // remove all
                        currentPart.Resources.list.Remove(resource);
                        DestroyImmediate(resource);
                        Debug.Log("InsterstellarFuelSwitch SetupTankInPart remove resource " + resource.resourceName);
                    }
                }

                // add any remaining bew nodes
                if (newResourceNodes.Count > 0)
                {
                    finalResourceNodes.AddRange(newResourceNodes);
                    newResourceNodes.Clear();
                }

                // add new resources
                //if (newResourceNodes.Count > 0)
                if (finalResourceNodes.Count > 0)
                {
                    Debug.Log("InsterstellarFuelSwitch SetupTankInPart adding resources: " + ParseTools.Print(newResources));
                    //foreach (var resourceNode in newResourceNodes)
                    foreach (var resourceNode in finalResourceNodes)
                    {
                        currentPart.AddResource(resourceNode);
                    }
                }

                // This also needs to be done when going from a setup with resources to a setup with no resources.
                currentPart.Resources.UpdateList();
                UpdateMass(currentPart, selectedTankSetup, calledByPlayer);
                UpdateCost();

                return(newResources);
            }
            catch (Exception e)
            {
                Debug.LogError("InsterstellarFuelSwitch SetupTankInPart Error");
                throw;
            }
        }