Bind native desk and training camps to Modern OBS careers (by Codex)
This commit is contained in:
1 parent
1fb6499b15
commit
85a1fe5a95
19 files changed
+733
-46
No files matched your search
@@ -0,0 +1,102 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
namespace {
|
||||
std::string engine_text(const Json &v) {
|
||||
return v.is_string() ? v.get<std::string>() : v.is_object() ? v.value("text", "") : "—";
|
||||
}
|
||||
std::string engine_price(const Json &v) {
|
||||
return money(engine_money_minor(v), {{"code", "EUR"}, {"minor_units", 2}});
|
||||
}
|
||||
}
|
||||
Json App::engine_camp_view() const {
|
||||
const auto art = Json::parse(editor::read_file(gui_.root() / "gui-assets.json")).at("demo");
|
||||
const auto &data = engine_data_.at("camps").at("data");
|
||||
Json camps = Json::array(), maps = Json::array();
|
||||
for (const auto &map : data.at("maps"))
|
||||
maps.push_back({{"id", map.at("id")}, {"name", engine_text(map.at("name"))}});
|
||||
for (const auto &item : data.at("camps")) {
|
||||
const auto &q = item.at("quality");
|
||||
Json camp = {{"id", item.at("id")}, {"map", item.at("mapId")},
|
||||
{"name", engine_text(item.at("name"))}, {"place", item.at("place")},
|
||||
{"quality", {q.at("pitch"), q.at("fitness"), q.at("catering"), q.at("lodging")}},
|
||||
{"price", nullptr}, {"gui_image", ""}, {"positioned", false}};
|
||||
// GUI placement is presentation metadata only. Never copy prices, quality,
|
||||
// focus or booking rules from the GUI resource catalogue into a real career.
|
||||
for (const auto &ref : art.at("training_camps"))
|
||||
if (ref.at("id") == item.at("id") && ref.at("map") == item.at("mapId")) {
|
||||
camp["x"] = ref.at("x"); camp["y"] = ref.at("y"); camp["positioned"] = true;
|
||||
}
|
||||
if (item.at("position").is_object()) {
|
||||
camp["x"] = item.at("position").at("x"); camp["y"] = item.at("position").at("y"); camp["positioned"] = true;
|
||||
}
|
||||
auto image = item.value("guiImageKey", "");
|
||||
if (image.starts_with("gui:camp/")) camp["gui_image"] = "camp." + image.substr(9);
|
||||
if (item.at("quote").is_object()) camp["price"] = engine_money_minor(item.at("quote").at("total"));
|
||||
camps.push_back(std::move(camp));
|
||||
}
|
||||
return {{"maps", maps}, {"training_camps", camps}};
|
||||
}
|
||||
void App::engine_render() {
|
||||
doc_->SetClassNames(theme_);
|
||||
std::string out;
|
||||
if (engine_data_.empty()) {
|
||||
out = "<div class=\"fill center\"><div class=\"panel\" style=\"padding:70dp;\"><h1>OpenBMH</h1><p>" +
|
||||
esc(engine_busy_ ? "Spielstand wird geladen …" : engine_notice_) + "</p></div></div>";
|
||||
} else {
|
||||
const auto &desk = engine_data_.at("desktop").at("data"), &meta = engine_data_.at("desktop").at("meta");
|
||||
const auto &team = desk.at("team"), &person = desk.at("manager");
|
||||
const auto *club = world_->find("clubs", team.at("id").get<std::string>());
|
||||
out = "<div class=\"desktop-layer\"><div class=\"info-bar\"><div class=\"identity\">" + crest(club, 82) +
|
||||
"<span><strong>" + esc(engine_text(team.at("name"))) + "</strong><small>" + esc(engine_text(person.at("name"))) +
|
||||
"</small></span></div><div class=\"info-date\">" + esc(meta.at("date").get<std::string>()) + "<small>" +
|
||||
esc(meta.at("season").at("label").get<std::string>()) + "</small></div><div class=\"info-cash\"><small>Guthaben</small><strong id=\"engine-cash\">" +
|
||||
esc(engine_price(desk.at("accounts").at("cash"))) + "</strong></div></div>";
|
||||
init_desktop();
|
||||
for (const auto &[id, o] : desktop_.at("objects").items()) {
|
||||
if (!o.value("visible", false)) continue;
|
||||
const auto style = rect(o.at("x"), o.at("y"), o.at("w"), o.at("h"));
|
||||
if (o.value("widget", false)) {
|
||||
std::string body;
|
||||
if (id == "portrait") {
|
||||
auto portrait = person.value("portraitGuiKey", "");
|
||||
if (portrait.starts_with("gui:manager/photo/"))
|
||||
body = img("manager." + portrait.substr(18), o.at("w"), o.at("h"), false, false, 768);
|
||||
body += "<div class=\"desk-portrait-caption\"><small>Manager</small><strong>" + esc(person.at("name").get<std::string>()) + "</strong></div>";
|
||||
} else if (id == "calendar") {
|
||||
const auto date = meta.at("date").get<std::string>();
|
||||
const int y = std::stoi(date.substr(0, 4)), m = std::stoi(date.substr(5, 2)), d = std::stoi(date.substr(8, 2));
|
||||
const auto ymd = std::chrono::year_month_day{std::chrono::year(y), std::chrono::month(unsigned(m)), std::chrono::day(unsigned(d))};
|
||||
if (!ymd.ok()) throw editor::Error("Ungültiges Engine-Datum.");
|
||||
const std::array<const char *, 12> months{"Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"};
|
||||
const std::array<const char *, 7> weekdays{"Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"};
|
||||
body = "<div class=\"desk-calendar-month\"><span>" + std::string(months[size_t(m - 1)]) + " " + std::to_string(y) + "</span></div><div class=\"desk-calendar-body\"><span>" + weekdays[std::chrono::weekday{std::chrono::sys_days(ymd)}.c_encoding()] + "</span><strong>" + std::to_string(d) + "</strong><small>" + esc(meta.at("season").at("label").get<std::string>()) + "</small></div>";
|
||||
} else if (id == "account") {
|
||||
const auto savings = desk.at("accounts").at("savings");
|
||||
body = widget_heading("Vereinskasse", false) + "<div class=\"desk-account-main\"><span>Guthaben</span><strong>" + esc(engine_price(desk.at("accounts").at("cash"))) + "</strong></div><div class=\"desk-account-bottom\"><div><span>Sparbuch</span><strong>" + (savings.is_null() ? std::string("—") : esc(engine_price(savings))) + "</strong></div>" + btn("engine-unavailable", glyph("ticket", 36) + "<span><span>Eintritt</span><strong>—</strong></span>", "desk-ticket", "disabled") + "</div>";
|
||||
} else if (id == "opponent-crest" && desk.at("nextFixture").is_object()) {
|
||||
const auto &next = desk.at("nextFixture");
|
||||
const auto &other = next.at(next.at("home").at("id") == team.at("id") ? "away" : "home");
|
||||
body = widget_heading("Nächster Gegner", false) + "<div class=\"center\" style=\"padding:30dp;\">" + crest(world_->find("clubs", other.at("id").get<std::string>()), 220) + "<p>" + esc(engine_text(other.at("name"))) + "</p></div>";
|
||||
}
|
||||
if (!body.empty()) out += "<div class=\"desktop-card desk-card\" style=\"" + style + "\">" + body + "</div>";
|
||||
} else {
|
||||
const auto route = id.substr(4);
|
||||
const bool camp_allowed = desk.at("menuAvailability").at("camps").value("status", "") == "available";
|
||||
const auto commands = meta.at("scope").value("allowedCommands", Json::array());
|
||||
const bool supported = route == "save" || (route == "camp" && engine_fresh_ && camp_allowed && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end());
|
||||
out += desktop_button(id, o, "engine-open", supported && !engine_busy_);
|
||||
}
|
||||
}
|
||||
out += "</div>";
|
||||
if (menu_ == "camp") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Trainingslager", render_camp()) + "</div>";
|
||||
}
|
||||
if (menu_.empty() || engine_data_.empty()) out += "<div class=\"panel\" style=\"position:absolute;left:850dp;bottom:24dp;right:100dp;padding:18dp;font-size:27dp;\" id=\"engine-status\">" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "</div>";
|
||||
element("canvas")->SetInnerRML(out); ++document_generation_;
|
||||
const auto size = context_->GetDimensions();
|
||||
element("background")->SetInnerRML(img("background", size.x / scale_, size.y / scale_, false, true, 2048));
|
||||
element("background")->SetProperty("filter", theme_ == "silver" ? "saturate(0.2) brightness(0.9)" : theme_ == "matchday" ? "saturate(0.13) brightness(0.56)" : "saturate(0.34) brightness(0.70)");
|
||||
if (engine_busy_) {
|
||||
Rml::ElementList controls; doc_->QuerySelectorAll(controls, "#canvas button,#canvas input");
|
||||
for (auto *node : controls) node->SetAttribute("disabled", true);
|
||||
}
|
||||
needs_render_ = false; dirty_ = true;
|
||||
}
|
||||
Reference in new issue
Block a user