Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
IBarBankPlayback.cpp
Go to the documentation of this file.
2
3#include <utility>
4#include <variant>
5#include <vector>
6
7namespace monopoly::ibar
8{
9 std::expected<void, std::string> BankPlayback::sync(
10 bool visible,
11 bool hovered,
13 {
14 if (!visible)
15 {
16 hovered = false;
17 }
18
19 const bool visibilityChanged = visible != visible_;
20 const bool hoverChanged = visible && hovered != hovered_;
22 {
23 return {};
24 }
25
26 std::shared_ptr<const sequence::SequenceProgram> program;
27 if (visible && !visible_)
28 {
30 playback.resources(), bankSequence());
31 if (!loaded)
32 {
33 return std::unexpected(loaded.error().detail);
34 }
35 program = std::move(*loaded);
36 }
37
38 std::vector<sequence::SequenceCommand> commands;
39 if (visible_ && !visible)
40 {
41 commands.push_back(sequence::StopSequenceCommand{
42 bankSequence(), BankPriority, false});
43 }
44 else if (!visible_ && visible)
45 {
46 commands.push_back(sequence::StartSequenceCommand{
47 program, BankPriority, {}});
48 commands.push_back(sequence::makeMoveXY(
50 if (hovered)
51 {
52 commands.push_back(sequence::makeMoveXY(
54 }
55 }
56 else if (hoverChanged)
57 {
58 commands.push_back(sequence::makeMoveXY(
60 BankX, BankY + (hovered ? 1 : 0)));
61 }
62
63 if (commands.size() >
65 playback.commands().pendingCount())
66 {
67 return std::unexpected(
68 "sequence command queue cannot fit IBar bank transition");
69 }
70
71 for (auto& command : commands)
72 {
73 const auto queued = std::visit(
74 [&](auto value)
75 {
76 return playback.commands().enqueue(std::move(value));
77 },
78 std::move(command));
79 if (!queued)
80 {
81 return std::unexpected(
82 "validated IBar bank command rejected");
83 }
84 }
85
86 visible_ = visible;
87 hovered_ = hovered;
88 return {};
89 }
90}
unsigned index
std::uint16_t value
Definition Timers.cpp:16
bool visible() const noexcept
bool hovered() const noexcept
std::expected< void, std::string > sync(bool visible, bool hovered, engine::SequencePlayback &playback)
static std::expected< std::shared_ptr< const SequenceProgram >, RuntimeError > load(const data::DataSource &source, data::DataId id, std::size_t offset=0, DescriptionLimits limits={})
constexpr std::uint16_t BankPriority
constexpr std::int32_t BankY
constexpr std::int32_t BankX
constexpr data::DataId bankSequence() noexcept
MoveSequenceCommand makeMoveXY(data::DataId dataId, std::uint16_t priority, std::int32_t x, std::int32_t y) noexcept