Something went wrong. Try again.
[Mirror] Libreopolis is a cross-platform city simulation game fully compatible with SimCity 2000. gitlab.com/conasg/libreopolis
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171// City Industry window data and deterministic chart geometry. The raw-table KAT is verified against// LONDON when installed; the synthetic fixture proves ratio, tax, signed-demand, localization, and// framebuffer presentation without depending on classic data.#include "sc2k/io/sc2_file.hpp"#include "sc2k/render/asset_loader.hpp"#include "sc2k/ui/industry_view.hpp"#include <cstdio>#include <fstream>#include <iterator>#include <string>
#include "test_harness.hpp"#include "test_paths.hpp"int main() { using namespace sc2k; i18n::load_locale(render::assets_dir() + "/lang", "en"); // sector names are catalog keys CHECK(std::string(ui::industry_name(0)) == "Steel/Mining"); CHECK(std::string(ui::industry_name(9)) == "Electronics"); CHECK(std::string(ui::industry_name(10)) == "Tourism");
City fixture; for (int index = 0; index < ui::kIndustrySectorCount; ++index) { fixture.set_misc_be32(misc::kIndustryPop + misc::kIndustryStride * index, (index + 1) * 100); fixture.set_misc_be32(misc::kIndustryTax + misc::kIndustryStride * index, 5 + index % 3); fixture.set_misc_be32(misc::kIndustryDemand + misc::kIndustryStride * index, -50 + index * 10); } const ui::IndustryViewModel fixtureView = ui::industry_view_model(fixture); CHECK(fixtureView.totalPopulation == 6600); CHECK(fixtureView.largestSector == 10); CHECK(fixtureView.averageTaxBasisPoints == 590); CHECK(fixtureView.lowestTaxSector == 0 && fixtureView.highestTaxSector == 2); CHECK(fixtureView.weakestDemandSector == 0 && fixtureView.strongestDemandSector == 10 && fixtureView.hasDemand); CHECK(ui::industry_share_basis_points(fixtureView, 10) == 1666); CHECK(ui::industry_chart_value_label(fixtureView, 0, 10) == "16.66% · 1,100"); CHECK(ui::industry_chart_value_label(fixtureView, 1, 10) == "6%"); CHECK(ui::industry_chart_value_label(fixtureView, 2, 10) == "+50");
CHECK(ui::industry_nice_step(1) == 1); CHECK(ui::industry_nice_step(17) == 20); CHECK(ui::industry_nice_step(334) == 500); CHECK(ui::industry_chart_axis(fixtureView, 0) == (ui::IndustryChartAxis{0, 2500, 500})); CHECK(ui::industry_chart_axis(fixtureView, 1) == (ui::IndustryChartAxis{0, 10, 2})); CHECK(ui::industry_chart_axis(fixtureView, 2) == (ui::IndustryChartAxis{-50, 50, 10}));
const ui::IndustryChartGeometry geometry = ui::industry_chart_geometry(700, 440); CHECK(geometry.rowsY == 43 && geometry.rowHeight == 28); CHECK(geometry.plotX == 170 && geometry.plotWidth == 414); CHECK(geometry.valueX == 592 && geometry.valueWidth == 108); CHECK(geometry.summaryY == 366 && geometry.summaryHeight == 64); const ui::IndustryChartGeometry hidpiGeometry = ui::industry_chart_geometry(1400, 880); CHECK(hidpiGeometry.rowsY == 86 && hidpiGeometry.rowHeight == 56); CHECK(hidpiGeometry.plotX == 340 && hidpiGeometry.plotWidth == 828); CHECK(hidpiGeometry.summaryY == 732 && hidpiGeometry.summaryHeight == 128); const ui::IndustryChartAxis demandAxis = ui::industry_chart_axis(fixtureView, 2); CHECK(ui::industry_chart_x(geometry, demandAxis, 0) == 377); CHECK(ui::industry_bar_geometry(geometry, demandAxis, -50) == (ui::IndustryBarGeometry{170, 207})); CHECK(ui::industry_bar_geometry(geometry, demandAxis, 50) == (ui::IndustryBarGeometry{377, 207}));
std::ifstream documentInput(render::assets_dir() + "/rml/industry.rml"); const std::string document((std::istreambuf_iterator<char>(documentInput)), std::istreambuf_iterator<char>()); std::ifstream styleInput(render::assets_dir() + "/rml/data_window.rcss"); const std::string style((std::istreambuf_iterator<char>(styleInput)), std::istreambuf_iterator<char>()); const std::size_t tabsPosition = document.find("class=\"industry-tabs chrome-tabs\""); const std::size_t surfacePosition = document.find("id=\"surface\""); CHECK(document.find("href=\"chrome.rcss\"") != std::string::npos); CHECK(tabsPosition != std::string::npos && tabsPosition < surfacePosition); CHECK(document.find("data-select=\"industry-tab\"") != std::string::npos); CHECK(document.find("class=\"data-hits\"") == std::string::npos); CHECK(style.find("body.industry {\n\twidth: 720dp;") != std::string::npos); CHECK(style.find("body.industry div.data-surface {\n\tbox-sizing: border-box;\n\twidth: 100%;\n\theight: 440dp;") != std::string::npos);
const std::string fontPath = render::assets_dir() + "/fonts/NotoSans-Regular.ttf"; if (exists(fontPath)) { ui::Font font(fontPath, 15); render::Framebuffer frame(700, 440); ui::draw_industry_chart(frame, font, fixtureView, 0); const int firstRowY = geometry.rowsY + 6; CHECK(frame.at(geometry.plotX + 5, firstRowY + 2) == ui::industry_bar_color(0, 1)); CHECK(frame.at(geometry.plotX, geometry.rowsY) == ui::kIndustrySurface); CHECK(frame.at(geometry.summaryX + 1, geometry.summaryY + 5) == ui::industry_bar_color(0, 1)); CHECK(frame.at(geometry.summaryX + 5, geometry.summaryY + 5) == ui::kIndustrySummary);
ui::draw_industry_chart(frame, font, fixtureView, 2); CHECK(frame.at(geometry.plotX + 5, firstRowY + 2) == ui::industry_bar_color(2, -50)); const int lastRowY = geometry.rowsY + 10 * geometry.rowHeight + 6; CHECK(frame.at(geometry.plotX + geometry.plotWidth - 5, lastRowY + 2) == ui::industry_bar_color(2, 50));
const int fittedSurfaceWidth = 684; const ui::IndustryChartGeometry fittedGeometry = ui::industry_chart_geometry(fittedSurfaceWidth, 440); for (const char* locale : {"en", "uk"}) { CHECK(i18n::load_locale(render::assets_dir() + "/lang", locale)); for (int index = 0; index < ui::kIndustrySectorCount; ++index) { CHECK(font.text_width(ui::industry_name(index)) < fittedGeometry.labelWidth); for (int mode = 0; mode < 3; ++mode) CHECK(font.text_width(ui::industry_chart_value_label( fixtureView, mode, index)) < fittedGeometry.valueWidth); } for (int mode = 0; mode < 3; ++mode) { const ui::IndustryChartContent content = ui::industry_chart_content(fixtureView, mode); const int unitX = fittedSurfaceWidth - 6 - font.text_width(content.unit); CHECK(fittedGeometry.titleX + font.text_width(content.title) + 12 < unitX); CHECK(font.text_width(content.summaryLeft) < fittedSurfaceWidth / 2 - 24); CHECK(font.text_width(content.summaryRight) < fittedSurfaceWidth / 2 - 16); } } CHECK(i18n::load_locale(render::assets_dir() + "/lang", "en")); }
const std::string p = city_file("LONDON.SC2"); if (!exists(p)) { std::printf("industry: name table OK; SKIP city (no LONDON)\n"); return failures ? 1 : 0; } City c; CHECK(io::load_sc2(p, c).ok);
const auto pop = ui::industry_values(c, 0); // Ratios = population const auto dem = ui::industry_values(c, 2); // Demand // LONDON's known figures (verified vs the original): Electronics dominates pop + demand; Food tiny. CHECK(pop[9] == 570 && dem[9] == 82); // Electronics CHECK(pop[3] == 12); // Food CHECK(pop[10] == 400); // Tourism // Electronics is the largest sector by population (its bar is the longest). int argmax = 0; for (int i = 1; i < 11; ++i) if (pop[i] > pop[argmax]) argmax = i; CHECK(argmax == 9); const ui::IndustryViewModel londonView = ui::industry_view_model(c); CHECK(londonView.population == pop); CHECK(londonView.demand == dem); CHECK(londonView.largestSector == 9); std::printf("industry: LONDON Electronics pop=%d demand=%d (largest sector) — offsets verified\n", pop[9], dem[9]);
if (failures == 0) { std::printf("industry: all checks passed\n"); return 0; } std::printf("industry: %d failure(s)\n", failures); return 1;}