Exemplo n.º 1
0
        public static void UpdateOutputSlot(MachineGasID intendedGas, Item input, Item output, ref float storedGas)
        {
            if (storedGas <= 0 || input.IsAir)
            {
                return;
            }

            //Check that the output is either 1) air or 2) is storing the same type of gas as "intendedGas"
            if (output.IsAir || (output.modItem is Capsule capsule && capsule.GasType == intendedGas))
            {
                do
                {
                    if (output.IsAir)
                    {
                        output.SetDefaults(TechMod.GetCapsuleType(intendedGas));
                        output.stack = 0;
                    }

                    input.stack--;
                    if (input.stack == 0)
                    {
                        input.TurnToAir();
                    }

                    output.stack++;

                    storedGas--;
                }while(!input.IsAir && storedGas > 0);
            }
        }
Exemplo n.º 2
0
        public override void Load(TagCompound tag)
        {
            if (tag.GetString("gas") is string gasName)
            {
                gasType = (MachineGasID)Enum.Parse(typeof(MachineGasID), gasName);
            }
            else
            {
                gasType = MachineGasID.None;
            }

            if (tag.GetString("liquid") is string liquidName)
            {
                liquidType = (MachineLiquidID)Enum.Parse(typeof(MachineLiquidID), liquidName);
            }
            else
            {
                liquidType = MachineLiquidID.None;
            }

            StoredFluid = tag.GetFloat("stored");

            if (tag.GetList <Point16>("pumpPositions") is List <Point16> dirPos && tag.GetList <short>("pumpDirs") is List <short> dirDirs)
            {
                if (dirPos.Count == dirDirs.Count)
                {
                    for (int i = 0; i < dirPos.Count; i++)
                    {
                        Framing.GetTileSafely(dirPos[i]).frameX = (short)(dirDirs[i] * 18);
                    }
                }
                else
                {
                    TechMod.Instance.Logger.Error("Network data was modified by an external program (entries: \"pumpPositions\", \"pumpDirs\")");
                }
            }

            pumpTimers = new Dictionary <Point16, Timer>();
            if (tag.GetList <Point16>("pumpTimerLocations") is List <Point16> pumpKeys && tag.GetList <byte>("pumpTimerValues") is List <byte> pumpValues)
            {
                if (pumpKeys.Count == pumpValues.Count)
                {
                    for (int i = 0; i < pumpKeys.Count; i++)
                    {
                        pumpTimers.Add(pumpKeys[i], new Timer()
                        {
                            value = pumpValues[i]
                        });
                    }
                }
                else
                {
                    TechMod.Instance.Logger.Error("Network data was modified by an external program (entries: \"pumpTimerLocations\", \"pumpTimerValues\")");
                }
            }

            RefreshConnections(NetworkCollection.ignoreCheckLocation);
        }
Exemplo n.º 3
0
        public static Color GetBackColor(MachineGasID id)
        {
            switch (id)
            {
            case MachineGasID.Hydrogen:
                return(Color.Orange);

            case MachineGasID.Oxygen:
                return(Color.LightBlue);

            case MachineGasID.Chlorine:
                return(Color.LimeGreen);

            default:
                throw new Exception("Invalid Gas ID requested: " + id.ToString());
            }
        }
Exemplo n.º 4
0
        public override void LoadCombinedData(TagCompound up, TagCompound left, TagCompound right, TagCompound down)
        {
            if (up?.GetString("gas") is string upGas)
            {
                gasType = (MachineGasID)Enum.Parse(typeof(MachineGasID), upGas);
            }
            else if (left?.GetString("gas") is string leftGas)
            {
                gasType = (MachineGasID)Enum.Parse(typeof(MachineGasID), leftGas);
            }
            else if (right?.GetString("gas") is string rightGas)
            {
                gasType = (MachineGasID)Enum.Parse(typeof(MachineGasID), rightGas);
            }
            else if (down?.GetString("gas") is string downGas)
            {
                gasType = (MachineGasID)Enum.Parse(typeof(MachineGasID), downGas);
            }

            if (up?.GetString("liquid") is string upLiquid)
            {
                liquidType = (MachineLiquidID)Enum.Parse(typeof(MachineLiquidID), upLiquid);
            }
            else if (left?.GetString("liquid") is string leftLiquid)
            {
                liquidType = (MachineLiquidID)Enum.Parse(typeof(MachineLiquidID), leftLiquid);
            }
            else if (right?.GetString("liquid") is string rightLiquid)
            {
                liquidType = (MachineLiquidID)Enum.Parse(typeof(MachineLiquidID), rightLiquid);
            }
            else if (down?.GetString("liquid") is string downLiquid)
            {
                liquidType = (MachineLiquidID)Enum.Parse(typeof(MachineLiquidID), downLiquid);
            }

            StoredFluid = (up?.GetFloat("stored") ?? 0)
                          + (left?.GetFloat("stored") ?? 0)
                          + (right?.GetFloat("stored") ?? 0)
                          + (down?.GetFloat("stored") ?? 0);
        }
 public void Load(TagCompound tag)
 {
     current = tag.GetFloat("cur");
     id      = (MachineGasID)tag.GetInt("id");
 }