382 lines
22 KiB
C++
382 lines
22 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
#include "modern/ui/demo_stadium.hpp"
|
|
#include "modern/ui/demo_career.hpp"
|
|
#include "modern/ui/demo_finance.hpp"
|
|
#include <algorithm>
|
|
#include <array>
|
|
|
|
namespace bmh::modern_ui {
|
|
namespace {
|
|
constexpr int64_t budget_units = 50000000;
|
|
constexpr std::array<int, 8> capacities{8000,18000,8000,14000,8000,18000,8000,14000};
|
|
constexpr std::array<int, 8> initial_places{3000,6000,3000,5000,3000,6000,3000,7000};
|
|
constexpr std::array<int, 8> initial_levels{1,2,1,1,2,2,2,1};
|
|
constexpr std::array<int, 8> block_rates{300000,375000,300000,350000,300000,375000,300000,350000};
|
|
constexpr std::array<int, 8> block_weeks{30,37,30,25,30,37,30,25};
|
|
constexpr std::array<const char *, 8> block_names{
|
|
"Nordwest-Kurve", "Nord-Tribüne", "Nordost-Kurve", "Ost-Block",
|
|
"Südost-Kurve", "Süd-Tribüne", "Südwest-Kurve", "West-Block"};
|
|
constexpr std::array<const char *, 8> facility_names{
|
|
"Flutlichtanlage", "Anzeigetafel", "Rasenheizung", "V.I.P.-Lounge",
|
|
"Rasenzustand", "Stadionkomfort", "Stadionzustand", "Stadionsicherheit"};
|
|
constexpr std::array<int, 8> facility_rates{250000,350000,850000,1200000,180000,200000,300000,400000};
|
|
constexpr std::array<int, 8> facility_weeks{12,15,16,18,8,5,10,14};
|
|
constexpr std::array<const char *, 14> periphery_names{
|
|
"Verkehrsanbindung", "Arcade-Spielhalle", "Einkaufszentrum", "Clubhaus", "Parkplatz", "Restaurant",
|
|
"1. Imbissbude", "2. Imbissbude", "3. Imbissbude", "4. Imbissbude",
|
|
"1. Fan-Shop", "2. Fan-Shop", "3. Fan-Shop", "4. Fan-Shop"};
|
|
constexpr std::array<int, 14> periphery_rates{700000,800000,1800000,650000,450000,550000,90000,90000,90000,90000,140000,140000,140000,140000};
|
|
constexpr std::array<int, 14> periphery_weeks{12,14,28,16,9,12,4,4,4,4,6,6,6,6};
|
|
int periphery_cap(size_t index) { return index == 0 ? 4 : index == 4 ? 3 : 1; }
|
|
Json initial_periphery() {
|
|
Json rows = Json::array();
|
|
for (size_t i = 0; i < 14; ++i) rows.push_back({{"level", i == 0 || i == 4 || i == 5 ? 1 : 0}, {"job", nullptr}});
|
|
return rows;
|
|
}
|
|
bool keys(const Json &value, std::initializer_list<const char *> expected) {
|
|
return value.is_object() && value.size() == expected.size() &&
|
|
std::all_of(expected.begin(), expected.end(), [&](auto *key) { return value.contains(key); });
|
|
}
|
|
bool integer(const Json &value, int64_t low, int64_t high) {
|
|
if (value.is_number_unsigned())
|
|
return high >= 0 && value.get<uint64_t>() <= uint64_t(high) &&
|
|
(low <= 0 || value.get<uint64_t>() >= uint64_t(low));
|
|
return value.is_number_integer() && value.get<int64_t>() >= low && value.get<int64_t>() <= high;
|
|
}
|
|
int facility_cap(size_t index) { return index == 2 || index == 3 ? 2 : 4; }
|
|
Json error(const char *code) { return {{"ok", false}, {"can_build", false}, {"error", code}}; }
|
|
std::string owner(const Catalog &world, const Json *state, std::string requested) {
|
|
if (requested.empty() && state && state->is_object()) {
|
|
const auto managers = state->find("managers");
|
|
if (managers != state->end() && managers->is_array() && !managers->empty() && (*managers)[0].is_object()) {
|
|
const auto &active=demo_career_manager(*state);
|
|
const auto club = active.find("club");
|
|
if (club != active.end() && club->is_string()) requested = club->get<std::string>();
|
|
}
|
|
}
|
|
if (!requested.empty()) {
|
|
if (!world.manageable(requested)) throw editor::Error("invalid_stadium_club");
|
|
return requested;
|
|
}
|
|
for (const auto *club : world.clubs())
|
|
if (world.manageable(club->at("id").get<std::string>())) return club->at("id").get<std::string>();
|
|
return {};
|
|
}
|
|
bool block_target(const Json &base, const Json &target, size_t index) {
|
|
return integer(target.at("places"), base.at("places").get<int64_t>(), capacities[index]) &&
|
|
target.at("places").get<int64_t>() % 1000 == 0 &&
|
|
target.at("seats").is_boolean() && target.at("roof").is_boolean() &&
|
|
!(base.at("seats").get<bool>() && !target.at("seats").get<bool>()) &&
|
|
!(base.at("roof").get<bool>() && !target.at("roof").get<bool>());
|
|
}
|
|
Json block_price(const Json &base, const Json &target, size_t index, int64_t factor) {
|
|
const auto added = target.at("places").get<int64_t>() - base.at("places").get<int64_t>();
|
|
const int64_t rate = block_rates[index] * factor;
|
|
const int64_t places = added / 1000 * rate;
|
|
// All fixed rates and legal thousand-place steps divide exactly. This is
|
|
// Gold's nearest-integer calculation without floating-point currency drift.
|
|
const int64_t seats = target.at("seats").get<bool>()
|
|
? (base.at("seats").get<bool>() ? added : target.at("places").get<int64_t>()) / 1000 * rate * 45 / 100 : 0;
|
|
const int64_t roof = target.at("roof").get<bool>()
|
|
? (base.at("roof").get<bool>() ? added : target.at("places").get<int64_t>()) / 1000 * rate * 30 / 100 : 0;
|
|
return {{"cost", places + seats + roof}, {"weeks", block_weeks[index]},
|
|
{"placesCost", places}, {"seatsCost", seats}, {"roofCost", roof}};
|
|
}
|
|
} // namespace
|
|
|
|
Json demo_stadium(const Catalog &world, const std::string &club) {
|
|
Json blocks = Json::array(), facilities = Json::array();
|
|
for (size_t i = 0; i < 8; ++i) {
|
|
blocks.push_back({{"places", initial_places[i]}, {"seats", false}, {"roof", false}, {"job", nullptr}});
|
|
facilities.push_back({{"level", initial_levels[i]}, {"job", nullptr}});
|
|
}
|
|
return {{"club", owner(world, nullptr, club)}, {"budget", budget_units * finance_currency_factor(world)},
|
|
{"blocks", blocks}, {"facilities", facilities}, {"periphery", initial_periphery()}};
|
|
}
|
|
|
|
bool valid_demo_stadium(const Json &state, const Catalog &world, const std::string &club) {
|
|
try {
|
|
if (!state.is_object()) return false;
|
|
const int64_t factor = finance_currency_factor(world), cap = budget_units * factor;
|
|
const auto &stadium = state.at("stadium");
|
|
if (!keys(stadium, {"club", "budget", "blocks", "facilities", "periphery"}) ||
|
|
!stadium.at("club").is_string() || stadium.at("club") != owner(world, &state, club) ||
|
|
!integer(stadium.at("budget"), 0, cap) ||
|
|
!stadium.at("blocks").is_array() || stadium.at("blocks").size() != 8 ||
|
|
!stadium.at("facilities").is_array() || stadium.at("facilities").size() != 8 ||
|
|
!stadium.at("periphery").is_array() || stadium.at("periphery").size() != 14) return false;
|
|
int64_t pending = 0;
|
|
for (size_t i = 0; i < 8; ++i) {
|
|
const auto &base = stadium.at("blocks")[i];
|
|
if (!keys(base, {"places", "seats", "roof", "job"}) ||
|
|
!integer(base.at("places"), 0, capacities[i]) || base.at("places").get<int64_t>() % 1000 ||
|
|
!base.at("seats").is_boolean() || !base.at("roof").is_boolean()) return false;
|
|
const auto &job = base.at("job");
|
|
if (job.is_null()) continue;
|
|
if (!keys(job, {"places", "seats", "roof", "weeks", "cost"}) ||
|
|
!block_target(base, job, i) || !integer(job.at("cost"), 1, cap)) return false;
|
|
const auto quote = block_price(base, job, i, factor);
|
|
if (!integer(job.at("weeks"), block_weeks[i], block_weeks[i]) ||
|
|
job.at("cost") != quote.at("cost")) return false;
|
|
const auto cost = job.at("cost").get<int64_t>();
|
|
if (cost > cap - pending) return false;
|
|
pending += cost;
|
|
}
|
|
for (size_t i = 0; i < 8; ++i) {
|
|
const auto &base = stadium.at("facilities")[i];
|
|
if (!keys(base, {"level", "job"}) || !integer(base.at("level"), 1, facility_cap(i))) return false;
|
|
const auto &job = base.at("job");
|
|
if (job.is_null()) continue;
|
|
if (!keys(job, {"level", "weeks", "cost"}) ||
|
|
!integer(job.at("level"), base.at("level").get<int64_t>() + 1, facility_cap(i)) ||
|
|
!integer(job.at("weeks"), facility_weeks[i], facility_weeks[i]) ||
|
|
!integer(job.at("cost"), 1, cap)) return false;
|
|
const int64_t cost = (job.at("level").get<int64_t>() - base.at("level").get<int64_t>()) * facility_rates[i] * factor;
|
|
if (job.at("cost") != cost || cost > cap - pending) return false;
|
|
pending += cost;
|
|
}
|
|
for (size_t i = 0; i < 14; ++i) {
|
|
const auto &base = stadium.at("periphery")[i];
|
|
if (!keys(base, {"level", "job"}) || !integer(base.at("level"), 0, periphery_cap(i))) return false;
|
|
const auto &job = base.at("job");
|
|
if (job.is_null()) continue;
|
|
const int next = base.at("level").get<int>() + 1;
|
|
const int64_t cost = periphery_rates[i] * factor;
|
|
if (next > periphery_cap(i) || !keys(job, {"level", "weeks", "cost"}) ||
|
|
!integer(job.at("level"), next, next) || !integer(job.at("weeks"), periphery_weeks[i], periphery_weeks[i]) ||
|
|
job.at("cost") != cost || cost > cap - pending) return false;
|
|
pending += cost;
|
|
}
|
|
return stadium.at("budget").get<int64_t>() == cap - pending;
|
|
} catch (const std::exception &) { return false; }
|
|
}
|
|
|
|
bool migrate_demo_stadium(Json &state, const Catalog &world, const std::string &club) {
|
|
try {
|
|
if (!state.is_object()) return false;
|
|
if (state.contains("stadium")) {
|
|
if (valid_demo_stadium(state, world, club)) return true;
|
|
if (!keys(state.at("stadium"), {"club", "budget", "blocks", "facilities"})) return false;
|
|
auto next = state;
|
|
next["stadium"]["periphery"] = initial_periphery();
|
|
if (!valid_demo_stadium(next, world, club)) return false;
|
|
state = std::move(next);
|
|
return true;
|
|
}
|
|
auto next = state;
|
|
next["stadium"] = demo_stadium(world, owner(world, &state, club));
|
|
if (!valid_demo_stadium(next, world, club)) return false;
|
|
state = std::move(next);
|
|
return true;
|
|
} catch (const std::exception &) { return false; }
|
|
}
|
|
|
|
Json demo_stadium_quote(const Json &state, const Json &request, const Catalog &world, const std::string &club) {
|
|
if (!valid_demo_stadium(state, world, club)) return error("invalid_stadium_state");
|
|
try {
|
|
if (!request.is_object() || !request.contains("kind") || !request.at("kind").is_string() ||
|
|
!request.contains("index") || !integer(request.at("index"), 0, request.value("kind", std::string()) == "periphery" ? 13 : 7)) return error("invalid_stadium_request");
|
|
const auto kind = request.at("kind").get<std::string>();
|
|
const auto index = request.at("index").get<size_t>();
|
|
const auto &stadium = state.at("stadium");
|
|
const int64_t factor = finance_currency_factor(world);
|
|
Json quote;
|
|
bool pending = false;
|
|
if (kind == "block") {
|
|
const auto &base = stadium.at("blocks")[index];
|
|
if (!keys(request, {"kind", "index", "places", "seats", "roof"}) ||
|
|
!block_target(base, request, index)) return error("invalid_stadium_block_target");
|
|
quote = block_price(base, request, index, factor);
|
|
pending = !base.at("job").is_null();
|
|
} else if (kind == "facility") {
|
|
const auto &base = stadium.at("facilities")[index];
|
|
if (!keys(request, {"kind", "index", "level"}) ||
|
|
!integer(request.at("level"), base.at("level").get<int64_t>(), facility_cap(index)))
|
|
return error("invalid_stadium_facility_target");
|
|
quote = {{"cost", (request.at("level").get<int64_t>() - base.at("level").get<int64_t>()) * facility_rates[index] * factor},
|
|
{"weeks", facility_weeks[index]}, {"placesCost", 0}, {"seatsCost", 0}, {"roofCost", 0}};
|
|
pending = !base.at("job").is_null();
|
|
} else if (kind == "periphery") {
|
|
const auto &base = stadium.at("periphery")[index];
|
|
const int next = base.at("level").get<int>() + 1;
|
|
if (!keys(request, {"kind", "index", "level"}) || next > periphery_cap(index) ||
|
|
!integer(request.at("level"), next, next)) return error("invalid_stadium_periphery_target");
|
|
quote = {{"cost", periphery_rates[index] * factor}, {"weeks", periphery_weeks[index]},
|
|
{"placesCost", 0}, {"seatsCost", 0}, {"roofCost", 0}};
|
|
pending = !base.at("job").is_null();
|
|
} else return error("unknown_stadium_request");
|
|
const auto cost = quote.at("cost").get<int64_t>(), budget = stadium.at("budget").get<int64_t>();
|
|
const auto reason = pending ? "stadium_pending" : !cost ? "stadium_no_change"
|
|
: cost > budget ? "stadium_budget_exceeded" : "";
|
|
quote["ok"] = true; quote["can_build"] = !*reason; quote["error"] = reason;
|
|
quote["kind"] = kind; quote["index"] = index; quote["request"] = request;
|
|
quote["budget"] = budget; quote["remaining"] = budget - cost;
|
|
return quote;
|
|
} catch (const std::exception &) { return error("invalid_stadium_request"); }
|
|
}
|
|
|
|
std::string edit_demo_stadium(Json &state, const Json &action, const Catalog &world, const std::string &club) {
|
|
if (!valid_demo_stadium(state, world, club)) return "invalid_stadium_state";
|
|
try {
|
|
if (!keys(action, {"kind", "request"}) || action.at("kind") != "build") return "invalid_stadium_action";
|
|
const auto quote = demo_stadium_quote(state, action.at("request"), world, club);
|
|
if (!quote.value("ok", false) || !quote.value("can_build", false)) return quote.value("error", std::string("invalid_stadium_request"));
|
|
const auto &request = quote.at("request");
|
|
const auto index = quote.at("index").get<size_t>();
|
|
Json job = {{"weeks", quote.at("weeks")}, {"cost", quote.at("cost")}};
|
|
auto next = state;
|
|
if (quote.at("kind") == "block") {
|
|
for (const auto *key : {"places", "seats", "roof"}) job[key] = request.at(key);
|
|
next["stadium"]["blocks"][index]["job"] = job;
|
|
} else {
|
|
job["level"] = request.at("level");
|
|
next["stadium"][quote.at("kind") == "periphery" ? "periphery" : "facilities"][index]["job"] = job;
|
|
}
|
|
next["stadium"]["budget"] = quote.at("remaining");
|
|
if (!valid_demo_stadium(next, world, club)) return "invalid_stadium_state";
|
|
state = std::move(next);
|
|
return {};
|
|
} catch (const std::exception &) { return "invalid_stadium_action"; }
|
|
}
|
|
|
|
Json demo_stadium_rules(const Catalog &world) {
|
|
const auto factor = finance_currency_factor(world);
|
|
Json blocks = Json::array(), facilities = Json::array();
|
|
for (size_t i = 0; i < 8; ++i) {
|
|
blocks.push_back({{"index", i}, {"letter", std::string(1, char('A' + i))}, {"name", block_names[i]},
|
|
{"max_places", capacities[i]}, {"rate", block_rates[i] * factor}, {"weeks", block_weeks[i]}});
|
|
const Json levels = i == 2 || i == 3 ? Json({"", "nicht vorhanden", "vorhanden"})
|
|
: i < 2 ? Json({"", "klein", "mittel", "groß", "mega"})
|
|
: Json({"", "schlecht", "ausreichend", "gut", "sehr gut"});
|
|
facilities.push_back({{"index", i}, {"name", facility_names[i]}, {"max_level", facility_cap(i)},
|
|
{"rate", facility_rates[i] * factor}, {"weeks", facility_weeks[i]}, {"levels", levels}});
|
|
}
|
|
Json periphery = Json::array();
|
|
for (size_t i = 0; i < 14; ++i)
|
|
periphery.push_back({{"index", i}, {"name", periphery_names[i]}, {"max_level", periphery_cap(i)},
|
|
{"rate", periphery_rates[i] * factor}, {"weeks", periphery_weeks[i]}});
|
|
return {{"budget_cap", budget_units * factor}, {"blocks", blocks}, {"facilities", facilities}, {"periphery", periphery}};
|
|
}
|
|
|
|
Json demo_stadium_view(const Json &state, const Catalog &world, bool future, const std::string &club) {
|
|
if (!valid_demo_stadium(state, world, club)) return error("invalid_stadium_state");
|
|
const auto &stadium = state.at("stadium");
|
|
const auto id = stadium.at("club").get<std::string>();
|
|
const auto *team = world.find("clubs", id);
|
|
const Json *record = nullptr;
|
|
if (team) {
|
|
if (auto ref = team->find("stadium"); ref != team->end() && ref->is_string()) record = world.find("stadiums", ref->get<std::string>());
|
|
if (!record) for (const auto &candidate : world.rows("stadiums")) {
|
|
const auto ref = candidate.find("owner");
|
|
if (ref != candidate.end() && ref->is_string() && ref->get<std::string>() == id) { record = &candidate; break; }
|
|
}
|
|
}
|
|
auto rules = demo_stadium_rules(world);
|
|
int64_t pending = 0, available = 0, planned = 0;
|
|
bool super_stadium = true;
|
|
for (size_t i = 0; i < 8; ++i) {
|
|
const auto &base = stadium.at("blocks")[i];
|
|
const auto &job = base.at("job");
|
|
const bool building = !job.is_null();
|
|
const auto &display = future && building ? job : base;
|
|
super_stadium = super_stadium &&
|
|
display.at("places").get<int64_t>() == capacities[i] &&
|
|
display.at("seats").get<bool>() && display.at("roof").get<bool>();
|
|
auto &row = rules["blocks"][i];
|
|
for (const auto *key : {"places", "seats", "roof", "job"}) row[key] = base.at(key);
|
|
row["building"] = building;
|
|
row["display_places"] = building && !future ? Json(0) : display.at("places");
|
|
row["display_seats"] = display.at("seats"); row["display_roof"] = display.at("roof");
|
|
available += building ? 0 : base.at("places").get<int64_t>();
|
|
planned += building ? job.at("places").get<int64_t>() : base.at("places").get<int64_t>();
|
|
if (building) pending += job.at("cost").get<int64_t>();
|
|
}
|
|
for (size_t i = 0; i < 8; ++i) {
|
|
const auto &base = stadium.at("facilities")[i]; const auto &job = base.at("job");
|
|
const bool building = !job.is_null();
|
|
auto &row = rules["facilities"][i];
|
|
row["level"] = base.at("level"); row["job"] = job; row["building"] = building;
|
|
const int level = (future && building ? job : base).at("level").get<int>();
|
|
row["display_level"] = level; row["display_label"] = row.at("levels")[size_t(level)];
|
|
if (building) pending += job.at("cost").get<int64_t>();
|
|
}
|
|
for (size_t i = 0; i < 14; ++i) {
|
|
const auto &base = stadium.at("periphery")[i]; const auto &job = base.at("job");
|
|
const bool building = !job.is_null(); auto &row = rules["periphery"][i];
|
|
row["level"] = base.at("level"); row["job"] = job; row["building"] = building;
|
|
row["display_level"] = (future && building ? job : base).at("level");
|
|
if (building) pending += job.at("cost").get<int64_t>();
|
|
}
|
|
// Closed blocks still contribute their completed size to the physical stadium.
|
|
int64_t physical = 0;
|
|
for (const auto &block : stadium.at("blocks")) physical += block.at("places").get<int64_t>();
|
|
rules["physical_capacity"] = future ? planned : physical;
|
|
rules["super_stadium"] = super_stadium;
|
|
rules["ok"] = true; rules["club"] = id; rules["club_name"] = team ? world.name(*team) : "—";
|
|
rules["stadium"] = record ? record->at("id") : Json();
|
|
const auto name = record ? world.name(*record) : "";
|
|
rules["name"] = name.empty() ? "Stadion" : name;
|
|
rules["budget"] = stadium.at("budget"); rules["pending_cost"] = pending;
|
|
rules["available_capacity"] = available; rules["planned_capacity"] = planned;
|
|
rules["capacity"] = future ? planned : available;
|
|
return rules;
|
|
}
|
|
Json demo_stadium_scene(const Json &configuration, const Json &overview, bool future) {
|
|
if (configuration.at("schemaVersion") != 1 || configuration.at("activeProfile") != "modern")
|
|
throw editor::Error("invalid_stadium_scene");
|
|
const auto &profile = configuration.at("profiles").at("modern");
|
|
if (profile.at("referenceSize").at("width") != 1920 || profile.at("referenceSize").at("height") != 1080 ||
|
|
profile.at("objects").size() != 14 || overview.at("periphery").size() != 14)
|
|
throw editor::Error("invalid_stadium_scene");
|
|
Json layers = Json::array(), areas = Json::array();
|
|
const auto place = [&](const Json &binding, const Json &transform, const Json &owner, const char *role) {
|
|
const auto asset = binding.at("asset").get<std::string>();
|
|
const auto &meta = configuration.at("assets").at(asset);
|
|
const double scale = transform.at("scale").get<double>();
|
|
const double width = binding.at("width").get<double>() * binding.at("scale").get<double>() * scale;
|
|
const double height = width * meta.at("height").get<double>() / meta.at("width").get<double>();
|
|
layers.push_back({{"asset", asset}, {"owner", owner}, {"role", role}, {"z", transform.at("z")},
|
|
{"x", transform.at("x").get<double>() + binding.at("offsetX").get<double>() * scale - binding.at("anchorX").get<double>() * width},
|
|
{"y", transform.at("y").get<double>() + binding.at("offsetY").get<double>() * scale - binding.at("anchorY").get<double>() * height},
|
|
{"width", width}, {"height", height}});
|
|
};
|
|
const auto &transport = overview.at("periphery")[0];
|
|
const int traffic = (transport.at("building").get<bool>() ? transport.at("job") : transport).at("level").get<int>();
|
|
const auto &background = profile.at("background");
|
|
place(profile.at("backgroundOptions")[0].at("variants").at(size_t(traffic)),
|
|
{{"x", background.at("offsetX")}, {"y", background.at("offsetY")}, {"scale", background.at("scale")}, {"z", 0}}, "background", "background");
|
|
const auto capacity = overview.at("physical_capacity").get<int64_t>();
|
|
// The sixth image is a fully upgraded bowl, not another capacity tier.
|
|
size_t stadium_index = 0;
|
|
if (overview.at("super_stadium").get<bool>()) stadium_index = 5;
|
|
else {
|
|
const auto &thresholds = profile.at("stadium").at("thresholds");
|
|
for (size_t i = 0; i < 4 && i < thresholds.size(); ++i)
|
|
if (capacity >= thresholds[i].get<int64_t>()) ++stadium_index;
|
|
}
|
|
place(profile.at("stadium").at("variants").at(stadium_index), profile.at("stadium").at("transform"), "stadium", "stadium");
|
|
for (size_t i = 0; i < 14; ++i) {
|
|
const auto &object = profile.at("objects")[i], &row = overview.at("periphery")[i];
|
|
if (object.at("id") != i) throw editor::Error("invalid_stadium_scene");
|
|
const auto &transform = object.at("transform"), &area = object.at("hitArea"), &sprites = object.at("sprites");
|
|
const bool pending = row.at("building").get<bool>(), building = pending && !future;
|
|
const int level = (pending ? row.at("job") : row).at("level").get<int>();
|
|
const double scale = transform.at("scale").get<double>();
|
|
const double w = area.at("width").get<double>() * scale, h = area.at("height").get<double>() * scale;
|
|
areas.push_back({{"index", i}, {"z", transform.at("z")},
|
|
{"x", transform.at("x").get<double>() + area.at("offsetX").get<double>() * scale - w / 2},
|
|
{"y", transform.at("y").get<double>() + area.at("offsetY").get<double>() * scale - h / 2}, {"width", w}, {"height", h}});
|
|
if (i == 0 || (building && i >= 6)) {
|
|
if (building) place(sprites.at("marker"), transform, i, "marker");
|
|
} else if (level) {
|
|
const size_t variant = i == 4 ? size_t(level - 1) : 0;
|
|
place(sprites.at("variants").at(variant), transform, i, "building");
|
|
if (building) place(sprites.at("overlays").at(variant), transform, i, "overlay");
|
|
}
|
|
}
|
|
std::stable_sort(layers.begin(), layers.end(), [](const Json &a, const Json &b) { return a.at("z").get<double>() < b.at("z").get<double>(); });
|
|
std::stable_sort(areas.begin(), areas.end(), [](const Json &a, const Json &b) { return a.at("z").get<double>() < b.at("z").get<double>(); });
|
|
return {{"layers", layers}, {"areas", areas}, {"stadium_index", stadium_index}, {"traffic_level", traffic}};
|
|
}
|
|
} // namespace bmh::modern_ui
|