Jump to content

Responding to TweakScale resizes


Recommended Posts

I did it by having a public float as a ksp field, and setting it up as a value that tweak scale modifies in my modules.

It's defaulted to 1 and used as a multiplier in the code. It's necessary for wheels to scale torque, power consumption, suspension movement and a load of other stuff.

You'll find it in the Kerbal Foundries (KFWheel) source and configs if you want to take a proper look.

Or, at least I think you mean making a part module aware of what size the part is scaled to?

Link to comment
Share on other sites

Tweakscale stores the scaled value as a KSPField in its module.

I account for this by checking for a TweakScale module on my part, checking for the "currentScale" field and modifying values as needed. The only problem is that Tweakscale stores the value differently depending on what type of scale you are using. The typical 1X, 2X, 3X type of scale just stores the value as a multiplier, but the free sliding scale stores it as a percentage, 0-100% or higher. Unless something has changed you might have to find a way to account for users with both types of scaling.


if (part.Modules.Contains("TweakScale"))
{
PartModule pM = part.Modules["TweakScale"];
if (pM.Fields.GetValue("currentScale") != null)
{
float tweakedScale = 1f;
try
{
tweakedScale = pM.Fields.GetValue<float>("currentScale");
DMUtils.Logging("TweakScale Value Detected On XRay Instrument; Drill Length Set To 8.8m * {0}", tweakedScale);
}
catch
{
DMUtils.Logging("Error in TweakScale PartModule Field; Resetting TweakScale Factor to 1");
}
scale *= tweakedScale;
}
}

Link to comment
Share on other sites

currentScale/defaultScale is what you are looking for. This is the scaling factor compared to the untouched part, and is independent of the scaletype. Both values are members of the TweakScale module.

@DMagic, do you want to do that yourself, or is this a workaround for a missing config on my side? The usual way would be to have a drillLength variable in your module, and a SCALEEXPONENTS config which tells TweakScale how to change it.

@FreeThinker: in the OP of the old TweakScale Thread under 'advanced features', there is an interface description for getting notified on rescale. Maybe this is what you are looking for.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...