ludic/examples/events/layer_events.ludic
Orkuncakilkaya bf36bc8a8f refactor(runtime,packages,examples): named constants, package enums, idiom sweep
- runtime: HEADLESS_FRAME_PATH, STICK_DEADZONE / STICK_LEFT_X/Y, key and
  byte codes as char literals throughout (`k == 'w'`, `fill(rt_map, ' ', …)`)
- ludic.gameplay/stats: drop the duplicate `stat_field` (it answered "atk"
  for every build stat); Stats.base uses stats_field_name
- ludic.shooter: compare aim modes and fire patterns with AimMode.* and
  WeaponPattern.* instead of raw ints; STICK_RIGHT_X/Y
- ludic.npcai: DecisionMade / brain_set_state use AiState.*
- examples/games/menu.ludic uses Font.load / Ui.* with FONT_PATH and
  BACKDROP named; strings.ludic header says what it prints
- whole tree: `x = x + 1` → `x += 1` (single-term right-hand sides only),
  `0 - x` → `-x`, ASCII codes → char literals; every .ludic and every
  ```ludic fence reformatted with the fixed formatter (whitespace only)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-05 01:12:26 +03:00

27 lines
1.1 KiB
Text

# layer_events.ludic — EV1 for layers + SCENES E2 (layer toggle). A `public` layer
# promotes its show/hide to events; `enable layer L` / `disable layer L` flips the
# layer on and off (its handlers stop running while hidden) and fires
# layer_<L>_show / layer_<L>_hide. This closes the last scope of "events across the
# whole architecture" — properties, models, scenes, program, and now layers.
#
# Running it prints: 50 2 1 50
program LayerEvents {
var step: int = 0
@On(layer_Hud_show) handler Shown { print(1) } # a mod reacts when the HUD returns
@On(layer_Hud_hide) handler Hidden { print(2) } # ...and when it's hidden
scene Main start {
layer Hud public {
handler Draw phase Update { print(50) } # only runs while Hud is enabled
}
layer Ctrl {
handler Drive phase LateUpdate {
step += 1
if step == 1 { disable layer Hud } # frame 1: hide -> Hidden 2, Draw stops
if step == 2 { enable layer Hud } # frame 2: show -> Shown 1, Draw resumes
if step == 3 { quit() } # frame 3: after Draw ran again
}
}
}
}