feat(target): tar.availableVessels + tar.switchVessel — list and fly to vessels#89
Open
jonpepler wants to merge 4 commits into
Open
feat(target): tar.availableVessels + tar.switchVessel — list and fly to vessels#89jonpepler wants to merge 4 commits into
jonpepler wants to merge 4 commits into
Conversation
Add a new TelemetryAPI handler that walks FlightGlobals.Vessels and
emits per-vessel records keyed by the integer index that
`tar.setTargetVessel` expects. Without this enumeration the action's
index argument is unobservable to any client; this closes that loop.
Per-row payload:
index — exact arg for tar.setTargetVessel[index]
name — Vessel.GetName()
type — Vessel.vesselType.ToString()
situation — Vessel.Situations.ToString()
body — mainBody.bodyName (or "")
position — active vessel local frame [x,y,z]
(transform.InverseTransformPoint)
Server-side filter: skip Flag, EVA, Debris, Unknown, and the active
vessel itself. Clients derive distance / bearing from the local-frame
position vector — saves CPU on the server and keeps the math
one-sided.
Returns List<Dictionary<string, object>>; MiniJSON's
generic-collection encoder handles serialisation without a dedicated
formatter.
Companion to tar.availableVessels + tar.setTargetVessel: lets a
client switch active vessel directly without going through the
Tracking Station scene. Same operation as the in-game 'Fly' button
under the hood.
[TelemetryAPI("tar.switchVessel", IsAction = true)]
takes an integer vesselIndex matching tar.availableVessels.index,
saves the current vessel's mid-flight state to the persistent slot
(so switching back later restores it), then calls
FlightDriver.StartAndFocusVessel — the same internal entry point
the Tracking Station uses for 'Fly'.
Useful for dashboard widgets that want to provide a switch-active-
vessel control without the user navigating menus. Pairs with the
existing tar.availableVessels enumeration so the client knows what
indices are live.
Out-of-range and unparsable indices return false; the actual scene
change happens asynchronously (standard FlightDriver semantics).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two new keys in the
tar.*family that finally maketar.setTargetVesselusable and add a flight-scene "fly to vessel":tar.availableVessels[{ index, name, type, situation, body, position }, …]— every vessel except the active vessel and theFlag/EVA/Debris/Unknowntypestar.switchVessel[index]tar.setTargetVessel[index]already worked, but it had no companion key to enumerate the indices it expects, so in practice it was unusable without an external source of indices.tar.availableVesselscloses that loop — both keys share the same index space, and the newpositionfield gives a client enough to sort the list by distance.Wire shape
{ "tar.availableVessels": [ { "index": 13, "name": "Munar Orbiter", "type": "Probe", "situation": "ORBITING", "body": "Mun", "position": [184523.4, 12055.2, -3217.8] } ] }index— the exactFlightGlobals.Vessels[index]slot. Non-contiguous once filtered vessels punch holes in the array.type—Vessel.vesselType:Ship,Probe,Lander,Plane,Rover,Station,Base,Relay,SpaceObject, …situation—Vessel.Situations:LANDED/SPLASHED/PRELAUNCH/FLYING/SUB_ORBITAL/ORBITING/ESCAPING/DOCKED.body— name of the orbited body. Sun-orbiting vessels report"Sun".position— vector in the active vessel's local frame (transform.InverseTransformPoint); its magnitude tracks the in-game distance readout. Omitted when there is no active vessel, so the key is flight-scene only.Design notes
FlightGlobals.Vesselswithout re-sorting, so the indices match KSP's internal addressing one-for-one and stay aligned withtar.setTargetVessel. A client that wants distance order sorts onpositionitself.Flag/EVA/Debris/Unknowncovers everything a client shouldn't normally target.SpaceObject(asteroids and comets) is kept — it's a legitimate target.tar.switchVesselsaves state before switching.HighLogic.CurrentGame.Updated()+GamePersistence.SaveGamepreserves the current vessel's mid-flight pose, fuel, and heat so they're restored on switch-back. This mirrors what the Tracking Station's "Fly" button does internally. The args/range/HighLogic.CurrentGameguards return early before any scene change is attempted.Validation
dotnet buildclean. OpenAPI anddocs/api-schema.jsonregenerated to include both keys. Exercised live against a running KSP install on 2026-05-15: the array carries every documented field with the active vessel correctly absent and indices non-contiguous;tar.setTargetVesselandtar.switchVesselboth act on the right vessel by index;positionmagnitude trackstar.distance; switching away and back restores the saved pose and fuel; and an out-of-range index returns false with no scene change. TheFlag/EVA/Debris/Unknownfilter holds whileSpaceObjectrows pass through.Behavioural notes
IsActionkeys, the HTTP response body returnsfalseeven on success. The action is queued onto the Unity main thread and the state change echoes back over the WebSocket stream, not the HTTP response.tar.availableVesselsindices can shift when the active vessel changes (KSP reshufflesFlightGlobals.Vesselson focus change), so clients should treat them as per-snapshot selectors, not stable identifiers.