Model native demo career roles, manager handover and separate indoor boards (by Codex)
This commit is contained in:
1 parent
b02ee52dee
commit
d88bf2872a
11 files changed
+996
-137
No files matched your search
+57
-8
@@ -3,6 +3,7 @@
|
||||
#include "modern/ui/demo_advertising.hpp"
|
||||
#include "modern/ui/demo_almanac.hpp"
|
||||
#include "modern/ui/demo_calendar.hpp"
|
||||
#include "modern/ui/demo_career.hpp"
|
||||
#include "modern/ui/demo_environment.hpp"
|
||||
#include "modern/ui/demo_finance.hpp"
|
||||
#include "modern/ui/demo_lineup.hpp"
|
||||
@@ -229,6 +230,8 @@ DemoSource::DemoSource(std::shared_ptr<const Catalog> catalog)
|
||||
throw editor::Error("invalid_demo_settings");
|
||||
if (!migrate_demo_opening(state_, *catalog_))
|
||||
throw editor::Error("Ungültige Saisonvorbereitung.");
|
||||
if (!migrate_demo_career(state_, *catalog_))
|
||||
throw editor::Error("invalid_demo_career");
|
||||
saved_ = state_;
|
||||
}
|
||||
Snapshot DemoSource::snapshot() const { return {revision_, catalog_, state_}; }
|
||||
@@ -243,7 +246,25 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
return {false, revision_, "stale_revision"};
|
||||
auto next = state_;
|
||||
try {
|
||||
if (action.kind == "settings") {
|
||||
if (action.kind == "career") {
|
||||
const auto previous_club = demo_career_manager(next).value("club", "");
|
||||
const auto old_view = demo_career_view(next);
|
||||
const auto error = edit_demo_career(next, action.value, *catalog_);
|
||||
if (!error.empty()) return {false, revision_, error};
|
||||
const auto current_club = demo_career_manager(next).value("club", "");
|
||||
if (current_club != previous_club) {
|
||||
next["career_views"][previous_club] = old_view;
|
||||
if (next["career_views"].contains(current_club))
|
||||
restore_demo_career_view(next, next["career_views"].at(current_club));
|
||||
else {
|
||||
DemoSource fresh(catalog_);
|
||||
const auto result = fresh.apply({0,"managers",Json::array({demo_career_manager(next)})});
|
||||
if (!result.ok) return {false,revision_,result.error};
|
||||
restore_demo_career_view(next,demo_career_view(fresh.snapshot().state));
|
||||
}
|
||||
}
|
||||
if(!migrate_demo_lineup(next,*catalog_,current_club))return {false,revision_,"invalid_demo_lineup"};
|
||||
} else if (action.kind == "settings") {
|
||||
const auto error = edit_demo_settings(next, action.value);
|
||||
if (!error.empty())
|
||||
return {false, revision_, error};
|
||||
@@ -273,14 +294,29 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
const auto error = normalized_managers(raw, *catalog_, managers);
|
||||
if (!error.empty())
|
||||
return {false, revision_, error};
|
||||
if (!start && next.contains("career") && next["career"].value("ended",false))
|
||||
return {false,revision_,"career_ended"};
|
||||
if (!start && !next.at("edits").value("setup",Json::object()).value("league",true) && managers.size()>1)
|
||||
return {false,revision_,"national_one_manager"};
|
||||
next["managers"] = std::move(managers);
|
||||
const auto first =
|
||||
next.at("managers").at(0).at("club").get<std::string>();
|
||||
if (start) {
|
||||
auto options=action.value.at("setup");options["mode"]=3;
|
||||
next["edits"]["setup"]=options;
|
||||
next["career"]=demo_career_defaults(next.at("managers"),options);
|
||||
next["career_views"]=Json::object();
|
||||
} else if (next.contains("career")) {
|
||||
const int active=next["career"].value("active_portrait",0);
|
||||
if (std::none_of(next["managers"].begin(),next["managers"].end(),[&](const auto &m){return m.value("portrait",0)==active;}))
|
||||
next["career"]["active_portrait"]=next["managers"][0].value("portrait",0);
|
||||
}
|
||||
const auto first=demo_career_manager(next).value("club", "");
|
||||
if (next.at("training").at("club") != first) {
|
||||
next["training"] = demo_training(*catalog_, first);
|
||||
next["tactics"] = demo_tactics();
|
||||
next["contracts"] = demo_contracts(*catalog_, first);
|
||||
next["lineup"] = demo_lineup(*catalog_, first);
|
||||
next["indoor_lineup"] = demo_lineup(*catalog_, first);
|
||||
next["indoor_lineup"]["points"] = demo_lineup_formations(true)[0];
|
||||
next["transfer"] = demo_transfer(*catalog_, first);
|
||||
next["stadium"] = demo_stadium(*catalog_, first);
|
||||
next["calendar"] = demo_calendar(*catalog_, next.at("date"), first);
|
||||
@@ -293,6 +329,7 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
}
|
||||
if (start) {
|
||||
next["edits"]["setup"] = action.value.at("setup");
|
||||
next["edits"]["setup"]["mode"] = 3;
|
||||
next["opening"] = action.value.at("setup").at("league").get<bool>()
|
||||
? "pending"
|
||||
: "complete";
|
||||
@@ -310,7 +347,7 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
if (!error.empty())
|
||||
return {false, revision_, error};
|
||||
} else if (action.kind == "lineup" || action.kind == "transfer") {
|
||||
const auto club = next["managers"][0]["club"].get<std::string>();
|
||||
const auto club = demo_career_manager(next).value("club", "");
|
||||
const auto error =
|
||||
action.kind == "lineup"
|
||||
? edit_demo_lineup(next, action.value, *catalog_, club)
|
||||
@@ -319,12 +356,12 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
return {false, revision_, error};
|
||||
} else if (action.kind == "stadium") {
|
||||
const auto error = edit_demo_stadium(next, action.value, *catalog_,
|
||||
next["managers"][0]["club"]);
|
||||
demo_career_manager(next).value("club", ""));
|
||||
if (!error.empty())
|
||||
return {false, revision_, error};
|
||||
} else if (action.kind == "finance") {
|
||||
const auto error = edit_demo_finance(next, action.value, *catalog_,
|
||||
next["managers"][0]["club"]);
|
||||
demo_career_manager(next).value("club", ""));
|
||||
if (!error.empty())
|
||||
return {false, revision_, error};
|
||||
} else if (action.kind == "training") {
|
||||
@@ -338,7 +375,7 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
} else if (action.kind == "calendar") {
|
||||
const auto error =
|
||||
edit_demo_calendar(next["calendar"], action.value, *catalog_,
|
||||
next["managers"][0]["club"]);
|
||||
demo_career_manager(next).value("club", ""));
|
||||
if (!error.empty())
|
||||
return {false, revision_, error};
|
||||
if (action.value.value("kind", "") == "league") {
|
||||
@@ -401,6 +438,7 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
} catch (const Json::exception &) {
|
||||
return {false, revision_, "invalid_action"};
|
||||
}
|
||||
if (!migrate_demo_career(next,*catalog_)) return {false,revision_,"invalid_demo_career"};
|
||||
sync_demo_settings_training(next);
|
||||
state_ = std::move(next);
|
||||
return {true, ++revision_, {}};
|
||||
@@ -431,7 +469,10 @@ Json DemoSource::load_data(Json data, bool saved) {
|
||||
if (!result.ok)
|
||||
throw editor::Error(result.error);
|
||||
data["managers"] = validation.snapshot().state.at("managers");
|
||||
const auto club = data.at("managers").at(0).at("club").get<std::string>();
|
||||
if (data.contains("edits") && data.at("edits").contains("setup") && !valid_start_setup(data.at("edits").at("setup")))
|
||||
throw editor::Error("invalid_setup");
|
||||
if (!migrate_demo_career(data,*catalog_)) throw editor::Error("invalid_demo_career");
|
||||
const auto club = demo_career_manager(data).value("club", "");
|
||||
if (!data.contains("training"))
|
||||
data["training"] = demo_training(*catalog_, club);
|
||||
if (!data.contains("tactics"))
|
||||
@@ -490,6 +531,14 @@ Json DemoSource::load_data(Json data, bool saved) {
|
||||
throw editor::Error("invalid_demo_settings");
|
||||
if (!migrate_demo_opening(data, *catalog_))
|
||||
throw editor::Error("Ungültige oder inkonsistente Saisonvorbereitung.");
|
||||
for (const auto &[id,view]:data.at("career_views").items()) {
|
||||
auto probe=data;probe["career_views"]=Json::object();probe["desktop"]=default_desktop();
|
||||
probe["managers"]=Json::array({{{"name","Vorschau"},{"club",id},{"portrait",0}}});
|
||||
const Json setup={{"duration",5},{"difficulty",3},{"players",1},{"mode",3},{"league",true},{"world",true}};
|
||||
probe["edits"]["setup"]=setup;probe["career"]=demo_career_defaults(probe.at("managers"),setup);
|
||||
restore_demo_career_view(probe,view);sync_demo_settings_training(probe);
|
||||
DemoSource validator(catalog_);validator.load_data(std::move(probe));
|
||||
}
|
||||
auto next = data;
|
||||
auto desktop = next.value("desktop", Json::object());
|
||||
if (!migrate_desktop(desktop))
|
||||
|
||||
Reference in new issue
Block a user