LeviLamina
Loading...
Searching...
No Matches
ScreenSession.h
1#pragma once
2
3#include <cstdint>
4#include <memory>
5#include <optional>
6#include <string>
7
8#include "ll/api/Expected.h"
9#include "ll/api/base/Macro.h"
10#include "ll/api/coro/CoroTask.h"
11#include "ll/api/ui/base/DataStore.h"
12
13#include "mc/platform/brstd/move_only_function.h"
14#include "mc/ui/DataDrivenScreenClosedReason.h"
15
16class Player;
17
18namespace ll::ui {
19
20// ScreenSession operations and final handle release must run on the server thread.
21
22using ScreenCloseReason = ::DataDrivenScreenClosedReason;
23
24enum class ScreenSessionState : std::uint8_t {
25 Ready = 0,
26 Showing = 1,
27 Closed = 2,
28};
29
30struct NoInstanceIdTag {
31 explicit constexpr NoInstanceIdTag() = default;
32};
33
34inline constexpr NoInstanceIdTag NoInstanceId{};
35
36namespace detail {
37class ScreenSessionImpl;
38}
39
40class ScreenSession {
41 std::shared_ptr<detail::ScreenSessionImpl> impl;
42
43public:
44 using Result = Expected<ScreenCloseReason>;
45 using Callback = brstd::move_only_function<void(Result)>;
46
47 LLAPI ScreenSession() noexcept;
48 LLNDAPI ScreenSession(Player& player, std::string screenId);
49 LLNDAPI ScreenSession(Player& player, std::string screenId, uint instanceId);
50 LLNDAPI ScreenSession(Player& player, std::string screenId, NoInstanceIdTag);
51 LLAPI ~ScreenSession();
52
53 LLAPI ScreenSession(ScreenSession const&);
54 LLAPI ScreenSession& operator=(ScreenSession const&);
55 LLAPI ScreenSession(ScreenSession&&) noexcept;
56 LLAPI ScreenSession& operator=(ScreenSession&&) noexcept;
57
58 LLNDAPI ScreenSessionState getState() const noexcept;
59 LLNDAPI std::optional<uint> getInstanceId() const noexcept;
60 LLNDAPI std::optional<uint> getFormId() const noexcept;
61
62 LLNDAPI Expected<Property>
63 createProperty(std::string datastore, std::string property, cereal::DynamicValue const& value) const;
64 LLNDAPI Expected<Property>
65 createProperty(std::string datastore, std::string property, std::string const& json) const;
66
67 LLNDAPI Expected<Property> borrowProperty(std::string datastore, std::string property) const;
68
69 // Direct path: no coroutine frame or executor hop is created.
70 LLNDAPI Expected<> show(Callback callback = {}) const;
71
72 // The caller must launch/await this task on the server thread.
73 LLNDAPI coro::CoroTask<Result> showAsync() const;
74
75 LLNDAPI Expected<> close() const;
76
77 [[nodiscard]] LLAPI explicit operator bool() const noexcept;
78};
79
80LLAPI void closeScreen(Player& player);
81
82} // namespace ll::ui
Definition Player.h:137
Definition move_only_function.h:9
Definition DynamicValue.h:14
Definition CoroTask.h:45
Definition ScreenSession.h:30