diff --git a/src/kOS/Suffixed/StageValues.cs b/src/kOS/Suffixed/StageValues.cs index 840adca77..8bac1232b 100644 --- a/src/kOS/Suffixed/StageValues.cs +++ b/src/kOS/Suffixed/StageValues.cs @@ -24,6 +24,7 @@ private void InitializeSuffixes() AddSuffix("NUMBER", new Suffix(() => Staging.CurrentStage)); AddSuffix("READY", new Suffix(() => shared.Vessel.isActiveVessel && Staging.separate_ready)); AddSuffix("RESOURCES", new Suffix>(GetResourceManifest)); + AddSuffix("RESOURCESLEX", new Suffix>(GetResourceDictionary)); } private ListValue GetResourceManifest() @@ -39,6 +40,19 @@ private ListValue GetResourceManifest() return toReturn; } + private Lexicon GetResourceDictionary() + { + var resources = shared.Vessel.GetActiveResources(); + var toReturn = new Lexicon(); + + foreach (var resource in resources) + { + toReturn.Add(resource.info.name, new ActiveResourceValue(resource, shared)); + } + + return toReturn; + } + public override object GetSuffix(string suffixName) { if (!IsResource(suffixName)) @@ -87,16 +101,9 @@ private bool IsResource(string suffixName) } if (list.Count == 0) { - return null; - } - double available = 0.0; - double capacity = 0.0; - foreach (var resource in list) - { - available += resource.amount; - capacity += resource.maxAmount; + return 0; } - return Math.Round(available, 2); + return Math.Round(list.GroupBy(e => e.part.flightID).Select(e => e.FirstOrDefault()).Sum(e => e.amount), 2); } public override string ToString()