-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
951 additions
and
926 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.