Kerbal Inventory System (KIS)

Kerbal Inventory System (KIS)

1M Downloads

Implement full support of TweakScale mod

ihsoft opened this issue ยท 17 comments

commented

Things to cover:

  • Part's volume.
  • Part's mass.
  • Volume of inventory parts.

Support from TweakScale side may be needed as KIS deals with prefabs that hold original model/mass.

commented

I'm thinking about adding a bit more intelligence to the prefab: pellinor0/TweakScale#39

So you would only need to remember the scale of a stored part and could call the TweakScale module of the prefab with things like getMassModifier(float currentScale) whenever that information is needed.

commented

This sounds promising, but KIS also needs volume modifier. And thinking about the future, KAS may want to adjust joint strength basing on the scale.

commented

Calculating scalingFactor is not really clear. I think I'll figure it out but another approach could be creating a method like this:

public double getDryCostFactor(ConfigNode node)

Where node is persistent state of Tweakable module. This way two goals are achieved:

  • Callers need not know how to calculate the scale factor.
  • Your code could be more flexible in case of you decide to consider extra settings in the caluclation.
commented

I wrote some functions so you can ask the prefab about how the scaled part would look like:
pellinor0/TweakScale@1b5c321

In this version the "TweakScale::debugOutput" method is an example how to use them. For dryCost and mass I use the configured exponents, volume is currently hardcoded to scale^3.

Would this be a good interface for you?

commented

Maybe rescaleFactor is a better name. It means the scale change compared to the prefab part, calculated as currentScale/defaultScale if you have a saved TweakScale module.

My doubt about the config node: is it an object that someone dealing with unloaded or hypothetical parts is guaranteed to have? The gain in flexibility is minor because extra settings should be part of the prefab (for example a new scaling exponent for volume).

Who else could have an interest in this interface? Maybe @magico13 from KCT: does your new part inventory have any requirements for TweakScale?

commented

@allista sorry I should have been more explicit. Like KIS, both hangar and GC deal with parts that are not alive in the current scene, and might contain TweakScale modules manipulating their size, mass and cost. KIS needs to query those manipulations without bringing the part to live. The question is if there are any other stakeholders for this new interface.
(this is my design so far: pellinor0/TweakScale@1b5c321 )

commented

Ah, I see.
Both Hangar and GC deal with the fully-loaded ShipConstruts in editor (to deal with that same problem), so modules that change part starts have already done their work by the time Hangar/GC read a construct in. The only thing both mods do with the saved construct, beside launching it, is transfer resources and crew by directly changing respective ConfiNodes. The stats are saved per construct, not part-wide.
So currently there's no need for me to query offloaded part stats.
Thanks for your concern!

commented

Additional ping @allista for hangar and ground construction: are you happy with what TweakScale offers today or do you need something more?

commented

It's hard to answer that one, @pellinor0. For hangar I had, from the beginning, to use my own light version of part resizer that has one feature TweakScale does not: different scale for Y and XZ dimensions. This allows me to change length of a hangar to fit possible content. GC uses the same part resizer as hangar by extension.

Er... should I be writing it here, or maybe move this to a separate discussion elsewhere?

commented

@ihsoft: the interface is now released in TweakScale v2.3.4. I changed the parameter name to scalingFactor and added a note about how to calculate it:
https://github.com/pellinor0/TweakScale/blob/master/Scale.cs#L845-L863
Please let me know if you could use any more help.

And as a note to TweakScale integration, it would be nice to have a text "x%" somewhere for parts in an inventory which are not the original size.

commented

If something needs to be done from TweakScale's side, I'd be glad to help.

This used to work in the past (1.0.x, when KIS inventories where already around). So most likely there is already code in KIS to handle these things. Currently TweakScale only handles the inventory capacity of scaled parts.

Parts inside an inventory do not exist for the game engine, so probably their TweakScale code is never called and the volume must be done by KIS in some way. Actually I have no idea how KIS calculated the mass of a scaled part inside an inventory (since what TweakScale does with it can be configured in quite complex ways). Currently I store massScale as a (non-persistent) field in the TweakScale module.

Mass might have broken with the changes of the stock mass handling. Generally TweakScale should behave the same as other mass-changing modules, like the part/fuel switches (reporting its changes with respect to the prefab mass via a getModuleMass method).

In case it helps, TweakScale now also exposes its API via the stock partMessage system
http://forum.kerbalspaceprogram.com/index.php?/topic/101540-113-tweakscale-v2213jun-24-the-chainscaling-update/&page=28

PS: I just stumbled upon exponents for two fields that seem dubious to me:

  • KASModuleContainer::maxSize - does that partModule still exist?
  • ModuleKISInventory::slotSize - what does that do, and should I scale it at all?
commented

@pellinor0
Good to know about the message. Though, it only fires on a real part while inventory works with prefabs.

Here is the code that figures out the adjusted volume: https://github.com/KospY/KIS/blob/master/Plugins/Source/KIS_Shared.cs#L525. It used to work fine but if anything changed in the config it may get broken. Mass is a different story - it is calculated in several places spanned across the code base, it's not refactored yet.

One way to have it fixed is providing two methods from the tweak scale module: GetVoulmeModifier() and GetMassModifier(). I'll call them and use as a ratio to the prefab's mass/volume values.

commented

KASModuleContainer::maxSize - does that partModule still exist?

There is no such module in KAS. Where did you get the link from?

ModuleKISInventory::slotSize - what does that do, and should I scale it at all?

It's GUI stuff. A really outdated one. You don't need to scale it.

commented

I don't see what would have changed with the currentScale/defaultScale, those values should behave as they always have. So VolumeModifier would always be (currentScale/defaultScale)^3. What is this configNode it uses? If this is the part as it would look in a save/craft file then it should work fine.

MassModifier would be TweakScale::MassScale. Unlike the others this field is currently not persistent (I could change that), so it is only available after the TweakScale partModule has come to life in the usual way (OnLoad/OnStart). This is how FAR gets it:

            if(part.Modules.Contains("TweakScale"))
            {
                PartModule m = part.Modules["TweakScale"];
                float massScale = (float)m.Fields.GetValue("MassScale");

PS: most likely KASModuleContainer was the predecessor of the KIS Inventories, before KIS existed as a separate mod. I vaguely remember a UI with a list of part names instead of the pictures we have now.

commented

TweakScale is now officially a compatible mod. If anything breaks, it's a bug.

@pellinor0 Please, notify me when your mod starts handling variants. This line of code is a dependency.

commented

TweakScale is now officially a compatible mod. If anything breaks, it's a bug.

@pellinor0 Please, notify me when your mod starts handling variants. This line of code is a dependency.

ping to @net-lisias-ksp since he has taken over the development of TweakScale