Skip to content

Commit

Permalink
add nearby to squaremap Towns
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Jun 23, 2024
1 parent afa604c commit d515844
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 123 deletions.
19 changes: 5 additions & 14 deletions src/api/dynmap/Towns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type Dynmap from "./Dynmap.js"

import {
formatString, asBool,
calcArea, hypot, range,
calcArea, range,
getExisting,
isInvitable
} from 'utils/functions.js'
Expand All @@ -15,7 +15,8 @@ import {
} from "utils/errors.js"

import type { EntityApi } from 'helpers/EntityApi.js'
import type { Nation, Town } from 'types'
import type { Nation, StrictPoint2D, Town } from 'types'
import { getNearest } from '../common.js'

class Towns implements EntityApi<Town | NotFoundError> {
#map: Dynmap
Expand Down Expand Up @@ -153,18 +154,8 @@ class Towns implements EntityApi<Town | NotFoundError> {
return cachedTowns as Town[]
}

readonly nearby = async(
xInput: number, zInput: number,
xRadius: number, zRadius: number,
towns?: Town[]
) => {
if (!towns) {
towns = await this.all()
if (!towns) return null
}

return towns.filter(t => hypot(t.x, [xInput, xRadius]) && hypot(t.z, [zInput, zRadius]))
}
readonly nearby = async (location: StrictPoint2D, radius: StrictPoint2D, towns?: Town[]) =>
getNearest<Town>(location, radius, towns, this.all)

readonly invitable = async(nationName: string, includeBelonging = false) => {
const nation = await this.map.Nations.get(nationName) as Nation
Expand Down
6 changes: 5 additions & 1 deletion src/api/squaremap/Towns.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type Squaremap from "./Squaremap.js"
import type { Nation, SquaremapTown } from "types"
import type { Nation, SquaremapTown, StrictPoint2D } from "types"

import type { EntityApi } from "helpers/EntityApi.js"
import { parseTowns } from "./parser.js"
Expand All @@ -10,6 +10,7 @@ import {
} from "utils/errors.js"

import { getExisting } from "utils/functions.js"
import { getNearest } from "../common.js"

class Towns implements EntityApi<SquaremapTown | NotFoundError> {
#map: Squaremap
Expand Down Expand Up @@ -50,6 +51,9 @@ class Towns implements EntityApi<SquaremapTown | NotFoundError> {

return towns
}

readonly nearby = async (location: StrictPoint2D, radius: StrictPoint2D, towns?: SquaremapTown[]) =>
getNearest<SquaremapTown>(location, radius, towns, this.all)
}

export {
Expand Down
32 changes: 0 additions & 32 deletions tests/dynmap/gps.test.ts

This file was deleted.

21 changes: 0 additions & 21 deletions tests/dynmap/nations.test.ts

This file was deleted.

26 changes: 0 additions & 26 deletions tests/dynmap/residents.test.ts

This file was deleted.

29 changes: 0 additions & 29 deletions tests/dynmap/towns.test.ts

This file was deleted.

0 comments on commit d515844

Please sign in to comment.