Skip to content

Commit

Permalink
Merge pull request #6 from lucasvmx/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
lucasvmx authored Jun 5, 2023
2 parents b8b2ed5 + 3db4e03 commit afd1e16
Show file tree
Hide file tree
Showing 23 changed files with 363 additions and 113 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.20

- name: Get packages
run: go get -v ./...

- name: Build
run: go build -v ./...

build-windows:
runs-on: windows-latest
steps:
Expand All @@ -32,7 +32,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.20

- name: Get packages
run: go get -v ./...
Expand All @@ -48,7 +48,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.20

- name: Get packages
run: go get -v ./...
Expand Down
18 changes: 10 additions & 8 deletions controller/gamechat.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@ package controller

import (
"encoding/json"
"log"
"sync"

"github.com/lucasvmx/WarTelemetry/model"
"github.com/lucasvmx/WarTelemetry/model/gamechat"
client "github.com/lucasvmx/WarTelemetry/network/http"
)

// GetGamechatData retrieves data about gamechat
func GetGamechatData(wg *sync.WaitGroup) (gc []gamechat.GameChat, err error) {
func GetGamechatData(wg *sync.WaitGroup) {

var gc []gamechat.GameChat = []gamechat.GameChat{}
defer wg.Done()

// Sends the GET request
body, err := client.GetDataFromURL(gamechat.GetURL())
if err != nil {
return nil, err
log.Printf("[ERROR] failed to get gamechat data: %v", err)
return
}

// Decode data into a struct
err = json.Unmarshal(body, &gc)
if err != nil {
return nil, err
}
json.Unmarshal(body, &gc)

DataChan <- gc
model.TelemetryInstance.LockMux()
defer model.TelemetryInstance.UnlockMux()

return
model.TelemetryInstance.Gamechat = gc
}
20 changes: 10 additions & 10 deletions controller/hudmsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@ package controller

import (
"encoding/json"
"log"
"sync"

"github.com/lucasvmx/WarTelemetry/model"
"github.com/lucasvmx/WarTelemetry/model/hudmsg"
network "github.com/lucasvmx/WarTelemetry/network/http"
)

// GetHudMessagesData function retrieves all messages from HUD
func GetHudMessagesData(wg *sync.WaitGroup) (messages *hudmsg.Hudmsg, err error) {

func GetHudMessagesData(wg *sync.WaitGroup) {
var messages *hudmsg.Hudmsg
defer wg.Done()

data, err := network.GetDataFromURL(hudmsg.GetURL())
if err != nil {
return nil, err
log.Printf("[ERROR] failed to get hud message data: %v", err)
return
}

// Decode data into a struct
failure := json.Unmarshal(data, &messages)
if failure != nil {
return nil, err
}

DataChan <- messages
err = json.Unmarshal(data, &messages)

return
model.TelemetryInstance.LockMux()
defer model.TelemetryInstance.UnlockMux()
model.TelemetryInstance.HudMessages = messages
}
19 changes: 10 additions & 9 deletions controller/indicators.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@ package controller

import (
"encoding/json"
"log"
"sync"

"github.com/lucasvmx/WarTelemetry/model"
"github.com/lucasvmx/WarTelemetry/model/indicators"
network "github.com/lucasvmx/WarTelemetry/network/http"
)

// GetIndicatorsData function retrieves data about aircraft indicators
func GetIndicatorsData(wg *sync.WaitGroup) (id *indicators.Indicators, err error) {
func GetIndicatorsData(wg *sync.WaitGroup) {
var id *indicators.Indicators = &indicators.Indicators{}
defer wg.Done()

data, err := network.GetDataFromURL(indicators.GetURL())
if err != nil {
return nil, err
log.Printf("[ERROR] failed to get indicators data: %v", err)
return
}

err = json.Unmarshal(data, &id)
if err != nil {
return nil, err
}

DataChan <- id
json.Unmarshal(data, &id)

return
model.TelemetryInstance.LockMux()
defer model.TelemetryInstance.UnlockMux()
model.TelemetryInstance.Indicators = id
}
18 changes: 10 additions & 8 deletions controller/mapinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@ package controller

import (
"encoding/json"
"log"
"sync"

"github.com/lucasvmx/WarTelemetry/model"
"github.com/lucasvmx/WarTelemetry/model/mapinfo"
network "github.com/lucasvmx/WarTelemetry/network/http"
)

// GetMapInfoData function retrieves information about current map
func GetMapInfoData(wg *sync.WaitGroup) (mi *mapinfo.MapInformation, err error) {
func GetMapInfoData(wg *sync.WaitGroup) {
var mi *mapinfo.MapInformation = &mapinfo.MapInformation{}
defer wg.Done()

data, err := network.GetDataFromURL(mapinfo.GetURL())
if err != nil {
return nil, err
log.Printf("[ERROR] failed to get map information data: %v", err)
return
}

failure := json.Unmarshal(data, &mi)
if failure != nil {
return nil, err
}
json.Unmarshal(data, &mi)

DataChan <- mi
model.TelemetryInstance.LockMux()
defer model.TelemetryInstance.UnlockMux()

return
model.TelemetryInstance.MapInfo = mi
}
21 changes: 10 additions & 11 deletions controller/mapobjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,30 @@ package controller

import (
"encoding/json"
"log"
"sync"

"github.com/lucasvmx/WarTelemetry/model"
"github.com/lucasvmx/WarTelemetry/model/mapobjects"
network "github.com/lucasvmx/WarTelemetry/network/http"
)

var objs *mapobjects.MapObjects

// GetMapObjsData function retrives data about all map objects
func GetMapObjsData(wg *sync.WaitGroup) (mo []mapobjects.MapObjects, err error) {
func GetMapObjsData(wg *sync.WaitGroup) {
var mo []mapobjects.MapObjects = []mapobjects.MapObjects{}
defer wg.Done()

// Sends GET request
data, err := network.GetDataFromURL(mapobjects.GetURL())
if err != nil {
return nil, err
log.Printf("[ERROR] failed to get map objects data: %v", err)
return
}

// Decode data into a json struct
err = json.Unmarshal(data, &mo)
if err != nil {
return nil, err
}

DataChan <- mo
json.Unmarshal(data, &mo)

return
model.TelemetryInstance.LockMux()
defer model.TelemetryInstance.UnlockMux()
model.TelemetryInstance.MapObjects = mo
}
16 changes: 11 additions & 5 deletions controller/mission.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,35 @@ package controller

import (
"encoding/json"
"log"
"sync"

"github.com/lucasvmx/WarTelemetry/model"
"github.com/lucasvmx/WarTelemetry/model/mission"
network "github.com/lucasvmx/WarTelemetry/network/http"
)

// GetMissionData function retrieves data about running missions
func GetMissionData(wg *sync.WaitGroup) (mi *mission.MissionInfo, err error) {
func GetMissionData(wg *sync.WaitGroup) {
var mi *mission.MissionInfo
defer wg.Done()

// Sends a HTTP request
data, err := network.GetDataFromURL(mission.GetURL())
if err != nil {
return nil, err
log.Printf("[ERROR] failed to get mission data: %v", err)
return
}

// Decode JSON into a struct
err = json.Unmarshal(data, &mi)
if err != nil {
return nil, err
log.Printf("[ERROR] failed to get mission data: %v", err)
return
}

DataChan <- mi
model.TelemetryInstance.LockMux()
defer model.TelemetryInstance.UnlockMux()

return
model.TelemetryInstance.MissionInfo = mi
}
12 changes: 2 additions & 10 deletions controller/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ const distanceFactor float64 = 66.32072
func IsAircraft(object *mapobjects.MapObjects) bool {

// Check type
if object.Type == "aircraft" {
return true
}

return false
return object.Type == "aircraft"
}

// IsCurrentPlayer function determines if current object is the current player
Expand All @@ -27,11 +23,7 @@ func IsCurrentPlayer(object *mapobjects.MapObjects) bool {
iconName := strings.ToLower(object.Icon)

// Check object
if iconName == "player" {
return true
}

return false
return iconName == "player"
}

// CalculateDistanceInKm gets the distance in kilometers between two objects
Expand Down
9 changes: 0 additions & 9 deletions controller/setup.go

This file was deleted.

17 changes: 10 additions & 7 deletions controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,34 @@ package controller

import (
"encoding/json"
"log"
"sync"

"github.com/lucasvmx/WarTelemetry/model"
"github.com/lucasvmx/WarTelemetry/model/state"
network "github.com/lucasvmx/WarTelemetry/network/http"
"github.com/lucasvmx/WarTelemetry/utils"
)

// GetStateData function retrieves data about running missions
func GetStateData(wg *sync.WaitGroup) (st *state.AircraftState, err error) {
func GetStateData(wg *sync.WaitGroup) {
var st *state.AircraftState = &state.AircraftState{}
defer wg.Done()

// Sends a HTTP request
data, err := network.GetDataFromURL(state.GetURL())
if err != nil {
return nil, err
log.Printf("[ERROR] failed to get state data: %v", err)
return
}

// Process JSON into a readable format
data = utils.ProcessJSON(data)

// Decode JSON into a struct
err = json.Unmarshal(data, &st)
if err != nil {
return nil, err
}
json.Unmarshal(data, &st)

return
model.TelemetryInstance.LockMux()
defer model.TelemetryInstance.UnlockMux()
model.TelemetryInstance.State = st
}
2 changes: 2 additions & 0 deletions model/gamechat/gamechat.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type GameChat struct {
Sender string `json:"sender"`
Enemy bool `json:"enemy"`
Mode string `json:"mode"`
Time int `json:"time"`
}

// path string
Expand All @@ -25,6 +26,7 @@ func GetURL() string {
url = utils.GetBaseURL()
url = strings.ReplaceAll(url, "$hostname$", utils.GetHostname())
url = strings.ReplaceAll(url, "$path$", path)
//url += "?lastId=0"
}

return url
Expand Down
1 change: 1 addition & 0 deletions model/hudmsg/hudmsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func GetURL() string {
url = utils.GetBaseURL()
url = strings.ReplaceAll(url, "$hostname$", utils.GetHostname())
url = strings.ReplaceAll(url, "$path$", path)
//url += "?lastEvt=0&lastDmg=0"
}

return url
Expand Down
2 changes: 2 additions & 0 deletions model/indicators/indicators.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type Indicators struct {
ClockSec float32 `json:"clock_sec"`
RpmMin float32 `json:"rpm_min"`
RpmMin1 float32 `json:"rpm1_min"`
AngleOfAttacl float32 `json:"aoa"`
SuperCharger float32 `json:"supercharger"`
}

var path string = "indicators"
Expand Down
Loading

0 comments on commit afd1e16

Please sign in to comment.