Port native season calendar and harden menu input QA (by Codex)
This commit is contained in:
1 parent
79bf38aa78
commit
de8b53fce2
19 files changed
+582
-14
No files matched your search
@@ -36,6 +36,19 @@ struct Renderer final : Rml::RenderInterface {
|
||||
void EnableScissorRegion(bool) override {}
|
||||
void SetScissorRegion(Rml::Rectanglei) override {}
|
||||
};
|
||||
struct System final : Rml::SystemInterface {
|
||||
size_t stylesheet_errors = 0;
|
||||
bool LogMessage(Rml::Log::Type type, const Rml::String &message) override {
|
||||
if ((type == Rml::Log::LT_WARNING || type == Rml::Log::LT_ERROR) &&
|
||||
(message.find("property") != message.npos ||
|
||||
message.find("style") != message.npos ||
|
||||
message.find("Syntax error") != message.npos)) {
|
||||
++stylesheet_errors;
|
||||
std::cerr << message << '\n';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
void text_centers(Rml::Element &node, float cx, float cy, bool horizontal,
|
||||
size_t &lines) {
|
||||
if (auto *text = dynamic_cast<Rml::ElementText *>(&node)) {
|
||||
@@ -72,7 +85,7 @@ int main(int argc, char **argv) try {
|
||||
require(argc == 2, "Pass the Modern asset directory");
|
||||
const auto root = std::filesystem::path(argv[1]);
|
||||
Renderer renderer;
|
||||
Rml::SystemInterface system;
|
||||
System system;
|
||||
Rml::SetRenderInterface(&renderer);
|
||||
Rml::SetSystemInterface(&system);
|
||||
require(Rml::Initialise(), "Rml initialization");
|
||||
@@ -84,9 +97,13 @@ int main(int argc, char **argv) try {
|
||||
Rml::Style::FontStyle::Normal,
|
||||
Rml::Style::FontWeight::Bold),
|
||||
"Bold font missing");
|
||||
std::ifstream input(root / "theme.rcss");
|
||||
std::ostringstream css;
|
||||
css << input.rdbuf();
|
||||
for (const auto *name : {"theme.rcss", "ticket.rcss", "sports.rcss",
|
||||
"calendar.rcss"}) {
|
||||
std::ifstream input(root / name);
|
||||
require(bool(input), "Production stylesheet missing");
|
||||
css << input.rdbuf() << '\n';
|
||||
}
|
||||
for (const auto *theme : {"midnight", "silver", "matchday"})
|
||||
for (float density : {1.f / 3, .5f, 1.f, 2.f}) {
|
||||
auto *context = Rml::CreateContext(
|
||||
@@ -136,6 +153,8 @@ int main(int argc, char **argv) try {
|
||||
"<rml><head><style>" + css.str() + "</style></head><body class='" +
|
||||
theme + "'>" + content + "</body></rml>");
|
||||
require(doc, "Document missing");
|
||||
require(system.stylesheet_errors == 0,
|
||||
"Rml rejected a production stylesheet declaration");
|
||||
doc->Show();
|
||||
context->Update();
|
||||
context->Render();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/demo_sports.hpp"
|
||||
#include "modern/ui/demo_calendar.hpp"
|
||||
#include "modern/ui/desktop.hpp"
|
||||
#include "modern/ui/gui_assets.hpp"
|
||||
#include "modern/ui/model.hpp"
|
||||
@@ -251,17 +252,85 @@ int main(int argc, char **argv) try {
|
||||
auto legacy = Json::parse(bmh::editor::read_file(root / "sports.ui.json"));
|
||||
legacy.erase("training");
|
||||
legacy.erase("tactics");
|
||||
legacy.erase("calendar");
|
||||
write(root, "legacy-ui.json", legacy);
|
||||
restored_sports.load(root / "legacy-ui.json");
|
||||
require(valid_demo_training(restored_sports.snapshot().state["training"],
|
||||
*world, "club:a"),
|
||||
"Older UI checkpoint did not migrate safely");
|
||||
require(valid_demo_calendar(restored_sports.snapshot().state["calendar"],
|
||||
*world),
|
||||
"Older UI checkpoint lost its season calendar");
|
||||
for (const auto *theme : {"midnight", "silver", "matchday"}) {
|
||||
const auto diagram = bmh::editor::images::decode(
|
||||
tactics_diagram(demo_tactics(), theme), ".svg", 256);
|
||||
require(diagram.width == 256 && diagram.height > 0,
|
||||
"Tactic SVG failed to decode");
|
||||
}
|
||||
const auto leap_days = calendar_days("2027-07-01");
|
||||
require(leap_days.size() == 366 && leap_days.front().weekday == 3 &&
|
||||
leap_days.back().iso == "2028-06-30" &&
|
||||
std::count_if(leap_days.begin(), leap_days.end(), [](const auto &d) {
|
||||
return d.iso == "2028-02-29";
|
||||
}) == 1,
|
||||
"Season dates lost weekday alignment or leap day");
|
||||
require(calendar_days("2026-07-01").size() == 365 &&
|
||||
calendar_days("2099-07-01").size() == 365 &&
|
||||
calendar_days("0000-07-01").empty() &&
|
||||
calendar_days("2027-06-01").empty(),
|
||||
"Season date validation or Gregorian century handling failed");
|
||||
auto calendar_clubs = world->rows("clubs");
|
||||
for (int i = 1; i < 20; ++i) {
|
||||
if (i < 18)
|
||||
calendar_clubs.push_back({{"id", "club:home" + std::to_string(i)},
|
||||
{"name", "Home " + std::to_string(i)},
|
||||
{"nation", "nation:de"},
|
||||
{"competition", "comp:home"}});
|
||||
calendar_clubs.push_back({{"id", "club:other" + std::to_string(i)},
|
||||
{"name", "Other " + std::to_string(i)},
|
||||
{"nation", "nation:other"},
|
||||
{"competition", "comp:other"}});
|
||||
}
|
||||
table(root, "clubs", calendar_clubs);
|
||||
auto calendar_world = Catalog::open(root);
|
||||
DemoSource calendar_source(calendar_world);
|
||||
auto calendar = calendar_source.snapshot().state.at("calendar");
|
||||
const auto fixtures = calendar_fixtures(calendar, *calendar_world, "club:a");
|
||||
require(fixtures.size() == 34, "Eighteen-team season needs 34 preview rounds");
|
||||
std::map<std::string, int> opponents;
|
||||
std::set<int> occupied;
|
||||
for (const auto &fixture : fixtures) {
|
||||
require(fixture.home == "club:a" || fixture.away == "club:a",
|
||||
"Calendar fixture belongs to another career club");
|
||||
require(fixture.home != fixture.away && occupied.insert(fixture.day).second,
|
||||
"Preview generated self match or duplicate date");
|
||||
++opponents[fixture.home == "club:a" ? fixture.away : fixture.home];
|
||||
}
|
||||
require(opponents.size() == 17 &&
|
||||
std::all_of(opponents.begin(), opponents.end(), [](const auto &p) {
|
||||
return p.second == 2;
|
||||
}),
|
||||
"Preview must show two meetings per opponent");
|
||||
const auto original_calendar = calendar_source.snapshot();
|
||||
require(!calendar_source.apply({0, "calendar", {{"kind", "select"}, {"value", -1}}}).ok &&
|
||||
!calendar_source.apply({0, "calendar", {{"kind", "select"}, {"value", 365}}}).ok &&
|
||||
!calendar_source.apply({0, "calendar", {{"kind", "select"}, {"value", 1.5}}}).ok &&
|
||||
calendar_source.snapshot().state == original_calendar.state &&
|
||||
calendar_source.snapshot().revision == 0,
|
||||
"Invalid calendar selection mutated the demo");
|
||||
require(calendar_source.apply({0, "calendar", {{"kind", "select"}, {"value", 30}}}).ok &&
|
||||
calendar_source.apply({1, "calendar", {{"kind", "league"}, {"value", "comp:other"}}}).ok,
|
||||
"Calendar day or foreign preview league selection failed");
|
||||
calendar = calendar_source.snapshot().state.at("calendar");
|
||||
require(calendar_fixtures(calendar, *calendar_world, "club:a").size() == 38 &&
|
||||
calendar["selected"] == 30 &&
|
||||
calendar_source.snapshot().state["managers"] == original_calendar.state["managers"],
|
||||
"Foreign calendar preview changed selection or career identity");
|
||||
calendar_source.save(root / "calendar.ui.json", default_desktop());
|
||||
DemoSource restored_calendar(calendar_world);
|
||||
restored_calendar.load(root / "calendar.ui.json");
|
||||
require(restored_calendar.snapshot().state["calendar"] == calendar,
|
||||
"Calendar selection was lost on process restoration");
|
||||
GuiAssets absent(root / "missing-gui");
|
||||
require(!absent.available(),
|
||||
"World resources were mistaken for GUI resources");
|
||||
|
||||
Reference in new issue
Block a user