2011-07-22 00:26:32 +02:00
|
|
|
regionConstructors['WorldGuard'] = function(dynmap, configuration) {
|
|
|
|
// Helper function.
|
2011-08-23 05:16:38 +02:00
|
|
|
function createBoxFromRegion(name, region, boxCreator) {
|
2011-07-22 00:26:32 +02:00
|
|
|
function ArrayMax( array ) {
|
|
|
|
return Math.max.apply( Math, array );
|
|
|
|
}
|
|
|
|
function ArrayMin( array ) {
|
|
|
|
return Math.min.apply( Math, array );
|
2011-07-21 00:49:52 +02:00
|
|
|
}
|
2011-07-22 00:26:32 +02:00
|
|
|
if(region.points) {
|
|
|
|
var i;
|
|
|
|
var xs = region.points.map(function(p) { return p.x; });
|
|
|
|
var zs = region.points.map(function(p) { return p.z; });
|
2011-08-23 05:16:38 +02:00
|
|
|
return boxCreator(ArrayMax(xs), ArrayMin(xs), region['max-y'], region['min-y'], ArrayMax(zs), ArrayMin(zs), configuration.getStyle(name));
|
2011-07-22 00:26:32 +02:00
|
|
|
}
|
|
|
|
if(!region.min || !region.max)
|
2011-08-10 15:14:48 +02:00
|
|
|
return null;
|
2011-07-22 00:26:32 +02:00
|
|
|
if(region.max.y <= region.min.y)
|
|
|
|
region.min.y = region.max.y - 1;
|
2011-08-23 05:16:38 +02:00
|
|
|
return boxCreator(region.max.x, region.min.x, region.max.y, region.min.y, region.max.z, region.min.z, configuration.getStyle(name));
|
2011-07-22 00:26:32 +02:00
|
|
|
}
|
2011-08-11 03:47:14 +02:00
|
|
|
|
2011-08-23 05:16:38 +02:00
|
|
|
function createOutlineFromRegion(name, region, outCreator) {
|
2011-08-11 03:47:14 +02:00
|
|
|
var xarray = [];
|
|
|
|
var zarray = [];
|
|
|
|
if(region.points) {
|
|
|
|
var i;
|
|
|
|
for(i = 0; i < region.points.length; i++) {
|
|
|
|
xarray[i] = region.points[i].x;
|
|
|
|
zarray[i] = region.points[i].z;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var ymin = 64;
|
|
|
|
var ymax = 64;
|
|
|
|
if(region['max-y'])
|
|
|
|
ymax = region['max-y'];
|
|
|
|
if(region['min-y'])
|
|
|
|
ymin = region['min-y'];
|
|
|
|
if(ymax < ymin) ymax = ymin;
|
|
|
|
|
2011-08-23 05:16:38 +02:00
|
|
|
return outCreator(xarray, ymax, ymin, zarray, configuration.getStyle(name));
|
2011-08-11 03:47:14 +02:00
|
|
|
}
|
2011-04-14 02:58:25 +02:00
|
|
|
|
2011-07-22 00:26:32 +02:00
|
|
|
var regionFile = configuration.filename.substr(0, configuration.filename.lastIndexOf('.'));
|
|
|
|
regionFile += '_'+configuration.worldName+'.json';
|
2011-07-21 00:49:52 +02:00
|
|
|
$.getJSON('standalone/'+regionFile, function(data) {
|
2011-07-22 00:26:32 +02:00
|
|
|
var boxLayers = [];
|
2011-07-21 00:49:52 +02:00
|
|
|
$.each(data, function(name, region) {
|
2011-08-10 15:14:48 +02:00
|
|
|
// Only handle cuboids for the moment (therefore skipping 'global')
|
|
|
|
if (region.type === 'cuboid') {
|
2011-08-23 05:16:38 +02:00
|
|
|
var boxLayer = createBoxFromRegion(name, region, configuration.createBoxLayer);
|
2011-08-10 15:14:48 +02:00
|
|
|
// Skip errorous regions.
|
|
|
|
if (boxLayer) {
|
|
|
|
boxLayer.bindPopup(configuration.createPopupContent(name, region));
|
|
|
|
|
|
|
|
boxLayers.push(boxLayer);
|
|
|
|
}
|
|
|
|
}
|
2011-08-11 03:47:14 +02:00
|
|
|
else if(region.type === 'poly2d') {
|
2011-08-23 05:16:38 +02:00
|
|
|
var outLayer = createOutlineFromRegion(name, region, configuration.createOutlineLayer);
|
2011-08-11 03:47:14 +02:00
|
|
|
if (outLayer) {
|
|
|
|
outLayer.bindPopup(configuration.createPopupContent(name, region));
|
|
|
|
boxLayers.push(outLayer);
|
|
|
|
}
|
|
|
|
}
|
2011-04-14 02:58:25 +02:00
|
|
|
});
|
2011-07-22 00:26:32 +02:00
|
|
|
configuration.result(new L.LayerGroup(boxLayers));
|
2011-07-21 00:49:52 +02:00
|
|
|
|
2011-04-14 02:58:25 +02:00
|
|
|
});
|
2011-07-21 00:49:52 +02:00
|
|
|
};
|