Added an interface to support multiple games

- In the same way, I expect the addition of the ability of holding
multiple sinks in memory like outputting to a TUI, GUI and other
hardware devices
This commit is contained in:
2024-10-19 21:42:54 +01:00
commit eea5925b90
6 changed files with 204 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
package beamng
import (
"fmt"
"esilva.org.localhost/bngsdk"
)
// This will implement the GameSink interface from the main package
type BeamNG struct {
SDK *bngsdk.BNGSDK
}
const (
NAME = "BeamNG.Drive"
)
func Init(ip string, port int) (BeamNG, error) {
var err error
sdk, err := bngsdk.Init(ip, port)
if err != nil {
return BeamNG{}, err
}
return BeamNG{SDK: &sdk}, nil
}
// GetData will retrieve a given field by its name from the OutGauge data
func (b *BeamNG) GetData(fieldName string) (interface{}, error) {
if val, ok := b.SDK.DataDict[fieldName]; ok {
return val, nil
}
return nil, fmt.Errorf("key `%s` doesn't exist", fieldName)
}
func (b *BeamNG) UpdateData() error {
return b.SDK.ReadData()
}