diff --git a/src/util.ts b/src/util.ts index e9b3b40..ed5a73a 100644 --- a/src/util.ts +++ b/src/util.ts @@ -20,7 +20,7 @@ import LiveAtlasMapDefinition from "@/model/LiveAtlasMapDefinition"; import { Coordinate, HeadQueueEntry, - LiveAtlasBounds, + LiveAtlasBounds, LiveAtlasDimension, LiveAtlasGlobalMessageConfig, LiveAtlasLocation, LiveAtlasMessageConfig, @@ -39,8 +39,8 @@ const documentRange = document.createRange(), headQueue: HeadQueueEntry[] = []; export const titleColoursRegex = /ยง[0-9a-f]/ig; -export const netherWorldNameRegex = /_?nether(_|$)/i; -export const endWorldNameRegex = /(^|_)end(_|$)/i; +export const netherWorldNameRegex = /[_\s]?nether([\s_]|$)/i; +export const endWorldNameRegex = /(^|[_\s])end([\s_]|$)/i; export const getMinecraftTime = (serverTime: number) => { const day = serverTime >= 0 && serverTime < 13700; @@ -260,6 +260,14 @@ const _getMessages = (messageKeys: any, config: any = {}) => { return messages as LiveAtlasGlobalMessageConfig; } +/** + * Determines the bounds required to enclose the given separate arrays of x, y and z coordinates + * All arrays are expected to be the same length + * @param {number[]} x X coordinates + * @param {number[]} y Y coordinates + * @param {number[]} z Z coordinates + * @returns {LiveAtlasBounds} The calculated bounds + */ export const getBounds = (x: number[], y: number[], z: number[]): LiveAtlasBounds => { return { min: {x: Math.min.apply(null, x), y: Math.min.apply(null, y), z: Math.min.apply(null, z)}, @@ -267,6 +275,12 @@ export const getBounds = (x: number[], y: number[], z: number[]): LiveAtlasBound }; } +/** + * Determines the bounds required to enclose the given array of {@see Coordinate}s + * Multiple dimension arrays are accepted and will be handled recursively + * @param {Coordinate[]} points Points to determine the bounds for + * @returns {LiveAtlasBounds} The calculated bounds + */ export const getBoundsFromPoints = (points: Coordinate[]): LiveAtlasBounds => { const bounds = { max: {x: -Infinity, y: -Infinity, z: -Infinity}, @@ -291,6 +305,11 @@ export const getBoundsFromPoints = (points: Coordinate[]): LiveAtlasBounds => { return bounds; } +/** + * Determines the center point of the given {@see LiveAtlasBounds} + * @param {LiveAtlasBounds} bounds The bounds to find the center point for + * @return {LiveAtlasLocation} The center point + */ export const getMiddle = (bounds: LiveAtlasBounds): LiveAtlasLocation => { return { x: bounds.min.x + ((bounds.max.x - bounds.min.x) / 2), @@ -299,6 +318,10 @@ export const getMiddle = (bounds: LiveAtlasBounds): LiveAtlasLocation => { }; } +/** + * Creates an "allow-scripts" sandboxed