Define competition trophy references and generic fallback (by Codex)
This commit is contained in:
1 parent
906cce902d
commit
faaecf2eb2
5 files changed
+70
No files matched your search
@@ -122,6 +122,7 @@ void competitions(Documents& out, const LeImage& exe) {
|
||||
std::string type = cup == 0 ? "cup" : cup >= 1 && cup <= 3 ? "club_international" :
|
||||
cup >= 4 && cup <= 8 ? "national_team" : cup == 10 ? "friendly" : cup == 11 && !english ? "indoor" : "cup";
|
||||
comps.emplace_back(O{{"id", "comp:classic-cup-" + std::to_string(cup)}, {"name", O{{"default", label}}},
|
||||
{"trophy", "asset:comp/classic-cup-" + std::to_string(cup) + "/trophy"},
|
||||
{"type", type}, {"played", true}, {"stages", std::move(stages)},
|
||||
{"classic", O{{"competition_id", cup}, {"calendar_bit", cup + 5},
|
||||
{"qualification", "classic-season-entrants@1"}, {"runtime_participants", true}}}});
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <iomanip>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string_view>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "formats/executable_layout.hpp"
|
||||
@@ -338,6 +339,7 @@ Documents convert_database(const Database& db, const TextDb& texts, const LeImag
|
||||
const auto nation = league < 5 ? nation_ids[0] : nation_ids[league - 4];
|
||||
const int tier = league < 5 ? (english ? int(league + 1) : (league < 3 ? int(league + 1) : int(league))) : 1;
|
||||
competitions.emplace_back(O{{"id", comp_ids[league]}, {"name", localized(label)}, {"type", "league"},
|
||||
{"trophy", "asset:comp/" + comp_ids[league].substr(5) + "/trophy"},
|
||||
{"nation", nation}, {"tier", tier}, {"played", played}, {"stages", A{std::move(stage)}},
|
||||
{"x-legacy", O{{"league_index", int(league)}, {"calendar_bit", int(bit)},
|
||||
{"relegation_places", int(exe.u8(layout::CareerSession_InstallLeagueSizes_RuntimeField2 + uint32_t(league)))},
|
||||
@@ -568,6 +570,19 @@ void validate(const Documents& documents) {
|
||||
}
|
||||
}
|
||||
if (std::string(name) == "competitions") {
|
||||
// Presentation references may be supplied by a later content pack.
|
||||
// Missing assets use the documented generic trophy fallback.
|
||||
if (item.object()->contains("trophy")) {
|
||||
const auto key = string_field(item, "trophy", at);
|
||||
constexpr std::string_view prefix = "asset:comp/", suffix = "/trophy";
|
||||
if (!key.starts_with(prefix) || !key.ends_with(suffix) ||
|
||||
key.size() <= prefix.size() + suffix.size()) fail(at + ": invalid trophy asset key");
|
||||
const auto name = key.substr(prefix.size(), key.size() - prefix.size() - suffix.size());
|
||||
if (!std::all_of(name.begin(), name.end(), [](unsigned char c) {
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
|
||||
(c >= '0' && c <= '9') || c == '.' || c == '_' || c == '-';
|
||||
}) || name == "." || name == "..") fail(at + ": invalid trophy asset key");
|
||||
}
|
||||
const auto* stages = field(item, "stages", at).array();
|
||||
if (!stages) fail(at + ": stages must be an array");
|
||||
for (const auto& stage : *stages) {
|
||||
|
||||
Reference in new issue
Block a user