Skip to content

Commit

Permalink
Merge pull request #17 from ankurkotwal/domain-update
Browse files Browse the repository at this point in the history
- Update domain name to mrc.metadawn.com
- Ignore all __deug_bin files
- Build script hide which output
- VSCode go.lintOnSave to workspace
- Bump version code
  • Loading branch information
ankurkotwal committed Nov 21, 2023
2 parents 53d9578 + b694f14 commit 36b03c2
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##### MetaRef files #####
debug.xml
debug.profile
__debug_bin
__debug_bin*
scratch
metarefcard

Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"comments": false,
"strings": true
}
}
},
"go.lintOnSave": "workspace"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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)
## Hosted at [metarefcard.com](https://metarefcard.com)
## Hosted at [mrc.metadawn.com](https://mrc.metadawn.com)

Here are some example images:
## Flight Simulator 2020 - Alpha Flight Controls
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

if [ `uname` == "Darwin" ]; then
brew_path=`which brew`
brew_path=`which brew 2>/dev/null`
if [ $? -eq 0 ]; then
jpeg_turbo_path=`brew --prefix jpeg-turbo 2>/dev/null`
jpeg_turbo_version=`brew list --versions jpeg-turbo 2>/dev/null | sed -E 's/^jpeg-turbo[[:space:]]+//'`
Expand Down
5 changes: 3 additions & 2 deletions config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
AppName: MetaRefCard
Version: 0.3.10
Version: 0.3.11
Domain: mrc.metadawn.com
DebugOutput: false
VerboseOutput: false
DevicesFile: config/devices.yaml
Expand Down Expand Up @@ -28,7 +29,7 @@ ImageHeader:
BackgroundColour: "#2780e3ff"

Watermark:
Text: MetaRefCard.com
Text: MetaRefCard
TextColour: "#ffffffff"
BackgroundColour: "#373a3cff"
Font: Dirga.ttf
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/pixiv/go-libjpeg v0.0.0-20190822045933-3da21a74767d
golang.org/x/image v0.14.0
golang.org/x/text v0.14.0
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -35,6 +36,5 @@ require (
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
5 changes: 5 additions & 0 deletions mrc/common/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package common

import "golang.org/x/text/cases"

// Config contains all the configuration data for the app
type Config struct {
AppName string `yaml:"AppName"`
Version string `yaml:"Version"`
Domain string `yaml:"Domain"`
DebugOutput bool `yaml:"DebugOutput"`
VerboseOutput bool `yaml:"VerboseOutput"`

Expand Down Expand Up @@ -31,6 +34,8 @@ type Config struct {
LightColour string `yaml:"LightColour"`
DarkColour string `yaml:"DarkColour"`
AlternateColours []string `yaml:"AlternateColours"`

LangTitleCase cases.Caser
}

// HeaderData contains necessary data to generate header
Expand Down
10 changes: 10 additions & 0 deletions mrc/common/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"fmt"
"regexp"
"strings"

"golang.org/x/text/cases"
"golang.org/x/text/language"
)

// GameData holds the game's parsed data
Expand Down Expand Up @@ -31,6 +34,13 @@ const (
ProfileDefault = "default_metarefcard"
)

// Caser that returns Title case for a string.
var titleCaser = cases.Title(language.AmericanEnglish)

func TitleCaser(text string) string {
return titleCaser.String(text)
}

// RegexByName - map of named regex strings
type RegexByName map[string]*regexp.Regexp

Expand Down
12 changes: 7 additions & 5 deletions mrc/common/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func GenerateImages(overlaysByProfile OverlaysByProfile,
config.Devices.DeviceLabelsByImage[imageName],
xOffset, pixelMultiplier, config.FontsDir,
config.InputMinFontSize)
addMRCLogo(dc, &config.Watermark, config.Version,
addMRCLogo(dc, &config.Watermark, config.Version, config.Domain,
xOffset, float64(config.InputPixelXInset), pixelMultiplier,
config.FontsDir)

Expand Down Expand Up @@ -158,8 +158,10 @@ func populateImage(dc *gg.Context, imageFilename string, imgSize image.Point,
}

var imgBytes bytes.Buffer
jpeg.Encode(&imgBytes, dc.Image(),
&jpeg.EncoderOptions{Quality: config.JpgQuality})
err := jpeg.Encode(&imgBytes, dc.Image(), &jpeg.EncoderOptions{Quality: config.JpgQuality})
if err != nil {
log.Err("jpeg encode failed: %v", err)
}
return imgBytes
}

Expand Down Expand Up @@ -301,11 +303,11 @@ func addImageHeader(dc *gg.Context, imageHeader *HeaderData, profile string,
imageHeader.Inset.Y*pixelMultiplier)
}

