forked from MTSR/mapserver
api/viewblock
This commit is contained in:
parent
467429ace8
commit
780fda8460
@ -1,13 +1,13 @@
|
||||
var camera, scene, renderer;
|
||||
var colormapping, geometry;
|
||||
var geometry;
|
||||
|
||||
init();
|
||||
animate();
|
||||
|
||||
function getNodePos(x,y,z){ return x + (y * 16) + (z * 256); }
|
||||
|
||||
function drawMapblock(posx,posy,posz){
|
||||
m.request("api/mapblock/"+posx+"/"+posy+"/"+posz)
|
||||
function drawMapblock(posx,posy,posz,colormapping){
|
||||
m.request("api/viewblock/"+posx+"/"+posy+"/"+posz)
|
||||
.then(function(mapblock){
|
||||
if (!mapblock)
|
||||
return;
|
||||
@ -16,7 +16,7 @@ function drawMapblock(posx,posy,posz){
|
||||
for (var y=0; y<16; y++){
|
||||
for (var z=0; z<16; z++){
|
||||
var i = getNodePos(x,y,z);
|
||||
var contentId = mapblock.mapdata.contentid[i];
|
||||
var contentId = mapblock.contentid[i];
|
||||
var nodeName = mapblock.blockmapping[contentId]
|
||||
var colorObj = colormapping[nodeName];
|
||||
|
||||
@ -50,12 +50,12 @@ function init() {
|
||||
geometry = new THREE.BoxGeometry( 3, 3, 3 );
|
||||
|
||||
m.request("api/colormapping")
|
||||
.then(function(_colormapping){
|
||||
colormapping = _colormapping;
|
||||
for (var x=-4; x<4; x++){
|
||||
.then(function(colormapping){
|
||||
|
||||
for (var x=0; x<14; x++){
|
||||
for (var y=0; y<2; y++){
|
||||
for (var z=-4; z<4; z++){
|
||||
drawMapblock(x,y,z);
|
||||
drawMapblock(x,y,z,colormapping);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ func Serve(ctx *app.App) {
|
||||
mux.Handle("/api/minetest", &Minetest{ctx: ctx})
|
||||
mux.Handle("/api/mapobjects/", &MapObjects{ctx: ctx})
|
||||
mux.Handle("/api/colormapping/", &ColorMappingHandler{ctx: ctx})
|
||||
mux.Handle("/api/viewblock/", &ViewMapblockHandler{ctx: ctx})
|
||||
|
||||
if ctx.Config.MapObjects.Areas {
|
||||
mux.Handle("/api/areas", &AreasHandler{ctx: ctx})
|
||||
|
54
web/viewblock.go
Normal file
54
web/viewblock.go
Normal file
@ -0,0 +1,54 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"mapserver/app"
|
||||
"mapserver/coords"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ViewBlock struct {
|
||||
BlockMapping map[int]string `json:"blockmapping"`
|
||||
ContentId []int `json:"contentid"`
|
||||
}
|
||||
|
||||
type ViewMapblockHandler struct {
|
||||
ctx *app.App
|
||||
}
|
||||
|
||||
func (h *ViewMapblockHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
||||
str := strings.TrimPrefix(req.URL.Path, "/api/viewblock/")
|
||||
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.MapBlockAccessor.GetMapBlock(c)
|
||||
|
||||
if err != nil {
|
||||
resp.WriteHeader(500)
|
||||
resp.Write([]byte(err.Error()))
|
||||
|
||||
} else {
|
||||
|
||||
var vb *ViewBlock
|
||||
if mb != nil {
|
||||
vb = &ViewBlock{}
|
||||
vb.BlockMapping = mb.BlockMapping
|
||||
vb.ContentId = mb.Mapdata.ContentId
|
||||
}
|
||||
|
||||
resp.Header().Add("content-type", "application/json")
|
||||
json.NewEncoder(resp).Encode(vb)
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user