GetTrainerServiceInfo answers "" for a rankless service's subText (#1947)
`GetTrainerServiceInfo` answered nil for a rankless service's subText. In 1.12.1 the subText is the Spell record's NameSubtext (`0x4d8b50`, read at `0x4d8b84`), the empty string for a spell with no rank; only a service with no Spell record answers nil (`0x4d8b58`). The resolver now keeps an empty rank as `""` and the binding pushes None as nil. Tests cover both rows and the install-backed Apprentice Blacksmith trainer. Supersedes #1935. Co-authored-by: kalistoking <148718830+kalistoking@users.noreply.github.com> 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -228,7 +228,9 @@ fn resolve_service(
|
||||
TrainerService {
|
||||
spell_id: wire.spell,
|
||||
name: display.map(|d| d.name.clone()),
|
||||
subtext: display.and_then(|d| d.rank.clone()),
|
||||
// `0x4d8b50` answers the record's NameSubtext, "" for a rankless spell (`0x4d8b84`), and
|
||||
// NULL without a Spell record (`0x4d8b58`), which `0x6f3890` pushes as nil.
|
||||
subtext: display.map(|d| d.rank.clone().unwrap_or_default()),
|
||||
// Over the wire spell, like the name and subtext ([`service_icon`]).
|
||||
texture: service_icon(wire.spell, trainer_type, spells, icons, items, ask),
|
||||
description: service_description(wire, trainer_type, spells, items, ask, text),
|
||||
|
||||
@@ -465,7 +465,11 @@ fn display_name_is_the_wire_spell_not_the_taught_one() {
|
||||
&BTreeSet::new(),
|
||||
);
|
||||
assert_eq!(svc.name.as_deref(), Some("Apprentice Blacksmith"));
|
||||
assert_eq!(svc.subtext.as_deref(), None);
|
||||
assert_eq!(
|
||||
svc.subtext.as_deref(),
|
||||
Some(""),
|
||||
"a rankless spell's NameSubtext is \"\" (0x4d8b84)"
|
||||
);
|
||||
assert_ne!(
|
||||
spells.get(2020).map(|d| d.name.as_str()),
|
||||
spells.get(2018).map(|d| d.name.as_str()),
|
||||
|
||||
@@ -109,7 +109,8 @@ pub struct TrainerService {
|
||||
pub spell_id: u32,
|
||||
/// The wire spell's name; `None` (before `Spell.dbc` loads) answers nil, shown as `UNKNOWN`.
|
||||
pub name: Option<String>,
|
||||
/// The wire spell's rank text, such as "Rank 2".
|
||||
/// The wire spell's NameSubtext, such as "Rank 2", "" for a rankless spell; `None` is no Spell
|
||||
/// record and answers nil (`0x4d8b58`).
|
||||
pub subtext: Option<String>,
|
||||
pub texture: Option<String>,
|
||||
/// The expanded text; `None` answers nil (`0x4d9d90`).
|
||||
|
||||
@@ -111,6 +111,53 @@ fn tree_interleaves_headers_and_ordered_services() {
|
||||
assert_eq!(info(&mut s, 5), ("Bloodrage".into(), "unavailable".into()));
|
||||
}
|
||||
|
||||
/// A service row whose spell has no rank answers the empty string for its subText (the Spell
|
||||
/// record's `NameSubtext`, `0x4d8b84`), never nil: a client's FrameXML may `format` it before its
|
||||
/// nil guard, which throws on nil. Without a Spell record `0x4d8b50` returns NULL (`0x4d8b58`),
|
||||
/// which `0x6f3890` pushes as nil.
|
||||
#[test]
|
||||
fn a_rankless_service_answers_an_empty_string_for_its_subtext() {
|
||||
let mut s = UiScript::new().unwrap();
|
||||
let mut t = trainer();
|
||||
t.services[0].subtext = Some(String::new()); // Heroic Strike, row 2
|
||||
s.set_trainer(Some(t));
|
||||
|
||||
let (name, sub, ty) = s
|
||||
.eval::<(String, mlua::Value, String)>(
|
||||
"local n,s,t = GetTrainerServiceInfo(2) return n,s,t",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!((name.as_str(), ty.as_str()), ("Heroic Strike", "available"));
|
||||
match sub {
|
||||
mlua::Value::String(v) => assert_eq!(v.to_str().unwrap(), ""),
|
||||
other => panic!("the rankless subText must be a string, got {other:?}"),
|
||||
}
|
||||
// A `format` over it must not throw.
|
||||
assert_eq!(
|
||||
s.eval::<String>("local _,sub = GetTrainerServiceInfo(2) return format(\"(%s)\", sub)")
|
||||
.unwrap(),
|
||||
"()"
|
||||
);
|
||||
// A ranked service is unchanged.
|
||||
assert_eq!(
|
||||
s.eval::<String>("local _,sub = GetTrainerServiceInfo(3) return sub")
|
||||
.unwrap(),
|
||||
"Rank 1"
|
||||
);
|
||||
}
|
||||
|
||||
/// A service with no Spell record has no subText: nil (`0x4d8b58` -> `0x6f3890`).
|
||||
#[test]
|
||||
fn a_service_without_a_spell_record_answers_nil_for_its_subtext() {
|
||||
let mut s = UiScript::new().unwrap();
|
||||
let mut t = trainer();
|
||||
t.services[0].subtext = None; // Heroic Strike, row 2
|
||||
s.set_trainer(Some(t));
|
||||
assert!(s
|
||||
.eval::<bool>("local _,sub = GetTrainerServiceInfo(2) return sub == nil")
|
||||
.unwrap());
|
||||
}
|
||||
|
||||
/// The fourth value of a service row is 1 (`0x4d8e42`: the header test `0x4d8c30` answers 0 for a
|
||||
/// row that is no header, which pushes 1), not nil; a collapsed header's is nil.
|
||||
#[test]
|
||||
|
||||
+3
-3
@@ -749,9 +749,9 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
|
||||
- An object no longer held, or a source that keeps no guid (the player's own trade slot), rebuilds from the instance the build read, where the reference's lookup finds no object and builds from the record and the block alone; benilla's views carry no object to read once it is gone, and the kept instance is what the plate showed. ([`src/script/tooltip_item/build.rs:154`](../crates/benilla-ui/src/script/tooltip_item/build.rs#L154))
|
||||
- The reference's padding repeats a mana stat once per zero entry; not emulated, since only the internal test ring 6674 has one. ([`src/script/tooltip_item/render.rs:416`](../crates/benilla-ui/src/script/tooltip_item/render.rs#L416))
|
||||
- The unknown-skill "Requires %s" shares it, though its reference red is `0xffff0000`, because a 32/255 difference in G and B does not show. ([`src/script/tooltip_unit.rs:30`](../crates/benilla-ui/src/script/tooltip_unit.rs#L30))
|
||||
- The selection clears to 0, because the header the reference re-selects (`0x4d7b42`, reading 1) has no spell id; the stock window's `> 1` test treats 0 and 1 alike. ([`src/script/trainer/mod.rs:197`](../crates/benilla-ui/src/script/trainer/mod.rs#L197))
|
||||
- A header clears it too, because it has no spell id; the reference stores its `0xffffffff` (`0x4d7b05`) and reads back 1, which the stock window's `> 1` test treats the same as 0. ([`src/script/trainer/mod.rs:871`](../crates/benilla-ui/src/script/trainer/mod.rs#L871))
|
||||
- Index 0 is a no-op, because one stray call would spend the purse; the reference buys every visible service for any index at or below 0 (`0x4da244`, `0x4d8a70`). ([`src/script/trainer/mod.rs:893`](../crates/benilla-ui/src/script/trainer/mod.rs#L893))
|
||||
- The selection clears to 0, because the header the reference re-selects (`0x4d7b42`, reading 1) has no spell id; the stock window's `> 1` test treats 0 and 1 alike. ([`src/script/trainer/mod.rs:198`](../crates/benilla-ui/src/script/trainer/mod.rs#L198))
|
||||
- A header clears it too, because it has no spell id; the reference stores its `0xffffffff` (`0x4d7b05`) and reads back 1, which the stock window's `> 1` test treats the same as 0. ([`src/script/trainer/mod.rs:872`](../crates/benilla-ui/src/script/trainer/mod.rs#L872))
|
||||
- Index 0 is a no-op, because one stray call would spend the purse; the reference buys every visible service for any index at or below 0 (`0x4da244`, `0x4d8a70`). ([`src/script/trainer/mod.rs:894`](../crates/benilla-ui/src/script/trainer/mod.rs#L894))
|
||||
- Kept apart from `Self::vertex_color`, which the reference's `Texture:SetAlpha` (`0x79b580`) rewrites, because the drawn product differs only on a region that sets both, or a gradient and an alpha, which no stock code does, and a FontString's `SetAlpha` then keeps its font colour. ([`src/script/types.rs:390`](../crates/benilla-ui/src/script/types.rs#L390))
|
||||
- UnitCanCooperate answers 1 for a friendly (5 and up) player, because the engine carries no faction templates; the reference resolves their cooperation masks. ([`src/script/unit/bindings.rs:612`](../crates/benilla-ui/src/script/unit/bindings.rs#L612))
|
||||
- Among whole-name matches ours picks the nearest, because the reference's first-walked pick is order-dependent and reads as a bug. ([`src/script/unit/bindings.rs:1115`](../crates/benilla-ui/src/script/unit/bindings.rs#L1115))
|
||||
|
||||
Reference in New Issue
Block a user