Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
pellinor0 committed Apr 16, 2018
1 parent 7e54309 commit 3c7b27a
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 92 deletions.
2 changes: 1 addition & 1 deletion GameData/TweakScale/TweakScale.version
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"VERSION":{
"MAJOR":2,
"MINOR":3,
"PATCH":11,
"PATCH":12,
"BUILD":0
},
"KSP_VERSION":{
Expand Down
Binary file modified GameData/TweakScale/plugins/Scale.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion( "2.3.11.0")]
[assembly: AssemblyFileVersion("2.3.11.0")]
[assembly: AssemblyVersion( "2.3.12.0")]
[assembly: AssemblyFileVersion("2.3.12.0")]
89 changes: 0 additions & 89 deletions Scale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public class TweakScale : PartModule, IPartCostModifier, IPartMassModifier
public float MassScale = 1;

private Hotkeyable _chainingEnabled;
private Hotkeyable _autoscaleEnabled;

/// <summary>
/// The ScaleType for this part.
Expand Down Expand Up @@ -271,8 +270,6 @@ public override void OnStart(StartState state)
GameEvents.onEditorShipModified.Add(OnEditorShipModified);
}

_autoscaleEnabled = HotkeyManager.Instance.AddHotkey("Autoscale", new[] {KeyCode.LeftShift},
new[] {KeyCode.LeftControl, KeyCode.L}, false);
_chainingEnabled = HotkeyManager.Instance.AddHotkey("Scale chaining", new[] {KeyCode.LeftShift},
new[] {KeyCode.LeftControl, KeyCode.K}, false);
}
Expand Down Expand Up @@ -336,12 +333,6 @@ void Update()

if (HighLogic.LoadedSceneIsEditor)
{
if (_firstUpdateWithParent && part.HasParent())
{
if ((_autoscaleEnabled != null) && _autoscaleEnabled.State)
AutoScale(part.parent.GetComponent<TweakScale>(), this);
}

if (currentScale >= 0f)
{
var changed = currentScale != (isFreeScale ? tweakScale : ScaleFactors[tweakName]);
Expand Down Expand Up @@ -716,86 +707,6 @@ private void MoveNode(AttachNode node, AttachNode baseNode, bool movePart, bool
ScaleAttachNode(node, baseNode);
}

/// <summary>
/// Find the Attachnode that fastens <paramref name="a"/> to <paramref name="b"/> and vice versa.
/// </summary>
/// <param name="a">The source part (often the parent)</param>
/// <param name="b">The target part (often the child)</param>
/// <returns>The AttachNodes between the two parts.</returns>
private static Tuple<AttachNode, AttachNode>? NodesBetween(Part a, Part b)
{
/*var nodeA = a.findAttachNodeByPart(b);
var nodeB = b.findAttachNodeByPart(a);
if (nodeA == null || nodeB == null)
return null;
return Tuple.Create(nodeA, nodeB);*/
return null;
}

/// <summary>
/// Calculate the correct scale to use for scaling a part relative to another.
/// </summary>
/// <param name="a">Source part, from which we get the desired scale.</param>
/// <param name="b">Target part, which will potentially be scaled.</param>
/// <returns>The difference in scale between the (scaled) attachment nodes connecting <paramref name="a"/> and <paramref name="b"/>, or null if somethinng went wrong.</returns>
private static float? GetRelativeScaling(TweakScale a, TweakScale b)
{
if (a == null || b == null)
return null;

var nodes = NodesBetween(a.part, b.part);

if (!nodes.HasValue)
return null;

var nodeA = nodes.Value.Item1;
var nodeB = nodes.Value.Item2;

var aIdx = a._prefabPart.attachNodes.FindIndex( t => t.id == nodeA.id);
var bIdx = b._prefabPart.attachNodes.FindIndex( t => t.id == nodeB.id);
if (aIdx < 0 || bIdx < 0
|| aIdx >= a._prefabPart.attachNodes.Count
|| aIdx >= a._prefabPart.attachNodes.Count)
return null;

var sizeA = (float)a._prefabPart.attachNodes[aIdx].size;
var sizeB = (float)b._prefabPart.attachNodes[bIdx].size;

if (sizeA == 0)
sizeA = 0.5f;
if (sizeB == 0)
sizeB = 0.5f;

return (sizeA * a.tweakScale/a.defaultScale)/(sizeB * b.tweakScale/b.defaultScale);
}

/// <summary>
/// Automatically scale part to match other part, if applicable.
/// </summary>
/// <param name="a">Source part, from which we get the desired scale.</param>
/// <param name="b">Target part, which will potentially be scaled.</param>
private static void AutoScale(TweakScale a, TweakScale b)
{
if (a == null || b == null)
return;

if (a.ScaleType != b.ScaleType)
return;

var factor = GetRelativeScaling(a,b);
if (!factor.HasValue)
return;

b.tweakScale = b.tweakScale * factor.Value;
if (!b.isFreeScale && (b.ScaleFactors.Length > 0))
{
b.tweakName = Tools.ClosestIndex(b.tweakScale, b.ScaleFactors);
}
b.OnTweakScaleChanged();
}

/// <summary>
/// Propagate relative scaling factor to children.
/// </summary>
Expand Down

0 comments on commit 3c7b27a

Please sign in to comment.