mapblock debugging
This commit is contained in:
parent
51bc900b00
commit
b74e9da1c1
@ -10,13 +10,23 @@ type Config struct {
|
|||||||
Port int `json:"port"`
|
Port int `json:"port"`
|
||||||
EnableInitialRendering bool `json:"enableinitialrendering"`
|
EnableInitialRendering bool `json:"enableinitialrendering"`
|
||||||
Webdev bool `json:"webdev"`
|
Webdev bool `json:"webdev"`
|
||||||
|
WebApi WebApiConfig `json:"webapi"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebApiConfig struct {
|
||||||
|
EnableMapblock bool `json:"enablemapblock"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseConfig(filename string) (*Config, error) {
|
func ParseConfig(filename string) (*Config, error) {
|
||||||
|
webapi := WebApiConfig{
|
||||||
|
EnableMapblock: false,
|
||||||
|
}
|
||||||
|
|
||||||
cfg := Config{
|
cfg := Config{
|
||||||
Port: 8080,
|
Port: 8080,
|
||||||
EnableInitialRendering: true,
|
EnableInitialRendering: true,
|
||||||
Webdev: false,
|
Webdev: false,
|
||||||
|
WebApi: webapi,
|
||||||
}
|
}
|
||||||
|
|
||||||
info, err := os.Stat(filename)
|
info, err := os.Stat(filename)
|
||||||
|
@ -1,11 +1,27 @@
|
|||||||
package mapblockparser
|
package mapblockparser
|
||||||
|
|
||||||
type MapBlock struct {
|
type MapBlock struct {
|
||||||
Version byte
|
Version byte `json:"version"`
|
||||||
Underground bool
|
Underground bool `json:"underground"`
|
||||||
Mapdata []byte
|
Mapdata []byte `json:"mapdata"`
|
||||||
Metadata Metadata
|
Metadata Metadata `json:"metadata"`
|
||||||
BlockMapping map[int]string
|
BlockMapping map[int]string `json:"blockmapping"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Metadata struct {
|
||||||
|
Inventories map[int]map[string]*Inventory `json:"inventories"`
|
||||||
|
Pairs map[int]map[string]string `json:"pairs"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Item struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Count int `json:"count"`
|
||||||
|
Wear int `json:"wear"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Inventory struct {
|
||||||
|
Size int `json:"size"`
|
||||||
|
Items []Item `json:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNodePos(x, y, z int) int {
|
func getNodePos(x, y, z int) int {
|
||||||
@ -25,11 +41,6 @@ func NewMapblock() MapBlock {
|
|||||||
return mb
|
return mb
|
||||||
}
|
}
|
||||||
|
|
||||||
type Metadata struct {
|
|
||||||
Inventories map[int]map[string]*Inventory
|
|
||||||
Pairs map[int]map[string]string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewMetadata() Metadata {
|
func NewMetadata() Metadata {
|
||||||
md := Metadata{}
|
md := Metadata{}
|
||||||
md.Inventories = make(map[int]map[string]*Inventory)
|
md.Inventories = make(map[int]map[string]*Inventory)
|
||||||
@ -67,14 +78,3 @@ func (md *Metadata) GetInventory(pos int, name string) *Inventory {
|
|||||||
|
|
||||||
return inv
|
return inv
|
||||||
}
|
}
|
||||||
|
|
||||||
type Item struct {
|
|
||||||
Name string
|
|
||||||
Count int
|
|
||||||
Wear int
|
|
||||||
}
|
|
||||||
|
|
||||||
type Inventory struct {
|
|
||||||
Size int
|
|
||||||
Items []Item
|
|
||||||
}
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
{
|
{
|
||||||
"port": 8080,
|
"port": 8080,
|
||||||
"enableinitialrendering": false,
|
"enableinitialrendering": false,
|
||||||
"webdev": true
|
"webdev": true,
|
||||||
|
"webapi": {
|
||||||
|
"enablemapblock": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
41
web/mapblock.go
Normal file
41
web/mapblock.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package web
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"mapserver/app"
|
||||||
|
"mapserver/coords"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MapblockHandler struct {
|
||||||
|
ctx *app.App
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *MapblockHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
||||||
|
str := strings.TrimPrefix(req.URL.Path, "/api/mapblock/")
|
||||||
|
parts := strings.Split(str, "/")
|
||||||
|
if len(parts) != 3 {
|
||||||
|
resp.WriteHeader(500)
|
||||||
|
resp.Write([]byte("wrong number of arguments"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
x, _ := strconv.Atoi(parts[0])
|
||||||
|
y, _ := strconv.Atoi(parts[1])
|
||||||
|
z, _ := strconv.Atoi(parts[2])
|
||||||
|
|
||||||
|
c := coords.NewMapBlockCoords(x, y, z)
|
||||||
|
mb, err := h.ctx.BlockAccessor.GetMapBlock(c)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
resp.WriteHeader(500)
|
||||||
|
resp.Write([]byte(err.Error()))
|
||||||
|
|
||||||
|
} else {
|
||||||
|
resp.Header().Add("content-type", "application/json")
|
||||||
|
json.NewEncoder(resp).Encode(mb)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -18,7 +18,11 @@ func Serve(ctx *app.App) {
|
|||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
mux.Handle("/", http.FileServer(vfs.FS(ctx.Config.Webdev)))
|
mux.Handle("/", http.FileServer(vfs.FS(ctx.Config.Webdev)))
|
||||||
mux.Handle("/tile/", &Tiles{ctx: ctx})
|
mux.Handle("/api/tile/", &Tiles{ctx: ctx})
|
||||||
|
|
||||||
|
if ctx.Config.WebApi.EnableMapblock {
|
||||||
|
mux.Handle("/api/mapblock/", &MapblockHandler{ctx: ctx})
|
||||||
|
}
|
||||||
|
|
||||||
err := http.ListenAndServe(":"+strconv.Itoa(ctx.Config.Port), mux)
|
err := http.ListenAndServe(":"+strconv.Itoa(ctx.Config.Port), mux)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
10
web/tiles.go
10
web/tiles.go
@ -4,8 +4,8 @@ import (
|
|||||||
"mapserver/app"
|
"mapserver/app"
|
||||||
"mapserver/coords"
|
"mapserver/coords"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Tiles struct {
|
type Tiles struct {
|
||||||
@ -13,8 +13,14 @@ type Tiles struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tiles) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
func (t *Tiles) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
||||||
str := strings.TrimPrefix(req.URL.Path, "/tile/")
|
str := strings.TrimPrefix(req.URL.Path, "/api/tile/")
|
||||||
parts := strings.Split(str, "/")
|
parts := strings.Split(str, "/")
|
||||||
|
if len(parts) != 4 {
|
||||||
|
resp.WriteHeader(500)
|
||||||
|
resp.Write([]byte("wrong number of arguments"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
layerid, _ := strconv.Atoi(parts[0])
|
layerid, _ := strconv.Atoi(parts[0])
|
||||||
x, _ := strconv.Atoi(parts[1])
|
x, _ := strconv.Atoi(parts[1])
|
||||||
y, _ := strconv.Atoi(parts[2])
|
y, _ := strconv.Atoi(parts[2])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user