Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
OptionsSaveRuntime.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "OptionsUI.hpp"
4#include "RuleTypes.hpp"
5#include "UIMessages.hpp"
6
7#include <array>
8#include <cstddef>
9#include <cstdint>
10#include <expected>
11#include <filesystem>
12#include <memory>
13#include <optional>
14#include <span>
15#include <string>
16#include <vector>
17
18namespace monopoly::data
19{
20 class ResourceSnapshot;
21}
22
23namespace monopoly::fonts
24{
25 class Runtime;
26}
27
28namespace monopoly::optionsui
29{
30 inline constexpr std::size_t SaveSlotCount = 5;
31
32 enum class FileDialogMode : std::uint8_t
33 {
34 None,
35 Load,
36 Save
37 };
39 {
40 std::u16string description;
41 std::int32_t city{};
42 std::int32_t system{};
43 std::array<std::uint32_t, rules::SquareCount> squareGameEarnings{};
44 std::string customBoardName;
45 };
46
47 struct SaveSlot
48 {
49 bool occupied{};
51 };
52
64
66 {
67 bool consumed{};
71 bool playClick{};
72 };
73
74 [[nodiscard]] std::filesystem::path saveGameDirectory();
75 [[nodiscard]] std::filesystem::path gameBlobPath(std::size_t slot);
76 [[nodiscard]] std::filesystem::path gameMetadataPath(std::size_t slot);
77
78 [[nodiscard]] std::expected<void, std::string> refreshSaveSlots(
79 SaveRuntimeState& state, FileDialogMode mode);
80 void closeSaveDialog(SaveRuntimeState& state) noexcept;
81
82 [[nodiscard]] SaveDialogInput processSaveDialogInput(
83 SaveRuntimeState& state,
84 const uimsg::Message& message,
86 std::shared_ptr<const data::ResourceSnapshot> resources);
87
88 [[nodiscard]] std::expected<std::vector<std::uint8_t>, std::string>
89 readSelectedGameBlob(const SaveRuntimeState& state);
90
91 [[nodiscard]] std::expected<void, std::string> beginPendingSave(
92 SaveRuntimeState& state,
93 const rules::GameState& ruleState,
94 int city,
95 int system,
96 std::string customBoardName,
98
99 void clearPendingSave(SaveRuntimeState& state) noexcept;
100
101 [[nodiscard]] std::expected<void, std::string> persistPendingSave(
102 SaveRuntimeState& state,
103 std::span<const std::uint8_t> gameBlob);
104
105 [[nodiscard]] std::expected<void, std::string> applySelectedMetadata(
106 const SaveRuntimeState& state,
107 rules::GameState& ruleState,
108 int& city,
109 int& system);
110
111 [[nodiscard]] Rect saveSlotRect(std::size_t slot) noexcept;
112 [[nodiscard]] Rect dialogOkayRect(int width, int height) noexcept;
113 [[nodiscard]] Rect dialogCancelRect(int width, int height) noexcept;
114}
PlayerNumber slot
std::uint32_t height
std::uint32_t width
unsigned state
unsigned index
void closeSaveDialog(SaveRuntimeState &state) noexcept
SaveDialogInput processSaveDialogInput(SaveRuntimeState &state, const uimsg::Message &message, fonts::Runtime *fontRuntime, std::shared_ptr< const data::ResourceSnapshot > resources)
std::expected< void, std::string > persistPendingSave(SaveRuntimeState &state, std::span< const std::uint8_t > gameBlob)
Rect saveSlotRect(std::size_t slot) noexcept
Rect dialogOkayRect(int width, int height) noexcept
constexpr std::size_t SaveSlotCount
std::expected< std::vector< std::uint8_t >, std::string > readSelectedGameBlob(const SaveRuntimeState &state)
void clearPendingSave(SaveRuntimeState &state) noexcept
std::expected< void, std::string > refreshSaveSlots(SaveRuntimeState &state, FileDialogMode mode)
std::filesystem::path gameMetadataPath(std::size_t slot)
std::filesystem::path gameBlobPath(std::size_t slot)
std::expected< void, std::string > applySelectedMetadata(const SaveRuntimeState &state, rules::GameState &ruleState, int &city, int &system)
std::filesystem::path saveGameDirectory()
std::expected< void, std::string > beginPendingSave(SaveRuntimeState &state, const rules::GameState &ruleState, int city, int system, std::string customBoardName, rules::PlayerNumber requester)
Rect dialogCancelRect(int width, int height) noexcept
std::uint8_t PlayerNumber
Definition RuleTypes.hpp:12
constexpr PlayerNumber NobodyPlayer
Definition RuleTypes.hpp:16
std::array< std::uint32_t, rules::SquareCount > squareGameEarnings
std::array< SaveSlot, SaveSlotCount > slots
std::optional< std::size_t > pendingSaveSlot