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
@@ -0,0 +1,213 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/demo_career.hpp"
|
||||
#include "modern/ui/demo_lineup.hpp"
|
||||
#include "modern/ui/demo_opening.hpp"
|
||||
#include "modern/ui/desktop.hpp"
|
||||
#include "modern/ui/model.hpp"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace bmh::modern_ui;
|
||||
namespace {
|
||||
void require(bool yes, const char *message) {
|
||||
if (!yes)
|
||||
throw std::runtime_error(message);
|
||||
}
|
||||
struct Fixture {
|
||||
fs::path root;
|
||||
std::shared_ptr<const Catalog> world;
|
||||
Fixture()
|
||||
: root(fs::temp_directory_path() /
|
||||
bmh::editor::new_id("openbmh-entry-test-")) {
|
||||
fs::create_directories(root / "world");
|
||||
const auto write = [&](const char *path, const Json &data) {
|
||||
bmh::editor::write_atomic(root / path, data.dump());
|
||||
};
|
||||
write("manifest.json", {{"format", "openbmh-world"},
|
||||
{"kind", "world"},
|
||||
{"format_version", "1.1"},
|
||||
{"id", "world:synthetic-entry"},
|
||||
{"start_date", "2032-07-01"},
|
||||
{"requires", {"editor:world-v1"}},
|
||||
{"x-editor", {{"profile", "editor-world-v1"}}}});
|
||||
write("world/nations.json",
|
||||
{{"items",
|
||||
{{{"id", "nation:de"}, {"name", "Synthetic Germany"}},
|
||||
{{"id", "nation:es"}, {"name", "Synthetic Spain"}}}}});
|
||||
write("world/competitions.json", {{"items",
|
||||
{{{"id", "competition:de"},
|
||||
{"name", "Synthetic DE"},
|
||||
{"nation", "nation:de"},
|
||||
{"type", "league"}},
|
||||
{{"id", "competition:es"},
|
||||
{"name", "Synthetic ES"},
|
||||
{"nation", "nation:es"},
|
||||
{"type", "league"}}}}});
|
||||
Json clubs = Json::array();
|
||||
for (int index = 0; index < 5; ++index)
|
||||
clubs.push_back({{"id", "club:entry-" + std::to_string(index)},
|
||||
{"name", "Synthetic club " + std::to_string(index)},
|
||||
{"nation", "nation:de"},
|
||||
{"competition", "competition:de"}});
|
||||
clubs.push_back({{"id", "club:foreign"},
|
||||
{"name", "Foreign club"},
|
||||
{"nation", "nation:es"},
|
||||
{"competition", "competition:es"}});
|
||||
write("world/clubs.json", {{"items", clubs}});
|
||||
Json players = Json::array();
|
||||
for (int team = 0; team < 5; ++team)
|
||||
for (int n = 0; n < 16; ++n)
|
||||
players.push_back(
|
||||
{{"id", "player:" + std::to_string(team) + "-" + std::to_string(n)},
|
||||
{"name", "Synthetic player " + std::to_string(n)},
|
||||
{"team", "club:entry-" + std::to_string(team)},
|
||||
{"squad_order", n},
|
||||
{"positions", Json::array({n < 2 ? "gk"
|
||||
: n < 7 ? "def"
|
||||
: n < 12 ? "mid"
|
||||
: "fwd"})}});
|
||||
write("world/players.json", {{"items", players}});
|
||||
world = Catalog::open(root);
|
||||
}
|
||||
~Fixture() {
|
||||
std::error_code error;
|
||||
fs::remove_all(root, error);
|
||||
}
|
||||
};
|
||||
Json setup(int players = 2, bool league = true, bool world = true) {
|
||||
return {{"duration", 5}, {"difficulty", 3}, {"players", players},
|
||||
{"mode", 3}, {"league", league}, {"world", world}};
|
||||
}
|
||||
Json manager(int index, const std::string &name = {}) {
|
||||
return {{"name", name.empty() ? "Manager " + std::to_string(index) : name},
|
||||
{"club", "club:entry-" + std::to_string(index)},
|
||||
{"portrait", index},
|
||||
{"portrait_style", index % 2 ? "painted" : "photo"},
|
||||
{"strength_choice", index % 3}};
|
||||
}
|
||||
Json start(int players = 2) {
|
||||
Json managers = Json::array();
|
||||
for (int index = 0; index < players; ++index)
|
||||
managers.push_back(manager(index));
|
||||
return {{"setup", setup(players)}, {"managers", managers}};
|
||||
}
|
||||
} // namespace
|
||||
int main() {
|
||||
try {
|
||||
Fixture f;
|
||||
DemoSource source(f.world);
|
||||
auto options = setup(4);
|
||||
options["mode"] = 1;
|
||||
auto payload = start(4);
|
||||
payload["setup"] = options;
|
||||
require(source.apply({0, "start", payload}).ok, "four-human start");
|
||||
require(source.snapshot().state.at("edits").at("setup").at("mode") == 3,
|
||||
"start mode3 normalization");
|
||||
auto act = [&](Json a) {
|
||||
return source.apply({source.snapshot().revision, "career", a});
|
||||
};
|
||||
require(act({{"kind", "select_manager"}, {"portrait", 2}}).ok,
|
||||
"manager select");
|
||||
require(demo_career_manager(source.snapshot().state).at("portrait") == 2,
|
||||
"requested active identity");
|
||||
auto context = demo_career_context(source.snapshot().state, *f.world);
|
||||
require(context.at("active_managers").size() == 4, "four active humans");
|
||||
require(act({{"kind", "role"}, {"value", "national"}}).ok, "national role");
|
||||
require(!demo_career_menu_available(source.snapshot().state, "stadium") &&
|
||||
!demo_career_menu_available(source.snapshot().state, "bank"),
|
||||
"national club menu guard");
|
||||
require(demo_career_context(source.snapshot().state, *f.world)
|
||||
.at("current_team")
|
||||
.at("id") == "national-de",
|
||||
"national identity");
|
||||
auto before = source.snapshot();
|
||||
require(!act({{"kind", "surface"}, {"value", "indoor"}}).ok &&
|
||||
source.snapshot().state == before.state,
|
||||
"national indoor rollback");
|
||||
require(!source.apply({before.revision - 1,
|
||||
"career",
|
||||
{{"kind", "resign"}, {"portrait", 0}}})
|
||||
.ok &&
|
||||
source.snapshot().state == before.state,
|
||||
"stale resignation rollback");
|
||||
require(act({{"kind", "role"}, {"value", "club"}}).ok, "club role");
|
||||
require(act({{"kind", "surface"}, {"value", "indoor"}}).ok &&
|
||||
demo_career_field_count(source.snapshot().state) == 6,
|
||||
"six indoor positions");
|
||||
const auto outdoor_before = source.snapshot().state.at("lineup");
|
||||
const auto player =
|
||||
source.snapshot().state.at("indoor_lineup").at("order").at(0);
|
||||
require(
|
||||
source
|
||||
.apply({source.snapshot().revision,
|
||||
"lineup",
|
||||
{{"kind", "move"}, {"player", player}, {"point", {1, 4}}}})
|
||||
.ok,
|
||||
"indoor move");
|
||||
require(source.snapshot().state.at("lineup") == outdoor_before,
|
||||
"indoor edits retain outdoor anchors");
|
||||
const auto bench =
|
||||
source.snapshot().state.at("indoor_lineup").at("order").at(6);
|
||||
const auto before_bench = source.snapshot();
|
||||
require(
|
||||
!source.apply(
|
||||
{before_bench.revision,
|
||||
"lineup",
|
||||
{{"kind", "move"}, {"player", bench}, {"point", {3, 4}}}})
|
||||
.ok &&
|
||||
source.snapshot().state == before_bench.state,
|
||||
"indoor bench cannot move as seventh field player");
|
||||
require(demo_lineup_active(source.snapshot().state).size() == 6,
|
||||
"read-side six starters");
|
||||
require(act({{"kind", "surface"}, {"value", "outdoor"}}).ok,
|
||||
"outdoor role");
|
||||
require(source
|
||||
.apply({source.snapshot().revision,
|
||||
"lineup",
|
||||
{{"kind", "weight"}, {"index", 0}}})
|
||||
.ok,
|
||||
"edit selected lineup");
|
||||
const auto edited = source.snapshot().state.at("lineup");
|
||||
require(act({{"kind", "select_manager"}, {"portrait", 1}}).ok,
|
||||
"switch other club");
|
||||
require(act({{"kind", "select_manager"}, {"portrait", 2}}).ok &&
|
||||
source.snapshot().state.at("lineup") == edited,
|
||||
"club views retain edited lineup");
|
||||
auto data = source.snapshot().state;
|
||||
data["desktop"] = default_desktop();
|
||||
data["edits"]["setup"]["mode"] = 2;
|
||||
DemoSource restored(f.world);
|
||||
restored.load_data(data);
|
||||
require(restored.snapshot().state.at("edits").at("setup").at("mode") == 3 &&
|
||||
demo_career_manager(restored.snapshot().state).at("portrait") ==
|
||||
2,
|
||||
"reload normalizes mode and preserves selected human");
|
||||
require(act({{"kind", "resign"}, {"portrait", 0}}).ok,
|
||||
"other person resigns");
|
||||
require(demo_career_manager(source.snapshot().state).at("portrait") == 2 &&
|
||||
source.snapshot().state.at("managers").size() == 3,
|
||||
"other resignation preserves active human");
|
||||
require(source.snapshot().state.at("career").at("ai_teams") ==
|
||||
Json::array({"club:entry-0"}),
|
||||
"AI handover");
|
||||
for (int p : {2, 1, 3})
|
||||
require(act({{"kind", "resign"}, {"portrait", p}}).ok,
|
||||
"remaining resignation");
|
||||
require(demo_career_context(source.snapshot().state, *f.world)
|
||||
.at("active_managers")
|
||||
.empty(),
|
||||
"last human ends career");
|
||||
require(!act({{"kind", "select_manager"}, {"portrait", 3}}).ok,
|
||||
"ended career blocked");
|
||||
source.save(f.root / "save.json", default_desktop());
|
||||
DemoSource end(f.world);
|
||||
end.load(f.root / "save.json");
|
||||
require(end.snapshot().state.at("career").at("ended") == true,
|
||||
"ended state persists");
|
||||
std::cout << "career UI model tests passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user