Files
flying-jib/test/border.test.js
T
2026-07-30 23:43:12 -04:00

41 lines
977 B
JavaScript

'use strict'
const test = require('brittle')
const { nearBorder, findNeighbor, mapPosition, borderAction } = require('../lib/border')
const a = {
regionId: 'a',
bounds: { minX: 0, maxX: 100, minZ: 0, maxZ: 100 },
offset: { x: 0, z: 0 }
}
const b = {
regionId: 'b',
bounds: { minX: 100, maxX: 200, minZ: 0, maxZ: 100 },
offset: { x: 100, z: 0 }
}
test('nearBorder', (t) => {
t.absent(nearBorder(a.bounds, 50, 50, 16))
t.ok(nearBorder(a.bounds, 95, 50, 16))
t.ok(nearBorder(a.bounds, 101, 50, 16))
})
test('findNeighbor prefers containing region', (t) => {
const n = findNeighbor([a, b], a, 150, 50)
t.is(n.regionId, 'b')
})
test('mapPosition across offsets', (t) => {
const p = mapPosition(a, b, 100, 64, 50)
t.is(p.x, 0)
t.is(p.z, 50)
t.is(p.y, 64)
})
test('borderAction migrate when outside', (t) => {
const act = borderAction([a, b], a, 120, 50, 16)
t.is(act.action, 'migrate')
t.is(act.neighbor.regionId, 'b')
t.ok(act.mapped)
})