Skip to content

Commit

Permalink
Merge pull request #8 from ankurkotwal/repo-rename-lower-case
Browse files Browse the repository at this point in the history
Rename MetaRefCard to metarefcard
  • Loading branch information
ankurkotwal authored Oct 8, 2021
2 parents b9d320f + 150a2da commit 974284f
Show file tree
Hide file tree
Showing 25 changed files with 114 additions and 138 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ debug.xml
debug.profile
__debug_bin
scratch
metarefcard

##### Output files #####
out/
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
A tool to generate reference cards for HOTAS (hands on throttle and stick) and game controllers. MetaRefCard is
designed to be flexible across many different controllers and many different
games.
![Build Status](https://github.com/ankurkotwal/MetaRefCard/actions/workflows/main.yml/badge.svg)
[![Go Report Card](https://goreportcard.com/badge/github.com/ankurkotwal/MetaRefCard)](https://goreportcard.com/report/github.com/ankurkotwal/MetaRefCard)
![Build Status](https://github.com/ankurkotwal/metarefcard/actions/workflows/main.yml/badge.svg)
[![Go Report Card](https://goreportcard.com/badge/github.com/ankurkotwal/metarefcard)](https://goreportcard.com/report/github.com/ankurkotwal/metarefcard)
## Hosted at [metarefcard.com](https://metarefcard.com)

Here are some example images:
Expand Down
2 changes: 1 addition & 1 deletion config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
AppName: MetaRefCard
Version: 0.3.4
Version: 0.3.5
DebugOutput: false
VerboseOutput: false
DevicesFile: config/devices.yaml
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/ankurkotwal/MetaRefCard
module github.com/ankurkotwal/metarefcard

go 1.16

Expand Down
18 changes: 3 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,18 @@ github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTM
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/go-playground/validator/v10 v10.8.0 h1:1kAa0fCrnpv+QYdkdcRzrRM7AyYs5o8+jZdJCz9xj6k=
github.com/go-playground/validator/v10 v10.8.0/go.mod h1:9JhgTzTaE31GZDpH/HSvHiRJrJ3iKAgqqH0Bl/Ocjdk=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ=
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand All @@ -39,11 +37,9 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA=
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
Expand All @@ -59,31 +55,25 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go v1.2.6 h1:tGiWC9HENWE2tqYycIqFTNorMmFRVhNwCpDOpWqnk8E=
github.com/ugorji/go v1.2.6/go.mod h1:anCg0y61KIhDlPZmnH+so+RQbysYVyDko0IMgJv0Nn0=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/ugorji/go/codec v1.2.6 h1:7kbGefxLoDBuYXOms4yD7223OpNMMPNPZxXk5TvFcyQ=
github.com/ugorji/go/codec v1.2.6/go.mod h1:V6TCNZ4PHqoHGFZuSG1W8nrCzzdgA2DozYxWFFpvxTw=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/image v0.0.0-20200801110659-972c09e46d76 h1:U7GPaoQyQmX+CBRWXKrvRzWTbd+slqeSh8uARsIyhAw=
golang.org/x/image v0.0.0-20200801110659-972c09e46d76/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -96,6 +86,7 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
Expand All @@ -105,12 +96,9 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import (
"os"
"path/filepath"

"github.com/ankurkotwal/MetaRefCard/metarefcard"
"github.com/ankurkotwal/metarefcard/mrc"
)

func main() {
debugMode, gameArgs := parseCliArgs()
router, port := metarefcard.GetServer(debugMode, gameArgs)
router, port := mrc.GetServer(debugMode, gameArgs)
err := router.Run(port)
if err != nil {
log.Fatal(err)
}
}

func parseCliArgs() (bool, metarefcard.GameToInputFiles) {
gameFiles := make(metarefcard.GameToInputFiles)
func parseCliArgs() (bool, mrc.GameToInputFiles) {
gameFiles := make(mrc.GameToInputFiles)
flag.Usage = func() {
fmt.Printf("Usage: %s file...\n\n", filepath.Base(os.Args[0]))
fmt.Printf("file\tSupported game input configration.\n")
Expand All @@ -33,9 +33,9 @@ func parseCliArgs() (bool, metarefcard.GameToInputFiles) {
flag.Parse()
// If in debug mode and a test data dir was provided, read files by game label dir
if debugMode && len(testDataDir) > 0 {
for _, getGameInfo := range metarefcard.GamesInfo {
for _, getGameInfo := range mrc.GamesInfo {
label, _, _, _ := getGameInfo()
gameFiles[label] = metarefcard.GetFilesFromDir(fmt.Sprintf("%s/%s", testDataDir, label))
gameFiles[label] = mrc.GetFilesFromDir(fmt.Sprintf("%s/%s", testDataDir, label))
}
}

Expand Down
14 changes: 7 additions & 7 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
"time"

"github.com/ankurkotwal/MetaRefCard/metarefcard"
"github.com/ankurkotwal/metarefcard/mrc"
)

func TestSwsSerial(t *testing.T) {
Expand All @@ -27,7 +27,7 @@ func TestFs2020Conc(t *testing.T) {
}

func runTestSerial(t *testing.T, url string, N int) {
router, _ := metarefcard.GetServer(true, getTestGameArgs())
router, _ := mrc.GetServer(true, getTestGameArgs())
time.Sleep(2 * time.Second) // a bit of time to properly init...

for n := 0; n < N; n++ {
Expand All @@ -39,7 +39,7 @@ func runTestSerial(t *testing.T, url string, N int) {
}

func runTestConc(t *testing.T, url string, N int) {
router, _ := metarefcard.GetServer(true, getTestGameArgs())
router, _ := mrc.GetServer(true, getTestGameArgs())
time.Sleep(2 * time.Second) // a bit of time to properly init...

var wg sync.WaitGroup
Expand All @@ -58,9 +58,9 @@ func runTestConc(t *testing.T, url string, N int) {
// exit unconditionnaly after the requests
}

func getTestGameArgs() metarefcard.GameToInputFiles {
cliGameArgs := make(metarefcard.GameToInputFiles)
cliGameArgs["fs2020"] = metarefcard.GetFilesFromDir("testdata/fs2020")
cliGameArgs["sws"] = metarefcard.GetFilesFromDir("testdata/sws")
func getTestGameArgs() mrc.GameToInputFiles {
cliGameArgs := make(mrc.GameToInputFiles)
cliGameArgs["fs2020"] = mrc.GetFilesFromDir("testdata/fs2020")
cliGameArgs["sws"] = mrc.GetFilesFromDir("testdata/sws")
return cliGameArgs
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
72 changes: 36 additions & 36 deletions metarefcard/fs2020/fs2020.go → mrc/fs2020/fs2020.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"strings"
"sync"

mrc "github.com/ankurkotwal/MetaRefCard/metarefcard/common"
"github.com/ankurkotwal/metarefcard/mrc/common"
)

var firstInit sync.Once
var sharedRegexes fs2020Regexes
var sharedGameData mrc.GameData
var sharedGameData common.GameData

const (
label = "fs2020"
Expand All @@ -29,15 +29,15 @@ const (
// * User friendly command line description
// * Func handler for incoming request
// * Func that matches the game input format to MRC's model
func GetGameInfo() (string, string, mrc.FuncRequestHandler, mrc.FuncMatchGameInputToModel) {
func GetGameInfo() (string, string, common.FuncRequestHandler, common.FuncMatchGameInputToModel) {
return label, desc, handleRequest, matchGameInputToModel
}

// handleRequest services the request to load files
func handleRequest(files [][]byte, config *mrc.Config, log *mrc.Logger) (mrc.GameData,
mrc.GameBindsByProfile, mrc.Set, mrc.ContextToColours, string) {
func handleRequest(files [][]byte, config *common.Config, log *common.Logger) (common.GameData,
common.GameBindsByProfile, common.Set, common.ContextToColours, string) {
firstInit.Do(func() {
sharedGameData = mrc.LoadGameModel("config/fs2020.yaml",
sharedGameData = common.LoadGameModel("config/fs2020.yaml",
"FS2020 Data", config.DebugOutput, log)
sharedRegexes.Button = regexp.MustCompile(sharedGameData.Regexes["Button"])
sharedRegexes.Axis = regexp.MustCompile(sharedGameData.Regexes["Axis"])
Expand All @@ -47,25 +47,25 @@ func handleRequest(files [][]byte, config *mrc.Config, log *mrc.Logger) (mrc.Gam
})
gameBinds, gameDevices, gameContextsToColours := loadInputFiles(files, config.Devices.DeviceToShortNameMap,
log, config.DebugOutput, config.VerboseOutput)
mrc.GenerateContextColours(gameContextsToColours, config)
common.GenerateContextColours(gameContextsToColours, config)
return sharedGameData, gameBinds, gameDevices, gameContextsToColours, sharedGameData.Logo
}

// Load the game config files (provided by user)
func loadInputFiles(files [][]byte, deviceShortNameMap mrc.DeviceNameFullToShort,
log *mrc.Logger, debugOutput bool, verboseOutput bool) (mrc.GameBindsByProfile,
mrc.Set, mrc.ContextToColours) {
func loadInputFiles(files [][]byte, deviceShortNameMap common.DeviceNameFullToShort,
log *common.Logger, debugOutput bool, verboseOutput bool) (common.GameBindsByProfile,
common.Set, common.ContextToColours) {

gameBinds := make(mrc.GameBindsByProfile)
defaultProfile := mrc.ProfileDefault
gameBinds[defaultProfile] = make(mrc.GameDeviceContextActions)
neededDevices := make(mrc.Set)
contextsToColours := make(mrc.ContextToColours)
gameBinds := make(common.GameBindsByProfile)
defaultProfile := common.ProfileDefault
gameBinds[defaultProfile] = make(common.GameDeviceContextActions)
neededDevices := make(common.Set)
contextsToColours := make(common.ContextToColours)

// XML state variables
var currentContext mrc.GameActions
var contextActions mrc.GameContextActions
currentAction := make(mrc.GameInput, mrc.NumInputs)
var currentContext common.GameActions
var contextActions common.GameContextActions
currentAction := make(common.GameInput, common.NumInputs)
currentKeyType := keyUnknown
var currentKey *int
var currentProfile *string
Expand Down Expand Up @@ -121,10 +121,10 @@ func loadInputFiles(files [][]byte, deviceShortNameMap mrc.DeviceNameFullToShort
out, _ := json.Marshal(aDevice)
log.Dbg("Info: FS2020 new device: %s", out)
}
contextActions = make(mrc.GameContextActions)
contextActions = make(common.GameContextActions)
neededDevices[shortName] = true // Add to set
gameBinds[*currentProfile][shortName] = contextActions
if shortName == mrc.DeviceMissingInfo {
if shortName == common.DeviceMissingInfo {
log.Err("FS2020 missing info for device '%s'",
shortName)
}
Expand All @@ -147,14 +147,14 @@ func loadInputFiles(files [][]byte, deviceShortNameMap mrc.DeviceNameFullToShort
if debugOutput {
log.Dbg("FS2020 new context: %s", contextName)
}
currentContext = make(mrc.GameActions)
currentContext = make(common.GameActions)
contextActions[contextName] = currentContext
}
case "Action":
// Found new action
currentKeyType = keyUnknown
var actionName string
action := make(mrc.GameInput, mrc.NumInputs)
action := make(common.GameInput, common.NumInputs)
for _, attr := range ty.Attr {
if attr.Name.Local == "ActionName" {
actionName = attr.Value
Expand All @@ -180,9 +180,9 @@ func loadInputFiles(files [][]byte, deviceShortNameMap mrc.DeviceNameFullToShort
if attr.Name.Local == "Information" {
switch currentKeyType {
case keyPrimary:
currentAction[mrc.InputPrimary] = attr.Value
currentAction[common.InputPrimary] = attr.Value
case keySecondary:
currentAction[mrc.InputSecondary] = attr.Value
currentAction[common.InputSecondary] = attr.Value
}
}
break
Expand All @@ -207,7 +207,7 @@ func loadInputFiles(files [][]byte, deviceShortNameMap mrc.DeviceNameFullToShort
currentProfile = &defaultProfile
}
if gameBinds[*currentProfile] == nil {
gameBinds[*currentProfile] = make(mrc.GameDeviceContextActions)
gameBinds[*currentProfile] = make(common.GameDeviceContextActions)
}
case "Device":
case "Context":
Expand All @@ -226,45 +226,45 @@ func loadInputFiles(files [][]byte, deviceShortNameMap mrc.DeviceNameFullToShort
}

if verboseOutput {
log.Dbg(mrc.GameBindsAsString(gameBinds))
log.Dbg(common.GameBindsAsString(gameBinds))
}

return gameBinds, neededDevices, contextsToColours
}

// matchGameInputToModel takes the game provided bindings with the device map to
// build a list of image overlays.
func matchGameInputToModel(deviceName string, actionData mrc.GameInput,
deviceInputs mrc.DeviceInputs, gameInputMap mrc.InputTypeMapping,
log *mrc.Logger) (mrc.GameInput, string) {
func matchGameInputToModel(deviceName string, actionData common.GameInput,
deviceInputs common.DeviceInputs, gameInputMap common.InputTypeMapping,
log *common.Logger) (common.GameInput, string) {
inputLookups := make([]string, 0, 2)

// First the primary input for this action
input := matchGameInputToModelByRegex(deviceName, actionData[mrc.InputPrimary],
input := matchGameInputToModelByRegex(deviceName, actionData[common.InputPrimary],
deviceInputs, gameInputMap, log)
if input != "" {
inputLookups = append(inputLookups, input)
} else {
log.Err("FS2020 did not find primary input for %s", actionData[mrc.InputPrimary])
log.Err("FS2020 did not find primary input for %s", actionData[common.InputPrimary])
}
// Now the secondary input
if len(actionData[mrc.InputSecondary]) > 0 {
input := matchGameInputToModelByRegex(deviceName, actionData[mrc.InputSecondary],
if len(actionData[common.InputSecondary]) > 0 {
input := matchGameInputToModelByRegex(deviceName, actionData[common.InputSecondary],
deviceInputs, gameInputMap, log)
if input != "" {
inputLookups = append(inputLookups, input)
} else {
log.Err("FS2020 did not find secondary input for %s",
actionData[mrc.InputSecondary])
actionData[common.InputSecondary])
}
}
return inputLookups, sharedGameData.Logo
}

// Matches an action to a device's inputs using regexes. Returns string to lookup input
func matchGameInputToModelByRegex(deviceName string, action string,
inputs mrc.DeviceInputs, gameInputMap mrc.InputTypeMapping,
log *mrc.Logger) string {
inputs common.DeviceInputs, gameInputMap common.InputTypeMapping,
log *common.Logger) string {
var matches [][]string

matches = sharedRegexes.Button.FindAllStringSubmatch(action, -1)
Expand Down
Loading

0 comments on commit 974284f

Please sign in to comment.