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>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-05 01:12:26 +03:00
parent e3e1bc7784
commit bf36bc8a8f
103 changed files with 1256 additions and 1252 deletions

View file

@ -38,12 +38,12 @@ event DialogEnded { e: int = 0 }
# Dialog.tree(name) — register (or fetch) a tree id.
@Namespace(Dialog) function dialog_tree(name: pointer) -> int {
dlg_ensure()
let ex = Dict.get_or(dlg_reg, name, 0 - 1)
let ex = Dict.get_or(dlg_reg, name, -1)
if ex >= 0 { return ex }
if dlg_tree_n >= DLG_TREE_MAX { return 0 - 1 }
if dlg_tree_n >= DLG_TREE_MAX { return -1 }
let id = dlg_tree_n
dlg_tree_start[id] = 0 - 1
dlg_tree_n = dlg_tree_n + 1
dlg_tree_start[id] = -1
dlg_tree_n += 1
Dict.set(dlg_reg, name, id)
return id
}
@ -52,21 +52,21 @@ event DialogEnded { e: int = 0 }
@Namespace(Dialog) function dialog_node(tree_name: pointer, text: pointer) -> int {
dlg_ensure()
let tid = dialog_tree(tree_name)
if tid < 0 { return 0 - 1 }
if dlg_node_n >= DLG_NODE_MAX { return 0 - 1 }
if tid < 0 { return -1 }
if dlg_node_n >= DLG_NODE_MAX { return -1 }
let id = dlg_node_n
dlg_node_tree[id] = tid; dlg_node_text[id] = text
dlg_node_n = dlg_node_n + 1
dlg_node_n += 1
if dlg_tree_start[tid] < 0 { dlg_tree_start[tid] = id }
return id
}
# Dialog.choice(node, label, next_node) — add a branch (next_node -1 ends).
@Namespace(Dialog) function dialog_choice(node: int, label: pointer, next_node: int) -> int {
dlg_ensure()
if dlg_choice_n >= DLG_CHOICE_MAX { return 0 - 1 }
if dlg_choice_n >= DLG_CHOICE_MAX { return -1 }
let id = dlg_choice_n
dlg_choice_node[id] = node; dlg_choice_label[id] = label; dlg_choice_next[id] = next_node
dlg_choice_n = dlg_choice_n + 1
dlg_choice_n += 1
return id
}
@ -101,7 +101,7 @@ function dlg_set(e: int, name: pointer, v: int) -> void {
if dlg_get(e, "active") == 0 { return 0 }
let node = dlg_get(e, "node")
var n = 0; var i = 0
while i < dlg_choice_n { if dlg_choice_node[i] == node { n = n + 1 }; i = i + 1 }
while i < dlg_choice_n { if dlg_choice_node[i] == node { n += 1 }; i += 1 }
return n
}
# Dialog.choose(e, i) — take the i-th choice (veto-able); advance or end.
@ -109,12 +109,12 @@ function dlg_set(e: int, name: pointer, v: int) -> void {
dlg_ensure()
if dlg_get(e, "active") == 0 { return 0 }
let node = dlg_get(e, "node")
var seen = 0; var i = 0; var pick = 0 - 1
var seen = 0; var i = 0; var pick = -1
while i < dlg_choice_n {
if dlg_choice_node[i] == node {
if seen == idx { pick = i; i = dlg_choice_n } else { seen = seen + 1 }
if seen == idx { pick = i; i = dlg_choice_n } else { seen += 1 }
}
i = i + 1
i += 1
}
if pick < 0 { return 0 }
if emit DialogChoice(e: e, node: node, choice: idx) != 0 { return 0 }