Create real careers from the native wizard and preserve manager presentation (by Codex)
This commit is contained in:
1 parent
738ecc7a09
commit
ce1535fe2d
38 files changed
+466
-75
No files matched your search
@@ -5,6 +5,7 @@
|
||||
#include <bit>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
#include <set>
|
||||
|
||||
#include "content/digest.hpp"
|
||||
#include "content/package.hpp"
|
||||
@@ -43,6 +44,20 @@ std::vector<std::string> strings(const J& value) {
|
||||
for (const J& v : arr(value)) out.push_back(str(v));
|
||||
return out;
|
||||
}
|
||||
J manager_presentations_json(const std::vector<ModernState::ManagerPresentation>& values) {
|
||||
A out;
|
||||
for (const auto& p : values) out.push_back(O{{"id", p.id}, {"name", p.name}, {"portrait_style", p.portrait_style}});
|
||||
return out;
|
||||
}
|
||||
std::vector<ModernState::ManagerPresentation> manager_presentations_json(const J& value) {
|
||||
std::vector<ModernState::ManagerPresentation> out; std::set<std::string> ids;
|
||||
for (const auto& row : arr(value)) {
|
||||
ModernState::ManagerPresentation p{str(get(row, "id")), str(get(row, "name")), str(get(row, "portrait_style"))};
|
||||
if (!p.id.starts_with("manager:") || p.id.size() > 64 || !ids.insert(p.id).second || p.name.empty() || p.name.size() > 96 || p.name.find('\0') != std::string::npos || (p.portrait_style != "photo" && p.portrait_style != "painted")) fail("invalid manager presentation");
|
||||
out.push_back(std::move(p));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
std::string world_identity(const World& world) { return world.id + "@" + world.data_revision; }
|
||||
|
||||
// Exclusive sponsor offers and queued contracts per manager (docs/new_engine/trainingslager.md).
|
||||
@@ -137,7 +152,7 @@ void save_world_career(const std::filesystem::path& path, const World& world, co
|
||||
{"world", O{{"id", world.id}, {"data_revision", world.data_revision}, {"title", world.title}}}});
|
||||
put(docs, "state/career.json", encode_native_state(state));
|
||||
put(docs, "state/modern.json",
|
||||
O{{"schema", "modern-state@1.1"},
|
||||
O{{"schema", state.manager_presentations.empty() ? "modern-state@1.1" : "modern-state@1.2"},
|
||||
{"club_ids", strings(state.world_club_id)},
|
||||
{"club_names", strings(state.world_club_name)},
|
||||
{"club_short_names", strings(state.world_club_short)},
|
||||
@@ -153,6 +168,7 @@ void save_world_career(const std::filesystem::path& path, const World& world, co
|
||||
{"career_id", state.career_id},
|
||||
{"manager_ids", strings(state.manager_ids)},
|
||||
{"manager_serial", int64_t(state.manager_serial)},
|
||||
{"manager_presentations", manager_presentations_json(state.manager_presentations)},
|
||||
{"traffic_scale", int64_t(state.traffic_scale)},
|
||||
{"press", press_json(state.press)},
|
||||
{"press_serial", int64_t(state.press_serial)},
|
||||
@@ -196,7 +212,8 @@ SavedWorldCareer load_world_career(const std::filesystem::path& path, const Worl
|
||||
SavedWorldCareer out;
|
||||
out.state = ModernState(decode_native_state(parse(docs, "state/career.json")));
|
||||
const auto modern = parse(docs, "state/modern.json");
|
||||
if (str(get(modern, "schema")) != "modern-state@1.1") fail("unsupported Modern state");
|
||||
const auto modern_schema = str(get(modern, "schema"));
|
||||
if (modern_schema != "modern-state@1.1" && modern_schema != "modern-state@1.2") fail("unsupported Modern state");
|
||||
out.state.world_club_id = strings(get(modern, "club_ids"));
|
||||
out.state.world_club_name = strings(get(modern, "club_names"));
|
||||
out.state.world_club_short = strings(get(modern, "club_short_names"));
|
||||
@@ -214,6 +231,7 @@ SavedWorldCareer load_world_career(const std::filesystem::path& path, const Worl
|
||||
out.state.career_id = str(get(modern, "career_id"));
|
||||
out.state.manager_ids = strings(get(modern, "manager_ids"));
|
||||
out.state.manager_serial = uint32_t(num(get(modern, "manager_serial")));
|
||||
if (o->count("manager_presentations")) out.state.manager_presentations = manager_presentations_json(get(modern, "manager_presentations"));
|
||||
if (o->count("traffic_scale")) out.state.traffic_scale = uint8_t(num(get(modern, "traffic_scale")));
|
||||
if (o->count("press")) {
|
||||
out.state.press = press_json(get(modern, "press"));
|
||||
|
||||
Reference in new issue
Block a user