kRPC: Control the game using C#, C++, Java, Lua, Python...

kRPC: Control the game using C#, C++, Java, Lua, Python...

7.8k Downloads

Add command to switch the altimeter mode

SofieBrink opened this issue · 3 comments

commented

What would you like to be added?

A command for the spacecenter service that allows you to switch the ingame altimeter at the top of the UI to one of its three possible modes.

Why is this needed?

It's not its just a nice to have, especially in the usecase i'm developing for which is controlling the game fully externally while still being able to see the screen (JonnyOThan's TPKSP if anyone is wondering)

commented

I'd be more than happy to take this up myself, just wanted to make an issue to discuss the way to implement this, The game knows three states for the altimeter; DEFAULT, ASL and AGL. default being hardcoded to always be ASL. these are stored in an enum. My first thought was to have the kRPC setter take in a string which is then attempted to be parsed into KSP's enum but i noticed that for the MAPFILTER kRPC maintains its own enum which may be a more desirable solution for this aswell.

Let me know

commented

Would be great if you could add this - thanks :)

It's best to avoid string parsing for things like this. Enums are much less error prone. SpaceCenter.MapFilter is indeed a good example of how to implement this using enums.

I think the best place to add this would be in the SpaceCenter class, as this feels like a very "top-level" thing. We could add a property called SpaceCenter.AltimeterMode which returns an enum of type SpaceCenter.AltimeterMode

Map filter is implemented using the following, which you could copy and edit to implement this:

And if you feel this needs a convenient way to convert between kRPC and KSP enums you could add extension methods, similar to these: https://github.com/krpc/krpc/blob/main/service/SpaceCenter/src/ExtensionMethods/VesselTypeExtensions.cs

commented

Yeah i agree, will see when i can implement it, shouldn’t take too long hopefully as its a pretty small thing