Skip to content

Commit

Permalink
Finish modular renderers
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsupermanhd committed Jun 6, 2022
1 parent 3df1b0b commit 5757b2b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 38 deletions.
6 changes: 5 additions & 1 deletion dim.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ func dimensionHandler(w http.ResponseWriter, r *http.Request) {
plainmsg(w, r, plainmsgColorRed, "Dimension not found")
return
}
basicLayoutLookupRespond("dim", w, r, map[string]interface{}{"Dim": dim, "World": world})
layers := make([]ttype, 0, len(ttypes))
for t := range ttypes {
layers = append(layers, t)
}
basicLayoutLookupRespond("dim", w, r, map[string]interface{}{"Dim": dim, "World": world, "Layers": layers})
}

func apiAddDimension(w http.ResponseWriter, r *http.Request) (int, string) {
Expand Down
35 changes: 9 additions & 26 deletions layouts/dim.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,9 @@
tileSize: 256, zoomReverse: true,
zoomSnap: 0.25, attribution: '© McWebChunk Contributors'}

var voidlayer = L.tileLayer('/thisdoesnotexist', defaultLayerSettings);
var terrainlayer = L.tileLayer('/worlds/{{.World.Name}}/{{.Dim.Name}}/tiles/terrain/{z}/{x}/{y}/png', defaultLayerSettings);
var number = L.tileLayer('/worlds/{{.World.Name}}/{{.Dim.Name}}/tiles/counttiles/{z}/{x}/{y}/png', defaultLayerSettings);
var numberheat = L.tileLayer('/worlds/{{.World.Name}}/{{.Dim.Name}}/tiles/counttilesheat/{z}/{x}/{y}/png', defaultLayerSettings);
var height = L.tileLayer('/worlds/{{.World.Name}}/{{.Dim.Name}}/tiles/heightmap/{z}/{x}/{y}/png', defaultLayerSettings);
var xray = L.tileLayer('/worlds/{{.World.Name}}/{{.Dim.Name}}/tiles/xray/{z}/{x}/{y}/png', defaultLayerSettings);
var portals = L.tileLayer('/worlds/{{.World.Name}}/{{.Dim.Name}}/tiles/portalsheat/{z}/{x}/{y}/png', defaultLayerSettings);
var chests = L.tileLayer('/worlds/{{.World.Name}}/{{.Dim.Name}}/tiles/chestheat/{z}/{x}/{y}/png', defaultLayerSettings);
var voidlayer = L.tileLayer('/thisdoesnotexist', defaultLayerSettings);
{{range $i, $l := .Layers}}var layer{{noescapeJS $l.Name}} = L.tileLayer('/worlds/{{$.World.Name}}/{{$.Dim.Name}}/tiles/{{$l.Name}}/{z}/{x}/{y}/png', defaultLayerSettings);
{{end}}

