UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

53 lines (42 loc) 1.05 kB
import { FogOfWar } from "./FogOfWar.js"; export class FogOfWarVisibilityPredicate { constructor() { /** * * @type {FogOfWar} */ this.fow = null; /** * Distance that the point is allowed to be away from the clear region to pass the test * @type {number} */ this.maxClearance = 0; } /** * * @param {Camera} camera * @param {EntityComponentDataset} ecd */ initialize(camera, ecd) { const fow = ecd.getAnyComponent(FogOfWar); this.fow = fow.component; } /** * * @param {number} x * @param {number} y * @param {number} z * @returns {boolean} */ test(x, y, z) { const fow = this.fow; if (fow !== null) { const clearance = fow.getWorldClearance(x, z); return clearance <= this.maxClearance; } else { return true; } } finalize() { } }