v0.5.87: fill ability loc tokens and tidy skill detail layout.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+48
-8
@@ -15,7 +15,11 @@ def fmt_num(v: float) -> str:
|
||||
def sv_lookup(
|
||||
special_values: list | None, prefer: str | None = None
|
||||
) -> dict[str, list[float]]:
|
||||
"""prefer: None | 'scepter' | 'shard' — choose values_* channel when present."""
|
||||
"""prefer: None | 'scepter' | 'shard' — choose values_* channel when present.
|
||||
|
||||
Keys are stored casefolded so Valve Chinese locs (lowercase tokens) match
|
||||
PascalCase special_values names.
|
||||
"""
|
||||
out: dict[str, list[float]] = {}
|
||||
for sv in special_values or []:
|
||||
if not isinstance(sv, dict):
|
||||
@@ -37,18 +41,57 @@ def sv_lookup(
|
||||
chosen = sc
|
||||
elif prefer == "shard" and sh:
|
||||
chosen = sh
|
||||
out[name] = [float(x) for x in chosen if isinstance(x, (int, float))]
|
||||
floats = [float(x) for x in chosen if isinstance(x, (int, float))]
|
||||
out[name.casefold()] = floats
|
||||
if sc:
|
||||
out["scepter_" + name] = [
|
||||
out[("scepter_" + name).casefold()] = [
|
||||
float(x) for x in sc if isinstance(x, (int, float))
|
||||
]
|
||||
if sh:
|
||||
out["shard_" + name] = [
|
||||
out[("shard_" + name).casefold()] = [
|
||||
float(x) for x in sh if isinstance(x, (int, float))
|
||||
]
|
||||
return out
|
||||
|
||||
|
||||
def _resolve_vals(
|
||||
lookup: dict[str, list[float]],
|
||||
key: str,
|
||||
prefer: str | None,
|
||||
) -> list[float] | None:
|
||||
"""Resolve a loc token against the casefolded SV lookup.
|
||||
|
||||
Handles ``bonus_<svname>`` upgrade tokens that point at the base SV's
|
||||
``values_shard`` / ``values_scepter`` (or ``shard_``/``scepter_`` aliases),
|
||||
including an extra ``bonus_`` when the SV name already starts with bonus_.
|
||||
"""
|
||||
key_cf = key.casefold()
|
||||
vals = lookup.get(key_cf)
|
||||
if vals:
|
||||
return vals
|
||||
if prefer:
|
||||
vals = lookup.get(f"{prefer}_{key}".casefold())
|
||||
if vals:
|
||||
return vals
|
||||
if not key_cf.startswith("bonus_"):
|
||||
return None
|
||||
base = key_cf[len("bonus_") :]
|
||||
if not base:
|
||||
return None
|
||||
vals = lookup.get(base)
|
||||
if vals:
|
||||
return vals
|
||||
if prefer:
|
||||
vals = lookup.get(f"{prefer}_{base}".casefold())
|
||||
if vals:
|
||||
return vals
|
||||
for ch in ("shard", "scepter"):
|
||||
vals = lookup.get(f"{ch}_{base}".casefold())
|
||||
if vals:
|
||||
return vals
|
||||
return None
|
||||
|
||||
|
||||
def strip_html(text: str) -> str:
|
||||
"""Remove HTML tags and collapse whitespace (no token filling)."""
|
||||
if not text:
|
||||
@@ -74,10 +117,7 @@ def format_loc(
|
||||
lookup = sv_lookup(special_values or [], prefer=prefer)
|
||||
|
||||
def repl_pct(m: re.Match) -> str:
|
||||
key = m.group(1)
|
||||
vals = lookup.get(key)
|
||||
if not vals and prefer:
|
||||
vals = lookup.get(f"{prefer}_{key}")
|
||||
vals = _resolve_vals(lookup, m.group(1), prefer)
|
||||
if not vals:
|
||||
return "?"
|
||||
if len(vals) == 1:
|
||||
|
||||
Reference in New Issue
Block a user