Reset new demo careers while retaining confirmed user choices (by Codex)
This commit is contained in:
1 parent
8e3d9f83e0
commit
e710937ca9
5 files changed
+165
-5
No files matched your search
@@ -193,10 +193,9 @@ void App::entry_confirm() {
|
||||
} else {
|
||||
// Construct and validate before releasing any part of the current session.
|
||||
auto demo = std::make_unique<DemoSource>(catalog);
|
||||
const auto result =
|
||||
demo->apply({demo->snapshot().revision,
|
||||
"start",
|
||||
{{"setup", start_options_}, {"managers", candidate}}});
|
||||
Json start={{"setup",start_options_},{"managers",candidate}};
|
||||
if(source_){const auto previous=snap();start["preferences"]=previous.state.at("preferences");start["settings"]=previous.state.at("settings");}
|
||||
const auto result=demo->apply({demo->snapshot().revision,"start",start});
|
||||
if (!result.ok) {
|
||||
message("Die neue Partie konnte nicht übernommen werden: " +
|
||||
result.error);
|
||||
|
||||
@@ -303,6 +303,14 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
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"};
|
||||
Json retained_preferences,retained_settings;
|
||||
if(start){
|
||||
retained_preferences=action.value.value("preferences",state_.at("preferences"));
|
||||
retained_settings=action.value.value("settings",state_.at("settings"));
|
||||
if(!preferences(retained_preferences))return {false,revision_,"invalid_preferences"};
|
||||
// A new presentation career never inherits progression or team data.
|
||||
DemoSource fresh(catalog_);next=fresh.snapshot().state;
|
||||
}
|
||||
next["managers"] = std::move(managers);
|
||||
if (start) {
|
||||
auto options=action.value.at("setup");options["mode"]=3;
|
||||
@@ -314,6 +322,11 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
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);
|
||||
}
|
||||
if(!start && next.contains("career")){
|
||||
Json ai=Json::array();for(const auto &id:next["career"].at("ai_teams"))
|
||||
if(std::none_of(next["managers"].begin(),next["managers"].end(),[&](const auto &m){return m.value("club","")==id.get<std::string>();}))ai.push_back(id);
|
||||
next["career"]["ai_teams"]=std::move(ai);
|
||||
}
|
||||
const auto first=demo_career_manager(next).value("club", "");
|
||||
if (next.at("training").at("club") != first) {
|
||||
next["training"] = demo_training(*catalog_, first);
|
||||
@@ -340,6 +353,9 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
: "complete";
|
||||
next["opening_created"] = false;
|
||||
next["opening_flow"] = make_demo_opening(*catalog_, next, action.value.at("setup").at("league").get<bool>());
|
||||
next["preferences"]=retained_preferences;
|
||||
const auto settings_error=edit_demo_settings(next,retained_settings);
|
||||
if(!settings_error.empty())return {false,revision_,settings_error};
|
||||
}
|
||||
} else if (action.kind == "environment" || action.kind == "advertising" ||
|
||||
action.kind == "toto") {
|
||||
|
||||
@@ -47,7 +47,8 @@ public:
|
||||
explicit DemoSource(std::shared_ptr<const Catalog>);
|
||||
Snapshot snapshot() const override;
|
||||
// "start" publishes {setup,managers} together; setup is kept in edits.setup
|
||||
// for checkpoint compatibility. It creates presentation state only.
|
||||
// for checkpoint compatibility. Optional checked settings/preferences carry
|
||||
// confirmed user choices into a fresh source. It creates presentation state only.
|
||||
ActionResult apply(const Action &) override;
|
||||
Json read_almanac(const Json &) const override;
|
||||
Json read_statistics(const Json &) const override;
|
||||
|
||||
Reference in new issue
Block a user