StretchyTanks.StretchyTanks.changeResource C# (CSharp) Method

changeResource() private method

private changeResource ( string resName, float amount, bool isTweakable = true ) : void
resName string
amount float
isTweakable bool
return void
        private void changeResource(string resName, float amount, bool isTweakable = true)
        {
            double fillFraction = 1.0d;
            int idx = part.Resources.list.FindIndex(res => res.resourceName == resName);
            if (idx >= 0)
            {
                PartResource oldRes = part.Resources.list[idx];
                part.Resources.list.RemoveAt(idx);
                fillFraction = oldRes.amount / oldRes.maxAmount;
                DestroyImmediate(oldRes);
            }

            ConfigNode node = new ConfigNode("RESOURCE");
            node.AddValue("name", resName);
            node.AddValue("amount", Math.Round(amount * fillFraction, 2));
            node.AddValue("maxAmount", Math.Round(amount, 2));
            node.AddValue("isTweakable", isTweakable);
            part.AddResource(node);
        }