Skip to content

Commit

Permalink
Map Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark7625 committed Jul 14, 2024
1 parent 603f5c3 commit 0de7e1b
Show file tree
Hide file tree
Showing 34 changed files with 951 additions and 926 deletions.
962 changes: 518 additions & 444 deletions css/external/leaflet.css

Large diffs are not rendered by default.

29 changes: 28 additions & 1 deletion css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
src: url(fonts/zrnic.ttf);
}

{
margin: 0;
padding: 0;
box-sizing: border-box;
}


html, body {
padding: 0;
margin: 0;
Expand All @@ -11,6 +18,26 @@ html, body {
overflow: hidden;
}

.leaflet-bar.leaflet-control.leaflet-control-custom.dropdown-dark {
background-color: #2b2b2b;
color: #ffffff;
border: 1px solid #444444;
padding: 5px;
border-radius: 4px;
}

.leaflet-bar.leaflet-control.leaflet-control-custom.dropdown-dark option {
background-color: #2b2b2b;
color: #ffffff;
}

.leaflet-bar.leaflet-control.leaflet-control-custom.dropdown-dark select {
background-color: #2b2b2b;
color: #ffffff;
border: 1px solid #444444;
padding: 5px;
border-radius: 4px;
}
#map-container, #output-container {
height: 100%;
}
Expand Down Expand Up @@ -54,7 +81,7 @@ html, body {
}

#titleLabel {
font-size: 28px;
font-size: 15px;
padding-left: 15px;
padding-right: 15px;
padding-top: 10px;
Expand Down
44 changes: 44 additions & 0 deletions js/bot_api_converters/117hd/AABB.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export class AABB {
constructor(x1, y1, z1, x2, y2, z2) {
if (arguments.length === 1) {
let regionId = arguments[0];
this.minX = (regionId >>> 8) << 6;
this.minY = (regionId & 0xFF) << 6;
this.maxX = this.minX + 63;
this.maxY = this.minY + 63;
this.minZ = Number.MIN_SAFE_INTEGER;
this.maxZ = Number.MAX_SAFE_INTEGER;
} else if (arguments.length === 2) {
this.minX = this.maxX = x1;
this.minY = this.maxY = y1;
this.minZ = Number.MIN_SAFE_INTEGER;
this.maxZ = Number.MAX_SAFE_INTEGER;
} else if (arguments.length === 3) {
this.minX = this.maxX = x1;
this.minY = this.maxY = y1;
this.minZ = this.maxZ = z1;
} else if (arguments.length === 4) {
this.minX = Math.min(x1, x2);
this.minY = Math.min(y1, y2);
this.maxX = Math.max(x1, x2);
this.maxY = Math.max(y1, y2);
this.minZ = Number.MIN_SAFE_INTEGER;
this.maxZ = Number.MAX_SAFE_INTEGER;
} else if (arguments.length === 5) {
this.minX = Math.min(x1, x2);
this.minY = Math.min(y1, y2);
this.maxX = Math.max(x1, x2);
this.maxY = Math.max(y1, y2);
this.minZ = this.maxZ = z1;
} else if (arguments.length === 6) {
this.minX = Math.min(x1, x2);
this.minY = Math.min(y1, y2);
this.minZ = Math.min(z1, z2);
this.maxX = Math.max(x1, x2);
this.maxY = Math.max(y1, y2);
this.maxZ = Math.max(z1, z2);
} else {
throw new Error('Invalid number of arguments for AABB constructor');
}
}
}
151 changes: 151 additions & 0 deletions js/bot_api_converters/117hd/HD117_areas_converter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
'use strict';

import {Area} from '../../model/Area.js';
import {Position} from '../../model/Position.js';
import {OSBotAreasConverter} from '../osbot/osbot_areas_converter.js';
import {AABB} from './AABB.js';
import {RegionBox} from './RegionBox.js';

