Add interactive CCS case practice

This commit is contained in:
hz
2026-07-15 10:17:53 -05:00
parent d73fd5f2cf
commit 7256f93002
23 changed files with 1429 additions and 4 deletions
+38
View File
@@ -0,0 +1,38 @@
extends VBoxContainer
const Style := preload("res://scripts/ui/ui_style.gd")
var main: Control
var title: Label
var body: RichTextLabel
func _ready() -> void:
set_anchors_preset(Control.PRESET_FULL_RECT); add_theme_constant_override("separation", 12)
title = Label.new(); Style.set_label(title, 32, Style.TEXT); add_child(title)
body = RichTextLabel.new(); body.bbcode_enabled = true; body.fit_content = false; body.size_flags_vertical = Control.SIZE_EXPAND_FILL
body.meta_clicked.connect(func(meta): OS.shell_open(str(meta))); add_child(body)
CCSService.attempt_changed.connect(_refresh_loaded_attempt)
var row := HBoxContainer.new(); add_child(row)
var cases := Button.new(); cases.text = "More cases"; Style.style_primary_button(cases); cases.pressed.connect(func(): main.show_screen("ccs_hub")); row.add_child(cases)
var history := Button.new(); history.text = "Case history"; history.pressed.connect(func(): main.show_screen("ccs_history")); row.add_child(history)
func on_show(payload: Variant = null) -> void:
if typeof(payload) == TYPE_STRING:
CCSService.load_attempt(str(payload))
return
var attempt: Dictionary = payload if typeof(payload) == TYPE_DICTIONARY else CCSService.attempt
if attempt.is_empty(): return
var score: Dictionary = attempt.get("score", {})
title.text = "%s: %d%%" % [attempt.get("caseTitle", "Case review"), int(round(float(score.get("percent", 0))))]
var text := "[b]Scoring review[/b]\n"
for criterion in score.get("criteria", []):
var status := str(criterion.get("status", "missed"))
text += "\n[color=%s][b]%s %s%d[/b][/color]\n%s\n" % [Style.LIME.to_html() if status in ["credited", "avoided"] else Style.RED.to_html(), status.capitalize(), "+" if int(criterion.get("points", 0)) >= 0 else "", criterion.get("points", 0), criterion.get("rationale", "")]
text += "\n[b]Case timeline[/b]\n"
for entry in attempt.get("chart", []): text += "\nT+%d [%s] %s" % [entry.get("simulatedMinute", 0), entry.get("category", "note"), entry.get("text", "")]
if not attempt.get("references", []).is_empty():
text += "\n\n[b]References[/b]\n"
for reference in attempt.get("references", []): text += "\n[url=%s]%s[/url]" % [reference.get("url", ""), reference.get("title", reference.get("url", "Reference"))]
body.text = text
func _refresh_loaded_attempt() -> void:
if visible and str(CCSService.attempt.get("state", "")) == "completed": on_show(CCSService.attempt)