Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav committed Apr 26, 2023
2 parents ed30223 + 1957f56 commit 8d345e5
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/msbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
env:
KSP_ZIP_PASSWORD: ${{ secrets.KSP_ZIP_PASSWORD }}
run: |
curl https://ksp-ro.s3-us-west-2.amazonaws.com/TestFlight_bin_KSP-1.10.zip --output /tmp/bins.zip
curl https://ksp-ro.s3-us-west-2.amazonaws.com/KSPAssemblies-1.12.zip --output /tmp/bins.zip
KSP_DLL_PATH="/opt/ksp/assembly"
echo "::set-output name=ksp-dll-path::${KSP_DLL_PATH}"
mkdir -p "${KSP_DLL_PATH}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
env:
KSP_ZIP_PASSWORD: ${{ secrets.KSP_ZIP_PASSWORD }}
run: |
curl https://ksp-ro.s3-us-west-2.amazonaws.com/TestFlight_bin_KSP-1.10.zip --output /tmp/bins.zip
curl https://ksp-ro.s3-us-west-2.amazonaws.com/KSPAssemblies-1.12.zip --output /tmp/bins.zip
KSP_DLL_PATH="/opt/ksp/assembly"
echo "::set-output name=ksp-dll-path::${KSP_DLL_PATH}"
mkdir -p "${KSP_DLL_PATH}"
Expand Down
5 changes: 1 addition & 4 deletions TestFlightAPI/TestFlightAPI/TestFlightPartData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ public int GetInt(string key)
public void SetValue(string key, object value)
{
key = key.ToLowerInvariant();
if (partData.ContainsKey(key))
partData[key] = value.ToString();
else
partData.Add(key, value.ToString());
partData[key] = value.ToString();
}

public void AddValue(string key, float value)
Expand Down
61 changes: 31 additions & 30 deletions TestFlightCore/TestFlightCore/TestFlight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,7 @@ public string GetValue(string key)
public void SetValue(string key, string value)
{
key = key.ToLowerInvariant();
if (saveData.ContainsKey(key))
saveData[key] = value;
else
saveData.Add(key, value);
saveData[key] = value;
}

private void DecodeRawSaveData()
Expand Down Expand Up @@ -616,47 +613,45 @@ public string PartWithNoData(string partList)
// Get access to a part's data store for further set/get
public TestFlightPartData GetPartDataForPart(string partName)
{
TestFlightPartData returnValue = null;

if (partData.ContainsKey(partName))
returnValue = partData[partName];
TestFlightPartData returnValue;
partData.TryGetValue(partName, out returnValue);

return returnValue;
}

// Sets the existing partData for this part, or adds a new one
public void SetPartDataForPart(string partName, TestFlightPartData newData)
{
if (partData.ContainsKey(partName))
partData[partName] = newData;
else
partData.Add(partName, newData);
partData[partName] = newData;
}

