wavePreviewKit.package
README.md
wavePreviewKit
An on-screen wave preview for any wave-based game: tower defense, horde mode, wave shooters, arena survival. Players always know what is coming next: which enemies and how many, the wave counter, a countdown to the next wave, and a "start next wave / call early" button (with the bonus for calling early) that also answers to a key, a gamepad button (with the right Xbox / PlayStation / Switch prompt) and touch. Six looks swap live with one word. It needs no tower defense kit: feed it waves and state from anything, or bind it to a spawnerKit Spawner in one line.
Install and use in two lines: run zero zeromind installAsset 67700fda-b723-4db2-9291-c308f157eead in the engine shell, then call require("wavePreviewKit.api").bindSpawner("Spawner") with spawnerKit, or feed it waves and state yourself as below.
Quick start
local WP = require("wavePreviewKit.api")
WP.setWaves({ { name = "Scouts", enemies = { { kind = "grunt", count = 6 }, { kind = "runner", count = 4 } } } }) -- spawnerKit's waveTable shape
WP.show({ style = "strip" }) -- per-player HUD
WP.setState({ wave = 0, waves = 10, phase = "build", nextIn = 20, canCall = true, callBonus = 25 })
WP.onCall(function(info) startNextWave(); gold += info.bonus end) -- button, N key, pad Y/triangle, tap
With spawnerKit, one line instead: WP.bindSpawner("Spawner", { callBonus = 25 }). No code at all: add the WavePreview component to any entity in the scene and set its style (and spawner).
The six styles
Swap any time with WP.setStyle(id); the new look plays its entrance and keeps all state.
| id | looks like | use it when |
|---|---|---|
strip (default, top) | A glass bar: the wave counter, "next in 0:15", the next wave's enemies as glowing icon badges with ×counts and names, the call button, and a thin countdown line. | The everyday choice for any wave game: readable at a glance, one row tall (two rows on a portrait phone). |
timeline (top) | A track of the next 4-7 waves: cleared waves ticked, each upcoming wave's lead enemy and total above its node, boss waves crowned in red, and a marker gliding toward the next node as the countdown runs. | Players plan ahead (tower defense with long builds), or you want boss waves visible from far off. |
cards (top right) | A card per upcoming wave (3 on desktop, 2 on a landscape phone, 1 upright): every enemy with icon and ×count, trait pills (FLYING, ARMOR, BOSS...), the total, and on the next card its countdown bar. | Strategy-heavy games where the enemy mix decides what to build (armour, fliers, healers). |
dial (top right) | A circular clock that fills toward the next wave with the wave number in its heart, the next wave's enemies orbiting it with counts, the wave name and a round call button. Turns red for a boss wave. | A striking corner piece for arena, horde and sci-fi games; the timer matters more than the details. |
minimal (top) | One pill-shaped line: Wave 4/10 · next: 12 runners, 2 brutes · 0:15 and a small call button. Shortens itself to fit a phone. | Clean HUDs, small screens, or when the preview should stay out of the way. |
pixel (top) | A chunky retro panel drawn in its own 5x7 bitmap font with 8x8 pixel enemy sprites, a stepped block countdown and a blinking call button with a pixel prompt. | Pixel-art, arcade and retro games. |
WP.catalog() lists the same with tags (WP.catalog({ tag = "retro" })).
Enemy looks
Waves name enemies by kind id. How a kind looks (label, plural, icon, colour, tags, traits, boss) comes from, in order:
- Your provider:
WP.setKinds({ ogre = { label = "Ogre", color = "#c0503a", icon = "☠", tags = { "tank" } } })orWP.setKinds(function(kind) return myCatalog[kind] end). - creepsKit's catalog when it is installed (
require("creepsKit.api").catalog(): label, icon/glyph, colour, tags, traits, layer). - spawnerKit's catalog (its sample grunt, runner, brute, flyer, spitter).
- The id itself ("fire_imp" → "Fire imp", a stable colour).
Icons need no textures. A kind's own svg wins, then its icon glyph (pictographic emoji draw as vectors instead, since no colour emoji face is guaranteed), then one of 12 built-in vector icons picked from the id, tags and traits: walker, fast, heavy, flying, ranged, boss, healer, shield, armor, stealth, splitter, swarm. The pixel style has an 8x8 sprite for each.
API
local WP = require("wavePreviewKit.api")
| call | what it does |
|---|---|
WP.show(opts?) | Show the preview on this peer. opts: style, anchor (top, topLeft, topRight, bottom, bottomLeft, bottomRight, left, right), showButton (true), theme (colour overrides), key ("KeyN"), padButton ("north" = Y / triangle / X), offset = { x, y }, layer (60). |
WP.hide() | Take it down (state, waves and handlers are kept). WP.isShown(). |
WP.setStyle(id) / WP.style() | Swap the look live: strip, timeline, cards, dial, minimal, pixel. |
WP.setAnchor(anchor?) | Move it; nil = the style's own default. |
WP.setTheme(t?) | Override colours: accent, panel, panel2, edge, ink, dim, danger, track, button, buttonInk. |
WP.setShowButton(on) | Show or hide the call button (its key and pad button follow). |
WP.setWaves(list) | spawnerKit's waveTable shape ({ { name, enemies = { { kind, count } }, script = {...} } }, or { waves = {...} }), or already summarised: { { name, groups = { { kind, count } } } }, or { enemies = { runner = 12 } }. Same kinds in one wave merge. |
WP.waves() | The summarised waves: { index, name, total, boss, groups = { { kind, count, info } } }. |
WP.setKinds(mapOrFn?) / WP.kind(id) | The enemy-look provider (see above) / what one kind resolves to. |
WP.setState(s) | { wave, waves (0 = endless), phase = "build" | "wave" | "done", nextIn (seconds or nil), nextTotal?, canCall, callBonus }. Partial updates keep the rest. The countdown runs on locally, so setting nextIn once per wait is enough. |
WP.state() | The state as shown now (nextIn counted down). |
WP.onCall(fn) → { Disconnect } | fn(info) when the player asks for the next wave: info = { source = "button" | "key" | "pad" | "code", wave, next, bonus, nextIn }. Only fires while canCall is true. |
WP.call() | Press the call button from code. |
WP.bindSpawner(sp, opts?) / WP.unbindSpawner() | Follow a spawnerKit Spawner (entity, name or component): its waves are planned with its difficulty curve (planWave), its phase/wave/countdown are read five times a second, and the button starts it, then skips each wait (SK.start / SK.nextWave) unless opts.onCall is given. opts.callBonus is a number or fn(state). |
WP.catalog(filter?) | The styles: { id, label, anchor, tags, description }. |
WP.view() / WP.preview(style, w, h, safe, touch) | The data a style draws / build a style's panel for any screen size without showing it (tests, custom layouts). |
WP.simulateScreen(w, h, safe, touch) | Lay out as if on that screen (nil = the real one). |
WP.stats() / WP.reset() | { builds, calls, shown, style, device, footprint } / back to defaults. |
WP.VERSION, WP.STYLES, WP.ANCHORS, WP.SCREEN | "1.1.8" (the released version), the style ids, the anchors, the UI screen name (wpk_hud). |
Phases: build = waiting for the next wave (the counter shows the upcoming wave), wave = a wave is running (the counter shows it; the preview shows the one after), done = all waves cleared.
How it behaves
- Per player. Each peer shows its own preview; nothing here is synced. Feed every peer the same state (a bound Spawner's state is already the same on every peer, and
SK.nextWavefrom any peer reaches the host). - Cheap. The widget tree is rebuilt only when something it shows changes: the countdown's seconds, the wave, the phase, the screen size, the input device. That is about once a second during a countdown, and never while nothing moves. Between rebuilds, bars, the dial and the timeline marker glide with CSS transitions, so motion is smooth with no per-frame work.
- Phone-safe. Sized from
ui.screenSize()inside the safe area: compact under 760 points wide or 460 tall, two rows on a portrait phone, fewer cards and timeline nodes, touch-sized (48 pt) buttons and no key glyph on touch devices. Tested at 1280x720, 390x844, 844x390 and 360x640. - Input. The button takes mouse and touch;
keyandpadButtoncall too (ignored while a text field has the keyboard). The prompt glyph follows the last device used, Xbox / PlayStation / Switch from the pad's name, drawn by controlsKit when it is installed. - Motion. Each new wave's pieces enter with a short staggered rise; the number counts in; the boss wave pulses; the pixel button blinks while it waits for you.
Parts
| part | what it is |
|---|---|
api | The public API above, the per-peer HUD loop, input, the spawnerKit binding. |
model | Pure: summarising waves, kind lookup, state normalising and every text the styles print. |
styles | The six builders, themes and the style catalog. |
layout | Screen size, safe area, compact/tiny, anchors. |
icons | 12 vector enemy icons and their 8x8 pixel sprites. |
pixelFont | A 5x7 bitmap font drawn as canvas rects. |
gallery | Sample waves and kinds, pose() for screenshots, and a demo wave loop. |
WavePreview component | No-code: put the preview up from a scene, optionally bound to a Spawner. |
wavePreviewKit test suite | 26 tests. tools.use("tests", "run", { suites = { "wavePreviewKit" } }) in edit mode. |
guide how-to-show-upcoming-waves | How to add the preview to a game, step by step. |
The demo scene scenes/wavePreviewGallery.scene runs an 8-wave sample and cycles all six styles every 8 seconds (◀ ▶ step through them by hand).
Version history
- 1.1.8: documentation only, no change to the preview: a store description that names all six styles and how to install and use the kit, and the same install-and-use line at the top of this README.
- 1.1.7: while a wave is on the road, the enemies shown beside it are tagged as the next wave, so wave 2's runners never read as part of wave 1: the strip and pixel styles put "NEXT · WAVE 2" over them, the timeline footer and the dial caption start with "NEXT ·", and the next card in the cards style says "NEXT" instead of "AFTER THIS" beside the clock's "LIVE".
- 1.1.6: released against controlsKit 1.3.1 (the release economyKit 1.2.9 carries), so a world that installs it beside towerDefenseKit and economyKit holds one controlsKit instead of one per release.
- 1.1.5: "LIVE" shows once while a wave runs. The pixel style read "LIVE LIVE", the timeline "WAVE LIVE LIVE" and the dial "WAVE LIVE" over its number with "LIVE" under it; now the pixel style shows one large "LIVE", the timeline "WAVE LIVE" and the dial "WAVE", the number and "LIVE". The README heading names no version (it had said 1.0.0);
WP.VERSIONcarries it. - 1.1.4: the strip style sizes each enemy chip to fit its own name and keeps 10 points between names, so three long names ("FOOTMEN", "SHIELDBEARERS", "HEALERS") no longer run into each other; as many chips as fit at their real widths are shown, then "+N". Each name is a label with its own id (
wpk_chip_name_<wave>_<i>), so a layout check can measure it. - 1.1.3: enemy names read right in the singular and the plural in every style. A kind that says its own
plural(creepsKit 1.3.0 gives every kind one) is used as is, and the English rule leaves words that already read as plural alone ("Shielded", "Undead"), so no "Shieldeds". A new test renders every creepsKit kind, one and several, in all six styles. - 1.1.2: an offset in y (
WP.show({ offset = { y = 60 } }), to step below a pause button, say) also takes that much height off the panel, the way an offset in x already took width. - 1.1.1: the dial's enemy icons orbit wholly outside the ring, so they never cover the WAVE label or the countdown (the dial face has the id
wpk_dial_facefor layout checks).WP.show({ offset = { x, y } })now also takes the sideways offset off the panel's width, so a wide style (strip, timeline) placed beside a game's own HUD never runs back over it. - 1.1.0: no backdrop blur behind the panels by default (a full-screen GPU pass, ~3 ms a frame on a modest GPU);
styles.BLUR = truebrings it back. - 1.0.0: six styles, spawnerKit binding, creepsKit and spawnerKit catalog fallbacks, key / pad / touch calling, phone layouts, 26 tests.