diff --git a/colormapping/colormapping.go b/colormapping/colormapping.go index 817dfcd..22248e8 100644 --- a/colormapping/colormapping.go +++ b/colormapping/colormapping.go @@ -1,89 +1,89 @@ package colormapping import ( - "mapserver/vfs" - "bufio" - "errors" - "bytes" - "strings" - "strconv" - "github.com/sirupsen/logrus" - "image/color" + "bufio" + "bytes" + "errors" + "github.com/sirupsen/logrus" + "image/color" + "mapserver/vfs" + "strconv" + "strings" ) type ColorMapping struct { - colors map[string]*color.RGBA + colors map[string]*color.RGBA } func (m *ColorMapping) GetColor(name string) *color.RGBA { - return m.colors[name] + return m.colors[name] } func (m *ColorMapping) LoadBytes(buffer []byte) error { - scanner := bufio.NewScanner(bytes.NewReader(buffer)) - for scanner.Scan() { - txt := strings.Trim(scanner.Text(), " ") + scanner := bufio.NewScanner(bytes.NewReader(buffer)) + for scanner.Scan() { + txt := strings.Trim(scanner.Text(), " ") - if len(txt) == 0 { - //empty - continue - } + if len(txt) == 0 { + //empty + continue + } - if strings.HasPrefix(txt, "#") { - //comment - continue - } + if strings.HasPrefix(txt, "#") { + //comment + continue + } - parts := strings.Fields(txt) + parts := strings.Fields(txt) - if len(parts) < 4 { - return errors.New("invalid line") - } + if len(parts) < 4 { + return errors.New("invalid line") + } - if len(parts) >= 4 { - r, err := strconv.ParseInt(parts[1], 10, 32) - if err != nil { - return err - } + if len(parts) >= 4 { + r, err := strconv.ParseInt(parts[1], 10, 32) + if err != nil { + return err + } - g, err := strconv.ParseInt(parts[2], 10, 32) - if err != nil { - return err - } + g, err := strconv.ParseInt(parts[2], 10, 32) + if err != nil { + return err + } - b, err := strconv.ParseInt(parts[3], 10, 32) - if err != nil { - return err - } + b, err := strconv.ParseInt(parts[3], 10, 32) + if err != nil { + return err + } - c := color.RGBA{uint8(r),uint8(g),uint8(b), 0xFF} - m.colors[parts[0]] = &c - } + c := color.RGBA{uint8(r), uint8(g), uint8(b), 0xFF} + m.colors[parts[0]] = &c + } - if len(parts) >= 5 { - //with alpha - } + if len(parts) >= 5 { + //with alpha + } - } + } - return nil + return nil } //TODO: colors from fs func (m *ColorMapping) LoadVFSColors(useLocal bool, filename string) error { - buffer, err := vfs.FSByte(useLocal, "/colors.txt") - if err != nil { - return err - } + buffer, err := vfs.FSByte(useLocal, "/colors.txt") + if err != nil { + return err + } - log.WithFields(logrus.Fields{"size": len(buffer), - "filename": filename, - "useLocal": useLocal}).Info("Loading local colors file") + log.WithFields(logrus.Fields{"size": len(buffer), + "filename": filename, + "useLocal": useLocal}).Info("Loading local colors file") - return m.LoadBytes(buffer) + return m.LoadBytes(buffer) } func NewColorMapping() *ColorMapping { - return &ColorMapping{colors: make(map[string]*color.RGBA)} + return &ColorMapping{colors: make(map[string]*color.RGBA)} } diff --git a/colormapping/colormapping_test.go b/colormapping/colormapping_test.go index a82222f..636e376 100644 --- a/colormapping/colormapping_test.go +++ b/colormapping/colormapping_test.go @@ -5,15 +5,15 @@ import ( ) func TestNewMapping(t *testing.T) { - m := NewColorMapping() - err := m.LoadVFSColors(false, "/colors.txt") - if err != nil { - t.Fatal(err) - } + m := NewColorMapping() + err := m.LoadVFSColors(false, "/colors.txt") + if err != nil { + t.Fatal(err) + } - c := m.GetColor("scifi_nodes:blacktile2") - if c == nil { - panic("no color") - } + c := m.GetColor("scifi_nodes:blacktile2") + if c == nil { + panic("no color") + } } diff --git a/colormapping/logger.go b/colormapping/logger.go index 9673cb6..e1e8e1b 100644 --- a/colormapping/logger.go +++ b/colormapping/logger.go @@ -1,10 +1,11 @@ package colormapping import ( - "github.com/sirupsen/logrus" + "github.com/sirupsen/logrus" ) var log *logrus.Entry -func init(){ + +func init() { log = logrus.WithFields(logrus.Fields{"prefix": "colormapping"}) } diff --git a/coords/convert.go b/coords/convert.go index 04380cc..6f7b89c 100644 --- a/coords/convert.go +++ b/coords/convert.go @@ -9,7 +9,6 @@ const ( maxValue = 1<<(numBitsPerComponent-1) - 1 ) - func CoordToPlain(c MapBlockCoords) int64 { return int64(c.Z)<<(2*numBitsPerComponent) + int64(c.Y)<