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
@@ -5,6 +5,7 @@
|
||||
#include "modern/ui/demo_finance.hpp"
|
||||
#include "modern/ui/demo_lineup.hpp"
|
||||
#include "modern/ui/demo_opening.hpp"
|
||||
#include "modern/ui/demo_settings.hpp"
|
||||
#include "modern/ui/demo_stadium.hpp"
|
||||
#include "modern/ui/demo_statistics.hpp"
|
||||
#include "modern/ui/demo_widgets.hpp"
|
||||
@@ -98,9 +99,114 @@ Json start(int players = 2) {
|
||||
return {{"setup", setup(players)}, {"managers", managers}};
|
||||
}
|
||||
} // namespace
|
||||
namespace {
|
||||
void historical_metadata(const Fixture &fixture) {
|
||||
DemoSource source(fixture.world);
|
||||
require(source.apply({0, "start", start(4)}).ok, "Metadata start");
|
||||
require(source
|
||||
.apply({source.snapshot().revision,
|
||||
"career",
|
||||
{{"kind", "select_manager"}, {"portrait", 2}}})
|
||||
.ok,
|
||||
"Metadata select");
|
||||
require(source
|
||||
.apply({source.snapshot().revision,
|
||||
"career",
|
||||
{{"kind", "role"}, {"value", "national"}}})
|
||||
.ok,
|
||||
"Metadata national role");
|
||||
const auto stored = source.snapshot().state;
|
||||
require(source
|
||||
.apply({source.snapshot().revision,
|
||||
"career",
|
||||
{{"kind", "role"}, {"value", "club"}}})
|
||||
.ok,
|
||||
"Metadata viewer role");
|
||||
require(source
|
||||
.apply({source.snapshot().revision,
|
||||
"career",
|
||||
{{"kind", "select_manager"}, {"portrait", 0}}})
|
||||
.ok,
|
||||
"Metadata viewer selection");
|
||||
const auto meta = DemoFiles::career_metadata(stored);
|
||||
require(meta.at("role") == "national" &&
|
||||
meta.at("current_manager").at("portrait") == 2,
|
||||
"Saved national role/person replaced by current viewer");
|
||||
}
|
||||
void start_reset(const Fixture &fixture, bool ended) {
|
||||
DemoSource source(fixture.world);
|
||||
const auto defaults = source.snapshot().state;
|
||||
const auto act = [&](const std::string &kind, const Json &value) {
|
||||
const auto r = source.apply({source.snapshot().revision, kind, value});
|
||||
require(r.ok, "Start-reset setup action failed");
|
||||
};
|
||||
act("finance", {{"kind", "deposit"}, {"value", 400}});
|
||||
act("ticket", 22);
|
||||
act("camp.select", "resort:2");
|
||||
act("camp.remember", nullptr);
|
||||
act("lineup", {{"kind", "weight"}, {"index", 0}});
|
||||
const Json preferences = {
|
||||
{"theme", "silver"}, {"volume", 33}, {"effects", false}};
|
||||
act("preferences", preferences);
|
||||
auto settings = source.snapshot().state.at("settings");
|
||||
settings["cells"][0] = 0;
|
||||
settings["automation"]["lineup"] = true;
|
||||
settings["automation"]["training"] = true;
|
||||
act("settings", settings);
|
||||
auto imported = source.snapshot().state;
|
||||
imported["date"] = "2040-05-17";
|
||||
imported["desktop"] = default_desktop();
|
||||
source.load_data(imported, false);
|
||||
if (ended)
|
||||
act("career", {{"kind", "resign"}, {"portrait", 0}});
|
||||
auto payload = Json{{"setup", setup(1)},
|
||||
{"managers", Json::array({manager(0, "New Coach")})}};
|
||||
const auto before = source.snapshot();
|
||||
const bool dirty = source.dirty();
|
||||
auto invalid = payload;
|
||||
invalid["settings"] = {
|
||||
{"version", 1}, {"cells", Json::array()}, {"automation", Json::object()}};
|
||||
require(!source.apply({before.revision, "start", invalid}).ok &&
|
||||
source.snapshot().state == before.state &&
|
||||
source.snapshot().revision == before.revision &&
|
||||
source.dirty() == dirty,
|
||||
"Rejected start changed canonical state/revision/dirty");
|
||||
require(source.apply({before.revision, "start", payload}).ok,
|
||||
"Start reset failed");
|
||||
const auto now = source.snapshot().state;
|
||||
for (const auto *key : {"cash", "deposit", "debt", "ticket", "camp", "lineup",
|
||||
"contracts", "stadium", "calendar", "date"})
|
||||
require(now.at(key) == defaults.at(key),
|
||||
"New start retained a career sentinel");
|
||||
require(now.at("preferences") == preferences &&
|
||||
now.at("settings") == settings,
|
||||
"New start lost confirmed display/sound/options/automation choices");
|
||||
require(now.at("training").at("areas") ==
|
||||
defaults.at("training").at("areas") &&
|
||||
now.at("training").at("autos") ==
|
||||
Json::array({true, true, true, true}),
|
||||
"Fresh training did not retain only the chosen automation preset");
|
||||
require(now.at("career_views").empty() &&
|
||||
now.at("career").at("ai_teams").empty() &&
|
||||
now.at("career").at("ended") == false,
|
||||
"New start retained old ownership/cache state");
|
||||
require(demo_career_manager(now).at("name") == "New Coach",
|
||||
"New start retained old manager identity");
|
||||
DemoSource app_target(fixture.world);
|
||||
payload["preferences"] = preferences;
|
||||
payload["settings"] = settings;
|
||||
require(app_target.apply({0, "start", payload}).ok &&
|
||||
app_target.snapshot().state.at("preferences") == preferences &&
|
||||
app_target.snapshot().state.at("settings") == settings,
|
||||
"Fresh App target did not carry explicit confirmed user choices");
|
||||
}
|
||||
} // namespace
|
||||
int main() {
|
||||
try {
|
||||
Fixture f;
|
||||
historical_metadata(f);
|
||||
start_reset(f, false);
|
||||
start_reset(f, true);
|
||||
DemoSource source(f.world);
|
||||
auto options = setup(4);
|
||||
options["mode"] = 1;
|
||||
@@ -217,6 +323,24 @@ int main() {
|
||||
require(source.snapshot().state.at("career").at("ai_teams") ==
|
||||
Json::array({"club:entry-0"}),
|
||||
"AI handover");
|
||||
auto joined = source.snapshot().state.at("managers");
|
||||
auto bad_join = joined;
|
||||
auto returned = manager(0, "Returning Coach");
|
||||
returned["club"] = "club:foreign";
|
||||
bad_join.push_back(returned);
|
||||
const auto join_before = source.snapshot();
|
||||
require(!source.apply({join_before.revision, "managers", bad_join}).ok &&
|
||||
source.snapshot().state == join_before.state,
|
||||
"Rejected rejoin changed roster or AI ownership");
|
||||
joined.push_back(manager(0, "Returning Coach"));
|
||||
require(source.apply({join_before.revision, "managers", joined}).ok,
|
||||
"Valid AI-team rejoin failed");
|
||||
require(source.snapshot().state.at("career").at("ai_teams").empty() &&
|
||||
demo_career_manager(source.snapshot().state).at("portrait") ==
|
||||
2,
|
||||
"Rejoin retained conflicting AI owner or switched active person");
|
||||
require(act({{"kind", "resign"}, {"portrait", 0}}).ok,
|
||||
"Rejoined owner resignation failed");
|
||||
for (int p : {2, 1, 3})
|
||||
require(act({{"kind", "resign"}, {"portrait", p}}).ok,
|
||||
"remaining resignation");
|
||||
|
||||
Reference in new issue
Block a user