grid line color/continent number font color should be configurable
This commit is contained in:
parent
4d96b7a7be
commit
b5421f3c70
|
@ -3,7 +3,6 @@ package generator
|
|||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"io"
|
||||
|
||||
|
@ -13,6 +12,8 @@ import (
|
|||
|
||||
const (
|
||||
defaultBackgroundColor = "#000"
|
||||
defaultGridLineColor = "#fff"
|
||||
defaultContinentNumberColor = "#fff"
|
||||
defaultMapSize = 1000
|
||||
)
|
||||
|
||||
|
@ -28,12 +29,20 @@ type Config struct {
|
|||
ContinentGrid bool
|
||||
ContinentNumbers bool
|
||||
BackgroundColor string
|
||||
GridLineColor string
|
||||
ContinentNumberColor string
|
||||
}
|
||||
|
||||
func (cfg *Config) init() {
|
||||
if cfg.BackgroundColor == "" {
|
||||
cfg.BackgroundColor = defaultBackgroundColor
|
||||
}
|
||||
if cfg.GridLineColor == "" {
|
||||
cfg.GridLineColor = defaultGridLineColor
|
||||
}
|
||||
if cfg.ContinentNumberColor == "" {
|
||||
cfg.ContinentNumberColor = defaultContinentNumberColor
|
||||
}
|
||||
if cfg.MapSize <= 0 {
|
||||
cfg.MapSize = defaultMapSize
|
||||
}
|
||||
|
@ -70,27 +79,35 @@ func Generate(cfg Config) error {
|
|||
|
||||
//Continents
|
||||
if cfg.ContinentGrid {
|
||||
gridLineColor, err := parseHexColorFast(cfg.GridLineColor)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "map-generator")
|
||||
}
|
||||
for y := cfg.MapSize / 10; y < cfg.MapSize; y += cfg.MapSize / 10 {
|
||||
for x := 0; x < cfg.MapSize; x++ {
|
||||
img.Set(x, y, color.White)
|
||||
img.Set(x, y, gridLineColor)
|
||||
}
|
||||
}
|
||||
for x := cfg.MapSize / 10; x < cfg.MapSize; x += cfg.MapSize / 10 {
|
||||
for y := 0; y < cfg.MapSize; y++ {
|
||||
img.Set(x, y, color.White)
|
||||
img.Set(x, y, gridLineColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.ContinentNumbers {
|
||||
continent := 0
|
||||
continentNumberColor, err := parseHexColorFast(cfg.ContinentNumberColor)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "map-generator")
|
||||
}
|
||||
for y := cfg.MapSize / 10; y <= cfg.MapSize; y += cfg.MapSize / 10 {
|
||||
for x := cfg.MapSize / 10; x <= cfg.MapSize; x += cfg.MapSize / 10 {
|
||||
continentStr := fmt.Sprintf("%d", continent)
|
||||
if continent < 10 {
|
||||
continentStr = fmt.Sprintf("0%d", continent)
|
||||
}
|
||||
drawText(img, x-16, y-3, continentStr)
|
||||
drawText(img, x-16, y-3, continentNumberColor, continentStr)
|
||||
continent++
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,8 +51,7 @@ func parseHexColorFast(s string) (color.RGBA, error) {
|
|||
return c, err
|
||||
}
|
||||
|
||||
func drawText(img *image.RGBA, x, y int, text string) {
|
||||
col := color.RGBA{200, 100, 0, 255}
|
||||
func drawText(img *image.RGBA, x, y int, col color.RGBA, text string) {
|
||||
point := fixed.Point26_6{fixed.Int26_6(x * 64), fixed.Int26_6(y * 64)}
|
||||
|
||||
d := &font.Drawer{
|
||||
|
|
Reference in New Issue
Block a user