// Tool cursors (ui/cursors.hpp): the .scur loader decodes the extracted original cursor art, and every build // tool that should have a distinctive cursor maps to a present resource. Skips the decode checks if the // cursors haven't been extracted (extract_cursors.py), but always checks the pure tool->id map. #include "sc2k/ui/cursors.hpp" #include "sc2k/render/asset_loader.hpp" #include using namespace sc2k; #include "test_harness.hpp" int main() { // The pure map — AUTHORITATIVE values from the original's tool→cursor tables. CHECK(ui::cursor_id_for_tool(ui::Tool::Bulldoze) == 1002); // group 0 (NOT the train — that's Rail) CHECK(ui::cursor_id_for_tool(ui::Tool::Trees) == 1003); CHECK(ui::cursor_id_for_tool(ui::Tool::ZoneR) == 1004); CHECK(ui::cursor_id_for_tool(ui::Tool::ZoneC) == 1005); CHECK(ui::cursor_id_for_tool(ui::Tool::ZoneI) == 1006); CHECK(ui::cursor_id_for_tool(ui::Tool::PowerLine) == 1008); CHECK(ui::cursor_id_for_tool(ui::Tool::Water) == 1016); CHECK(ui::cursor_id_for_tool(ui::Tool::Pipe) == 1019); CHECK(ui::cursor_id_for_tool(ui::Tool::Road) == 1021); // group 6 (NOT 1017 = river) CHECK(ui::cursor_id_for_tool(ui::Tool::Rail) == 1022); // group 7 locomotive CHECK(ui::cursor_id_for_tool(ui::Tool::Query) == 1023); CHECK(ui::cursor_id_for_tool(ui::Tool::Seaport) == 1025); CHECK(ui::cursor_id_for_tool(ui::Tool::Sign) == 1027); CHECK(ui::cursor_id_for_tool(ui::Tool::Dispatch) == 1028); CHECK(ui::cursor_id_for_tool(ui::Tool::Center) == 1011); CHECK(ui::cursor_id_for_tool(ui::Tool::RaiseTerrain) == 1012); // Tool::Building resolves by the building's group: police (210) → protection 1020, school (214) → 1007. CHECK(ui::cursor_id_for_tool(ui::Tool::Building, 210) == 1020); CHECK(ui::cursor_id_for_tool(ui::Tool::Building, 214) == 1007); CHECK(ui::cursor_id_for_tool(ui::Tool::None) == 0); CHECK(ui::cursor_id_for_context(ui::Tool::Trees, 0, true, false) == 1003); // persists without a hover hit CHECK(ui::cursor_id_for_context(ui::Tool::Trees, 0, true, true) == 0); // modal dialog restores arrow CHECK(ui::cursor_id_for_context(ui::Tool::Trees, 0, false, false) == 0); // front-end shell uses arrow int custom = 0; for (int i = 0; i < 28; ++i) if (ui::cursor_id_for_tool(static_cast(i)) != 0) ++custom; CHECK(custom >= 18); // "custom cursors for a lot of the tools" // Decode the real extracted art, if present. const std::string dir = render::classic_assets_dir() + "/cursors"; if (!std::ifstream(dir + "/cur_1002.scur").good()) { std::printf("cursors: map OK; SKIP decode (run extract_cursors.py)\n"); return failures ? 1 : 0; } for (int id : {1002, 1004, 1008, 1016, 1023, 1025}) { const ui::CursorImage c = ui::load_cursor(dir + "/cur_" + std::to_string(id) + ".scur"); CHECK(c.ok()); // decoded to w*h*4 RGBA CHECK(c.w == 32 && c.h == 32); // SC2K cursors are 32×32 CHECK(c.hotX >= 0 && c.hotX < c.w && c.hotY >= 0 && c.hotY < c.h); long opaque = 0; for (std::size_t i = 3; i < c.rgba.size(); i += 4) if (c.rgba[i]) ++opaque; CHECK(opaque > 50); // the cursor isn't blank (it drew something) if (std::ifstream(dir + "/cur_" + std::to_string(id) + ".png").good()) { const ui::CursorImage png = ui::load_cursor_from_directory(dir, id); CHECK(png.ok() && png.w == c.w && png.h == c.h && png.hotX == c.hotX && png.hotY == c.hotY); CHECK(png.rgba == c.rgba); } } // A missing/garbage file must fail safely (empty image → caller falls back to the arrow). CHECK(!ui::load_cursor(dir + "/does_not_exist.scur").ok()); if (failures == 0) { std::printf("cursors: all checks passed\n"); return 0; } std::printf("cursors: %d failure(s)\n", failures); return 1; }