Files
Dreierpack-Manager/tests/modern_live_dump.cpp
T
MichaelandClaude Fable 5.2 7c0e66affe Bind the kickoff of the Modern desk to the engine and show its recording in the ticker
The kickoff button sends session.advance; the engine's recording of the
played matchday is shaped for the live ticker (phases, per-match tables,
the desk manager's squad). A contract running out on the way asks the
manager to extend at the player's demand or to release him. The UI script
driver accepts optional clicks, and modern_live_dump writes the engine's
recording for inspection.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-14 00:05:04 +01:00

59 lines
2.9 KiB
C++

// SPDX-License-Identifier: GPL-3.0-only
// Developer probe: advances a Modern career through the UI command path and writes the
// engine's kickoff recording, post-match read and line-up read as JSON files.
// usage: modern_live_dump <world.obw> <career.obs> <output dir> [kickoffs]
#include "modern/ui/engine_bridge.hpp"
#include <filesystem>
#include <fstream>
#include <iostream>
using bmh::modern_ui::EngineBridge;
using bmh::modern_ui::Json;
namespace fs = std::filesystem;
int main(int argc, char **argv) {
if (argc < 4) { std::cerr << "usage: modern_live_dump <world.obw> <career.obs> <output dir> [kickoffs]\n"; return 2; }
try {
const fs::path out = argv[3];
fs::create_directories(out);
const int wanted = argc > 4 ? std::atoi(argv[4]) : 1;
auto link = EngineBridge::open(argv[1], argv[2]);
const auto write = [&](const std::string &name, const Json &value) {
std::ofstream(out / name, std::ios::binary) << value.dump(1);
};
int found = 0;
Json expiry = Json::object();
for (int step = 0; step < 400 && found < wanted; ++step) {
const auto bundle = link->snapshot();
const auto &meta = bundle.at("desktop").at("meta");
if (step == 0) write("bundle.json", bundle);
const Json command = {{"messageType", "command"}, {"contractVersion", meta.at("contractVersion")},
{"requestId", "request:dump-" + std::to_string(step)}, {"careerId", meta.at("careerId")},
{"expectedRevision", meta.at("stateRevision")},
{"owner", {{"managerId", meta.at("scope").at("managerId")}}},
{"kind", "session.advance"}, {"payload", {{"contractExpiry", expiry}}}};
const auto reply = link->command(command);
write("advance-" + std::to_string(step) + ".json", reply);
if (reply.value("messageType", "") != "command_result") {
if (reply.value("code", "") == "decision_pending") {
expiry[reply.at("message").at("args").at("playerId").get<std::string>()] = {{"action", "release"}};
continue;
}
std::cerr << "advance refused: " << reply.dump() << "\n";
return 1;
}
const auto fixture = link->read_live({{"kind", "fixture"}});
std::cout << "step " << step << ": " << (fixture.value("ok", false) ? "fixture" : fixture.value("error", "?")) << "\n";
if (!fixture.value("ok", false)) continue;
const std::string tag = std::to_string(found++);
write("fixture-" + tag + ".json", fixture);
write("postmatch-" + tag + ".json", link->read({{"kind", "postmatch"}}));
write("lineup-" + tag + ".json", link->read({{"kind", "lineup"}}));
write("tactics-" + tag + ".json", link->read({{"kind", "tactics"}}));
}
std::cout << found << " recordings written\n";
return found ? 0 : 1;
} catch (const std::exception &e) { std::cerr << e.what() << "\n"; return 1; }
}