api
The public surface of fogOfWarKit: `local Fog = require("fogOfWarKit.api")`. Configure the grid (`Fog.setup`), pick a look (`Fog.setLook`), choose which team this screen draws (`Fog.setViewer`), feed sources (`Fog.setSources` batched, `Fog.addSource`/`moveSource`/`removeSource` k…
api
The public surface of fogOfWarKit: local Fog = require("fogOfWarKit.api"). Configure the grid (Fog.setup), pick a look (Fog.setLook), choose which team this screen draws (Fog.setViewer), feed sources (Fog.setSources batched, Fog.addSource/moveSource/removeSource keyed, or entity-following), ask Fog.isVisible / isExplored / state, reveal ground, hide enemies on this screen with Fog.track, add line-of-sight blockers, subscribe to Fog.on("updated"), read Fog.texture() for a minimap and Fog.stats() for costs. Games call it directly; the FogOfWar, FogSource, FogHideable and FogBlocker components are thin wrappers over it.
Interface
What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.
conforms to
zero/source-extract/v2fogOfWarKit: fog of war for strategy, stealth and exploration games. Unexplored ground is hidden, explored ground out of sight is dimmed, and only what one of the viewing team's sources can see is drawn clear. Grid on the CPU (span-filled discs, optional line of sight), drawn on the GPU as a full-screen pass in one of four looks. Computed locally on every peer from positions every peer already has: nothing here is networked. local Fog = require("fogOfWarKit.api") Fog.setup({ center = {0, 0}, size = {160, 120}, cellSize = 1, look = "classic", viewer = 1 }) Fog.setSources(1, { {x, z, r}, ... }) -- fast batched path (RTS) Fog.addSource("hero", { team = 1, entity = hero, radius = 14 }) -- follows an entity if Fog.isVisible(1, enemy.x, enemy.z) then ... end
featureRef( ) → any
ensureFeature( ) → void
setup(opts: any?) → void
(Re)configure the fog grid. Can be called again at any time; changing center, size or cellSize rebuilds the grid (explored memory is forgotten), every other key changes in place. viewer = 1, updateRate = 8, lineOfSight = false, groundY = 0, enabled = true, revealSpeed = 7, hideSpeed = 2.5 }
| arg | type | description |
|---|---|---|
| opts | any? | { center = {x, z}, size = {w, d}, cellSize = 1, look = "classic", |
examples
Fog.setup({ center = {0, 0}, size = {160, 120}, cellSize = 1, look = "mist", viewer = 1 })setLook(id: string) → boolean
Switch the look live: "classic" | "mist" | "parchment" | "pixel".
| arg | type | description |
|---|---|---|
| id | string |
look( ) → string
The current look id.
looks( ) → void
Every look: { {id, label, description, tags} }.
setViewer(team: number) → void
Which team's fog THIS screen draws (local to this peer).
| arg | type | description |
|---|---|---|
| team | number |
viewer( ) → number
The team this screen draws fog for.
setSources(team: number, list: { { number } }) → void
Fast batched path: replace a team's batched sources with this list of { x, z, radius } triples (x/z world metres). Meant to be called every few frames by a game that already loops its units. The list is kept by reference until the next call, so hand over a fresh table or reuse one you no longer mutate mid-update.
| arg | type | description |
|---|---|---|
| team | number | |
| list | { { number } } |
addSource(key: any, src: any) → void
Add (or replace) a persistent keyed source. Give `entity` to have it follow that entity's position; otherwise move it with `moveSource`.
| arg | type | description |
|---|---|---|
| key | any | any unique key |
| src | any | { team = 1, x = 0, z = 0, radius = 10, entity = ent?, enabled = true } |
moveSource(key: any, x: number, z: number) → boolean
Move a keyed source. Returns false for an unknown key.
| arg | type | description |
|---|---|---|
| key | any | |
| x | number | |
| z | number |
updateSource(key: any, changes: any) → boolean
Change a keyed source's radius, team or enabled flag in place.
| arg | type | description |
|---|---|---|
| key | any | |
| changes | any |
removeSource(key: any) → boolean
Remove a keyed source. Returns false for an unknown key.
| arg | type | description |
|---|---|---|
| key | any |
isVisible(team: number, x: number, z: number) → boolean
Can `team` see this point right now?
| arg | type | description |
|---|---|---|
| team | number | |
| x | number | |
| z | number |
isExplored(team: number, x: number, z: number) → boolean
Has `team` ever seen this point (or is seeing it now)?
| arg | type | description |
|---|---|---|
| team | number | |
| x | number | |
| z | number |
state(team: number, x: number, z: number) → number
0 unexplored, 1 explored (not visible now), 2 visible.
| arg | type | description |
|---|---|---|
| team | number | |
| x | number | |
| z | number |
reveal(team: number, x: number, z: number, r: number) → void
Permanently explore a disc for a team (map start, scouting reveal).
| arg | type | description |
|---|---|---|
| team | number | |
| x | number | |
| z | number | |
| r | number |
setRevealAll(on: boolean) → void
Debug / spectator: draw no fog at all (queries stay honest).
| arg | type | description |
|---|---|---|
| on | boolean |
reset(team: number?) → void
Forget explored ground for one team, or for every team.
| arg | type | description |
|---|---|---|
| team | number? |
setEnabled(on: boolean) → void
Draw the fog or not (the grid and the queries keep running).
| arg | type | description |
|---|---|---|
| on | boolean |
enabled( ) → boolean
Whether the fog is drawn.
on(event: string, fn: (any) → void
Subscribe to grid updates. fn receives { team, updates }. Returns a function that disconnects.
| arg | type | description |
|---|---|---|
| event | string | |
| fn | (any |
texture( ) → any
The smoothed fog texture for minimaps: W x H cells, R = visible, G = explored (both feathered and eased over time), B = crisp visible, A = crisp explored. Texel (i, j) is the cell at world x = x0 + (i + 0.5) * cellSize, z = z0 + (j + 0.5) * cellSize (row 0 is the map's minimum z); `Fog.bounds()` gives x0/z0. Nil until the grid exists.
bounds( ) → any
The grid geometry: { x0, z0, x1, z1, cellSize, cols, rows }.
exploredFraction(team: number) → number
Share of the map `team` has explored (0..1).
| arg | type | description |
|---|---|---|
| team | number |
stats( ) → any
Cost and size figures: { cells, sources, teams, updateMs, updateMsAvg, uploadMs, hideMs, updates, uploads, tracked, look, viewer, updateRate }.
update( ) → void
Run a grid update now instead of waiting for the next tick.
track(e: any, team: number) → void
Hide this entity's visuals on THIS screen whenever the viewer team cannot see its position (entities of the viewer's own team always show). Checked in one batch on every grid update. `hide`/`show` are local to this peer's view.
| arg | type | description |
|---|---|---|
| e | any | |
| team | number |
untrack(e: any) → void
Stop tracking an entity (it is shown again).
| arg | type | description |
|---|---|---|
| e | any |
followLocalPlayer(opts: any?) → void
Let the local player see: keeps a FogSource on this machine's player body (now, or as soon as it exists, and again after a respawn) and makes this screen draw that team's fog. opts: { team = 1, radius = 15 }. Works pasted into the console mid-play or in a scene's code. Returns a stop function.
| arg | type | description |
|---|---|---|
| opts | any? |
readXZ(v: any) → void
| arg | type | description |
|---|---|---|
| v | any |
setLineOfSight(on: boolean) → void
Turn line of sight on or off (walls block vision when on).
| arg | type | description |
|---|---|---|
| on | boolean |
setBlocker(key: any, min: any?, max: any?) → void
Add or replace a rectangular vision blocker (a wall, a building). min/max are {x, z} corners (or vectors). Pass nil min to remove it.
| arg | type | description |
|---|---|---|
| key | any | |
| min | any? | |
| max | any? |
examples
Fog.setBlocker("wall1", {-5, 2}, {5, 3})removeBlocker(key: any) → void
Remove one blocker.
| arg | type | description |
|---|---|---|
| key | any |
clearBlockers( ) → void
Remove every blocker.
addBlockerEntity(e: any, key: any?) → boolean
Add an entity's world bounds as a blocker (its footprint blocks sight).
| arg | type | description |
|---|---|---|
| e | any | |
| key | any? |
scanBlockers(opts: any?) → number
Build blockers from the scene's colliders: a downward ray per cell; a hit standing more than `minHeight` (default 1.5 m) above the ground plane marks that cell as a wall. One-off cost; call after the level loads.
| arg | type | description |
|---|---|---|
| opts | any? |
isBlocked(x: number, z: number) → boolean
Is this point inside a vision blocker?
| arg | type | description |
|---|---|---|
| x | number | |
| z | number |
clear( ) → void
Stop drawing and drop every source, blocker and tracked entity (the grid shape and look are kept).
feature( ) → any
The render feature handle (nil until setup / a FogOfWar exists).
Sub-parts
Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.
Showing up to 3 levels deep. Open a part to see what it holds further down.
Problems
Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.
agent_score is exposed.+ quality × 0.35
+ performance × 0.25
± compat factor
Usability ratings
Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".
Scoped to this part · feeds back into the world's score.