diff --git a/server/colormapping/colormapping.go b/server/colormapping/colormapping.go index 53da4f6..73c3f3f 100644 --- a/server/colormapping/colormapping.go +++ b/server/colormapping/colormapping.go @@ -20,6 +20,10 @@ func (m *ColorMapping) GetColor(name string) *color.RGBA { return m.colors[name] } +func (m *ColorMapping) GetColors() map[string]*color.RGBA { + return m.colors +} + func (m *ColorMapping) LoadBytes(buffer []byte) (int, error) { scanner := bufio.NewScanner(bytes.NewReader(buffer)) count := 0 diff --git a/server/web/colormapping.go b/server/web/colormapping.go new file mode 100644 index 0000000..2a7ba09 --- /dev/null +++ b/server/web/colormapping.go @@ -0,0 +1,29 @@ +package web + +import ( + "encoding/json" + "mapserver/app" + "net/http" +) + +type ColorMappingHandler struct { + ctx *app.App +} + +type Color struct { + R uint8 `json:"r"` + G uint8 `json:"g"` + B uint8 `json:"b"` +} + +func (h *ColorMappingHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { + + cm := make(map[string]Color) + + for k, v := range h.ctx.Colormapping.GetColors() { + cm[k] = Color{R: v.R, G: v.G, B: v.B} + } + + resp.Header().Add("content-type", "application/json") + json.NewEncoder(resp).Encode(cm) +} diff --git a/server/web/serve.go b/server/web/serve.go index 71bea21..11e63e1 100644 --- a/server/web/serve.go +++ b/server/web/serve.go @@ -31,6 +31,7 @@ func Serve(ctx *app.App) { mux.Handle("/api/config", &ConfigHandler{ctx: ctx}) mux.Handle("/api/minetest", &Minetest{ctx: ctx}) mux.Handle("/api/mapobjects/", &MapObjects{ctx: ctx}) + mux.Handle("/api/colormapping/", &ColorMappingHandler{ctx: ctx}) if ctx.Config.MapObjects.Areas { mux.Handle("/api/areas", &AreasHandler{ctx: ctx})