Files
aetherbound-guild/runtime/tools/m66_party_risk_visual_probe.gd
T

402 lines
18 KiB
GDScript

extends SceneTree
## M66 strict visual probe for the DEV-4R preparation pages: Party Line,
## Risk Board and Risk Commitment. Single authoritative size (owner policy),
## both shipped locales, static-only / dynamic-only / final composite views.
## Any ink violation fails the probe.
const PartyLine = preload("res://entry/views/party_line_page_view.gd")
const RiskBoard = preload("res://entry/views/risk_board_page_view.gd")
const RiskCommitment = preload("res://entry/views/risk_commitment_page_view.gd")
const InkCheck = preload("res://tools/ui_ink_check.gd")
const FIXTURES := [Vector2i(1280, 720)]
const LOCALES := ["zh_CN", "en"]
# Accessibility pass: 1.0 plus the shipped 130% text scale (M73).
const TEXT_SCALES := [1.0, 1.3]
## M83: the Party Line top rail's four authored text boxes, measured on the
## approved master (`docs/design-authority/pages/PTY-001-party-line/
## approved/v001/master.png`) and scaled to the 1280x720 design canvas.
const RAIL_SLOTS := [
{"node": "PartyTitle", "owner": "party_title", "rect": Rect2(Vector2(263.8, 31.2), Vector2(415.0 - 263.8, 65.6 - 31.2))},
{"node": "PartyPressureValue", "owner": "pressure_value", "rect": Rect2(Vector2(511.2, 35.0), Vector2(664.4 - 511.2, 63.8 - 35.0))},
{"node": "PartyCompanyValue", "owner": "company_value", "rect": Rect2(Vector2(788.8, 31.2), Vector2(933.8 - 788.8, 65.6 - 31.2))},
{"node": "PartyCompanyCapacityValue", "owner": "party_capacity", "rect": Rect2(Vector2(1050.6, 31.2), Vector2(1191.9 - 1050.6, 65.6 - 31.2))},
]
# A rail label whose type is identical at 130% still sits under the page-wide
# 16px ceiling, which makes the accessibility scale a no-op on that page.
var rail_font_by_scale := {}
var ink_scanned := 0
var scale_samples := {}
var ceiling_samples := {}
var probe_text_scale := 1.0
var ink_violations: Array = []
func _initialize() -> void:
call_deferred("_run")
func _run() -> void:
var out := OS.get_environment("ABG_EVIDENCE_DIR")
if out.is_empty():
push_error("requires ABG_EVIDENCE_DIR")
quit(1)
return
DirAccess.make_dir_recursive_absolute(out)
var ink_self := InkCheck.self_test(root)
if ink_self.size() < 3:
push_error("M66 ink self-test expected at least 3 violations, got %d" % ink_self.size())
quit(1)
return
print("ABG_M66_INK_SELF_TEST_OK violations=%d" % ink_self.size())
ink_scanned = 0
ink_violations = []
var pages: Array = [
{"script": PartyLine, "name": "party_line", "data": Callable(self, "_party_data")},
{"script": RiskBoard, "name": "risk_board", "data": Callable(self, "_risk_board_data")},
{"script": RiskCommitment, "name": "risk_commitment", "data": Callable(self, "_risk_commitment_data")},
]
for fixture in FIXTURES:
for locale in LOCALES:
for text_scale in TEXT_SCALES:
probe_text_scale = float(text_scale)
for page in pages:
await _capture(page, fixture, String(locale), out)
if ink_violations.is_empty():
var scale_failures := _text_scale_failures()
for failure in scale_failures:
push_error("M84-C text scale: %s" % failure)
if not scale_failures.is_empty():
print("ABG_M84_TEXT_SCALE_FAIL failures=%d" % scale_failures.size())
quit(1)
return
print("ABG_M84_TEXT_SCALE_OK ceilings=%s body_labels=%d" % [str(ceiling_samples), scale_samples.size()])
print("ABG_M66_PARTY_RISK_INK_OK scanned=%d violations=0" % ink_scanned)
else:
for violation in ink_violations:
push_error("M66 ink violation %s %s %s %s: %s" % [
violation.get("page", "?"), violation.get("locale", "?"),
violation.get("fixture", "?"), violation.get("kind", "?"),
violation.get("detail", ""),
])
print("ABG_M66_PARTY_RISK_INK_FAIL scanned=%d violations=%d" % [ink_scanned, ink_violations.size()])
quit(1)
return
print("ABG_M83_PARTY_TOP_RAIL_OK slots=%d node=PartyTitle,PartyPressureValue,PartyCompanyValue,PartyCompanyCapacityValue scales=1.0,1.3 fonts=%s" % [
RAIL_SLOTS.size(), str(rail_font_by_scale)])
print("ABG_M66_PARTY_RISK_VISUAL_PROBE_OK pages=party_line,risk_board,risk_commitment locales=%d scans=%d views=static,dynamic,final" % [LOCALES.size(), ink_scanned])
quit(0)
func _capture(page: Dictionary, fixture: Vector2i, locale: String, out: String) -> void:
var page_name := String(page.get("name", "page"))
for mode in ["static", "dynamic", "final"]:
var viewport := SubViewport.new()
viewport.size = fixture
viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
root.add_child(viewport)
var view: Control = page.script.new()
view.name = "M66ProbeView"
view.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
view.configure_presentation({"safe_area": 24, "text_scale": probe_text_scale, "locale": locale})
viewport.add_child(view)
view.render(page.data.call(locale))
_apply_mode(view, page_name, mode)
for _i in range(3):
await process_frame
var violations := InkCheck.scan(view)
ink_scanned += 1
for violation in violations:
violation["page"] = page_name
violation["locale"] = locale
violation["fixture"] = "%dx%d" % [fixture.x, fixture.y]
violation["mode"] = mode
ink_violations.append(violation)
if mode == "final":
for _i in range(3):
await process_frame
_collect_scale_samples(view, page_name, locale)
ceiling_samples["%s|%s|%.1f" % [page_name, locale, probe_text_scale]] = _page_ceiling(view, page_name)
if page_name == "party_line" and mode == "final":
for problem in _rail_problems(view, locale):
ink_violations.append({
"kind": "rail_slot", "page": page_name, "locale": locale,
"fixture": "%dx%d" % [fixture.x, fixture.y], "mode": mode,
"node": String(problem.get("node", "rail")),
"path": "party_line/rail",
"detail": String(problem.get("detail", "")),
})
var image := viewport.get_texture().get_image()
if image != null:
image.save_png(out.path_join("%s-%dx%d-%s-ts%.1f-%s.png" % [page_name, fixture.x, fixture.y, locale, probe_text_scale, mode]))
view.queue_free()
viewport.queue_free()
await process_frame
func _rail_problems(view: Control, locale: String) -> Array:
# M83: every authored top-rail box must carry a non-empty, contained engine
# text at both shipped text scales, and the 130% scale must actually change
# the rail type (the page-wide 16px ceiling used to make it a no-op).
var problems: Array = []
var fonts: Array = []
for slot in RAIL_SLOTS:
var node_name := String(slot.get("node", ""))
var owner := String(slot.get("owner", ""))
var box := Rect2(slot.get("rect", Rect2()))
var label := view.find_child(node_name, true, false) as Label
if label == null:
problems.append({"node": node_name, "detail": "rail slot %s has no runtime text node" % owner})
continue
if label.text.strip_edges().is_empty():
problems.append({"node": node_name, "detail": "rail slot %s is empty" % owner})
continue
var rect := label.get_global_rect()
if not _rect_inside(rect, box):
problems.append({"node": node_name, "detail": "label rect %s leaves the authored box %s" % [str(rect), str(box)]})
var ink: Rect2 = InkCheck.ink_rect(label)
if not _rect_inside(ink, box):
problems.append({"node": node_name, "detail": "ink %s leaves the authored box %s" % [str(ink), str(box)]})
fonts.append(label.get_theme_font_size("font_size"))
rail_font_by_scale["%s@%.1f" % [locale, probe_text_scale]] = fonts
if OS.get_environment("ABG_M66_RAIL_TRACE") == "1":
print("ABG_M66_RAIL_TRACE locale=%s scale=%.1f fonts=%s problems=%d" % [locale, probe_text_scale, str(fonts), problems.size()])
var at_100: Array = Array(rail_font_by_scale.get("%s@1.0" % locale, []))
if is_equal_approx(probe_text_scale, 1.3) and at_100.size() == fonts.size() and not at_100.is_empty():
var raised := false
for index in range(fonts.size()):
if int(fonts[index]) > int(at_100[index]):
raised = true
if not raised:
problems.append({"node": "PartyRailScale",
"detail": "rail type is identical at 100%% and 130%% (%s)" % str(fonts)})
return problems
func _rect_inside(inner: Rect2, outer: Rect2) -> bool:
return inner.position.x >= outer.position.x - 0.5 and inner.position.y >= outer.position.y - 0.5 \
and inner.end.x <= outer.end.x + 0.5 and inner.end.y <= outer.end.y + 0.5
func _apply_mode(view: Control, page_name: String, mode: String) -> void:
# static-only: the authored master with no runtime content.
# dynamic-only: runtime content on a neutral field (slot overflow, contrast,
# alignment defects are visible here). Product code carries no test switches.
var master_names: Array = {
"party_line": ["PartyMasterImage", "PartyMasterMatte"],
"risk_board": ["RiskBoardStaticMaster", "RiskMasterMatte"],
"risk_commitment": ["RiskCommitmentStaticMaster", "RiskMasterMatte"],
}.get(page_name, [])
var overlay_names: Array = {
"party_line": ["PartyMasterOverlay"],
"risk_board": ["RiskBoardOverlay", "RiskMasterOverlay"],
"risk_commitment": ["RiskCommitmentOverlay", "RiskMasterOverlay"],
}.get(page_name, [])
if mode == "static":
for name in overlay_names:
var overlay := view.find_child(name, true, false) as Control
if overlay != null:
overlay.visible = false
elif mode == "dynamic":
for name in master_names:
var master := view.find_child(name, true, false) as Control
if master != null:
master.visible = false
var neutral := ColorRect.new()
neutral.name = "M66NeutralProbeBackground"
neutral.color = Color("#26353c")
neutral.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
neutral.mouse_filter = Control.MOUSE_FILTER_IGNORE
view.add_child(neutral)
view.move_child(neutral, 0)
func _locale_of(locale: String) -> bool:
return locale == "zh_CN"
func _party_data(locale: String) -> Dictionary:
var is_zh := _locale_of(locale)
var names := ["阿里", "布兰", "塞拉", "戴恩"] if is_zh else ["Ari", "Bram", "Cera", "Dain"]
var ids := ["r-1", "r-2", "r-3", "r-4"]
var ordered: Array = []
for index in range(ids.size()):
ordered.append({
"position": index,
"recruit_id": ids[index],
"recruit": {"recruit_id": ids[index], "profession_id": "PF-B01", "rendered_name_snapshot": {locale: names[index]}},
"relation": {"position": index, "recruit_id": ids[index], "first_threat_target": index == 0, "expected_target_rank": index + 1, "protected_by_recruit_ids": ["r-1"] if index == 1 else [], "reach_id": "full_line" if index > 0 else "front_two"},
})
return {
"ok": true,
"page_id": "party_line",
"locale": locale,
"company": {"company_id": "company-001", "owned_count": 4, "line_capacity": 4},
"contract": {"contract_id": "CTR-R1-01", "difficulty": "stormbound", "line_capacity": 4},
"formation": {"status": "draft", "orientation": "rear_left_front_right", "front_position": 0, "line_capacity": 4, "base_front_to_rear_ids": ["r-4", "r-3", "r-2", "r-1"], "first_threat": {"target_position": 0, "target_recruit_id": "r-1", "enemy_count": 3, "wave_count": 2}},
"order": {"front_to_rear_ids": ids, "ordered_recruits": ordered, "selected_recruit_id": "r-2", "selection_reason": "selected"},
"preview": {"ok": true, "order_hash": "hash-001", "coverage": {"protection": 2, "long_reach": 2, "sustain": 1, "control": 1}, "relations": ordered.map(func(row): return row.relation)},
"commands": {"undo_enabled": true, "reset_enabled": true, "save_enabled": true, "back_enabled": true},
}
func _risk_board_data(locale: String) -> Dictionary:
return {
"ok": true,
"page_id": "risk_board",
"locale": locale,
"party": {
"snapshot_id": "snapshot-001",
"snapshot_hash": "snapshot-hash-001",
"front_to_rear_ids": ["r-1", "r-2", "r-3", "r-4"],
"ordered_recruits": [
{"position": 0, "recruit_id": "r-1", "recruit": _recruit("r-1", "PF-B01", "阿里", "Ari", locale)},
{"position": 1, "recruit_id": "r-2", "recruit": _recruit("r-2", "PF-B05", "布兰", "Bram", locale)},
{"position": 2, "recruit_id": "r-3", "recruit": _recruit("r-3", "PF-B07", "塞拉", "Cera", locale)},
{"position": 3, "recruit_id": "r-4", "recruit": _recruit("r-4", "PF-B03", "戴恩", "Dain", locale)},
],
"coverage": {"protection": 2, "long_reach": 2, "sustain": 1, "control": 1},
},
"options": {"items": [
_option("risk-1", 0, "steady", 2, 1, "disclosed", 0, "standard_supplies", "low"),
_option("risk-2", 1, "pressured", 3, 2, "one_intent_unresolved", 2, "enhanced_choice", "moderate"),
_option("risk-3", 2, "elite", 4, 3, "elite_response_unresolved", 4, "elite_cache", "high"),
], "ids": ["risk-1", "risk-2", "risk-3"], "count": 3},
"selection": {"selected_risk_id": "risk-2", "state": "selected", "auto_selected": false},
"commands": {"review_enabled": true, "back_enabled": true, "settings_enabled": true},
}
func _option(option_id: String, risk: int, tier: String, enemies: int, waves: int, uncertainty: String, cost: int, reward: String, recovery: String) -> Dictionary:
return {
"risk_option_id": option_id,
"risk": risk,
"tier_id": tier,
"known_threat": {"enemy_count": enemies, "wave_count": waves},
"uncertainty_id": uncertainty,
"entry_cost": cost,
"reward_class_id": reward,
"recovery_exposure_id": recovery,
}
func _risk_commitment_data(locale: String) -> Dictionary:
var facts: Array = []
for item in [
["威胁", "3 · 2 波", "!", Color("#a74337")],
["不确定", "一项意图未定", "?", Color("#5d3f91")],
["入场金币", "4 · 剩 34", "¢", Color("#a07816")],
["奖励", "27 · 强化", "◆", Color("#3d7449")],
["恢复", "中等", "!", Color("#a44a2e")],
["撤退", "下阶段", "↩", Color("#2c67a3")],
]:
facts.append({"label": item[0], "value": item[1], "text": item[1], "glyph": item[2], "color": item[3]})
return {
"ok": true,
"page_id": "risk_commitment",
"locale": locale,
"contract": {"contract_id": "CTR-R1-01", "coin": 38},
"risk": {"risk_option_id": "risk-2", "option": {
"risk_option_id": "risk-2", "tier_id": "pressured", "risk": 1,
"option_hash": "option-hash-001",
"known_threat": {"enemy_count": 3, "wave_count": 2},
"uncertainty_id": "one_intent_unresolved", "entry_cost": 4,
"reward_coin": 27, "reward_class_id": "enhanced_choice", "recovery_exposure_id": "moderate",
}},
"consequences": {"facts": facts, "count": facts.size()},
"party": {
"snapshot_id": "snapshot-001",
"snapshot_hash": "snapshot-hash-001",
"front_to_rear_ids": ["r-1", "r-2", "r-3", "r-4"],
"ordered_recruits": [
{"position": 0, "recruit": _recruit("r-1", "PF-B01", "阿里", "Ari", locale), "relation": {"exposure_id": "highest", "reach_id": "front_two"}},
{"position": 1, "recruit": _recruit("r-2", "PF-B05", "布兰", "Bram", locale), "relation": {"exposure_id": "high", "reach_id": "front_three"}},
{"position": 2, "recruit": _recruit("r-3", "PF-B07", "塞拉", "Cera", locale), "relation": {"exposure_id": "guarded", "reach_id": "full_line"}},
{"position": 3, "recruit": _recruit("r-4", "PF-B03", "戴恩", "Dain", locale), "relation": {"exposure_id": "rear", "reach_id": "limited"}},
],
"coverage": {"protection": 2, "long_reach": 2, "sustain": 1, "control": 1},
},
"dependency": {"ok": true, "code": "READY", "facts": {"ok": true, "code": "READY", "coin": 38, "cost": 4}},
"confirmation": {"acknowledged": false, "state": "required"},
"commands": {
"settings_enabled": true, "selected_details_enabled": true,
"consequences_review_enabled": true, "cancel_enabled": true,
"acknowledge_enabled": true, "begin_enabled": false,
},
"notice": "",
}
func _recruit(recruit_id: String, profession_id: String, zh_name: String, en_name: String, locale: String) -> Dictionary:
return {"recruit_id": recruit_id, "profession_id": profession_id, "rendered_name_snapshot": {locale: zh_name if _locale_of(locale) else en_name}}
func _page_ceiling(view: Control, page_name: String) -> int:
# The page ceiling is what the view's own text-size helper returns for a label
# that is large enough to hit it: 16 (party), 18 (risk board), 17 (risk
# commitment). M84-C raises it with the accessibility scale.
var base := 16
if page_name == "risk_board":
base = 18
elif page_name == "risk_commitment":
base = 17
var ceiling := mini(30, int(round(float(base) * probe_text_scale)))
return ceiling
func _collect_scale_samples(view: Control, page_name: String, locale: String) -> void:
for node in _all_labels(view):
var label := node as Label
if label == null or label.text.strip_edges().is_empty() or not label.is_visible_in_tree():
continue
scale_samples["%s|%s|%s|%.1f" % [page_name, locale, label.name, probe_text_scale]] = int(label.get_theme_font_size("font_size"))
func _all_labels(node: Node) -> Array:
var found: Array = []
for child in node.get_children():
if child is Label:
found.append(child)
found.append_array(_all_labels(child))
return found
func _text_scale_failures() -> Array:
# M84-C gate: 130% must be a real step. Per page and locale:
# (a) the ceiling must rise (16->21 / 18->23 / 17->22);
# (b) at least one visible body label must grow;
# (c) no label may exceed the 130% ceiling.
var failures: Array = []
# M83 rail slots own their ceiling (RAIL_FONT_CEILING=30) and their own gate;
# they still count for the growth sample, but not for the page body ceiling.
const RAIL_EXEMPT := ["PartyTitle", "PartyPressureValue", "PartyCompanyValue", "PartyCompanyCapacityValue"]
for page_name in ["party_line", "risk_board", "risk_commitment"]:
for locale in LOCALES:
var base_key := "%s|%s|1.0" % [page_name, locale]
var grown_key := "%s|%s|1.3" % [page_name, locale]
var low_ceiling := int(ceiling_samples.get(base_key, 0))
var high_ceiling := int(ceiling_samples.get(grown_key, 0))
if low_ceiling <= 0 or high_ceiling <= 0:
failures.append("%s %s has no ceiling sample" % [page_name, locale])
elif high_ceiling <= low_ceiling:
failures.append("%s %s ceiling did not rise (%d -> %d)" % [page_name, locale, low_ceiling, high_ceiling])
var grown := 0
var sampled := 0
for key in scale_samples.keys():
var parts := String(key).split("|")
if parts.size() != 4 or parts[0] != page_name or parts[1] != locale:
continue
if not is_equal_approx(float(parts[3]), 1.3):
continue
sampled += 1
var low_key := "%s|%s|%s|1.0" % [parts[0], parts[1], parts[2]]
if scale_samples.has(low_key) and int(scale_samples[key]) > int(scale_samples[low_key]):
grown += 1
if high_ceiling > 0 and int(scale_samples[key]) > high_ceiling and not (parts[2] in RAIL_EXEMPT):
failures.append("%s %s label %s font %d above the 130%% ceiling %d" % [page_name, locale, parts[2], int(scale_samples[key]), high_ceiling])
if sampled == 0:
failures.append("%s %s sampled no visible labels at 130%%" % [page_name, locale])
elif grown < 1:
failures.append("%s %s has no label growing at 130%% (%d sampled)" % [page_name, locale, sampled])
return failures