func addMRCLogo(dc *gg.Context, watermark *WatermarkData, version string,
func addMRCLogo(dc *gg.Context, watermark *WatermarkData, version string, domain string,
xOffset float64, xInset float64, pixelMultiplier float64, fontsDir string) {
fontSize := int(math.Round(watermark.FontSize * pixelMultiplier))
// Generate watermark
text := fmt.Sprintf("%s v%s", watermark.Text, version)
text := fmt.Sprintf("%s v%s (%s)", watermark.Text, version, domain)
drawTextWithBackgroundRec(dc, text, xOffset, watermark.Location, 0, 0,
fontSize, pixelMultiplier,
loadFont(fontsDir, watermark.Font, fontSize),
Expand Down
4 changes: 2 additions & 2 deletions mrc/common/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Logger []*LogEntry

// Dbg prints an informational message
func (l *Logger) Dbg(format string, v ...interface{}) {
log.Println(fmt.Sprintf(format, v...))
log.Printf("%s\n", fmt.Sprintf(format, v...))
}

// Msg logs an informational message
Expand All @@ -23,7 +23,7 @@ func (l *Logger) Msg(format string, v ...interface{}) {
// Err logs an error message
func (l *Logger) Err(format string, v ...interface{}) {
msg := fmt.Sprintf(format, v...)
log.Println(fmt.Sprintf("Error: %s", msg))
log.Printf("%s\n", fmt.Sprintf("Error: %s", msg))
*l = append(*l, &LogEntry{true, msg})
}

Expand Down
6 changes: 3 additions & 3 deletions mrc/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package common

import (
"fmt"
"io/ioutil"
"log"
"os"
"sync"

"github.com/golang/freetype/truetype"
Expand All @@ -25,7 +25,7 @@ func (m Set) Keys() []string {

// LoadYaml loads Yaml file and prints any errors
func LoadYaml(filename string, out interface{}, label string, log *Logger) {
yamlData, err := ioutil.ReadFile(filename)
yamlData, err := os.ReadFile(filename)
if err != nil {
log.Fatal("yaml ioutil.ReadFile %v ", err)
}
Expand Down Expand Up @@ -58,7 +58,7 @@ func loadFont(dir string, name string, size int) font.Face {
font = v.(*truetype.Font)
} else {
fontPath := fmt.Sprintf("%s/%s", dir, name)
fontBytes, err := ioutil.ReadFile(fontPath)
fontBytes, err := os.ReadFile(fontPath)
if err != nil {
panic(err)
}
Expand Down
15 changes: 6 additions & 9 deletions mrc/fs2020/fs2020.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"io"
"regexp"
"strconv"
"strings"
"sync"

"github.com/ankurkotwal/metarefcard/mrc/common"
Expand All @@ -25,10 +24,10 @@ const (

// GetGameInfo returns the info needed to fit into MetaRefCard
// Returns:
// * Game label / name
// * User friendly command line description
// * Func handler for incoming request
// * Func that matches the game input format to MRC's model
// - Game label / name
// - 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, common.FuncRequestHandler, common.FuncMatchGameInputToModel) {
return label, desc, handleRequest, matchGameInputToModel
}
Expand Down Expand Up @@ -98,10 +97,8 @@ func loadInputFiles(files [][]byte, deviceShortNameMap common.DeviceNameFullToSh
// Found new device
var aDevice string
for _, attr := range ty.Attr {
switch attr.Name.Local {
case "DeviceName":
if attr.Name.Local == "DeviceName" {
aDevice = attr.Value
break
}
}
var found bool
Expand Down Expand Up @@ -287,7 +284,7 @@ func matchGameInputToModelByRegex(deviceName string, action string,
}
matches = sharedRegexes.Pov.FindAllStringSubmatch(action, -1)
if matches != nil {
direction := strings.Title(strings.ToLower(matches[0][2]))
direction := common.TitleCaser(matches[0][2])
pov := fmt.Sprintf("POV%s%s", "1", direction)
if len(matches[0][1]) > 0 {
pov = fmt.Sprintf("POV%s%s", matches[0][1], direction)
Expand Down
17 changes: 9 additions & 8 deletions mrc/metarefcard.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/base64"
"fmt"
"html/template"
"io/ioutil"
"io"
"log"
"net/http"
"os"
Expand All @@ -22,10 +22,10 @@ var config *common.Config

// GameInfo is the info needed to fit into MetaRefCard
// Returns:
// * Game label / name
// * User friendly command line description
// * Func handler for incoming request
// * Func that matches the game input format to MRC's model
// - Game label / name
// - User friendly command line description
// - Func handler for incoming request
// - Func that matches the game input format to MRC's model
type GameInfo func() (string, string, common.FuncRequestHandler,
common.FuncMatchGameInputToModel)

Expand Down Expand Up @@ -65,6 +65,7 @@ func GetServer(debugMode bool, gameArgs GameToInputFiles) (*gin.Engine, string)
c.HTML(http.StatusOK, fmt.Sprintf("%s.html", label), gin.H{
"Title": config.AppName,
"Version": config.Version,
"Domain": config.Domain,
})
})
// Flight simulator endpoint
Expand Down Expand Up @@ -93,7 +94,7 @@ func GetServer(debugMode bool, gameArgs GameToInputFiles) (*gin.Engine, string)
func loadLocalFiles(files []string, log *common.Logger) [][]byte {
var inputFiles [][]byte
for _, filename := range files {
file, err := ioutil.ReadFile(filename)
file, err := os.ReadFile(filename)
if err != nil {
log.Err("Error reading file. %s", err)
}
Expand All @@ -117,7 +118,7 @@ func loadFormFiles(c *gin.Context, log *common.Logger) [][]byte {
log.Err("Error opening multipart file %s - %s", file.Filename, err)
continue
}
contents, err := ioutil.ReadAll(multipart)
contents, err := io.ReadAll(multipart)
if err != nil {
log.Err("Error reading multipart file %s - %s", file.Filename, err)
continue
Expand Down Expand Up @@ -203,7 +204,7 @@ func (i *Filenames) Set(value string) error {

// GetFilesFromDir returns a list of file names from a directory
func GetFilesFromDir(path string) *Filenames {
files, err := ioutil.ReadDir(path)
files, err := os.ReadDir(path)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 36b03c2

Please sign in to comment.