Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StageValue.cs #1243

Merged
merged 1 commit into from
Nov 13, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/kOS/Suffixed/StageValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private void InitializeSuffixes()
AddSuffix("NUMBER", new Suffix<int>(() => Staging.CurrentStage));
AddSuffix("READY", new Suffix<bool>(() => shared.Vessel.isActiveVessel && Staging.separate_ready));
AddSuffix("RESOURCES", new Suffix<ListValue<ActiveResourceValue>>(GetResourceManifest));
AddSuffix("RESOURCESLEX", new Suffix<Lexicon<string, ActiveResourceValue>>(GetResourceDictionary));
}

private ListValue<ActiveResourceValue> GetResourceManifest()
Expand All @@ -39,6 +40,19 @@ private ListValue<ActiveResourceValue> GetResourceManifest()
return toReturn;
}

private Lexicon<string, ActiveResourceValue> GetResourceDictionary()
{
var resources = shared.Vessel.GetActiveResources();
var toReturn = new Lexicon<string, ActiveResourceValue>();

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))
Expand Down Expand Up @@ -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()
Expand Down