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