Skip to content

Commit

Permalink
Fix #5: struts and fuel lines update properly when parts are scaled
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyOThan committed Feb 3, 2024
1 parent 79955bb commit 645b7a3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Source/ConstructionModeScale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ private void onScaleGizmoHandleDrag(GizmoOffsetHandle handle, Vector3 axis, floa
var tweakScaleModule = selectedPart.FindModuleImplementing<TweakScale>();
float newScaleFactor = previousScaleFactor + amount;
tweakScaleModule.SetScaleFactor(newScaleFactor, GetScaleSnapMode());

GameEvents.onEditorPartEvent.Fire(ConstructionEventType.PartOffsetting, selectedPart);
}

private void onScaleGizmoUpdated(Vector3 arg1)
Expand Down Expand Up @@ -398,8 +400,7 @@ private void partscaleInputUpdate()
fsm.RunEvent(on_scaleReset);
}

// TODO: do we need to emit a construction event? What kind? Where?
//GameEvents.onEditorPartEvent.Fire(ConstructionEventType.PartOffset, selectedPart);
GameEvents.onEditorPartEvent.Fire(ConstructionEventType.PartOffset, selectedPart);
}
}

Expand Down
27 changes: 27 additions & 0 deletions Source/HarmonyPatching/Squad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,31 @@ static void Prefix(InternalModel __instance, Part p)
__instance.transform.localScale = tweakScaleModule.currentScaleFactor * Vector3.one;
}
}

[HarmonyPatch(typeof(CompoundPart), nameof(CompoundPart.UpdateWorldValues))]
static class CompoundPart_UpdateWorldValue
{
static void Postfix(CompoundPart __instance)
{
__instance.wTgtPos /= __instance.target.rescaleFactor;
}
}

[HarmonyPatch(typeof(CompoundPart), nameof(CompoundPart.UpdateTargetCoords))]
static class CompoundPart_UpdateTargetCoords
{
static void Prefix(CompoundPart __instance, ref Vector3 __state)
{
__state = __instance.wTgtPos;
if (__instance.target != null)
{
__instance.wTgtPos *= __instance.target.rescaleFactor;
}
}

static void Postfix(CompoundPart __instance, Vector3 __state)
{
__instance.wTgtPos = __state;
}
}
}

0 comments on commit 645b7a3

Please sign in to comment.