Pitch photographs lie behind the match sheet; a managed ground shows how full it is
The stadium pictures give way to nine photographs of the pitch, used unscaled. The live read carries the capacity of a managed home ground. The manager's eleven stays on the team page after the final whistle, and the cards of two to four matches keep their grid. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
13f5b1e4d4
commit
20b8406763
42 files changed
+73
-213
No files matched your search
@@ -126,8 +126,9 @@ std::string App::live_weather_icon(int code, double size) {
|
||||
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: a ground of about the crowd's size in about this
|
||||
// weather. Empty when the match is played in a hall or the pictures are not installed.
|
||||
// The picture behind the match sheet: one of the pitch photographs. The home club keeps its
|
||||
// picture; in rain or snow it is the wet pitch at dusk. Empty when the match is played in a
|
||||
// hall or the pictures are not installed.
|
||||
std::string App::live_backdrop() const {
|
||||
if (scene_ != "live" || !live_.available()) return {};
|
||||
try {
|
||||
@@ -137,35 +138,17 @@ std::string App::live_backdrop() const {
|
||||
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;
|
||||
const int64_t crowd = match->contains("attendance") && match->at("attendance").is_number_integer() ? match->at("attendance").get<int64_t>() : 20000;
|
||||
const int size = crowd < 8000 ? 0 : crowd < 20000 ? 1 : crowd < 40000 ? 2 : 3;
|
||||
int code = 2;
|
||||
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>();
|
||||
// the eight weather pictures as five kinds of sky: sun, fair, cloud, rain, snow
|
||||
static constexpr std::array<int, 8> kSky{0, 1, 2, 2, 3, 3, 4, 4};
|
||||
const int sky = kSky[size_t(std::clamp(code, 0, 7))];
|
||||
struct Ground { int size, sky; const char *key; };
|
||||
static constexpr std::array<Ground, 24> grounds{{
|
||||
{0, 0, "match.0-sun-a"}, {0, 2, "match.0-cloud-a"}, {0, 3, "match.0-rain-a"},
|
||||
{1, 0, "match.1-sun-a"}, {1, 0, "match.1-sun-b"}, {1, 0, "match.1-sun-c"}, {1, 1, "match.1-fair-a"}, {1, 1, "match.1-fair-b"},
|
||||
{1, 2, "match.1-cloud-a"}, {1, 2, "match.1-cloud-b"}, {1, 3, "match.1-rain-a"}, {1, 4, "match.1-snow-a"}, {1, 4, "match.1-snow-b"},
|
||||
{2, 0, "match.2-sun-a"}, {2, 0, "match.2-sun-b"}, {2, 0, "match.2-sun-c"}, {2, 1, "match.2-fair-a"},
|
||||
{3, 1, "match.3-fair-a"}, {3, 1, "match.3-fair-b"}, {3, 1, "match.3-fair-c"}, {3, 2, "match.3-cloud-a"},
|
||||
{3, 3, "match.3-rain-a"}, {3, 3, "match.3-rain-b"}, {3, 4, "match.3-snow-a"}}};
|
||||
// the nearest in size and sky; among equals the home club keeps its ground
|
||||
int best = 99;
|
||||
std::vector<const char *> nearest;
|
||||
for (const auto &ground : grounds) {
|
||||
if (!gui_.contains(ground.key)) continue;
|
||||
const int cost = std::abs(ground.size - size) + std::abs(ground.sky - sky);
|
||||
if (cost < best) { best = cost; nearest.clear(); }
|
||||
if (cost == best) nearest.push_back(ground.key);
|
||||
}
|
||||
if (nearest.empty()) return {};
|
||||
if (code >= 4 && gui_.contains("match.pitch-2")) return "match.pitch-2";
|
||||
std::vector<std::string> fair;
|
||||
for (const int number : {1, 3, 4, 5, 6, 7, 8, 9})
|
||||
if (const std::string key = "match.pitch-" + std::to_string(number); gui_.contains(key)) fair.push_back(key);
|
||||
if (fair.empty()) return {};
|
||||
size_t hash = 2166136261u;
|
||||
for (const unsigned char c : match->at("home").at("id").get<std::string>()) hash = (hash ^ c) * 16777619u;
|
||||
return nearest[hash % nearest.size()];
|
||||
return fair[hash % fair.size()];
|
||||
} catch (const std::exception &) { return {}; }
|
||||
}
|
||||
// Played in a hall: the fixture says so, or the engine named the competition a hall tournament.
|
||||
@@ -606,8 +589,16 @@ std::string App::live_sheet(const std::string &over) {
|
||||
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 ? "Halle" : "Stadion")) + "</span><span class=\"big\">" + esc(crowd) +
|
||||
"</span><span class=\"sub\">" + esc("Heimspiel von " + match->at("home").at("name").get<std::string>()) + "</span></div>";
|
||||
"</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());
|
||||
|
||||
Reference in new issue
Block a user