Beispiel #1
0
        /// <summary>
        /// Removes a specific gas type
        /// </summary>
        public static void RemoveGasType(this GasData data, GasSO gasType)
        {
            var newData = new GasValues[data.GasesArray.Length - 1];
            var count   = 0;

            foreach (var gas in data.GasesArray)
            {
                if (gas.GasSO == gasType)
                {
                    continue;
                }

                newData[count] = gas;
                count++;
            }

            data.GasesArray = newData;
            data.GasesDict.Remove(gasType);
        }
Beispiel #2
0
 /// <summary>
 /// Gets a specific gas from the gas array, returns null if gas isn't in mix
 /// </summary>
 public static void GetGasType(this GasData data, GasSO gasType, out GasValues gasData)
 {
     gasData = GetGasType(data, gasType);
 }
Beispiel #3
0
        private static void InternalSetMoles(GasData data, GasSO gasType, float moles, bool isChange)
        {
            //Try to get gas value if already inside mix
            GetGasType(data, gasType, out var gas);

            if (gas != null)
            {
                if (isChange)
                {
                    gas.Moles += moles;
                }
                else
                {
                    gas.Moles = moles;
                }

                //Remove gas from mix if less than threshold
                if (gas.Moles <= AtmosConstants.MinPressureDifference)
                {
                    data.RemoveGasType(gasType);
                }

                return;
            }

            //Gas isn't inside mix so we'll add it

            //Dont add new data for negative moles
            if (Math.Sign(moles) == -1)
            {
                return;
            }

            //Dont add if approx 0 or below threshold
            if (moles.Approx(0) || moles <= AtmosConstants.MinPressureDifference)
            {
                return;
            }

            //Create new array and add old gas values and new gas
            var newValues = new GasValues {
                Moles = moles, GasSO = gasType
            };
            var newArray = new GasValues[data.GasesArray.Length + 1];

            for (int i = 0; i < newArray.Length; i++)
            {
                if (data.GasesArray.Length == i)
                {
                    newArray[i] = newValues;

                    //Should only happen on last index since we are adding only one thing so can break
                    break;
                }

                newArray[i] = data.GasesArray[i];
            }

            data.GasesArray = newArray;
            data.GasesDict.Add(gasType, newValues);
        }