Files
Dreierpack-Manager/src/modern/content/ui_contract.hpp
T
ClaudeandClaude Opus 5.5 78b827a0e6 Modern UI contract: lineup, tactics and training reads and commands
lineup.commit takes the squad order and swaps rows into place after opening
the board as the desk does; tactics.commit sets the eight values through the
board's checks; training.commit initializes the plan when needed and applies
decreases before increases so every step stays within the limits. Each is one
revision and is rolled back as a whole when the engine refuses a step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 08:39:41 +01:00

63 lines
3.0 KiB
C++

// SPDX-License-Identifier: GPL-3.0-only
#pragma once
// The engine side of the Modern interface contract (docs/new_ui/integration, draft
// "bmh-modern-ui@draft1"; engine decisions in docs/new_engine/ui-anbindung.md).
//
// A read answers in the contract's envelope:
// {messageType: "snapshot", requestId, meta: {contractVersion, careerId, worldId, worldRevision,
// stateRevision, projectionRevision, locale, date, season, scope, availability, currency}, data}
// or {messageType: "error", requestId, code, message, currentRevision, retryable, stateChanged}.
//
// Reads never change the game, draw random numbers or move the revision. Money is the
// contract's Money {minor: decimal string, currency: "EUR", minorUnits: 2}: the engine keeps
// whole euros, converted here exactly once. Revisions are decimal strings.
//
// Read kinds so far: "session" (the human managers and who is at the desk) and "desktop"
// (the desk of the active manager: manager, team, account, next match, menu availability).
#include <cstdint>
#include <string>
#include <vector>
#include "cli/json.hpp"
#include "modern/game/modern_state.hpp"
namespace bmh::modern {
// What the session adds to the state: the revision the interface acts on and the manager at
// the desk (runtime manager slot).
struct UiContext {
uint64_t state_revision = 0;
int manager = 0;
// The desk's next match as the session prepared it (DeskState): the opponent's runtime
// team (-1: none, nullopt: not known), the competition label, whether it is away.
std::optional<int> next_opponent;
std::string next_competition;
bool next_away = false;
};
// Gives a career without them its identities: a career id ("career:" + 16 hex digits, drawn
// from the system, not from a game generator) and an id per human manager slot
// ("manager:<n>", counted per career, never reused). Called after the career start, a join
// and loading; changes nothing that is already set.
void ensure_ui_identities(ModernState& g);
// The money of the engine (whole euros) as the contract's Money.
cli::Json ui_money(int64_t euros);
cli::Json ui_read(const ModernState& g, const UiContext& context, const cli::Json& request);
// The parts of a command answer the session puts together (ModernSession::ui_command).
cli::Json ui_command_result(const std::string& request_id, uint64_t previous, uint64_t next,
const std::vector<std::string>& changed_reads, const std::string& feedback);
cli::Json ui_error(const std::string& request_id, const std::string& code, const std::string& message,
uint64_t revision, bool retryable);
// The contract id of a manager slot ("manager:<n>").
std::string ui_manager_id(const ModernState& g, int manager);
// Reads the session answers itself (they need the executable's tables): data in the envelope.
cli::Json ui_snapshot(const ModernState& g, const UiContext& context, const std::string& request_id, cli::Json data);
std::string ui_team_id(const ModernState& g, int team);
std::string ui_player_id(const ModernState& g, int player);
} // namespace bmh::modern