Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
TradeOfferIconPlayback.cpp
Go to the documentation of this file.
2
3#include <memory>
4#include <utility>
5#include <variant>
6#include <vector>
7
8namespace monopoly::tradeui
9{
10 namespace
11 {
12 struct IconSpec
13 {
15 std::uint16_t priority{};
16 std::int32_t x{};
17 std::int32_t y{};
18 bool desired{};
19 };
20
21 using Specs = std::array<IconSpec, 16>;
22
24 const State& state,
26 {
27 Specs specs{};
29 for (std::size_t slot = 0; slot < TradeIconSlots; ++slot)
30 {
31 const auto priority = static_cast<std::uint16_t>(
33 specs[slot] = {
36 tradeVisible && (state.jailCardDesired[0] & (1u << slot)) != 0};
40 tradeVisible && (state.jailCardDesired[1] & (1u << slot)) != 0};
41 specs[2 * TradeIconSlots + slot] = {
44 tradeVisible && (state.immunityFutureDesired[0] & (1u << slot)) != 0};
45 specs[3 * TradeIconSlots + slot] = {
48 tradeVisible && (state.immunityFutureDesired[1] & (1u << slot)) != 0};
49 }
50 return specs;
51 }
52 }
53
54 std::expected<void, std::string> OfferIconPlayback::sync(
55 const State& state,
58 {
59 const auto specs = desiredIcons(state, desiredView);
60 std::array<std::shared_ptr<const sequence::SequenceProgram>, 16> programs{};
61
62 for (std::size_t index = 0; index < specs.size(); ++index)
63 {
64 if (!specs[index].desired || current_[index])
65 continue;
67 playback.resources(), specs[index].id);
68 if (!loaded)
69 return std::unexpected(loaded.error().detail);
70 programs[index] = std::move(*loaded);
71 }
72
73 std::vector<sequence::SequenceCommand> commands;
74 for (std::size_t index = 0; index < specs.size(); ++index)
75 {
76 if (specs[index].desired == current_[index])
77 continue;
78 const auto& spec = specs[index];
79 if (!spec.desired)
80 {
81 commands.push_back(sequence::StopSequenceCommand{
82 spec.id, spec.priority, false});
83 }
84 else
85 {
86 commands.push_back(sequence::StartSequenceCommand{
87 programs[index], spec.priority, {}});
88 commands.push_back(sequence::makeMoveXY(
89 spec.id, spec.priority, spec.x, spec.y));
90 }
91 }
92
93 if (commands.size() > sequence::SequenceCommandQueue::Capacity -
94 playback.commands().pendingCount())
95 {
96 return std::unexpected(
97 "sequence command queue cannot fit Trade offer-icon transition");
98 }
99
100 for (auto& command : commands)
101 {
102 const auto queued = std::visit(
103 [&](auto value)
104 {
105 return playback.commands().enqueue(std::move(value));
106 },
107 std::move(command));
108 if (!queued)
109 return std::unexpected("validated Trade offer-icon command rejected");
110 }
111
112 for (std::size_t index = 0; index < specs.size(); ++index)
113 current_[index] = specs[index].desired;
114 return {};
115 }
116}
std::uint16_t priority
PlayerNumber slot
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)
std::uint32_t DataId
Definition DataBanks.hpp:10
constexpr DataId EmptyDataId
Definition DataBanks.hpp:13
MoveSequenceCommand makeMoveXY(data::DataId dataId, std::uint16_t priority, std::int32_t x, std::int32_t y) noexcept
constexpr std::array< std::int32_t, TradeIconSlots > TradeFutureX
constexpr std::array< std::int32_t, TradeIconSlots > TradeChanceY
constexpr std::array< std::int32_t, TradeIconSlots > TradeCommunityX
constexpr std::array< std::int32_t, TradeIconSlots > TradeFutureY
constexpr data::DataId tradeJailIcon(std::size_t deck) noexcept
constexpr std::uint16_t TradeIconBasePriority
constexpr std::array< std::int32_t, TradeIconSlots > TradeImmunityY
constexpr data::DataId tradeContractIcon(std::size_t kind) noexcept
constexpr std::size_t TradeIconSlots
constexpr std::array< std::int32_t, TradeIconSlots > TradeImmunityX
constexpr std::array< std::int32_t, TradeIconSlots > TradeCommunityY
constexpr std::array< std::int32_t, TradeIconSlots > TradeChanceX