KSP-RO / TestFlight

KSP Mod that provides a part research and reliability system
42 stars 31 forks source link

[QUESTION] Is there a way to set the starting DU for an engine config? #212

Closed dgfl-gh closed 4 years ago

dgfl-gh commented 4 years ago

This isn't really an issue for TestFlight, it's actually an issue for me. I'm trying to add a way for my CustomScenarioManager mod to set the DU amount for an arbitrary config. The idea is that you'd have a tfStartingDU field that you could populate with a comma-separated list of EngineConfig@DU. My mod would then check if TF is installed, find that engine config and set its DU amount so that the player will find that specific engine with the specified data amount.

My question therefore is: how do I do that? I read through TF's documentation and code, but it hasn't occurred to me exactly what would the outcome of that method be (check the "code" link), and how how I would call it from the KSC.

I preemptively ask for forgiveness if this is addressed 15 lines further than what I've linked, but I wasn't able to figure it out myself. @jwvanderbeck would you be available to give some directions?

jwvanderbeck commented 4 years ago

If I understand you properly, then I think you just want the ModifyFlightData method in the API?

dgfl-gh commented 4 years ago

Probably, as I said, but I don't understand why ApplyFlightDataMultiplier is the way it is nor how I would call the ModifyFlightData method for a config. It's a part module, how does that translate to a generalized per-config thing?

jwvanderbeck commented 4 years ago

I apologize for not taking the time to click on your link which showed you were already looking at that method.

In hindsight that probably won't work for what you want to do anyway because there are a lot of assumptions made about the context of that call. Plus, I think you just want to set a flat value not actually modify an existing value.

Ideally you really need to be interacting with the scenario store directly I think, though none of that is exposed if I recall correctly.

Would probably need to add a new method to the API class for this.

jwvanderbeck commented 4 years ago

Ultimately what you want to be hitting is this: https://github.com/KSP-RO/TestFlight/blob/master/TestFlightCore/TestFlightCore/TestFlight.cs#L1022

But I don't think that is currently accessible through reflection.

dgfl-gh commented 4 years ago

Yeah, that seems pretty much what I need. Would it be possible to expose it? I'd make a PR myself, but reflection makes my head spin every time I look at something beyond the basics. Is making the method static enough?

jwvanderbeck commented 4 years ago

Probably. I'll try to find the time to look at it but I'm in the middle of a big push at work right now.

On Tue, Sep 8, 2020 at 3:24 PM Standecco notifications@github.com wrote:

Yeah, that seems pretty much what I need. Would it be possible to expose it? I'd make a PR myself, but reflection makes my head spin every time I look at something beyond the basics. Is making the method static enough?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/KSP-RO/TestFlight/issues/212#issuecomment-689167919, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABHKZXML7SBNDIRUAZ44XDSE2VJ5ANCNFSM4Q63A6GQ .

dgfl-gh commented 4 years ago

Can confirm that SetFlightDataForPartName was indeed the right method, and also that it can be called by reflection just fine. If you want to check out the reflection code, here it is: CustomScenarioManager/ModIntegration/TestFlight.cs

Closing since the feature works. Thanks for the help @jwvanderbeck!