Skip to content

Commit

Permalink
add variable for accessing the propellant resource name
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyOThan committed Aug 11, 2024
1 parent f15bd46 commit f126146
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
10 changes: 9 additions & 1 deletion RasterPropMonitor/Core/RPMCEvaluators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ internal VariableEvaluator GetEvaluator(string input, out VariableUpdateType upd
return null;
}

case "PROPELLANTR":
if (tokens[2] == "NAME")
{
ushort propellantIndex = Convert.ToUInt16(tokens[1]);
return (RPMVesselComputer comp) => comp.resources.GetPropellantResourceName(propellantIndex);
}
return null;

case "CREWLOCAL":
int crewSeatID = Convert.ToInt32(tokens[1]);
return (RPMVesselComputer comp) =>
Expand Down Expand Up @@ -363,7 +371,7 @@ internal NumericVariableEvaluator GetNumericEvaluator(string input, out Variable
return null;
}
}
case "PROPLNTR":
case "PROPELLANTR":
{
if (tokens.Length == 3 && uint.TryParse(tokens[1], out uint propellantIndex))
{
Expand Down
19 changes: 16 additions & 3 deletions RasterPropMonitor/Core/ResourceDataStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public double ListElement(string resourceName, ResourceProperty valueType, bool
}
}

public double GetPropellantResourceValue(uint propellantIndex, ResourceProperty valueType, bool stage)
private ResourceData GetPropellantResource(uint propellantIndex)
{
uint currentPropellantIndex = 0;

Expand All @@ -255,7 +255,7 @@ public double GetPropellantResourceValue(uint propellantIndex, ResourceProperty
{
if (currentPropellantIndex == propellantIndex)
{
return (double)resource.GetProperty(valueType, stage);
return resource;
}
else
{
Expand All @@ -265,7 +265,20 @@ public double GetPropellantResourceValue(uint propellantIndex, ResourceProperty
}
}

return 0;
return null;
}

public double GetPropellantResourceValue(uint propellantIndex, ResourceProperty valueType, bool stage)
{
ResourceData rd = GetPropellantResource(propellantIndex);

return rd == null ? 0 : rd.GetProperty(valueType, stage);
}

public string GetPropellantResourceName(uint propellantIndex)
{
ResourceData rd = GetPropellantResource(propellantIndex);
return rd == null ? "" : rd.resourceDefinition.name;
}

private class ResourceData
Expand Down

0 comments on commit f126146

Please sign in to comment.