mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-08-28 00:10:23 +02:00
37 lines
652 B
Go
37 lines
652 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"fmt"
|
||
|
"image/color"
|
||
|
"os"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func ParseColors(filename string) (colors map[string]color.RGBA, err error) {
|
||
|
|
||
|
var file *os.File
|
||
|
if file, err = os.Open(filename); err != nil {
|
||
|
return
|
||
|
}
|
||
|
defer file.Close()
|
||
|
|
||
|
colors = make(map[string]color.RGBA)
|
||
|
|
||
|
scanner := bufio.NewScanner(file)
|
||
|
for scanner.Scan() {
|
||
|
line := scanner.Text()
|
||
|
if strings.HasPrefix(line, "#") {
|
||
|
continue
|
||
|
}
|
||
|
c := color.RGBA{A: 0xff}
|
||
|
var name string
|
||
|
if n, _ := fmt.Sscanf(
|
||
|
line, "%s %d %d %d %d", &name, &c.R, &c.G, &c.B, &c.A); n > 0 {
|
||
|
colors[name] = c
|
||
|
}
|
||
|
}
|
||
|
err = scanner.Err()
|
||
|
return
|
||
|
}
|