// New noscope Format
// This is a utility method that will return the "flightData" value directly or -1 if not found
public float GetFlightDataForPartName(string partName)
{
if (partData.ContainsKey(partName))
TestFlightPartData data;
if (partData.TryGetValue(partName, out data))
{
return partData[partName].flightData;
return data.flightData;
}
else
return -1f;
}
// This is a utility method that will return the "transferData" value directly or -1 if not found
public float GetTransferDataForPartName(string partName)
{
if (partData.ContainsKey(partName))
return partData[partName].transferData;
TestFlightPartData data;
if (partData.TryGetValue(partName, out data))
return data.transferData;
else
return -1f;
}
// This is a utility method that will return the "researchData" value directly or -1 if not found
public float GetResearchDataForPartName(string partName)
{
if (partData.ContainsKey(partName))
return partData[partName].researchData;
TestFlightPartData data;
if (partData.TryGetValue(partName, out data))
return data.researchData;
else
return -1f;
}
Expand All @@ -665,8 +660,9 @@ public float GetResearchDataForPartName(string partName)
// This is a utility method that sets the "flightData" value directly
public void SetFlightDataForPartName(string partName, float data)
{
if (partData.ContainsKey(partName))
partData[partName].flightData = data;
TestFlightPartData pd;
if (partData.TryGetValue(partName, out pd))
pd.flightData = data;
else
{
TestFlightPartData newData = new TestFlightPartData();
Expand All @@ -678,8 +674,9 @@ public void SetFlightDataForPartName(string partName, float data)
// This is a utility method that sets the "transferData" value directly
public void SetTransferDataForPartName(string partName, float data)
{
if (partData.ContainsKey(partName))
partData[partName].transferData = data;
TestFlightPartData pd;
if (partData.TryGetValue(partName, out pd))
pd.transferData = data;
else
{
TestFlightPartData newData = new TestFlightPartData();
Expand All @@ -691,8 +688,9 @@ public void SetTransferDataForPartName(string partName, float data)
// This is a utility method that sets the "researchData" value directly
public void SetResearchDataForPartName(string partName, float data)
{
if (partData.ContainsKey(partName))
partData[partName].researchData = data;
TestFlightPartData pd;
if (partData.TryGetValue(partName, out pd))
pd.researchData = data;
else
{
TestFlightPartData newData = new TestFlightPartData();
Expand All @@ -704,8 +702,9 @@ public void SetResearchDataForPartName(string partName, float data)
// This is a utility method that adds the "flightData" value directly
public void AddFlightDataForPartName(string partName, float data)
{
if (partData.ContainsKey(partName))
partData[partName].flightData += data;
TestFlightPartData pd;
if (partData.TryGetValue(partName, out pd))
pd.flightData += data;
else
{
TestFlightPartData newData = new TestFlightPartData();
Expand All @@ -717,8 +716,9 @@ public void AddFlightDataForPartName(string partName, float data)
// This is a utility method that adds the "transferData" value directly
public void AddTransferDataForPartName(string partName, float data)
{
if (partData.ContainsKey(partName))
partData[partName].transferData += data;
TestFlightPartData pd;
if (partData.TryGetValue(partName, out pd))
pd.transferData += data;
else
{
TestFlightPartData newData = new TestFlightPartData();
Expand All @@ -730,8 +730,9 @@ public void AddTransferDataForPartName(string partName, float data)
// This is a utility method that adds the "researchData" value directly
public void AddResearchDataForPartName(string partName, float data)
{
if (partData.ContainsKey(partName))
partData[partName].researchData += data;
TestFlightPartData pd;
if (partData.TryGetValue(partName, out pd))
pd.researchData += data;
else
{
TestFlightPartData newData = new TestFlightPartData();
Expand Down
18 changes: 15 additions & 3 deletions TestFlightCore/TestFlightCore/TestFlightCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class TestFlightCore : PartModuleExtended, ITestFlightCore
[KSPField]
public float techTransferMax = 1000;
[KSPField]
public float perFlightMax = 0;
[KSPField]
public float techTransferGenerationPenalty = 0.05f;
[KSPField]
public float maxData = 0f;
Expand Down Expand Up @@ -183,6 +185,7 @@ bool SetActiveConfigFromInterop()
currentConfig.TryGetValue("techTransferMax", ref techTransferMax);
currentConfig.TryGetValue("techTransferGenerationPenalty", ref techTransferGenerationPenalty);
currentConfig.TryGetValue("maxData", ref maxData);
currentConfig.TryGetValue("perFlightMax", ref perFlightMax);
currentConfig.TryGetValue("failureRateModifier", ref failureRateModifier);
currentConfig.TryGetValue("scienceDataValue", ref scienceDataValue);
currentConfig.TryGetValue("rndMaxData", ref rndMaxData);
Expand Down Expand Up @@ -552,8 +555,14 @@ public float ModifyFlightData(float modifier, bool additive)
{
newFlightData = existingData * modifier;
}

if (perFlightMax > 0f)
{
newFlightData = Math.Min(newFlightData, initialFlightData + perFlightMax);
}

// Adjust new flight data if neccesary to stay under the cap
if (newFlightData > (maxData * dataCap))
if (dataCap != 1f && newFlightData > (maxData * dataCap))
newFlightData = maxData * dataCap;
if (newFlightData > maxData)
newFlightData = maxData;
Expand Down Expand Up @@ -852,8 +861,11 @@ public void InitializeFlightData(float flightData)

currentFlightData = Mathf.Min(maxData, flightData);
initialFlightData = Mathf.Min(maxData, flightData + researchData + transferData);

TestFlightManagerScenario.Instance.SetFlightDataForPartName(Alias, flightData);

// Keep scenario flight data unchanged if it's higher than this part's flight data
float savedFlightData = TestFlightManagerScenario.Instance.GetFlightDataForPartName(Alias);
TestFlightManagerScenario.Instance.SetFlightDataForPartName(Alias, Mathf.Max(flightData, savedFlightData));

missionStartTime = Planetarium.GetUniversalTime();

initialized |= HighLogic.LoadedSceneIsFlight;
Expand Down
5 changes: 3 additions & 2 deletions TestFlightCore/TestFlightCore/TestFlightRnDScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,10 @@ public bool GetPartResearchState(string partName)

public void SetPartResearchState(string partName, bool researchActive)
{
if (activeTeams.ContainsKey(partName))
TestFlightRnDTeam teams;
if (activeTeams.TryGetValue(partName, out teams))
{
activeTeams[partName].ResearchActive = researchActive;
teams.ResearchActive = researchActive;
}
}

Expand Down
3 changes: 2 additions & 1 deletion TestFlightCore/TestFlightCore/TestFlightWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ internal override void DrawWindow(Int32 id)
// Display information on active vessel
Guid currentVessel = FlightGlobals.ActiveVessel.id;

if (masterStatus.ContainsKey(currentVessel) && masterStatus[currentVessel].allPartsStatus.Count > 0)
MasterStatusItem statusItem;
if (masterStatus.TryGetValue(currentVessel, out statusItem) && statusItem.allPartsStatus.Count > 0)
{
tfScenario.userSettings.currentMSDScrollPosition = GUILayout.BeginScrollView(tfScenario.userSettings.currentMSDScrollPosition);
foreach (PartStatus status in masterStatus[currentVessel].allPartsStatus)
Expand Down

0 comments on commit 8d345e5

Please sign in to comment.