export class HD117AreasConverter extends OSBotAreasConverter {

constructor() {
super();
this.javaArea = "AABB";
this.javaPosition = "AABB";
}



parseSections(jsonStrings, keys) {
let parsedSectionsArray = [];

// Ensure jsonStrings is an array (if it's not already)
if (!Array.isArray(jsonStrings)) {
jsonStrings = [jsonStrings];
}

// Loop through each JSON string
jsonStrings.forEach(jsonString => {
let sections = {};

// Trim whitespace from JSON string
jsonString = jsonString.trim();

// Parse the JSON string into an object
let jsonObject = JSON.parse(jsonString);

// Loop through each key and extract the corresponding section
keys.forEach(key => {
if (jsonObject.hasOwnProperty(key)) {
// Check if the value is an array or a single element
if (Array.isArray(jsonObject[key][0])) {
// It's an array of arrays
sections[key] = jsonObject[key];
} else {
// Wrap single element in an array
sections[key] = [jsonObject[key]];
}
}
});

// Push parsed sections object into array
parsedSectionsArray.push(sections);
});

return parsedSectionsArray;
}

fromJava(text, areas) {
areas.removeAll();
let keys = ["regionBoxes", "aabbs", "regions"];

try {
const formattedText = `{${text}}`;
let parsedSections = this.parseSections(formattedText, keys);

parsedSections.forEach((sections, index) => {
// Process aabbs
if (sections.aabbs && Array.isArray(sections.aabbs)) {
sections.aabbs.forEach(aabb => {
let aabbData;

switch (aabb.length) {
case 4:
aabbData = new AABB(aabb[0], aabb[1], 0, aabb[2], aabb[3], 0);
break;
case 6:
aabbData = new AABB(aabb[0], aabb[1], aabb[2], aabb[3], aabb[4], aabb[5]);
break;
default:
console.log(`Unexpected format for AABB: ${aabb}`);
return; // Exit the current iteration if format is unexpected
}

// Add the area after switch cases
areas.add(new Area(
new Position(aabbData.minX, aabbData.minY, aabbData.minZ),
new Position(aabbData.maxX, aabbData.maxY, aabbData.maxZ)
));
});
}

// Process regions
if (sections.regions && Array.isArray(sections.regions)) {
sections.regions.forEach(regionId => {
let regionData = new AABB(regionId);
areas.add(new Area(
new Position(regionData.minX, regionData.minY, regionData.minZ),
new Position(regionData.maxX, regionData.maxY, regionData.maxZ)
));
});
} else if (sections.regions) {
console.log('Regions field is not an array:', sections.regions);
}

// Process regionBoxes
if (sections.regionBoxes && Array.isArray(sections.regionBoxes)) {
sections.regionBoxes.forEach(box => {
const from = box[0];
const to = box[1];

const regionBox = new RegionBox(from, to);
const aabb = regionBox.toAabb();

areas.add(new Area(
new Position(aabb.minX, aabb.minY, aabb.minZ),
new Position(aabb.maxX, aabb.maxY, aabb.maxZ)
));
});
} else if (sections.regionBoxes) {
console.log('RegionBoxes field is not an array:', sections.regionBoxes);
}
});

} catch (error) {
console.error('Error parsing or processing input:', error);
}
}

toJavaArray(areas) {
if (areas.areas.length === 1) {
let singleArea = this.toJavaSingle(areas.areas[0]);
return `"aabbs": [\n [ ${singleArea.join(', ')} ]\n ]`;
} else if (areas.areas.length > 1) {
let aabbs = areas.areas.map(area => this.toJavaSingle(area));
let formattedAABBs = aabbs.map(arr => ` [ ${arr.join(', ')} ]`).join(',\n');
return `"aabbs": [\n${formattedAABBs}\n]`;
}
return "";
}

toJavaSingle(area) {
let startX = Math.min(area.startPosition.x, area.endPosition.x);
let endX = Math.max(area.startPosition.x, area.endPosition.x);
let startY = Math.min(area.startPosition.y, area.endPosition.y);
let endY = Math.max(area.startPosition.y, area.endPosition.y);

let plane = area.startPosition.z;

return plane > 0 ? [startX, startY, plane, endX, endY, plane] : [startX, startY, endX, endY];
}
}
31 changes: 31 additions & 0 deletions js/bot_api_converters/117hd/RegionBox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {AABB} from './AABB.js';

export class RegionBox {
constructor(from, to) {
this.from = from;
this.to = to;
}

toAabb() {
let x1 = this.from >>> 8;
let y1 = this.from & 0xFF;
let x2 = this.to >>> 8;
let y2 = this.to & 0xFF;

if (x1 > x2) {
[x1, x2] = [x2, x1]; // Swap values
}
if (y1 > y2) {
[y1, y2] = [y2, y1]; // Swap values
}

return new AABB(
(x1 << 6),
(y1 << 6),
0,
((x2 + 1) << 6) - 1,
((y2 + 1) << 6) - 1,
0
);
}
}
6 changes: 3 additions & 3 deletions js/bot_api_converters/dreambot/dreambot_areas_converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class DreamBotAreasConverter extends OSBotAreasConverter {

constructor() {
super();
this.javaArea = "AABB";
this.javaArea = "Area";
this.javaPosition = "Tile";
}

Expand Down Expand Up @@ -53,8 +53,8 @@ export class DreamBotAreasConverter extends OSBotAreasConverter {

toJavaSingle(area) {
if (area.startPosition.z == 0) {
return `AreaName(${area.startPosition.x}, ${area.startPosition.y}, ${area.endPosition.x}, ${area.endPosition.y})`;
return `new ${this.javaArea}(${area.startPosition.x}, ${area.startPosition.y}, ${area.endPosition.x}, ${area.endPosition.y})`;
}
return `AreaName(${area.startPosition.x}, ${area.startPosition.y}, ${area.endPosition.x}, ${area.endPosition.y}, ${area.endPosition.z})`;
return `new ${this.javaArea}(${area.startPosition.x}, ${area.startPosition.y}, ${area.endPosition.x}, ${area.endPosition.y}, ${area.endPosition.z})`;
}
}
2 changes: 1 addition & 1 deletion js/bot_api_converters/dreambot/dreambot_path_converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class DreamBotPathConverter extends OSBotPathConverter {

constructor() {
super();
this.javaArea = "AABB";
this.javaArea = "Area";
this.javaPosition = "Tile";
}

Expand Down
4 changes: 2 additions & 2 deletions js/bot_api_converters/dreambot/dreambot_polyarea_converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class DreamBotPolyAreaConverter extends OSBotPolyAreaConverter {

constructor() {
super();
this.javaArea = "AABB";
this.javaArea = "Area";
this.javaPosition = "Tile";
}

Expand Down Expand Up @@ -40,7 +40,7 @@ export class DreamBotPolyAreaConverter extends OSBotPolyAreaConverter {
if (polyarea.positions.length == 0) {
return "";
}
var output = `AreaName((\n new ${this.javaPosition}[] {`;
var output = `${this.javaArea} area = new ${this.javaArea}(\n new ${this.javaPosition}[] {`;
for (var i = 0; i < polyarea.positions.length; i++) {
var position = polyarea.positions[i];
output += `\n new ${this.javaPosition}(${position.x}, ${position.y}, ${position.z})`;
Expand Down
Loading

0 comments on commit 0de7e1b

Please sign in to comment.