4. The HUD and a test
Goal: know the hero's HUD parts, hide or replace one, and test Judgement with no page. The HUD's hero parts appear on their own once a player has a hero.
The hero's parts
| Part | Id | Shows |
|---|---|---|
| Hero bar | heroes | A button per hero: level, health, experience, + for a point. Click selects, double-click looks. |
| Hero panel | heroPanel | Abilities with levels and +, items, stats. |
| Card | card | Abilities on their keys (Q, W, E), usable items. |
| Shop | shop | What a nearby shop sells. |
| Floating words | Bounty gold, "Level 2". |
Players rebind keys in the pause menu's Keys, the hero.* actions included.
Hide or replace a part
ts
// src/campaign/view/index.ts
export const campaignView: GameView<CampaignUnit, CampaignResource, CampaignMessage> = {
hud: {
// the campaign has one hero: the bar of heroes is not needed, the hero panel is
hide: ['heroes'],
widgets: [
{
// the client's hero panel in a frame of the game's own, as plain DOM
id: 'heroPanel',
mount: (element, client) => {
element.style.outline = '2px solid #e0c060'
return client.ui.watch(
() => client.ui.slot('heroes'),
(heroes) => (element.title = heroes.map((hero) => `${hero.name}, level ${hero.level}`).join(', '))
)
}
}
]
}
// …
}The starter leaves the parts as they are; this is what it would take. See Add a HUD part, or replace one.
Test the ability
ts
// tests/rules.test.ts
import { learn } from '@v12-engine/engine'
import { order, run, testWorld } from '@v12-engine/engine/testing'
describe('the hero', () => {
it('strikes with Judgement, an effect of the game’s own, and heals for what it took', async () => {
const world = await testWorld(rules)
const hero = world.spawn(UNIT.knight, PLAYER, { x: 20, z: 20 })
// something of the enemy's that does not hit back: what the strike took is then the strike's alone
const captive = world.spawn(UNIT.prisoner, ENEMY, { x: 23, z: 20 })
learn(world, hero, 'judgement')
hero.health = 300
// a tick first: an enemy is a target once it is seen, and the fog is worked out as the game steps
run(world, 0.1)
order(world, [hero], { type: 'cast', ability: 'judgement', target: captive.id })
run(world, 3, () => captive.health <= captive.maxHealth - 120)
expect(captive.maxHealth - captive.health).toBeGreaterThanOrEqual(120)
expect(hero.health).toBeGreaterThanOrEqual(300 + 120 - 1)
world.dispose()
})
})The target is an enemy prisoner that doesn't hit back, so the knight's health shows the heal. The same shape tests any ability.
Where next
- Heroes, items and abilities: everything heroes can be.
- Abilities: every field and effect.