linuxgurugamer / KCT

Kerbal Construction Time - An addon for Kerbal Space Program
GNU General Public License v3.0
11 stars 15 forks source link

Setting isKCTBuilt = true fields for all the modules KCT sees in the ship's config tree #73

Closed DarthPointer closed 3 years ago

DarthPointer commented 4 years ago

This code does a simple trick. Each ship added to build list or to storage via recovery is checked for isKCTBuilt fields in modules and these fields are set to true. The affected modules should set it back to false on their own in order not to get foolished if a ship is saved in such a state.

I have done it for consistency of automatic reliability updates in my PayToPlay mod (this issue). I'd like to release P2P 1.5.0 using this feature by the end of July. Any other mod can use this feature, provided that its module has a bool "isKCTBuilt" field and sets it to false before its part is saved as a part of a ship or a subassembly.

siimav commented 4 years ago

It would be better if you extracted that code into a method and messed with the part nodes only if PayToPlay is installed.

DarthPointer commented 4 years ago

I need to know the answer for "Am I KCT-built?" by the time OnLoad (or what is the method used for telling PartModules they have entered the scene). Is there a way I call a method of a module on a part that has just been added to the scene, before OnLoad is called?

DarthPointer commented 4 years ago

And on second thought... KCT can search for modules implementing an interface like IKCTBuiltChecking and call IKCTBuiltChecking.YouAreKCTBuilt() before retrieving craft tree node...

siimav commented 4 years ago

Maybe you need an event instead where KCT would signal that it's going to queue a vessel for build. Similar to these: https://github.com/linuxgurugamer/KCT/blob/master/Kerbal_Construction_Time/KCT_Events.cs#L18-L21

DarthPointer commented 4 years ago

Maybe you need an event instead where KCT would signal that it's going to queue a vessel for build. Similar to these: https://github.com/linuxgurugamer/KCT/blob/master/Kerbal_Construction_Time/KCT_Events.cs#L18-L21

Seems to be the most reasonable solution. I'll try to get how the events work and be back with another PR.

DarthPointer commented 4 years ago

Upd: GameEvents is not a solution... If I send a callback to event system from a real PartModule of a Part in editor and then it is told that it is going to be a new KCT-built vessel and I save it as a subassembly problems arise. I have literally no idea how to prevent a saved subassm have a flag of being KCT-built. I'm afraid that changing fields in the vessel tree right after it is added to KCT's lists is the only way out I see. Thus I'd like to wait for LGG to response and tell us his opinion.

I know that the design of the solution is very ugly, but since I see no other options at the moment, I nearly insist on such a feature being added. If it is rejected, then I WILL ask for permission to redistribute changed KCT (ofc with following all the license-related stuff).

linuxgurugamer commented 4 years ago

Change the way you set the flag so that it is only set AFTER a vessel is built and launched

DarthPointer commented 4 years ago

Change the way you set the flag so that it is only set AFTER a vessel is built and launched

Then we have a problem if I only set the flag after launching the vessel. Launch, recovery and consequent edits without launching will cause VAB scene loads with unset flags because the flags should be read and unset in editor ASAP. Otherwise we can save a subassembly with the flags set to true. I'll doublecheck the GamEvent-s system for possible solution, probably I have missed a helpful event.

Codestyle: ofc I should have done a separate method to replase the two similar insertions with single calls.

DarthPointer commented 4 years ago

Probably it will make sense to make the feature enabled for KCT-1.8 only with preprocessor #if. But I can't find out what should be the argument for 1.8 build, I have seen in the code only RO one.

Activation only if P2P is present: how should it be done and does it worth doing it?

linuxgurugamer commented 4 years ago

Probably it will make sense to make the feature enabled for KCT-1.8 only with preprocessor #if. But I can't find out what should be the argument for 1.8 build, I have seen in the code only RO one.

Activation only if P2P is present: how should it be done and does it worth doing it?

KCT is only being built for 1.8, nothing earlier

What is the name of the DLL file for P2P, it's fairly easy to do

DarthPointer commented 4 years ago

EngineDecay.dll

linuxgurugamer commented 4 years ago

EngineDecay.dll

Ok. I have a method in a library (SpaceTuxLibrary) called HasMod, it's very simple:

if (SpaceTuxUtility.HasMod.hasMod("EngineDecay"))
{
}

You can certainly copy it if you want, or just add the library as a reference. FYI, I'm slowly adding this library to most of my mods, and KCT is one of them which I'll start using it soon with.

DarthPointer commented 4 years ago

I have got the SpaceTuxLibrary, built KCT with the latest commits (SpaceTuxUtility becomes dependency with this PR). Everything seems to work right.

Should I wait for you to merge the PR, make sure everything works right and probably make a new release? As you can see, the PR affects only sources, I have done all the binary building in a separate project away from the repository. It is done so not to break anything in your building system (that I could not run on my machine).