diff --git a/app/setup.go b/app/setup.go index f9beb98..edf8e9f 100644 --- a/app/setup.go +++ b/app/setup.go @@ -14,7 +14,6 @@ import ( "mapserver/settings" "mapserver/tiledb" "mapserver/tilerenderer" - "mapserver/vfs" "mapserver/worldconfig" "time" @@ -106,14 +105,8 @@ func Setup(p params.ParamsType, cfg *Config) *App { } - fullpalette, err := colormapping.NewPalette(vfs.FSMustByte(false, "/pics/unifieddyes_palette_extended.png")) - - if err != nil { - panic(err) - } - //mapblock renderer - a.Mapblockrenderer = mapblockrenderer.NewMapBlockRenderer(a.BlockAccessor, a.Colormapping, fullpalette) + a.Mapblockrenderer = mapblockrenderer.NewMapBlockRenderer(a.BlockAccessor, a.Colormapping) //mapserver database if a.Worldconfig[worldconfig.CONFIG_PSQL_MAPSERVER] != "" { diff --git a/colormapping/colormapping.go b/colormapping/colormapping.go index 53da4f6..d4bf931 100644 --- a/colormapping/colormapping.go +++ b/colormapping/colormapping.go @@ -13,10 +13,17 @@ import ( ) type ColorMapping struct { - colors map[string]*color.RGBA + colors map[string]*color.RGBA + extendedpalette *Palette } -func (m *ColorMapping) GetColor(name string) *color.RGBA { +func (m *ColorMapping) GetColor(name string, param2 int) *color.RGBA { + //TODO: list of node->palette + if name == "unifiedbricks:brickblock" { + // param2 coloring + return m.extendedpalette.GetColor(param2) + } + return m.colors[name] } @@ -95,5 +102,14 @@ func (m *ColorMapping) LoadVFSColors(useLocal bool, filename string) (int, error } func NewColorMapping() *ColorMapping { - return &ColorMapping{colors: make(map[string]*color.RGBA)} + extendedpalette, err := NewPalette(vfs.FSMustByte(false, "/pics/unifieddyes_palette_extended.png")) + + if err != nil { + panic(err) + } + + return &ColorMapping{ + colors: make(map[string]*color.RGBA), + extendedpalette: extendedpalette, + } } diff --git a/colormapping/colormapping_test.go b/colormapping/colormapping_test.go index ff218df..06129dc 100644 --- a/colormapping/colormapping_test.go +++ b/colormapping/colormapping_test.go @@ -11,12 +11,12 @@ func TestNewMapping(t *testing.T) { t.Fatal(err) } - c := m.GetColor("scifi_nodes:blacktile2") + c := m.GetColor("scifi_nodes:blacktile2", 0) if c == nil { panic("no color") } - c = m.GetColor("default:river_water_flowing") + c = m.GetColor("default:river_water_flowing", 0) if c == nil { panic("no color") } diff --git a/mapblockrenderer/renderer.go b/mapblockrenderer/renderer.go index 72b923d..112678c 100644 --- a/mapblockrenderer/renderer.go +++ b/mapblockrenderer/renderer.go @@ -17,16 +17,14 @@ import ( type MapBlockRenderer struct { accessor *mapblockaccessor.MapBlockAccessor colors *colormapping.ColorMapping - fullpalette *colormapping.Palette enableShadow bool enableTransparency bool } -func NewMapBlockRenderer(accessor *mapblockaccessor.MapBlockAccessor, colors *colormapping.ColorMapping, fullpalette *colormapping.Palette) *MapBlockRenderer { +func NewMapBlockRenderer(accessor *mapblockaccessor.MapBlockAccessor, colors *colormapping.ColorMapping) *MapBlockRenderer { return &MapBlockRenderer{ accessor: accessor, colors: colors, - fullpalette: fullpalette, enableShadow: true, enableTransparency: false, } @@ -132,18 +130,13 @@ func (r *MapBlockRenderer) Render(pos1, pos2 *coords.MapBlockCoords) (*image.NRG } nodeName := mb.GetNodeName(x, y, z) + param2 := mb.GetParam2(x, y, z) if nodeName == "" { continue } - c := r.colors.GetColor(nodeName) - hasfullpalette := nodeName == "unifiedbricks:brickblock" - - if hasfullpalette && r.fullpalette != nil { - param2 := mb.GetParam2(x, y, z) - c = r.fullpalette.GetColor(param2) - } + c := r.colors.GetColor(nodeName, param2) if c == nil { continue diff --git a/mapblockrenderer/renderer_test.go b/mapblockrenderer/renderer_test.go index 6a42143..5fb8d47 100644 --- a/mapblockrenderer/renderer_test.go +++ b/mapblockrenderer/renderer_test.go @@ -52,18 +52,7 @@ func TestSimpleRender(t *testing.T) { t.Fatal(err) } - palettedata, err := ioutil.ReadFile("./testdata/unifieddyes_palette_extended.png") - if err != nil { - t.Fatal(err) - } - - palette, err := colormapping.NewPalette(palettedata) - - if err != nil { - t.Fatal(err) - } - - r := NewMapBlockRenderer(cache, c, palette) + r := NewMapBlockRenderer(cache, c) os.Mkdir("../test-output", 0755) results := make(chan JobResult, 100) diff --git a/mapblockrenderer/testdata/unifieddyes_palette_extended.png b/mapblockrenderer/testdata/unifieddyes_palette_extended.png deleted file mode 100644 index 2ff0323..0000000 Binary files a/mapblockrenderer/testdata/unifieddyes_palette_extended.png and /dev/null differ diff --git a/tilerenderer/renderer_test.go b/tilerenderer/renderer_test.go index 7d16a22..cb9a5f6 100644 --- a/tilerenderer/renderer_test.go +++ b/tilerenderer/renderer_test.go @@ -46,7 +46,7 @@ func TestTileRender(t *testing.T) { t.Fatal(err) } - r := mapblockrenderer.NewMapBlockRenderer(cache, c, nil) + r := mapblockrenderer.NewMapBlockRenderer(cache, c) tiletmpdir, err := ioutil.TempDir("", "TestTileRenderTiles.*.sqlite") defer os.RemoveAll(tiletmpdir)