Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
TradeContractDialogPlayback.cpp
Go to the documentation of this file.
2
3#include <array>
4#include <memory>
5#include <utility>
6#include <variant>
7#include <vector>
8
9namespace monopoly::tradeui
10{
11 std::expected<void, std::string> ContractDialogPlayback::sync(
12 const State& state,
15 {
16 const bool desired =
18 state.contractDialogVisible;
19 if (desired == visible_)
20 return {};
21
22 constexpr std::size_t ArrowCount = 2;
23 std::array<std::shared_ptr<const sequence::SequenceProgram>,
25 if (desired)
26 {
27 for (std::size_t index = 0; index < ArrowCount; ++index)
28 {
31 if (!loaded)
32 return std::unexpected(loaded.error().detail);
33 programs[index] = std::move(*loaded);
34 }
35 }
36
37 std::vector<sequence::SequenceCommand> commands;
38 for (std::size_t index = 0; index < ArrowCount; ++index)
39 {
40 const auto id = tradeContractArrowSequence(index);
41 if (!desired)
42 {
43 commands.push_back(sequence::StopSequenceCommand{
45 continue;
46 }
47
48 commands.push_back(sequence::StartSequenceCommand{
50 commands.push_back(sequence::makeMoveXY(
53 }
54
55 if (commands.size() > sequence::SequenceCommandQueue::Capacity -
56 playback.commands().pendingCount())
57 {
58 return std::unexpected(
59 "sequence command queue cannot fit Trade contract-arrow transition");
60 }
61
62 for (auto& command : commands)
63 {
64 const auto queued = std::visit(
65 [&](auto value)
66 {
67 return playback.commands().enqueue(std::move(value));
68 },
69 std::move(command));
70 if (!queued)
71 {
72 return std::unexpected(
73 "validated Trade contract-arrow command rejected");
74 }
75 }
76
77 visible_ = desired;
78 return {};
79 }
80}
data::DataId id
unsigned state
unsigned index
std::uint16_t value
Definition Timers.cpp:16
static std::expected< std::shared_ptr< const SequenceProgram >, RuntimeError > load(const data::DataSource &source, data::DataId id, std::size_t offset=0, DescriptionLimits limits={})
std::expected< void, std::string > sync(const State &state, display::Screen2D desiredView, engine::SequencePlayback &playback)
MoveSequenceCommand makeMoveXY(data::DataId dataId, std::uint16_t priority, std::int32_t x, std::int32_t y) noexcept
constexpr std::uint16_t TradeContractArrowPriority
constexpr std::array< std::int32_t, 2 > TradeContractArrowX
constexpr std::array< std::int32_t, 2 > TradeContractArrowY
constexpr data::DataId tradeContractArrowSequence(std::size_t index) noexcept