76 lines
2.8 KiB
C++
76 lines
2.8 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
#pragma once
|
|
#include "modern/ui/catalog.hpp"
|
|
#include <optional>
|
|
#include <string_view>
|
|
|
|
namespace bmh::modern_ui {
|
|
// Shared UI/model boundary: valid UTF-8, trimmed Unicode whitespace, no control
|
|
// characters, at most 24 codepoints. Invalid input has no normalized value.
|
|
std::optional<std::string> normalized_manager_name(std::string_view);
|
|
struct Snapshot {
|
|
uint64_t revision = 0;
|
|
std::shared_ptr<const Catalog> world;
|
|
Json state;
|
|
};
|
|
struct Action {
|
|
uint64_t revision = 0;
|
|
std::string kind;
|
|
Json value;
|
|
};
|
|
struct ActionResult {
|
|
bool ok = false;
|
|
uint64_t revision = 0;
|
|
std::string error;
|
|
};
|
|
// The native view depends on this presentation boundary, never on GameState.
|
|
class DataSource {
|
|
public:
|
|
virtual ~DataSource() = default;
|
|
virtual Snapshot snapshot() const = 0;
|
|
virtual ActionResult apply(const Action &) = 0;
|
|
// Read-side history projections can be backed by lazy engine-season decoding.
|
|
// Browsing does not change the game revision or copy the archive into a save.
|
|
virtual Json read_almanac(const Json &) const {
|
|
return {{"ok", false}, {"error", "almanac_unavailable"}};
|
|
}
|
|
virtual Json read_statistics(const Json &) const {
|
|
return {{"ok", false}, {"error", "statistics_unavailable"}};
|
|
}
|
|
// Explicit authoritative adapter required; reading never starts a match.
|
|
virtual Json read_live(const Json &) const {
|
|
return {{"ok", false}, {"error", "live_unavailable"}};
|
|
}
|
|
// An authoritative adapter must confirm its own completed match state.
|
|
// Demo completion only acknowledges the final prerecorded presentation frame.
|
|
virtual Json read_post_match(const Json &) const {
|
|
return {{"ok", false}, {"error", "post_match_unavailable"}};
|
|
}
|
|
};
|
|
class DemoSource final : public DataSource {
|
|
public:
|
|
explicit DemoSource(std::shared_ptr<const Catalog>);
|
|
Snapshot snapshot() const override;
|
|
// "start" publishes {setup,managers} together; setup is kept in edits.setup
|
|
// for checkpoint compatibility. Optional checked settings/preferences carry
|
|
// confirmed user choices into a fresh source. It creates presentation state only.
|
|
ActionResult apply(const Action &) override;
|
|
Json read_almanac(const Json &) const override;
|
|
Json read_statistics(const Json &) const override;
|
|
Json read_live(const Json &) const override;
|
|
Json read_post_match(const Json &) const override;
|
|
void save(const fs::path &, const Json &desktop);
|
|
Json load(const fs::path &);
|
|
// UI continuation may retain the previous explicit-save clean baseline.
|
|
Json load_data(Json, bool saved = true);
|
|
bool mark_saved(uint64_t expected_revision);
|
|
bool dirty() const { return state_ != saved_; }
|
|
|
|
private:
|
|
std::shared_ptr<const Catalog> catalog_;
|
|
const Json almanac_;
|
|
Json state_, saved_;
|
|
uint64_t revision_ = 0;
|
|
};
|
|
} // namespace bmh::modern_ui
|