Categorygithub.com/dazoe/krpcgo
modulepackage
0.1.1
Repository: https://github.com/dazoe/krpcgo.git
Documentation: pkg.go.dev

# README

krpc-go

krpc-go is a Go client for kRPC, a Kerbal Space Program mod for controlling the game with an external program.

Installation

go get github.com/atburke/krpc-go

Getting Started

This sample program will launch a vessel sitting on the launchpad. Error handling is omitted for brevity.

package main

import (
    "context"

    krpcgo "github.com/atburke/krpc-go"
    "github.com/atburke/krpc-go/krpc"
    "github.com/atburke/krpc-go/spacecenter"
)

func main() {
    // Connect to the kRPC server with all default parameters.
    client := krpcgo.DefaultKRPCClient()
    client.Connect(context.Background())
    defer client.Close()

    sc := spacecenter.New(client)
    vessel, _ := sc.ActiveVessel()
    control, _ := vessel.Control()

    control.SetSAS(true)
    control.SetRCS(false)
    control.SetThrottle(1.0)
    control.ActivateNextStage()
}

Types

This section describes type mappings from the kRPC protocol.

  • Primitives are mapped to Go primitives.
  • Arrays are mapped to slices. Dictionaries and sets are mapped to maps.
  • Tuples are mapped to a special tuple type in the types package. For example, a tuple of strings would map to types.Tuple3[string, string, string].
    • types also contains some convenience types that can be converted to/from the appropriate tuple, such as types.Vector2D, types.Vector3D, and types.Color.
  • Classes and enums are mapped to local structs and constants defined in the appropriate service. For example, a Vessel will be mapped to a *spacecenter.Vessel, and a GameScene will be mapped to a krpc.GameScene.
  • Existing protobuf types can be found in the types package. For example, a Status will be mapped to a *types.Status.

Streams

krpc-go uses Go's built-in channels to handle streams.

Here's an example of using streams to autostage a vessel until a specific stage is reached.

func AutoStageUntil(vessel *spacecenter.Vessel, stopStage int32) {
    go func() {
        control, _ := vessel.Control()
        stage, _ := control.CurrentStage()

        for stage > stopStage {
            resources, _ := vessel.ResourcesInDecoupleStage(stage-1, false)
            amountStream, _ := resources.AmountStream("LiquidFuel")

            // Wait until this stage runs out of liquid fuel.
            for amount := <-amountStream.C; amount > 0.1 {}

            amountStream.Close()
            control.ActivateNextStage()
            stage--
        }
    }()
}

More examples

See tests in integration/ for more usage examples.

Building

TODO

Links

TODO krpc-go docs link kRPC documentation

# Packages

Package dockingcamera provides methods to invoke procedures in the DockingCamera service.
Package drawing provides methods to invoke procedures in the Drawing service.
Package infernalrobotics provides methods to invoke procedures in the InfernalRobotics service.
No description provided by the author
Package kerbalalarmclock provides methods to invoke procedures in the KerbalAlarmClock service.
Package krpc provides methods to invoke procedures in the KRPC service.
No description provided by the author
Package lidar provides methods to invoke procedures in the LiDAR service.
Package remotetech provides methods to invoke procedures in the RemoteTech service.
Package spacecenter provides methods to invoke procedures in the SpaceCenter service.
Package types provides various types for krpc-go.
Package ui provides methods to invoke procedures in the UI service.

# Functions

DefaultKRPCClient creates a new kRPC client with all default parameters.
MapStream converts a stream to another type.
NewKRPCClient creates a new client.
NewStreamClient creates a new stream client with an existing connection.

# Structs

KRPCClient is a client for a kRPC server.
KRPCClientConfig is the config for a kRPC client.
Stream is a struct for receiving stream data.
StreamClient is a client for kRPC streams.