Skip to content

Commit

Permalink
Merge pull request #325 from ihsoft/next
Browse files Browse the repository at this point in the history
Release v1.9
  • Loading branch information
ihsoft authored Jul 2, 2021
2 parents dd028b8 + 3fab7a5 commit 7aea8a0
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 73 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.9 (July 1st, 2021):
* [Fix #324] Resources intermittently disappear from RTS transfer dialog.

# 1.8 (June 27th, 2021):
* [NOTICE] If a connected KAS part gets involved in a stock EVA construction operation, it will get immediately detached from the peer. To avoid unpexected behvior, it's recommended to manually break the link before using EVA construction mode.
* [NOTICE] The interactive links (like in `PCB`) are now not possible in EVA construction mode.
Expand Down
8 changes: 4 additions & 4 deletions KAS.version
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"KSP_VERSION": {
"MAJOR": 1,
"MINOR": 12,
"PATCH": 0
"PATCH": 1
},
"KSP_VERSION_MAX": {
"MAJOR": 1,
Expand All @@ -23,9 +23,9 @@
"NAME": "KAS",
"URL": "https://github.com/ihsoft/KAS/blob/master/KAS.version",
"VERSION": {
"BUILD": 38781,
"BUILD": 42225,
"MAJOR": 1,
"MINOR": 8,
"PATCH": 7848
"MINOR": 9,
"PATCH": 7852
}
}
6 changes: 3 additions & 3 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion ("1.8.*")]
[assembly: AssemblyInformationalVersion ("1.8 for KSP v1")]
[assembly: KSPAssembly ("KAS", 1, 8)]
[assembly: AssemblyVersion ("1.9.*")]
[assembly: AssemblyInformationalVersion ("1.9 for KSP v1")]
[assembly: KSPAssembly ("KAS", 1, 9)]
[assembly: AssemblyFlags (AssemblyNameFlags.PublicKey)]
113 changes: 50 additions & 63 deletions Source/modules/KASLinkResourceConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,8 @@ bool isGuiOpen {
/// <summary>Definition of all the resources for the both linked vessels.</summary>
ResourceTransferOption[] _resourceRows = new ResourceTransferOption[0];

/// <summary>List of resources that can actually be transferred in any direction.</summary>
/// <remarks>
/// It's derived from <see cref="_resourceRows"/> and only have rows where both sides of the link have non zero
/// capacity for the resource.
/// </remarks>
ResourceTransferOption[] _canTransferResources = new ResourceTransferOption[0];

/// <summary>Index of the vessels resources.</summary>
Dictionary<int, ResourceTransferOption> _resourceRowsHash =
new Dictionary<int, ResourceTransferOption>();
Dictionary<int, ResourceTransferOption> _resourceRowsHash = new();

/// <summary>The currently behaving resource transfer.</summary>
ResourceTransferOption _pendingOption;
Expand Down Expand Up @@ -403,14 +395,13 @@ class ResourceTransferOption {
public readonly double[] leftCapacities;
public readonly double[] rightAmounts;
public readonly double[] rightCapacities;
public readonly GUIContent caption = new GUIContent();
public readonly GUIContent leftInfo = new GUIContent();
public readonly GUIContent rightInfo = new GUIContent();
public readonly GUIContent caption = new();
public readonly GUIContent leftInfo = new();
public readonly GUIContent rightInfo = new();

public bool canMoveRightToLeft;
public bool canMoveLeftToRight;
public bool leftHasCapacity;
public bool rightHasCapacity;
public bool zeroCapacity;
public double previousUpdate;

readonly int _hashCode;
Expand Down Expand Up @@ -486,6 +477,45 @@ public void StopAllTransfers() {
_rightToLeftTransferToggle = false;
}

/// <summary>Updates the internal state to the current state of the parts.</summary>
/// <remarks>This method is called at a high frequency, so it must be optimized.</remarks>
/// <param name="leftPart">The owner vessel RTS part.</param>
/// <param name="rightPart">The connected vessel socket part.</param>
public void Update(Part leftPart, Part rightPart) {
var leftInfoString = "";
var rightInfoString = "";
canMoveRightToLeft = true;
canMoveLeftToRight = true;
for (var i = 0; i < resources.Length; i++) {
leftPart.GetConnectedResourceTotals(
resources[i], ResourceFlowMode.ALL_VESSEL_BALANCE, out leftAmounts[i], out leftCapacities[i]);
leftInfoString += (i > 0 ? "\n" : "")
+ CompactNumberType.Format(leftAmounts[i]) + " / " + CompactNumberType.Format(leftCapacities[i]);
rightPart.GetConnectedResourceTotals(
resources[i], ResourceFlowMode.ALL_VESSEL_BALANCE,
out rightAmounts[i], out rightCapacities[i]);
rightInfoString += (i > 0 ? "\n" : "")
+ CompactNumberType.Format(rightAmounts[i]) + " / " + CompactNumberType.Format(rightCapacities[i]);
if (rightAmounts[i] < double.Epsilon || leftAmounts[i] >= leftCapacities[i]) {
canMoveRightToLeft = false;
}
if (leftAmounts[i] < double.Epsilon || rightAmounts[i] >= rightCapacities[i]) {
canMoveLeftToRight = false;
}
}
leftInfo.text = leftInfoString;
rightInfo.text = rightInfoString;

// If either of the sides has zero capacity for the resource, then it cannot be transferred.
zeroCapacity = false;
for (var i = leftCapacities.Length - 1; !zeroCapacity && i >= 0; i--) {
zeroCapacity = leftCapacities[i] < double.Epsilon;
}
for (var i = rightCapacities.Length - 1; !zeroCapacity && i >= 0; i--) {
zeroCapacity = rightCapacities[i] < double.Epsilon;
}
}

/// <summary>Updates the transfer trigger flag.</summary>
/// <remarks>Ensures that the values are not updated when the property hasn't changed.</remarks>
void UpdateTransferTriggerFlag(ref bool property, bool newValue) {
Expand Down Expand Up @@ -625,18 +655,17 @@ void TransferResourcesWindowFunc(int windowId) {
GUILayout.Label(ConnectedVesselTxt.Format(linkTarget.part.vessel.vesselName), _guiNoWrapCenteredStyle);

// No resources, no transfer.
if (_canTransferResources.Length == 0) {
if (_resourceRows.Length == 0) {
GUILayout.Label(NoResourcesFound, _guiNoWrapCenteredStyle);
if (GUILayout.Button(CloseDialogBtn)) {
// GuiActions.Add(() => _isGuiOpen = false);
isGuiOpen = false;
_guiActions.Add(() => _isGuiOpen = false);
}
SetPendingTransferOption(null); // Cancel all transfers.
GUI.DragWindow();
return;
}

for (var i = _canTransferResources.Length - 1; i >= 0; i--) {
for (var i = _resourceRows.Length - 1; i >= 0; i--) {
var row = _resourceRows[i];
_guiResourcesTable.StartNewRow();
using (new GUILayout.HorizontalScope()) {
Expand Down Expand Up @@ -794,52 +823,8 @@ void UpdateResourcesTransferGui(bool force = false) {
}
_lastResourcesGuiUpdate = Time.unscaledTime;
for (var i = _resourceRows.Length - 1; i >= 0; i--) {
UpdateOptionTransferGui(_resourceRows[i]);
}
_canTransferResources =
_resourceRows.Where(r => r.leftHasCapacity && r.rightHasCapacity).ToArray();
}

/// <summary>Updates the resources amounts and the transfer states in GUI.</summary>
/// <remarks>This method must be performance optimized.</remarks>
/// <param name="resOption">The resource transfer option to update.</param>
void UpdateOptionTransferGui(ResourceTransferOption resOption) {
var leftInfoString = "";
var rightInfoString = "";
resOption.canMoveRightToLeft = true;
resOption.canMoveLeftToRight = true;
var leftCapacity = 0.0;
var rightCapacity = 0.0;
for (var i = 0; i < resOption.resources.Length; i++) {
part.GetConnectedResourceTotals(
resOption.resources[i], ResourceFlowMode.ALL_VESSEL_BALANCE,
out resOption.leftAmounts[i], out resOption.leftCapacities[i]);
leftCapacity += resOption.leftCapacities[i];
leftInfoString += (i > 0 ? "\n" : "")
+ CompactNumberType.Format(resOption.leftAmounts[i])
+ " / "
+ CompactNumberType.Format(resOption.leftCapacities[i]);
linkTarget.part.GetConnectedResourceTotals(
resOption.resources[i], ResourceFlowMode.ALL_VESSEL_BALANCE,
out resOption.rightAmounts[i], out resOption.rightCapacities[i]);
rightCapacity += resOption.rightCapacities[i];
rightInfoString += (i > 0 ? "\n" : "")
+ CompactNumberType.Format(resOption.rightAmounts[i])
+ " / "
+ CompactNumberType.Format(resOption.rightCapacities[i]);
if (resOption.rightAmounts[i] < double.Epsilon
|| resOption.leftAmounts[i] >= resOption.leftCapacities[i]) {
resOption.canMoveRightToLeft = false;
}
if (resOption.leftAmounts[i] < double.Epsilon
|| resOption.rightAmounts[i] >= resOption.rightCapacities[i]) {
resOption.canMoveLeftToRight = false;
}
_resourceRows[i].Update(part, linkTarget.part);
}
resOption.leftHasCapacity = leftCapacity >= double.Epsilon;
resOption.rightHasCapacity = rightCapacity >= double.Epsilon;
resOption.leftInfo.text = leftInfoString;
resOption.rightInfo.text = rightInfoString;
}

/// <summary>
Expand Down Expand Up @@ -912,7 +897,9 @@ void MaybeUpdateResourceOptionList() {
mixture.components.Select(x => x.ratio).ToArray()));
}

movableResources.ForEach(r => r.Update(part, linkTarget.part));
_resourceRows = movableResources
.Where(r => !r.zeroCapacity)
.Select(resource => _resourceRowsHash.ContainsKey(resource.GetHashCode())
? _resourceRowsHash[resource.GetHashCode()]
: resource)
Expand Down
2 changes: 1 addition & 1 deletion Tools/publish_curseforge_args.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
--github=ihsoft/KAS
--versions=latest_all_builds
--title=KAS {tag}
--archive=../KAS_v1.8.zip
--archive=../KAS_v1.9.zip
2 changes: 1 addition & 1 deletion Tools/publish_github_args.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
--changelog=../CHANGELOG.md
--as_draft
--title=KAS v{tag}
--archive=../KAS_v1.8.zip
--archive=../KAS_v1.9.zip
2 changes: 1 addition & 1 deletion Tools/publish_spacedock_args.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
--changelog=../CHANGELOG.md
--github=ihsoft/KAS
--ksp_version=latest
--archive=../KAS_v1.8.zip
--archive=../KAS_v1.9.zip

0 comments on commit 7aea8a0

Please sign in to comment.