Files
benilla-octo/crates/benilla-app/src/ui_script/content.rs
T
Sam SungandClaude Opus 5.5 eba558a5d2 Comments in benilla-app, the UI script layer: one line of fact each, no history, no record numbers (#184)
Part of #41: the first of five `benilla-app` pieces. This one is the UI script layer: `ui_script` with its test harnesses, the text engine and layout (`ui_text`), the UI pass and the UI model panes. Its comments are rewritten to the rule in `docs/METHOD.md`, which is what the code does and the reference fact behind it, in a line. 22,041 comment lines become 7,133.

- **The mechanical strip.** The citations that were only a private record number go first, and each edit is shown to be a pure removal.
- **Wrong facts corrected.** The rewrite corrects the comments that stated wrong facts. Among them:
  - On a fresh login the reference fires `PLAYER_LOGIN` and `PLAYER_ENTERING_WORLD` from the player's create (`0x5deb60` → `0x4908c0`); only a `/reload` goes through `0x490168`. The comments now state both paths.
  - `ComputeStep` (`0x5ca2d0`) applies negative pair kerns and rounds up. It does have a kerning term.
  - A fallback icon global and the retired `UiPanels.xml` panels no longer exist. The comments that named them now describe the stock FrameXML mechanism that replaced them.
  - Stock FrameXML line citations are checked against the stock 1.12 files and corrected, and several misattributed files are fixed (`MainMenuBarArtFrame` lives in `MainMenuBar.xml`).
  - Dozens more turned up on the way: docs sitting on the wrong item, removed functions, stale counts and links.
- **Deviation labels.** "Deviation:" now marks only a choice with a reason. An unbuilt behaviour says so plainly.
- **Verification.** Every file strips to identical code, and `cargo fmt --check` is clean. Five second readers compared every file old against new, restored the facts the rewrite had dropped, and checked each new citation against the code, the stock files, vmangos and the reference.

Behaviour differences the rewrite surfaced are filed as their own issues (#183 among them). The comments here state what the code does. String literals are untouched; they are #92.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 08:20:21 +07:00

85 lines
3.2 KiB
Rust

//! The shipped UI's files (`assets/ui`), compiled into the binary so the interface cannot be
//! missing; `load_ui_files` and its `<Include>` provider read them here, never through `std::fs`.
//! A dev build reads the source tree first, so an edit needs no recompile.
/// The shipped UI tree: `benilla.toc` and every file it names.
static UI: include_dir::Dir<'_> = include_dir::include_dir!("$CARGO_MANIFEST_DIR/assets/ui");
/// The text of one shipped UI file, by path relative to `assets/ui`; the basename fallback for a
/// FrameXML reference is the caller's.
pub(super) fn read(req: &str) -> Option<String> {
if let Some(text) = read_source_tree(req) {
return Some(text);
}
UI.get_file(req)?.contents_utf8().map(str::to_owned)
}
/// `assets/ui/<req>` on disk, or `None` in a player build, whose binary holds no source path.
fn read_source_tree(req: &str) -> Option<String> {
let dir = crate::run_mode::dev_source_dir()?.join("assets/ui");
std::fs::read_to_string(dir.join(req)).ok()
}
/// FNV-1a (not cryptographic) over the manifest and each file it names, in load order, as eight
/// hex digits: a stamp that tells two runs whether they loaded the same interface.
pub(crate) fn digest() -> String {
let mut h: u64 = 0xcbf2_9ce4_8422_2325;
let mut eat = |bytes: &[u8]| {
for b in bytes {
h ^= u64::from(*b);
h = h.wrapping_mul(0x1000_0000_01b3);
}
};
eat(super::manifest::MANIFEST.as_bytes());
if let Some(toc) = read(super::manifest::MANIFEST) {
eat(toc.as_bytes());
}
for name in super::addons::Addon::builtin().toc.files {
// Only a chain entry's name counts: its bytes are the player's install.
eat(name.as_bytes());
if let Some(text) = read(&name) {
eat(text.as_bytes());
}
}
format!("{:08x}", h as u32)
}
/// Every shipped file's path, relative to `assets/ui`, from the compiled-in set, not the disk.
#[cfg(test)]
pub(super) fn shipped_files() -> impl Iterator<Item = &'static str> {
UI.files().filter_map(|f| f.path().to_str())
}
#[cfg(test)]
mod tests {
#[test]
fn every_manifest_entry_is_compiled_in() {
for name in crate::ui_script::manifest::shipped_manifest_files() {
assert!(
super::read(&name).is_some(),
"benilla.toc names {name}, which is not in assets/ui"
);
}
}
/// A dev build prefers disk, so without this the two copies could disagree unnoticed.
#[test]
fn the_source_tree_and_the_compiled_in_copy_agree() {
// A player build has no source tree to disagree with.
let Some(dir) = crate::run_mode::dev_source_dir().map(|d| d.join("assets/ui")) else {
return;
};
let mut on_disk: Vec<String> = std::fs::read_dir(dir)
.unwrap()
.map(|e| e.unwrap().file_name().to_string_lossy().into_owned())
.collect();
let mut embedded: Vec<String> = super::shipped_files().map(str::to_owned).collect();
on_disk.sort();
embedded.sort();
assert_eq!(
on_disk, embedded,
"assets/ui on disk and the compiled-in copy disagree — rebuild, or one of them is stale"
);
}
}