L.GridLayer.GridCoordinates = L.GridLayer.extend({
createTile: function (coords) {
Expand All @@ -102,27 +97,15 @@
cursor: false,
crs: L.CRS.Simple,
fullscreenControl: true,
layers: [terrainlayer, coordinatelayer]
layers: [{{range $1, $l := .Layers}}{{if $l.IsDefault}}layer{{noescapeJS $l.Name}},{{end}}{{end}} coordinatelayer]
}).setView([0, 0], 3);
// var circle = L.square([0, 0], {
// color: 'red',
// fillColor: '#f03',
// fillOpacity: 0.5,
// radius: 100
// }).addTo(mymap);
L.control.scale().addTo(mymap);
L.control.layers({
"Terrain": terrainlayer,
"Terrain height": height,
"Xray": xray,
"Void": voidlayer
}, {
"Chunk count heat": numberheat,
"Chunk count": number,
"Coordinate grid": coordinatelayer,
"Portal heat": portals,
"Chest heat": chests
}).addTo(mymap);
{{range $1, $l := .Layers}}{{if $l.IsOverlay}}{{else}}"{{$l.DisplayName}}": layer{{noescapeJS $l.Name}},
{{end}}{{end}}}, {
{{range $1, $l := .Layers}}{{if $l.IsOverlay}}"{{$l.DisplayName}}": layer{{noescapeJS $l.Name}},
{{else}}{{end}}{{end}}"Coordinates": coordinatelayer
}).addTo(mymap);
</script>
</body>
</html>
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ var layoutFuncs = template.FuncMap{
"noescape": func(s string) template.HTML {
return template.HTML(s)
},
"noescapeJS": func(s string) template.JS {
return template.JS(s)
},
"inc": func(i int) int {
return i + 1
},
Expand Down
24 changes: 13 additions & 11 deletions scaleimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,52 +44,54 @@ type chunkPainterFunc = func(interface{}) *image.RGBA
type ttypeProviderFunc = func(chunkStorage.ChunkStorage) (chunkDataProviderFunc, chunkPainterFunc)

type ttype struct {
name string
isOverlay bool
Name string
DisplayName string
IsOverlay bool
IsDefault bool
}

var ttypes = map[ttype]ttypeProviderFunc{
{"terrain", false}: func(s chunkStorage.ChunkStorage) (chunkDataProviderFunc, chunkPainterFunc) {
{"terrain", "Terrain", false, true}: func(s chunkStorage.ChunkStorage) (chunkDataProviderFunc, chunkPainterFunc) {
return s.GetChunksRegion, func(i interface{}) *image.RGBA {
s := i.(save.Chunk)
return drawChunk(&s)
}
},
{"counttiles", false}: func(s chunkStorage.ChunkStorage) (chunkDataProviderFunc, chunkPainterFunc) {
{"counttiles", "Chunk count", false, false}: func(s chunkStorage.ChunkStorage) (chunkDataProviderFunc, chunkPainterFunc) {
return s.GetChunksCountRegion, func(i interface{}) *image.RGBA {
return drawNumberOfChunks(int(i.(int32)))
}
},
{"counttilesheat", false}: func(s chunkStorage.ChunkStorage) (chunkDataProviderFunc, chunkPainterFunc) {
{"counttilesheat", "Chunk count heatmap", true, false}: func(s chunkStorage.ChunkStorage) (chunkDataProviderFunc, chunkPainterFunc) {
return s.GetChunksCountRegion, func(i interface{}) *image.RGBA {
return drawHeatOfChunks(int(i.(int32)))
}
},
{"heightmap", false}: func(s chunkStorage.ChunkStorage) (chunkDataProviderFunc, chunkPainterFunc) {
{"heightmap", "Heightmap", false, false}: func(s chunkStorage.ChunkStorage) (chunkDataProviderFunc, chunkPainterFunc) {
return s.GetChunksRegion, func(i interface{}) *image.RGBA {
s := i.(save.Chunk)
return drawChunkHeightmap(&s)
}
},
{"xray", false}: func(s chunkStorage.ChunkStorage) (chunkDataProviderFunc, chunkPainterFunc) {
{"xray", "Xray", false, false}: func(s chunkStorage.ChunkStorage) (chunkDataProviderFunc, chunkPainterFunc) {
return s.GetChunksRegion, func(i interface{}) *image.RGBA {
s := i.(save.Chunk)
return drawChunkXray(&s)
}
},
{"biomes", false}: func(s chunkStorage.ChunkStorage) (chunkDataProviderFunc, chunkPainterFunc) {
{"biomes", "Biomes", false, false}: func(s chunkStorage.ChunkStorage) (chunkDataProviderFunc, chunkPainterFunc) {
return s.GetChunksRegion, func(i interface{}) *image.RGBA {
s := i.(save.Chunk)
return drawChunkBiomes(&s)
}
},
{"portalsheat", false}: func(s chunkStorage.ChunkStorage) (chunkDataProviderFunc, chunkPainterFunc) {
{"portalsheat", "Portals heatmap", true, false}: func(s chunkStorage.ChunkStorage) (chunkDataProviderFunc, chunkPainterFunc) {
return s.GetChunksRegion, func(i interface{}) *image.RGBA {
s := i.(save.Chunk)
return drawChunkPortalBlocksHeatmap(&s)
}
},
{"chestheat", false}: func(s chunkStorage.ChunkStorage) (chunkDataProviderFunc, chunkPainterFunc) {
{"chestheat", "Chest heatmap", true, false}: func(s chunkStorage.ChunkStorage) (chunkDataProviderFunc, chunkPainterFunc) {
return s.GetChunksRegion, func(i interface{}) *image.RGBA {
s := i.(save.Chunk)
return drawChunkChestBlocksHeatmap(&s)
Expand Down Expand Up @@ -122,7 +124,7 @@ func tileRouterHandler(w http.ResponseWriter, r *http.Request) {
var ff ttypeProviderFunc
ffound := false
for tt := range ttypes {
if tt.name == datatype {
if tt.Name == datatype {
ff = ttypes[tt]
ffound = true
}
Expand Down

0 comments on commit 5757b2b

Please sign in to comment.