Skip to main content

Module check_text

Module check_text 

Source
Expand description

check-text: counts the player-facing text still written as string literals in the screens’ source (CheckText::dir), instead of asked for by key with ctx.text("screen.thing") from the game’s language file. It fails when the count is above CheckText::max_literals.

Like check-keys it is a line-based scanner, not a parser, built on the same lexer. A string literal counts when it holds a word (letters outside {…} placeholders) and is

  • an argument of a call that puts text on the screen (print…, draw…, MenuItem::new, MenuItem::disabled, with_suffix, help_line), directly or inside a format! there; or
  • prose, wherever it stands: it has a capital letter or a space (format!("Turn {n}") kept in a variable, "out of range".to_owned(), a &str constant). Cue names, storage keys and screen names ("menu_tick") don’t; or
  • one lowercase word ("acted", "info") that is the value of a let, a match arm or an if, or stands in a tuple or an array: a label. As a constant, a call’s own argument (Some("heal")), a pattern ("foot" =>) or a value’s name (("count", &n)) it is an id.

The arguments of text(…), text_with(…), MenuItem::keyed(…) and Label::key(…) are keys and value names, never text; those of an assertion, a panic or expect are never shown, and neither is an attribute’s (#[error("…")]). Tests, the test harness, the snapshots’ text form and the debug screens are skipped. A literal the rules get wrong is let through with a // check-text: not player text comment, with the reason, on its line or the line above its item.

It also fails on a screen that reads a name field itself: the data’s names are English, and a screen shows one through the game’s helpers (CheckText::words_file), which give it in the player’s language. Reading .name (not calling .name()) on anything but self counts; a view’s own field is let through with a // check-text: not a data name comment.

Structs§

Hit
One literal found.

Constants§

MARKER
The comment that lets the next item (or its own line) through.
NAME_MARKER
The comment that lets a .name read on its line (or the item below it) through.

Functions§

report
The report: the count in the folder dir against max, then the literals by file.
run
Scans the project at root and returns every literal found, by file then line, and every file that couldn’t be read.
run_names
Scans the project at root and returns what is wrong, one line each: every .name field read found (scan_names), by file then line, and every file that couldn’t be read. Empty when the screens read none.
scan
Scans one Rust file (rel is its repo-relative path, for the report).
scan_names
The .name field reads of one Rust file (rel is its repo-relative path, for the report): .name not followed by (, on anything but self, outside tests and lines let through by NAME_MARKER. A hit’s text is what was read (unit.name).
verdict
What the count means against max: an error when above it, a note when below it (the number in the project file should come down too). hint says what to do about a literal.