Files
Dreierpack-Manager/src/modern/ui/live_screens.inc
T
MichaelandClaude Fable 5.2 72e06aabdb Players wear shirt numbers the manager can change
Every player keeps a number from 1 to 99, unique within his squad. The
line-up shows it and changes it by a click; the tactics sketch and the
match sheet wear it too.

Engine: shirt_numbers.hpp, squad read player.shirtNumber, command
lineup.setNumber; saved in state/modern.json.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-17 16:58:34 +01:00

706 lines
53 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// SPDX-License-Identifier: GPL-3.0-only
namespace {
std::string live_text(const std::string &value, const std::string &css = {}) {
return "<span" + (css.empty() ? std::string() : " class=\"" + css + "\"") + ">" + esc(value) + "</span>";
}
std::string live_score_text(const Json &score) {
return std::to_string(score[0].get<int>()) + " : " + std::to_string(score[1].get<int>());
}
// A value of the engine's tactics board in words: the attitude (item 0, lowest = most
// defensive), the commitment (item 7) and the numbered variants of the play patterns.
std::string live_tactic_value(size_t index, int value, int maximum) { return tactic_value_text(index, value, maximum); }
const Json &live_match_by_id(const Json &rows, const Json &id) {
for (const auto &row : rows) if (row.at("id") == id) return row;
throw editor::Error("live_match_unavailable");
}
// Relative luminance and contrast of "#rrggbb" colours, for type on a club's colour.
double mv_lum(const std::string &colour) {
if (colour.size() < 7) return 0;
double v[3];
for (size_t i = 0; i < 3; ++i) {
const double x = std::stoi(colour.substr(1 + i * 2, 2), nullptr, 16) / 255.0;
v[i] = x <= .03928 ? x / 12.92 : std::pow((x + .055) / 1.055, 2.4);
}
return .2126 * v[0] + .7152 * v[1] + .0722 * v[2];
}
double mv_contrast(const std::string &a, const std::string &b) {
const double x = mv_lum(a), y = mv_lum(b);
return (std::max(x, y) + .05) / (std::min(x, y) + .05);
}
std::string mv_ink(const std::string &colour) { return mv_lum(colour) > .4 ? "#1d1611" : "#fffdf6"; }
// A player's position as the three letters of the squad lists.
std::string live_position_text(const Json &value) {
if (!value.is_string()) return {};
std::string code = value.get<std::string>();
for (auto &c : code) c = char(std::toupper(static_cast<unsigned char>(c)));
if (code == "TW" || code == "T" || code == "GK") return "TW";
if (code == "ABW" || code == "A" || code == "AB" || code == "DEF") return "ABW";
if (code == "MIT" || code == "M" || code == "MF" || code == "MID") return "MIT";
if (code == "STU" || code == "S" || code == "ST" || code == "FWD") return "STU";
return code;
}
const Json &live_score_by_id(const Json &frame, const Json &id) {
for (const auto &row : frame.at("matches")) if (row.at("match_id") == id) return row;
throw editor::Error("live_score_unavailable");
}
} // namespace
Json App::live_owner() const {
for (const auto &owner : live_.fixture().at("owners")) if (owner.at("id") == live_.owner()) return owner;
return Json();
}
Json App::live_owner_state(const Json &owner) const {
if (owner.at("view").value("engine", false)) return Json::object();
const auto id = owner.at("id").get<std::string>();
return live_drafts_.contains(id) ? live_drafts_.at(id) : owner.at("view").at("edit_state");
}
Json App::live_owner_rows(const Json &owner) const {
if (owner.at("view").value("engine", false)) return owner.at("view").at("rows");
if (!live_world_) return Json::array();
const auto view = live_owner_state(owner);
const auto projection = demo_lineup_rows(view, *live_world_, owner.at("view").at("club_basis"));
if (!projection.value("ok", false)) return Json::array();
auto rows = projection.at("rows");
for (auto &row : rows) {
row["caps"] = nullptr; row["international_goals"] = nullptr;
for (const auto &base : owner.at("view").at("rows")) if (base.at("id") == row.at("id")) {
row["caps"] = base.at("caps"); row["international_goals"] = base.at("international_goals");
}
}
return rows;
}
std::string App::live_badge(const Json &team, double size) {
std::string art;
if (team.value("role", "club") == "national") {
auto nation = team.value("nation", team.value("id", "") == "national-de" ? "nation:de" : "");
if (nation.starts_with("nation:")) nation = nation.substr(7);
const auto flag = ui_nation_flag_svg(nation);
if (!flag.empty()) art = picture(renderer_.diagram("live-flag-" + nation, flag, int(size * 2)), size, size * .7);
} else if (live_world_) {
if (const auto *club = live_world_->find("clubs", team.value("id", "")); club && !club->value("crest", "").empty()) art = crest(club, size);
}
if (art.empty()) art = glyph(team.value("role", "club") == "national" ? "world" : "shirt", size);
return "<div class=\"live-badge\" style=\"width:" + scalar(size) + "dp;height:" + scalar(size) + "dp;\">" + art + "</div>";
}
// The small signs of the ticker and the squad list, drawn in the paper's ink.
std::string App::live_icon(const std::string &kind, double size) {
const bool dark = theme_ != "silver" && theme_ != "matchday";
const std::string ink = dark ? "#f0ece2" : "#2a211a", paper = dark ? "#2a2d34" : "#fffdf6";
std::string g;
if (kind == "goal")
g = "<circle cx='10' cy='10' r='8.4' fill='" + paper + "' stroke='" + ink + "' stroke-width='1.6'/><path d='M10 5.7l4 2.9-1.5 4.7h-5L6 8.6z' fill='" + ink + "'/>";
else if (kind == "chance" || kind == "save")
g = "<path d='M3 16V5h14v11' fill='none' stroke='" + ink + "' stroke-width='2'/><circle cx='10' cy='12' r='2.6' fill='#c67139'/>";
else if (kind == "miss")
g = "<path d='M3 17V8h10v9' fill='none' stroke='#8a8072' stroke-width='2'/><circle cx='16.5' cy='4.5' r='2.4' fill='#8a8072'/>";
else if (kind == "yellow")
g = "<rect x='5.5' y='2.5' width='9' height='14' rx='1.5' fill='#e9c53a' stroke='#2a211a' stroke-width='1.2'/>";
else if (kind == "second_yellow")
g = "<rect x='3' y='2.5' width='8.5' height='13' rx='1.5' fill='#e9c53a' stroke='#2a211a' stroke-width='1.2'/><rect x='8.5' y='5' width='8.5' height='13' rx='1.5' fill='#c8372d' stroke='#2a211a' stroke-width='1.2'/>";
else if (kind == "red")
g = "<rect x='5.5' y='2.5' width='9' height='14' rx='1.5' fill='#c8372d' stroke='#2a211a' stroke-width='1.2'/>";
else if (kind == "injury")
g = "<path d='M7.5 2.5h5v5h5v5h-5v5h-5v-5h-5v-5h5z' fill='#c8372d'/>";
else if (kind == "up")
g = "<path d='M10 4l7 12H3z' fill='#3f7a35'/>";
else if (kind == "down")
g = "<path d='M10 16L3 4h14z' fill='#b8402f'/>";
else if (kind == "same")
g = "<circle cx='10' cy='10' r='4' fill='#b9ae9a'/>";
else if (kind == "substitution")
g = "<path d='M6 17V6M2.5 9.5L6 6l3.5 3.5' fill='none' stroke='#56874a' stroke-width='2.2'/><path d='M14 3v11M10.5 10.5L14 14l3.5-3.5' fill='none' stroke='#c8372d' stroke-width='2.2'/>";
else
g = "<circle cx='10' cy='10' r='7.5' fill='none' stroke='" + ink + "' stroke-width='1.8'/><path d='M10 5.5V10l3 2' fill='none' stroke='" + ink + "' stroke-width='1.8'/>";
return picture(renderer_.diagram("mv-icon-" + kind + (dark ? "-d" : "-l"), "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'>" + g + "</svg>", 96), size, size);
}
// The weather of a match as a picture; the code is the engine's weather picture 0-7.
std::string App::live_weather_icon(int code, double size) {
const std::string sun = "<circle cx='14' cy='14' r='6' fill='#e9b53a'/><g stroke='#e9b53a' stroke-width='2' stroke-linecap='round'><path d='M14 2.5v3M14 22.5v3M2.5 14h3M22.5 14h3M5.9 5.9l2.1 2.1M20 20l2.1 2.1M5.9 22.1L8 20M20 8l2.1-2.1'/></g>";
const auto cloud = [](const char *colour) { return std::string("<path d='M12 31a7 7 0 0 1 .6-14 9 9 0 0 1 17.3 2A6 6 0 0 1 29 31z' fill='") + colour + "'/>"; };
std::string g;
if (code <= 0) g = "<g transform='translate(6 6)'>" + sun + "</g>";
else if (code == 1) g = "<g transform='translate(0 -1) scale(.85)'>" + sun + "</g>" + cloud("#cfc7b8");
else if (code <= 3) g = cloud("#b9b1a3");
else if (code <= 5) g = cloud("#9aa3a8") + "<g stroke='#5b86a8' stroke-width='2' stroke-linecap='round'><path d='M14 33l-1.5 4M21 33l-1.5 4M28 33l-1.5 4'/></g>";
else g = cloud("#aeb6ba") + "<g fill='#8fb0c8'><circle cx='14' cy='35' r='1.7'/><circle cx='21' cy='36.5' r='1.7'/><circle cx='28' cy='35' r='1.7'/></g>";
return picture(renderer_.diagram("mv-weather-" + std::to_string(std::clamp(code, 0, 7)), "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'>" + g + "</svg>", 160), size, size);
}
// The picture behind the match sheet. In fair weather it is one of the pitch photographs and
// the home club keeps its picture; in rain it is one of the rain photographs, in snow the one
// with sleet on the pane. Empty when the match is played in a hall or no picture is installed.
std::string App::live_backdrop() const {
if (scene_ != "live" || !live_.available()) return {};
try {
const auto &fixture = live_.fixture();
if (live_indoor()) return {};
const auto owner = live_owner();
const Json *match = &fixture.at("matches").front();
if (owner.is_object())
for (const auto &row : fixture.at("matches")) if (row.at("id") == owner.at("match_id")) match = &row;
int code = 0;
if (match->contains("weather") && match->at("weather").is_object() && match->at("weather").value("rain", Json()).is_number_integer())
code = match->at("weather").at("rain").get<int>();
const auto installed = [&](const char *family, std::initializer_list<int> numbers) {
std::vector<std::string> keys;
for (const int number : numbers)
if (const std::string key = std::string(family) + std::to_string(number); gui_.contains(key)) keys.push_back(key);
return keys;
};
std::vector<std::string> pictures;
if (code >= 6) pictures = installed("match.rain-", {4});
if (pictures.empty() && code >= 4) pictures = installed("match.rain-", {1, 2, 3, 4, 5});
if (pictures.empty()) pictures = installed("match.pitch-", {1, 3, 4, 5, 6, 7, 8, 9});
if (pictures.empty()) return {};
size_t hash = 2166136261u;
for (const unsigned char c : match->at("home").at("id").get<std::string>()) hash = (hash ^ c) * 16777619u;
return pictures[hash % pictures.size()];
} catch (const std::exception &) { return {}; }
}
// Played in a hall: the fixture says so, or the engine named the competition a hall tournament.
bool App::live_indoor() const {
if (!live_.available()) return false;
const auto &fixture = live_.fixture();
if (fixture.at("surface") == "indoor") return true;
for (const auto &match : fixture.at("matches"))
if (match.value("competition", std::string()).find("Halle") != std::string::npos) return true;
return false;
}
std::string App::live_roster(const Json &owner) {
const bool national = live_.fixture().at("role") == "national";
const int field_count = live_.fixture().at("field_count");
const auto rows = live_owner_rows(owner);
const bool recorded = live_.fixture().at("source") == "engine-recording";
// what the match has brought each player so far: goals, a yellow card, a knock
std::map<std::string, std::array<int, 3>> marks;
const auto frame = live_.frame();
for (const auto &event : frame.at("events")) {
if (!event.contains("player") || !event.at("player").is_object()) continue;
const std::string id = event.at("player").value("id", std::string()), kind = event.value("kind", std::string());
if (id.empty()) continue;
if (kind == "goal") ++marks[id][0];
if (kind == "yellow") ++marks[id][1];
if (kind == "injury") ++marks[id][2];
}
const auto cell = [](const std::string &text, const char *css) { return "<span class=\"" + std::string(css) + "\">" + esc(text) + "</span>"; };
const auto section = [](const std::string &text) { return "<div class=\"mv-tr sec\"><span class=\"l\">" + esc(pg_upper(text)) + "</span></div>"; };
std::string out = "<div class=\"mv-tr hd\">" + cell("NR.", "w1") + cell("POS.", "w2 l") + cell("SPIELER", "g") +
cell(national ? "CAPS" : "STÄRKE", "w3") + cell(national ? "TORE" : "KONDITION", "w4") + "</div>";
if (national && !recorded) out += section("Demokader auf Vereinsbasis · keine Nationalkaderberufung");
for (size_t i = 0; i < rows.size(); ++i) {
if (int(i) == field_count) out += section(field_count == 6 ? "Rotationspartner · erster 11er-Plan" : recorded ? "Ersatzbank und Reserve" : "Reserven · Demovorschau");
if (field_count == 6 && i == 11) out += section("Weitere Kaderreserven");
const auto &row = rows[i];
const std::string id = row.at("id").get<std::string>();
std::string badges;
if (const auto at = marks.find(id); at != marks.end()) {
if (at->second[0]) badges += live_icon("goal", 31) + (at->second[0] > 1 ? "<span>×" + std::to_string(at->second[0]) + "</span>" : std::string());
if (at->second[1]) badges += "<span class=\"mv-card-mark\"></span>";
if (at->second[2]) badges += live_icon("injury", 27);
}
std::string last = cell(lineup_value(row.at(national ? "international_goals" : "condition")), "w4");
if (!national && row.at("condition").is_number()) {
const int value = std::clamp(int(row.at("condition").get<double>()), 0, 100);
last = "<div class=\"mv-ko\"><span class=\"bar\"><div style=\"width:" + std::to_string(value) + "%;background-color:" +
(value > 70 ? "#56874a" : value > 50 ? "#d9a441" : "#c8372d") + ";\"></div></span><span>" + std::to_string(value) + "</span></div>";
}
out += "<div class=\"mv-tr\" data-live-player=\"" + esc(id) + "\">" + cell(engine_shirt(id, i + 1), "w1") +
cell(live_position_text(row.value("position", Json())), "w2 l pos") +
"<span class=\"nm\"><span class=\"t\">" + esc(row.at("name").get<std::string>()) + "</span>" + badges + "</span>" +
cell(lineup_value(row.at(national ? "caps" : "strength")), "w3") + last + "</div>";
}
if (rows.empty()) out += "<p class=\"mv-empty\">" + esc(recorded ? "Für diese Mannschaft liegt keine Kaderansicht vor." : "Für diese Demomannschaft sind keine Kaderspieler verfügbar.") + "</p>";
return out;
}
std::string App::live_detail(const Json &owner, const Json &frame) {
const auto &fixture = live_.fixture();
const auto &match = live_match_by_id(fixture.at("matches"), owner.at("match_id"));
const auto &score = live_score_by_id(frame, match.at("id"));
if (live_tab_ == "team") return live_roster(owner);
const bool recorded = fixture.at("source") == "engine-recording";
const auto note = [](const std::string &text) { return "<p class=\"mv-empty\">" + esc(text) + "</p>"; };
const auto cell = [](const std::string &text, const char *css) { return "<span class=\"" + std::string(css) + "\">" + esc(text) + "</span>"; };
if (live_tab_ == "table") {
if (recorded && score.at("standings").empty()) return note("Diese Partie gehört zu keiner Ligatabelle.");
if (fixture.at("role") == "national") return note("Dieses Länderspiel gehört zu keiner Liga.");
// where every club stood at the kickoff, for the arrows
std::map<std::string, int> before;
try {
for (const auto &row : live_score_by_id(fixture.at("frames").front(), match.at("id")).at("standings"))
before[row.at("team").at("id").get<std::string>()] = row.at("position").get<int>();
} catch (const std::exception &) {}
bool results = false;
for (const auto &row : score.at("standings")) results = results || (row.contains("won") && row.at("won").is_number_integer());
std::string out = "<div class=\"mv-tr hd\">" + cell("PL.", "w1") + cell("", "w0") + cell("VEREIN", "g") + cell("SP.", "w1") +
(results ? cell("S", "w1") + cell("U", "w1") + cell("N", "w1") : std::string()) + cell("TORE", "w3") + cell("DIFF.", "w2") + cell("PKT.", "w2") + "</div>";
const auto colours = live_colours(match);
for (const auto &row : score.at("standings")) {
const std::string id = row.at("team").at("id").get<std::string>();
const bool own = row.at("team").at("id") == owner.at("team").at("id");
const int position = row.at("position").get<int>(), difference = row.at("gf").get<int>() - row.at("ga").get<int>();
const int was = before.contains(id) ? before.at(id) : position;
const std::string colour = colours[match.at("home").at("id") == owner.at("team").at("id") ? 0 : 1];
const auto count = [&](const char *key) { return cell(row.contains(key) && row.at(key).is_number_integer() ? std::to_string(row.at(key).get<int>()) : "–", "w1"); };
out += "<div class=\"mv-tr" + std::string(own ? " own" : "") + "\" data-live-table-team=\"" + esc(id) + "\"" +
(own ? " aria-current=\"true\" style=\"background-color:" + colour + ";color:" + mv_ink(colour) + ";\"" : "") + ">" +
cell(std::to_string(position), "w1") +
"<span class=\"w0\">" + (own ? std::string() : live_icon(position < was ? "up" : position > was ? "down" : "same", 22)) + "</span>" +
"<span class=\"nm\">" + live_badge(row.at("team"), 40) + "<span class=\"t\">" + esc(row.at("team").at("name").get<std::string>()) + "</span></span>" +
cell(std::to_string(row.at("played").get<int>()), "w1") + (results ? count("won") + count("drawn") + count("lost") : std::string()) +
cell(std::to_string(row.at("gf").get<int>()) + ":" + std::to_string(row.at("ga").get<int>()), "w3") +
cell((difference > 0 ? "+" : "") + std::to_string(difference), "w2") + cell(std::to_string(row.at("points").get<int>()), "w2") + "</div>";
}
return out;
}
if (live_tab_ == "tactics" && live_.running() && engine_live_tactics_.size() == 8) {
std::string out;
for (size_t i = 0; i < engine_live_tactics_.size(); ++i)
out += "<div class=\"mv-trow\"><span class=\"k\">" + esc(engine_live_tactics_[i].at("label").get<std::string>()) + "</span><span class=\"v\">" +
esc(i == 0 && engine_live_assistant_ ? std::string("Assistent passt an") : live_tactic_value(i, engine_live_tactics_[i].at("value").get<int>(), engine_live_tactics_[i].at("max").get<int>())) + "</span></div>";
return out + "<div class=\"mv-pad\">" + btn("live-intervene-tactics", "Taktik ändern", "mv-btn sm", "id=\"live-tactics-edit\"") + "</div>";
}
if (live_tab_ == "tactics" && recorded)
return note("Dieser Spieltag wurde mit der Aufstellung und Taktik vom Schreibtisch gespielt.");
if (live_tab_ == "tactics") {
const auto state = live_owner_state(owner), board = demo_lineup_visible(state);
Json points = Json::array(); const int count = fixture.at("field_count");
for (int i = 0; i < count; ++i) points.push_back(board.at("points")[size_t(i)]);
return "<div class=\"mv-pad\"><p>" + esc(std::to_string(count) + " Spieler auf dem Feld · unabhängige Manageransicht") + "</p>" +
picture(renderer_.diagram("live-formation", lineup_mini(points, theme_), 1200), 1140, 684) +
btn("live-intervene-tactics", "Taktik als Demo bearbeiten", "mv-btn sm", "id=\"live-tactics-edit\" " + std::string(live_.finished() ? "disabled" : "")) + "</div>";
}
if (live_tab_ == "opponent" && recorded) {
// the other matches of the day, own competition first; known once the day is played
if (!live_.finished() || !fixture.contains("conference") || !fixture.at("conference").is_array() || fixture.at("conference").empty())
return note(live_.finished() ? "An diesem Tag gab es keine weiteren Spiele." : "Die Ergebnisse der anderen Spiele stehen nach dem Abpfiff hier.");
const std::string own = match.value("competition", std::string());
std::vector<std::string> order;
std::map<std::string, std::string> groups;
for (const auto &other : fixture.at("conference")) {
const std::string name = other.at("competition").value("name", std::string("Weitere Spiele"));
if (!groups.contains(name)) order.push_back(name);
const auto &result = other.at("result").at("final");
Json home = other.at("home"), away = other.at("away");
if (!home.contains("role")) home["role"] = "club";
if (!away.contains("role")) away["role"] = "club";
groups[name] += "<div class=\"mv-res\"><span class=\"h\">" + esc(home.value("name", std::string())) + "</span>" + live_badge(home, 40) +
"<span class=\"sc\">" + std::to_string(result[0].get<int>()) + " : " + std::to_string(result[1].get<int>()) + "</span>" +
live_badge(away, 40) + "<span class=\"a\">" + esc(away.value("name", std::string())) + "</span></div>";
}
std::stable_sort(order.begin(), order.end(), [&](const std::string &a, const std::string &b) { return (a == own) > (b == own); });
std::string list;
for (const auto &name : order) list += "<div class=\"mv-tr sec\"><span class=\"l\">" + esc(pg_upper(name)) + "</span></div>" + groups.at(name);
return list;
}
std::string out;
if (live_tab_ == "opponent") {
const auto &opponent = match.at(owner.at("team").at("id") == match.at("home").at("id") ? "away" : "home");
return "<div class=\"mv-pad\"><h3 class=\"mv-k\">" + esc(pg_upper("Gegner")) + "</h3><p>" + esc(opponent.at("name").get<std::string>()) + "</p></div>";
}
const auto colours = live_colours(match);
out = "<div class=\"mv-cmp\"><div class=\"t\">" + live_badge(match.at("home"), 58) + "<span>" + esc(match.at("home").at("name").get<std::string>()) +
"</span></div><span class=\"mv-k\">VERGLEICH</span><div class=\"t a\"><span>" + esc(match.at("away").at("name").get<std::string>()) + "</span>" + live_badge(match.at("away"), 58) + "</div></div>";
const std::array<std::pair<const char *, const char *>, 5> fields{{{"Tore", "score"}, {"Chancen", "chances"}, {"Gelbe Karten", "yellow"}, {"Rote Karten", "red"}, {"Spieler auf dem Feld", "players"}}};
for (const auto &[label, key] : fields) {
const auto &pair = score.at(key); const int a = pair[0], b = pair[1];
const double percent = a + b ? 100.0 * a / (a + b) : 50;
out += "<div class=\"mv-stat\"><span class=\"lb\">" + esc(pg_upper(label)) + "</span><div class=\"ln\"><span class=\"n h\">" + std::to_string(a) +
"</span><div class=\"bar\">" + (a + b ? "<div style=\"width:" + scalar(percent) + "%;background-color:" + colours[0] + ";\"></div><div class=\"a\" style=\"background-color:" + colours[1] + ";\"></div>" : std::string()) +
"</div><span class=\"n\">" + std::to_string(b) + "</span></div></div>";
}
return out;
}
std::string App::live_dialog_markup(const Json &owner) {
if (live_dialog_.empty()) return "";
const auto rows = live_owner_rows(owner);
const bool lineup = live_dialog_ == "lineup";
const std::string team = owner.at("team").at("name").get<std::string>();
std::string body = "<div class=\"mv-tape\"></div><div><span class=\"mv-k\">" + esc(pg_upper(live_.running() ? team : team + " · Demo")) + "</span><h2 id=\"live-dialog-heading\">" +
esc(lineup ? "Aufstellung & Wechsel" : "Taktik") + "</h2></div>";
std::string hint;
if (lineup) {
const size_t count = size_t(live_.fixture().at("field_count").get<int>());
std::string lists[2], names[2];
for (size_t i = 0; i < rows.size(); ++i) {
const bool bench = i >= count;
const std::string id = rows[i].at("id").get<std::string>();
const bool chosen = id == (bench ? live_in_ : live_out_);
if (chosen) names[bench] = rows[i].at("name").get<std::string>();
const std::string strength = lineup_value(rows[i].value("strength", Json())), condition = lineup_value(rows[i].value("condition", Json()));
lists[bench] += btn(bench ? "live-pick-in" : "live-pick-out",
"<span class=\"nr\">" + engine_shirt(id, i + 1) + "</span><span class=\"ps\">" + esc(live_position_text(rows[i].value("position", Json()))) + "</span><span class=\"nm\">" +
esc(rows[i].at("name").get<std::string>()) + "</span><span class=\"vl\">" + esc(strength + " · " + condition) + "</span>",
std::string("mv-pick") + (chosen ? " selected" : ""),
"id=\"live-pick-" + std::to_string(i) + "\" data-id=\"" + esc(id) + "\" aria-pressed=\"" + (chosen ? "true" : "false") + "\"");
}
for (auto &list : lists) if (list.empty()) list = "<p class=\"mv-empty\">" + esc("Niemand verfügbar.") + "</p>";
body += "<div class=\"mv-cols\"><div class=\"col\"><span class=\"mv-k\">VOM FELD</span><div id=\"live-player-out\" class=\"mv-list\" style=\"height:" + pg(344) + ";\">" + lists[0] +
"</div></div><div class=\"col\"><span class=\"mv-k\">VON DER ERSATZBANK</span><div id=\"live-player-in\" class=\"mv-list\" style=\"height:" + pg(344) + ";\">" + lists[1] + "</div></div></div>";
hint = !names[0].empty() && !names[1].empty() ? names[1] + " kommt für " + names[0] + "."
: live_.running() ? "Wähle einen Spieler vom Feld und einen von der Bank. Das Spiel steht so lange." : "Nur lokale Vorschau; der feste Spielverlauf bleibt unverändert.";
} else {
const std::array<const char *, 8> names{"Defensiv / offensiv", "Pass-/Schussbild unten", "Pass-/Schussbild Mitte", "Pass-/Schussbild links", "Flache / hohe Bälle", "Flügelbild links", "Flügelbild rechts", "Einsatz"};
const bool engine_board = live_.running() && engine_live_tactics_.size() == 8;
const auto &values = engine_board ? live_dialog_draft_.at("values") : live_dialog_draft_.at("tactics").at("values");
body += "<div class=\"mv-list rows\">";
for (size_t i = 0; i < names.size(); ++i)
body += btn("live-tactic-cycle",
"<span class=\"k\">" + esc(engine_board ? engine_live_tactics_[i].at("label").get<std::string>() : std::string(names[i])) + "</span><span class=\"v\">" +
esc(engine_board ? live_tactic_value(i, values[i].get<int>(), engine_live_tactics_[i].at("max").get<int>()) : "Wert " + std::to_string(values[i].get<int>())) + "</span><span class=\"go\">›</span>",
"mv-trow", "id=\"live-tactic-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\"");
body += "</div><p id=\"live-tactic-effect\">" + esc((engine_board ? tactic_effect_text(size_t(std::clamp(last_tactic_, 0, 7))) + " " : std::string()) + "Ein Klick auf eine Zeile schaltet den Wert weiter.") + "</p>";
}
body += "<div class=\"mv-acts\">" + (hint.empty() ? std::string() : "<span class=\"hint\">" + esc(hint) + "</span>") + btn("live-dialog-cancel", "Abbrechen", "mv-btn", "id=\"live-dialog-cancel\"") +
btn("live-dialog-apply", live_.running() ? (lineup ? "Wechsel ausführen" : "Taktik übernehmen") : "Demovorschau anzeigen", "mv-btn primary",
"id=\"live-dialog-apply\" " + std::string(lineup && (live_out_.empty() || live_in_.empty()) ? "disabled" : "")) + "</div>";
return "<div class=\"mv-veil\"><div id=\"live-dialog\" class=\"mv-note\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"live-dialog-heading\" style=\"width:" + pg(lineup ? 820 : 560) + ";\">" + body + "</div></div>";
}
std::string App::live_ticker_events(const Json &frame, size_t &shown) {
const auto &fixture = live_.fixture();
const bool recorded = fixture.at("source") == "engine-recording";
const bool several = fixture.at("matches").size() > 1;
const bool dark = theme_ != "silver" && theme_ != "matchday";
const std::string paper = dark ? "#2a2d34" : "#fffdf6";
shown = 0;
std::string out;
for (auto i = frame.at("events").rbegin(); i != frame.at("events").rend(); ++i) {
const auto &event = *i; const auto kind = event.value("kind", "");
if (live_coverage_ == "single" && event.at("match_id") != live_selected_match_) continue;
if (live_filter_ == "goal" && kind != "goal") continue;
if (live_filter_ == "yellow" && kind != "yellow" && kind != "red" && kind != "second_yellow") continue;
if (live_filter_ == "highlights" && kind != "goal" && kind != "chance" && kind != "miss" && kind != "red" && kind != "second_yellow") continue;
const auto &match = live_match_by_id(fixture.at("matches"), event.at("match_id"));
const bool whistle = kind == "kickoff" || kind == "interval" || kind == "fulltime" || kind == "restart";
const auto side = event.at("side").get<std::string>();
// one line per report: minute, what happened, the club, the wording, the score
std::string head_style;
if (kind == "goal") {
const std::string colour = live_colours(match)[side == "away" ? 1 : 0];
if (mv_contrast(colour, paper) >= (dark ? 4.5 : 3)) head_style = " style=\"color:" + colour + ";\"";
}
out += "<article class=\"mv-ev kind-" + esc(kind) + (kind == "goal" ? " goal" : "") + "\" data-live-event=\"" + esc(event.at("id").get<std::string>()) + "\">" +
"<span class=\"m\">" + std::to_string(event.at("minute").get<int>()) + "′</span><span class=\"i\">" + live_icon(whistle ? "time" : kind, 40) + "</span><span class=\"c\">" +
(whistle ? std::string() : live_badge(match.at(side), 50)) + "</span><div class=\"tx\">" +
(several || !recorded ? "<span class=\"who\">" + esc(match.at("home").at("name").get<std::string>() + " – " + match.at("away").at("name").get<std::string>()) + "</span>" : std::string()) +
"<h3 class=\"hd\"" + head_style + ">" + esc(event.at("headline").get<std::string>()) + "</h3><p>" + esc(event.at("body").get<std::string>()) + "</p></div><span class=\"sc\">" +
std::to_string(event.at("score")[0].get<int>()) + ":" + std::to_string(event.at("score")[1].get<int>()) + "</span></article>";
++shown;
}
if (!shown && recorded && live_filter_ == "all" && frame.at("events").empty()) {
// before the first report: who starts
for (const auto &match : fixture.at("matches")) {
if (live_coverage_ == "single" && match.at("id") != live_selected_match_) continue;
if (!match.contains("lineups") || !match.at("lineups").is_object()) continue;
std::string columns;
for (const auto *side : {"home", "away"}) {
const auto names = match.at("lineups").value(side, Json());
columns += "<div class=\"side\"><h3>" + esc(match.at(side).at("name").get<std::string>()) + "</h3>";
if (names.is_array() && !names.empty()) {
size_t number = 0;
for (const auto &name : names) columns += "<div class=\"row\"><span class=\"nr\">" + std::to_string(++number) + "</span><span class=\"nm\">" + esc(name.get<std::string>()) + "</span></div>";
} else columns += "<p class=\"mv-mut\">" + esc("Aufstellung nicht bekannt.") + "</p>";
columns += "</div>";
}
out += "<div class=\"mv-lineups\">" + columns + "</div>";
}
if (!out.empty()) return out;
}
if (!shown) out += "<p class=\"mv-empty\">" + esc(frame.at("events").empty() ? "Noch ist nichts passiert." : "Keine Meldungen in dieser Auswahl.") + "</p>";
return out;
}
std::array<std::string, 2> App::live_colours(const Json &match) {
// from the crests; a club without one, or a national side, plays in slate. Two sides in
// nearly the same colour: the guests change into a dark neutral.
const auto colour = [&](const Json &team) {
std::string value;
if (team.value("role", "club") != "national" && live_world_)
if (const auto *club = live_world_->find("clubs", team.value("id", "")); club && !club->value("crest", "").empty())
value = renderer_.crest_colour(club->value("crest", ""));
return value;
};
std::array<std::string, 2> out{colour(match.at("home")), colour(match.at("away"))};
const auto channel = [](const std::string &c, size_t at) { return std::stoi(c.substr(at, 2), nullptr, 16); };
if (out[0].empty()) out[0] = "#3d5a73";
if (out[1].empty()) out[1] = "#7a4a3a";
int distance = 0;
for (size_t at : {1u, 3u, 5u}) distance += std::abs(channel(out[0], at) - channel(out[1], at));
if (distance < 110) out[1] = "#3a4148";
return out;
}
// One match on the sheet: crests, the score tiles in the clubs' colours, the clock, who is
// pressing, and the time line with every goal, card and injury so far. `layout` is solo
// (one match), duo (two) or quad (three or four).
std::string App::live_card(const Json &match, const Json &frame, const std::string &layout, size_t index) {
const auto &fixture = live_.fixture();
const bool recorded = fixture.at("source") == "engine-recording";
const auto &value = live_score_by_id(frame, match.at("id"));
const int minute = frame.at("minute"), duration = std::max(1, fixture.value("duration", 90));
const auto colours = live_colours(match);
const bool quad = layout == "quad", solo = layout == "solo";
const bool dark = theme_ != "silver" && theme_ != "matchday";
const std::string ink = dark ? "#f0ece2" : "#2a211a", paper = dark ? "#2a2d34" : "#fffdf6";
const auto id = match.at("id").get<std::string>();
// the clock: a ring that fills with the minutes
const double round = 2 * 3.14159265 * 13, turn = std::clamp(double(minute) / duration, 0.0, 1.0) * round;
const std::string ring = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><circle cx='16' cy='16' r='13' fill='none' stroke='" + ink +
"' stroke-opacity='.14' stroke-width='4'/><circle cx='16' cy='16' r='13' fill='none' stroke='#c67139' stroke-width='4' stroke-linecap='round' stroke-dasharray='" +
scalar(turn) + " " + scalar(round) + "' transform='rotate(-90 16 16)'/></svg>";
// the time line: grass in bands of fifteen minutes, the home side's marks above, the guests' below
const double W = solo ? 868 : 421, H = quad ? 34 : 76, y0 = quad ? 10 : 22, sh = quad ? 14 : 32, away_y = y0 + sh + (quad ? 5 : 12), home_y = y0 - (quad ? 5 : 12);
const auto X = [&](double at) { return 10 + at / duration * (W - 20); };
int press[2] = {0, 0};
std::string marks, bands;
for (int from = 0; from < duration; from += 15)
bands += "<rect x='" + scalar(X(from)) + "' y='" + scalar(y0) + "' width='" + scalar(X(std::min(duration, from + 15)) - X(from)) + "' height='" + scalar(sh) +
"' fill='" + ((from / 15) % 2 ? "#3f7336" : "#4a8040") + "'/>";
for (const auto &event : frame.at("events")) {
if (event.at("match_id") != match.at("id")) continue;
const auto kind = event.value("kind", std::string());
const size_t side = event.value("side", std::string("home")) == "away" ? 1 : 0;
const int at = event.at("minute").get<int>();
if ((kind == "goal" || kind == "chance" || kind == "miss") && at > minute - 10) press[side] += kind == "goal" ? 3 : 1;
const double x = X(std::clamp(at, 0, duration)), y = side ? away_y : home_y;
if (kind == "goal")
marks += "<circle cx='" + scalar(x) + "' cy='" + scalar(y) + "' r='" + (quad ? "4" : "6.5") + "' fill='" + colours[side] + "' stroke='" + ink + "' stroke-width='1.5'/>";
else if (kind == "yellow" || kind == "red" || kind == "second_yellow")
marks += "<rect x='" + scalar(x - (quad ? 2.5 : 4)) + "' y='" + scalar(y - (quad ? 4 : 6.5)) + "' width='" + (quad ? "5" : "8") + "' height='" + (quad ? "8" : "13") +
"' rx='1.2' fill='" + (kind == "yellow" ? "#e9c53a" : "#d8452f") + "' stroke='#2a211a' stroke-width='.8'/>";
else if (kind == "injury") {
const double arm = quad ? 3.5 : 5.5;
marks += "<path d='M" + scalar(x - arm) + " " + scalar(y) + "h" + scalar(arm * 2) + "M" + scalar(x) + " " + scalar(y - arm) + "v" + scalar(arm * 2) + "' stroke='#e0564a' stroke-width='" + (quad ? "2.4" : "3.6") + "'/>";
}
}
const double now = X(std::clamp(minute, 0, duration));
const std::string timeline = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 " + scalar(W) + " " + scalar(H) + "'><rect x='8' y='" + scalar(y0 - 2) + "' width='" + scalar(W - 16) +
"' height='" + scalar(sh + 4) + "' rx='5' fill='#2f5a29'/>" + bands +
"<path d='M" + scalar(X(duration / 2.0)) + " " + scalar(y0) + "v" + scalar(sh) + "' stroke='#ffffff' stroke-opacity='.75' stroke-width='2'/><circle cx='" + scalar(X(duration / 2.0)) + "' cy='" +
scalar(y0 + sh / 2) + "' r='" + scalar(sh * .3) + "' fill='none' stroke='#ffffff' stroke-opacity='.75' stroke-width='2'/>" +
"<rect x='" + scalar(now) + "' y='" + scalar(y0) + "' width='" + scalar(X(duration) - now) + "' height='" + scalar(sh) + "' fill='" + paper + "' fill-opacity='.62'/>" +
(live_.finished() || minute < 1 ? std::string() : "<path d='M" + scalar(now) + " " + scalar(y0 - 3) + "v" + scalar(sh + 6) + "' stroke='" + ink + "' stroke-width='2.5'/>") + marks + "</svg>";
const int total = press[0] + press[1];
const double share = total ? 100.0 * press[0] / total : 50;
const auto phase = frame.at("phase").get<std::string>();
const std::string status = live_.finished() ? "Abpfiff" : phase == "interval" ? "Halbzeit" : minute < 1 ? "Anpfiff" : std::to_string(minute) + "′";
std::string names;
for (const auto &owner_id : match.at("owners")) for (const auto &person : fixture.at("owners")) if (person.at("id") == owner_id) { if (!names.empty()) names += " · "; names += person.at("name").get<std::string>(); }
const bool several = fixture.at("owners").size() > 1;
const std::string competition = recorded ? match.value("competition", std::string("Spieltag")) : std::string("Demospiel");
const double crest = solo ? 86 : quad ? 34 : 50;
const auto team = [&](size_t side) {
const auto &club = match.at(side ? "away" : "home");
const int players = value.at("players")[side].get<int>();
return "<div class=\"mv-team " + std::string(side ? "a" : "h") + "\">" + live_badge(club, crest * 2.25) + "<div class=\"mv-team-nm\"><span class=\"n live-team-name\">" + esc(club.at("name").get<std::string>()) +
"</span><span class=\"bar\" style=\"decorator:linear-gradient(" + (side ? "270deg" : "90deg") + "," + colours[side] + " 0%," + colours[side] + " 60%," + colours[side] + "00 100%);\"></span><span class=\"s\">" +
esc(std::string(side ? "Gast" : "Heim") + (players < int(fixture.value("field_count", 11)) ? " · " + std::to_string(players) + " Spieler" : std::string())) + "</span></div></div>";
};
const auto tile = [&](size_t side) {
return "<div class=\"mv-tile\" style=\"background-color:" + colours[side] + ";color:" + mv_ink(colours[side]) + ";\"><span>" + std::to_string(value.at("score")[side].get<int>()) + "</span></div>";
};
std::string out = "<button data-action=\"live-match\" class=\"mv-card live-game " + layout + (!solo && match.at("id") == live_selected_match_ ? " sel" : "") + "\" data-live-match=\"" + esc(id) + "\" data-id=\"" + esc(id) + "\">";
out += "<div class=\"mv-chead\"><span class=\"l\">" + esc(pg_upper(quad && several ? names : competition)) + "</span><span class=\"r" + std::string(quad ? " now" : "") + "\">" +
esc(quad ? status : several ? names : live_match_info_text(match, live_indoor())) + "</span></div>";
out += "<div class=\"mv-score\">" + team(0) + "<div class=\"mv-mid\">";
if (!quad) out += "<div class=\"mv-clock\">" + picture(renderer_.diagram("live-clock-" + std::to_string(index), ring, 160), solo ? 67.5 : 54, solo ? 67.5 : 54) + "<span>" + esc(status) + "</span></div>";
out += "<div class=\"mv-tiles\">" + tile(0) + "<span class=\"c\">:</span>" + tile(1) + "</div>";
if (!quad)
out += "<div class=\"mv-press\" aria-label=\"Druck der letzten zehn Minuten\"><div style=\"width:" + scalar(share) + "%;background-color:" + colours[0] + ";\"></div><div class=\"a\" style=\"background-color:" + colours[1] + ";\"></div></div>";
out += "</div>" + team(1) + "</div><div class=\"mv-tl\">" + picture(renderer_.diagram("live-line-" + std::to_string(index), timeline, 2048), W * 2.25, H * 2.25);
if (!quad)
for (int at = 15; at < duration; at += 15)
if (at * 2 != duration) out += "<span class=\"t\" style=\"left:" + pg(X(at) + 5) + ";\">" + std::to_string(at) + "′</span>";
out += "</div>";
// a goal that has just fallen: a banner across this card, once
if (minute == 0) live_moment_.clear(); // a new match day: its banners are new again
if (!frame.at("events").empty() && !live_.finished()) {
// this match's latest report of the running minute; several matches may score at once
const Json *goal = nullptr;
const auto &events = frame.at("events");
for (size_t at = events.size(); at-- > 0;) {
const auto &event = events[at];
if (event.at("minute").get<int>() < minute - 3) break; // long enough to be read at any speed
if (event.at("match_id") != match.at("id")) continue;
if (event.value("kind", std::string()) == "goal") goal = &event;
break;
}
if (goal) {
// it stays while the minute lasts and slides in only the first time it is drawn
const auto mark = "|" + goal->at("id").get<std::string>() + "|";
const bool fresh = live_moment_.find(mark) == std::string::npos;
if (fresh) live_moment_ += mark;
const size_t side = goal->value("side", std::string("home")) == "away" ? 1 : 0;
const std::string scorer = goal->contains("player") && goal->at("player").is_object() ? goal->at("player").value("name", std::string()) : std::string();
const std::string club = match.at(side ? "away" : "home").at("name").get<std::string>();
out += "<div class=\"mv-goal live-moment" + std::string(fresh ? " fresh" : "") + "\" style=\"background-color:" + colours[side] + ";color:" + mv_ink(colours[side]) + ";\">" +
live_badge(match.at(side ? "away" : "home"), (solo ? 92 : quad ? 44 : 58) * 2.25) +
"<div class=\"tx\"><span class=\"t\">TOR!</span><span class=\"s\">" + esc(scorer.empty() ? goal->value("headline", std::string()) : scorer + " trifft für " + club) + "</span></div><span class=\"r\">" +
esc(live_score_text(goal->at("score"))) + "</span></div>";
}
}
return out + "</button>";
}
std::string App::render_live() {
if(live_review_) return render_postmatch();
return live_sheet({});
}
// The match sheet; `over` replaces the sheet's own notes (substitution, tactics) on top of it.
std::string App::live_sheet(const std::string &over) {
if (!live_.available()) return "";
if (auto *node = element("live-ticker")) live_ticker_scroll_ = live_reset_ticker_ ? 0 : node->GetScrollTop();
if (auto *node = element("live-detail-body")) live_detail_scroll_ = live_reset_detail_ ? 0 : node->GetScrollTop();
live_reset_detail_ = live_reset_ticker_ = false;
live_restore_scroll_ = true;
const auto &fixture = live_.fixture(); const auto frame = live_.frame(); const auto owner = live_owner();
const int minute = frame.at("minute"); const auto phase = frame.at("phase").get<std::string>();
const bool recorded = fixture.at("source") == "engine-recording";
const size_t count = fixture.at("matches").size();
const std::string layout = count == 1 ? "solo" : count == 2 ? "duo" : "quad";
const auto phase_text = live_.finished() ? "Beendet" : phase == "interval" ? "Halbzeit" : live_.speed() ? (recorded ? (phase == "extra_time" ? "Verlängerung" : phase == "shootout" ? "Elfmeterschießen" : "Spiel läuft") : "Aufzeichnung läuft") : (recorded ? "Pausiert" : "Gemeinsam pausiert");
const bool indoor = live_indoor();
const std::string title = fixture.at("role") == "national" ? "Länderspiel" : indoor ? "Hallenturnier" : recorded && count == 1 ? fixture.at("matches").front().value("competition", std::string("Spieltag")) : std::string("Spieltag");
const auto tab = [](const char *action, const std::string &id, const std::string &text, bool selected, const std::string &prefix) {
return btn(action, text, std::string("mv-tab") + (selected ? " selected" : ""), "id=\"" + prefix + id + "\" data-id=\"" + id + "\" aria-pressed=\"" + (selected ? "true" : "false") + "\"");
};
// an open match sheet in front of the stadium: on the left page the cards of the human
// managers' matches and the ticker, on the right the ground, the weather and the manager's
// team; the controls run along the foot
std::string out = "<section id=\"live-stage\" class=\"mv-stage " + layout + "\" data-source=\"" + std::string(recorded ? "engine-recording" : "ui-demo-fixture") + "\" data-fixture-id=\"" + esc(fixture.at("fixture_id").get<std::string>()) + "\">";
out += "<header class=\"mv-head\"><div class=\"ttl\"><span class=\"mv-k\">" + esc(pg_upper("Spieltag · Textmodus")) + "</span><h1>" + esc(title) + "</h1></div><span class=\"mv-date\">" +
esc(recorded ? ui_long_date(fixture.value("date", std::string())) : std::string("Demo · vorgegebene Ergebnisse")) + "</span></header>";
out += "<div id=\"live-underlay\" class=\"mv-body\"><section class=\"mv-left\"><div class=\"mv-cards " + layout + "\">";
size_t index = 0;
for (const auto &match : fixture.at("matches")) out += live_card(match, frame, layout, index++);
out += "</div><div class=\"mv-box\"><nav id=\"live-filters\" class=\"mv-tabs\"><span class=\"ttl\">Ticker</span>";
for (const auto &[id, label] : std::array<std::pair<const char *, const char *>, 4>{{{"all", "Alles"}, {"highlights", "Highlights"}, {"goal", "Tore"}, {"yellow", "Karten"}}}) out += tab("live-filter", id, label, live_filter_ == id, "live-filter-");
out += "<span class=\"sp\"></span>";
if (count > 1) {
out += "<div class=\"mv-seg\">";
for (const auto &[id, text] : std::array<std::pair<const char *, const char *>, 2>{{{"all", "Alle Spiele"}, {"single", "Gewähltes Spiel"}}})
out += btn("live-coverage", text, live_coverage_ == id ? "selected" : "", "id=\"live-coverage-" + std::string(id) + "\" data-id=\"" + id + "\" aria-pressed=\"" + (live_coverage_ == id ? "true" : "false") + "\"");
out += "</div>";
}
out += "</nav><div class=\"mv-in\"><div id=\"live-ticker\" class=\"mv-scroll\" tabindex=\"0\" aria-label=\"Ereignisverlauf\">";
size_t shown = 0;
out += live_ticker_events(frame, shown);
out += "</div><footer class=\"mv-foot\"><span id=\"live-event-count\">" + esc(std::to_string(shown) + (shown == 1 ? " Meldung" : " Meldungen")) + "</span><span id=\"live-phase-status\" class=\"b\">" + esc(phase_text) + "</span></footer></div></div></section>";
// the right page: the ground and the weather, then the manager's team
out += "<aside id=\"live-detail\" class=\"mv-right\">";
{
const Json *match = &fixture.at("matches").front();
for (const auto &row : fixture.at("matches")) if (row.at("id") == owner.at("match_id")) match = &row;
std::string crowd = live_attendance_text(*match);
std::string filling, bar;
if (!indoor && match->contains("capacity") && match->at("capacity").is_number_integer() && match->at("capacity").get<int64_t>() > 0 &&
match->contains("attendance") && match->at("attendance").is_number_integer()) {
const int64_t places = match->at("capacity").get<int64_t>(), seen = std::min(places, match->at("attendance").get<int64_t>());
const int percent = int(std::lround(100.0 * seen / places));
filling = "von " + number(places) + " Plätzen · " + std::to_string(percent) + " % ausgelastet · ";
bar = "<span class=\"mv-capbar\"><div style=\"width:" + std::to_string(percent) + "%;\"></div></span>";
}
out += "<div class=\"mv-info\"><div class=\"main\"><span class=\"mv-k\">" + esc(pg_upper(indoor ? std::string("Halle") : match->contains("stadiumName") && match->at("stadiumName").is_string() ? match->at("stadiumName").get<std::string>() : std::string("Stadion"))) + "</span><span class=\"big\">" + esc(crowd) +
"</span>" + bar + "<span class=\"sub\">" + esc(filling + "Heimspiel von " + match->at("home").at("name").get<std::string>()) + "</span></div>";
const auto weather = match->value("weather", Json());
if (!indoor && weather.is_object()) {
const Json rain = weather.value("rain", Json()), temperature = weather.value("temperature", Json());
out += "<div class=\"mv-wx\">" + (rain.is_number_integer() ? live_weather_icon(rain.get<int>(), 104) : std::string()) + "<div class=\"v\"><span class=\"t\">" +
esc(temperature.is_number_integer() ? std::to_string(temperature.get<int>()) + " °C" : std::string("—")) + "</span><span class=\"l\">" +
esc(rain.is_number_integer() ? live_weather_label(rain.get<int>()) : std::string("Wetter —")) + "</span></div></div>";
}
out += "</div>";
}
out += "<header class=\"mv-phead\">" + live_badge(owner.at("team"), 99) + "<div class=\"nm\"><h2><span id=\"live-owner-team\">" + esc(owner.at("team").at("name").get<std::string>()) +
"</span></h2><p>Manager: <span id=\"live-owner-name\">" + esc(owner.at("name").get<std::string>()) + "</span></p></div>";
if (fixture.at("owners").size() > 1)
out += btn("live-owner-prev", "‹", "mv-ic", "id=\"live-owner-prev\" aria-label=\"Vorheriger Manager\"") + btn("live-owner-next", "›", "mv-ic", "id=\"live-owner-next\" aria-label=\"Nächster Manager\"");
out += "</header><div class=\"mv-box\"><nav class=\"mv-tabs\">";
for (const auto &[id, label] : std::array<std::pair<const char *, const char *>, 5>{{{"team", "Team"}, {"tactics", "Taktik"}, {"opponent", recorded ? "Ergebnisse" : "Gegner"}, {"table", "Tabelle"}, {"stats", "Statistik"}}}) out += tab("live-tab", id, label, live_tab_ == id, "live-tab-");
out += "</nav><div class=\"mv-in\"><div id=\"live-detail-body\" class=\"mv-scroll\" tabindex=\"0\">" + live_detail(owner, frame) + "</div><footer class=\"mv-foot\"><span>" +
esc(live_.running() ? "Das Spiel steht, solange du eingreifst." : "") + "</span>" +
btn("live-intervene-lineup", "Aufstellung &amp; Wechsel", "mv-btn sm", "id=\"live-lineup-edit\" " + std::string(live_.finished() || (recorded && !live_.running()) ? "disabled" : "")) + "</footer></div></div></aside></div>";
out += "<footer class=\"mv-bar\">" + btn("live-back", live_.running() ? "Zu Ende spielen" : recorded ? "Zum Schreibtisch" : "Zum Desktop", "mv-btn", "id=\"live-back\"") +
btn("live-pause", live_.speed() ? "Pause" : "Abspielen", "mv-btn play", "id=\"live-pause\" " + std::string(live_.finished() ? "disabled" : ""));
out += "<div id=\"live-speed\" class=\"mv-seg\" role=\"group\" aria-label=\"Tempo\">";
for (int step = 0; step <= 4; ++step)
out += btn("live-speed-set", step ? std::to_string(step) + "×" : std::string("II"), live_.speed() == step ? "selected" : "",
"id=\"live-speed-" + std::to_string(step) + "\" data-id=\"" + std::to_string(step) + "\" aria-pressed=\"" + (live_.speed() == step ? "true" : "false") + "\" aria-label=\"" +
(step ? "Tempo " + std::to_string(step) : std::string("Pause")) + "\" " + (live_.finished() ? "disabled" : ""));
out += "</div>";
if (live_.running()) {
const auto halt = [](const char *id, const char *label, bool on) {
return btn("live-halt", "<span class=\"tr\"><span class=\"kn\"></span></span><span class=\"lb\">" + std::string(label) + "</span>", std::string("mv-sw") + (on ? " selected" : ""),
"id=\"live-halt-" + std::string(id) + "\" data-id=\"" + id + "\" aria-pressed=\"" + (on ? "true" : "false") + "\"");
};
out += halt("interval", "Zur Halbzeit anhalten", live_halt_interval_) + halt("behind", "Bei Rückstand anhalten", live_halt_behind_);
}
out += "<span id=\"live-playback-status\" class=\"mv-status\">" + esc(live_feedback_.empty() ? (recorded ? std::string() : std::string(phase_text) + " · " + std::to_string(minute) + "′ · keine Spielwertänderung") : live_feedback_) + "</span>" +
btn(live_.finished() ? "live-review" : "live-next", live_.finished() ? "Zur Auswertung" : live_.running() ? "Nächste Minute" : "Nächste Meldung", "mv-btn primary", "id=\"" + std::string(live_.finished() ? "live-review" : "live-next") + "\"") + "</footer>";
return out + (over.empty() ? live_dialog_markup(owner) : over) + "</section>";
}
void App::live_after_render() {
if(live_review_){postmatch_after_render();return;}
if (scene_ != "live" || !live_restore_scroll_) return;
live_restore_scroll_ = false;
if (auto *node = element("live-ticker")) node->SetScrollTop(live_ticker_scroll_);
if (auto *node = element("live-detail-body")) node->SetScrollTop(live_detail_scroll_);
if (!live_dialog_.empty()) {
Rml::ElementList controls; doc_->QuerySelectorAll(controls, "#live-underlay button,#live-stage .mv-bar button");
for (auto *node : controls) { node->SetProperty("pointer-events", "none"); node->SetAttribute("tabindex", "-1"); }
}
}
// Apply local navigation only after event dispatch. The untouched match cards,
// ticker and speed input retain their DOM identity, focus and pointer capture.
void App::live_update_parts() {
if (!live_detail_pending_ && !live_ticker_pending_ && focus_after_render_.empty()) return;
if (scene_ != "live" || live_review_ || !live_.available() ||
!live_dialog_.empty() || !popup_.empty()) {
live_detail_pending_ = live_ticker_pending_ = false;
return;
}
const auto frame = live_.frame();
if (live_detail_pending_) {
const auto owner = live_owner();
auto *body = element("live-detail-body");
auto *team = element("live-owner-team");
auto *name = element("live-owner-name");
if (!body || !team || !name) { refresh(); return; }
team->SetInnerRML(esc(owner.at("team").at("name").get<std::string>()));
name->SetInnerRML(esc(owner.at("name").get<std::string>()));
body->SetInnerRML(live_detail(owner, frame));
body->SetScrollTop(0); live_detail_scroll_ = 0; live_reset_detail_ = false;
Rml::ElementList tabs; doc_->QuerySelectorAll(tabs, "#live-detail .mv-tab");
for (auto *tab : tabs) {
const bool selected = tab->GetAttribute<Rml::String>("data-id", "") == live_tab_;
tab->SetClass("selected", selected); tab->SetAttribute("aria-pressed", selected ? "true" : "false");
}
++live_detail_updates_;
}
if (live_ticker_pending_) {
auto *list = element("live-ticker"); auto *count = element("live-event-count");
if (!list || !count) { refresh(); return; }
size_t shown = 0; list->SetInnerRML(live_ticker_events(frame, shown));
count->SetInnerRML(esc(std::to_string(shown) + (shown == 1 ? " Meldung" : " Meldungen")));
list->SetScrollTop(0); live_ticker_scroll_ = 0; live_reset_ticker_ = false;
Rml::ElementList filters; doc_->QuerySelectorAll(filters, "#live-filters .mv-tab");
for (auto *filter : filters)
{
const bool selected = filter->GetAttribute<Rml::String>("data-id", "") == live_filter_;
filter->SetClass("selected", selected); filter->SetAttribute("aria-pressed", selected ? "true" : "false");
}
++live_ticker_updates_;
}
live_detail_pending_ = live_ticker_pending_ = false;
if (!focus_after_render_.empty()) {
if (auto *node = element(focus_after_render_)) node->Focus(keyboard_navigation_);
focus_after_render_.clear();
}
dirty_ = true;
}