The console and its desk/window actions are compiled a second time against ModernSession (src/app/session.hpp, OPENBMH_MODERN_SESSION), so a Modern world can be played before the new interface is connected: new career, club picker, desk, live matchday, results, save and load. - The CLI opens a Modern world like the season sim and keys its save folder by the SHA-256 of the world id. - Rollbacks keep the whole session state (app::SessionState) instead of slicing it to GameState, which would drop Modern data. - Club picker: clubs a world adds get unused master ids so the original picker's order stays unique; only German clubs can be confirmed in Modern. Classic openbmh_cli is unchanged (same sources without the switch). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
1.2 KiB
C++
38 lines
1.2 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
#pragma once
|
|
|
|
#include "app/session.hpp"
|
|
|
|
namespace bmh::app::detail {
|
|
|
|
template<class Checkpoint, class Restore>
|
|
bool apply_window(CareerSession& session, uint64_t& revision, Checkpoint before,
|
|
Restore restore_checkpoint, const std::function<bool()>& action) {
|
|
const auto game = session.game();
|
|
const auto rand = session.rand();
|
|
const auto old_revision = revision;
|
|
const auto restore = [&] {
|
|
session.game() = game;
|
|
session.rand() = rand;
|
|
// Some owners reconstruct their saved RNG identity during restore.
|
|
restore_checkpoint(std::move(before));
|
|
revision = old_revision;
|
|
};
|
|
try {
|
|
if (action()) return true;
|
|
} catch (...) {
|
|
restore();
|
|
throw;
|
|
}
|
|
restore();
|
|
return false;
|
|
}
|
|
|
|
inline bool apply_native(CareerSession& session, uint64_t& revision, const std::function<bool()>& action) {
|
|
return apply_window(session, revision, session.state(),
|
|
// the whole session state (the Modern one carries more than GameState)
|
|
[&](SessionState before) { session.state() = std::move(before); }, action);
|
|
}
|
|
|
|
} // namespace bmh::app::detail
|