-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspacecenter.go
More file actions
110 lines (95 loc) · 3.32 KB
/
spacecenter.go
File metadata and controls
110 lines (95 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package sturdyengine
import (
"errors"
"fmt"
"github.com/golang/protobuf/proto"
util "github.com/jwuensche/sturdyengine/internal"
krpc "github.com/jwuensche/sturdyengine/internal/krpcproto"
)
// SpaceCenter saves all information used by `SpaceCenter` service of kRPC
type SpaceCenter struct {
conn *Connection
Vessel []byte
Control []byte
}
//NewSpaceCenter creates a SpaceCenter instance with Vessel and Control being set to the current active Values
func NewSpaceCenter(conn *Connection) (sc SpaceCenter, e error) {
if conn.Conn == nil {
e = errors.New("Connection ist nil")
return
}
sc = SpaceCenter{}
sc.conn = conn
return
}
//GetGameMode returns the current active GameMode (currently not implemented)
func (sc *SpaceCenter) GetGameMode() (r []byte, e error) {
pr := createRequest("SpaceCenter", "get_GameMode", nil)
p, e := sc.conn.sendMessage(pr)
res := &krpc.Response{}
proto.Unmarshal(p, res)
//TODO: Translate to enums
return
}
//SetPhysicsWarpFactor sets the physical warp factor on a range of 0 ... 3, this resets to 0 if onrailswarp is active
func (sc *SpaceCenter) SetPhysicsWarpFactor(factor uint8) (e error) {
//krpc requires in this case the a multiplied value, this is only a fix for this, I do not know if this is intended behaviour
arg := [][]byte{{2 * factor}}
pr := createRequest("SpaceCenter", "set_PhysicsWarpFactor", createArguments(arg))
_, e = sc.conn.sendMessage(pr)
return
}
//GetPhysicsWarpFactor returns the current on a range of 0 ... 3
func (sc *SpaceCenter) GetPhysicsWarpFactor() (fac uint8, e error) {
pr := createRequest("SpaceCenter", "get_PhysicsWarpFactor", nil)
p, e := sc.conn.sendMessage(pr)
res := &krpc.Response{}
proto.Unmarshal(p, res)
fac = res.GetResults()[0].GetValue()[0] / 2
return
}
func (sc *SpaceCenter) SetWarp(factor uint64) (e error) {
arg := [][]byte{util.Uint64ToByte(factor)}
pr := createRequest("SpaceCenter", "set_RailsWarpFactor", createArguments(arg))
_, e = sc.conn.sendMessage(pr)
return
}
func (sc *SpaceCenter) GetWarp() (fac uint64, e error) {
pr := createRequest("SpaceCenter", "get_RailsWarpFactor", nil)
p, e := sc.conn.sendMessage(pr)
res := &krpc.Response{}
proto.Unmarshal(p, res)
fac = util.ByteToUint64(res.GetResults()[0].GetValue())
return
}
//GetMaximumWarpFactor returns the maximal available RailsWarpFactor at the moment
func (sc *SpaceCenter) GetMaximumWarpFactor() (fac uint64, e error) {
pr := createRequest("SpaceCenter", "get_MaximumRailsWarpFactor", nil)
p, e := sc.conn.sendMessage(pr)
res := &krpc.Response{}
proto.Unmarshal(p, res)
fac = util.ByteToUint64(res.GetResults()[0].GetValue())
return
}
func (sc *SpaceCenter) CheckWarpFactor(factor uint64) (result bool, e error) {
arg := [][]byte{util.Uint64ToByte(factor)}
pr := createRequest("SpaceCenter", "CanRailsWarpAt", createArguments(arg))
p, e := sc.conn.sendMessage(pr)
res := &krpc.Response{}
proto.Unmarshal(p, res)
fmt.Println(res.GetResults())
result = util.ByteToBool(res.GetResults()[0].GetValue())
return
}
//Quicksave creates a Quicksave
func (sc *SpaceCenter) Quicksave() (e error) {
pr := createRequest("SpaceCenter", "Quicksave", nil)
_, e = sc.conn.sendMessage(pr)
return
}
//Quickload loads the last used Quicksave
func (sc *SpaceCenter) Quickload() (e error) {
pr := createRequest("SpaceCenter", "Quickload", nil)
_, e = sc.conn.sendMessage(pr)
return
}