载入中...
搜索中...
未找到
PcgPhotoModeSession.cpp
浏览该文件的文档.
2
3#include <simplesquirrel/simplesquirrel.hpp>
4
6
7namespace eve::ui {
8 // namespace
9
10Result<void> PcgPhotoModeSession::begin(const std::string& capturedJson, const std::string& savedJson,
11 bool loadSaved, bool savedEver, int currentPipeline, int savedPipeline,
12 const std::string& sceneName, int lightingProfile) {
13 if (active_) return Result<void>::failure(
14 Diagnostic::error(DiagnosticCode::InvalidArgument, "photo-mode session is already active", {}, {}, "ui.pcgPhotoModeSession"));
15 PcgPhotoModeValues captured;
16 auto capturedResult = captured.restoreJson(capturedJson);
17 if (!capturedResult.ok()) return Result<void>::failure(capturedResult.status());
18
19 PcgPhotoModeValues working = captured;
21 if (loadSaved && savedEver && currentPipeline == savedPipeline && !savedJson.empty()) {
23 auto savedResult = saved.restoreJson(savedJson);
24 if (!savedResult.ok()) return Result<void>::failure(savedResult.status());
25 auto savedScene = saved.getString("m_lastSceneName");
26 auto savedLighting = saved.getInt("m_selectedPcgLightingProfile");
27 auto savedPcg = saved.getBool("m_isUsingPcgLighting");
28 if (!savedScene.ok()) return Result<void>::failure(savedScene.status());
29 if (!savedLighting.ok()) return Result<void>::failure(savedLighting.status());
30 if (!savedPcg.ok()) return Result<void>::failure(savedPcg.status());
31 const bool lightingMatches = savedLighting.value() == lightingProfile &&
32 savedPcg.value() == (lightingProfile >= 0);
33 if (savedScene.value() == sceneName && lightingMatches) {
34 working = std::move(saved);
36 } else {
38 }
39 }
40
41 captured_ = std::move(captured);
42 working_ = working;
43 output_ = working_;
44 loadDecision_ = decision;
45 active_ = true;
46 restoreRequested_ = false;
47 removePhotoCameraRequested_ = false;
48 unfreezePlayerRequested_ = false;
49 ++revision_;
50 return Result<void>::success();
51}
52
54 if (!active_) return Result<void>::failure(
55 Diagnostic::error(DiagnosticCode::InvalidArgument, "photo-mode session is not active", {}, {}, "ui.pcgPhotoModeSession"));
56 PcgPhotoModeValues candidate;
57 auto result = candidate.restoreJson(json);
58 if (!result.ok()) return Result<void>::failure(result.status());
59 working_ = std::move(candidate);
60 output_ = working_;
61 ++revision_;
62 return Result<void>::success();
63}
64
65Result<void> PcgPhotoModeSession::end(bool resetOnDisable, bool applicationPlaying) {
66 if (!active_) return Result<void>::failure(
67 Diagnostic::error(DiagnosticCode::InvalidArgument, "photo-mode session is not active", {}, {}, "ui.pcgPhotoModeSession"));
68 removePhotoCameraRequested_ = true;
69 unfreezePlayerRequested_ = true;
70 restoreRequested_ = resetOnDisable && applicationPlaying;
71 output_ = restoreRequested_ ? captured_ : working_;
72 active_ = false;
73 ++revision_;
74 return Result<void>::success();
75}
76
79
80void exposePcgPhotoModeSessionBindings(ssq::Table& table) {
81 auto vm = table.getHandle();
82 auto cls = table.addClass("PcgPhotoModeSession", ssq::Class::Ctor<PcgPhotoModeSession()>());
83 cls.addFunc("begin", [vm](PcgPhotoModeSession* self, const std::string& captured, const std::string& saved,
84 bool loadSaved, bool savedEver, int currentPipeline, int savedPipeline,
85 const std::string& sceneName, int lightingProfile) {
86 return eve::script::projectResult(vm, self->begin(captured, saved, loadSaved, savedEver, currentPipeline,
87 savedPipeline, sceneName, lightingProfile));
88 });
89 cls.addFunc("replaceWorkingJson", [vm](PcgPhotoModeSession* self, const std::string& value) {
91 });
92 cls.addFunc("end", [vm](PcgPhotoModeSession* self, bool reset, bool playing) {
93 return eve::script::projectResult(vm, self->end(reset, playing));
94 });
95 cls.addFunc("workingJson", [vm](const PcgPhotoModeSession* self) {
96 return eve::script::projectResult(vm, self->workingJson(), [](const std::string& value) { return value; });
97 });
98 cls.addFunc("outputJson", [vm](const PcgPhotoModeSession* self) {
99 return eve::script::projectResult(vm, self->outputJson(), [](const std::string& value) { return value; });
100 });
101 cls.addFunc("getActive", [](const PcgPhotoModeSession* self) { return self->getActive(); });
102 cls.addFunc("getRestoreRequested", [](const PcgPhotoModeSession* self) { return self->getRestoreRequested(); });
103 cls.addFunc("getRemovePhotoCameraRequested",
104 [](const PcgPhotoModeSession* self) { return self->getRemovePhotoCameraRequested(); });
105 cls.addFunc("getUnfreezePlayerRequested",
106 [](const PcgPhotoModeSession* self) { return self->getUnfreezePlayerRequested(); });
107 cls.addFunc("getLoadDecision", [](const PcgPhotoModeSession* self) { return self->getLoadDecision(); });
108 cls.addFunc("getRevision", [](const PcgPhotoModeSession* self) { return self->getRevision(); });
109}
110} // namespace eve::ui
double value
HSQUIRRELVM vm
Definition ECS.cpp:20
HSQOBJECT cls
Definition ECS.cpp:21
The single Squirrel projection for common Result, Status and Value.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Transactional lifecycle state for Pcg PhotoMode setup, disable and destroy.
Result< std::string > outputJson() const
Encode values that the caller must apply after end.
Result< void > replaceWorkingJson(const std::string &json)
Replace the working values after a UI or engine edit.
bool getActive() const noexcept
Returns the active.
bool getRemovePhotoCameraRequested() const noexcept
Returns the remove photo camera requested.
Result< void > end(bool resetOnDisable, bool applicationPlaying)
End the session; restore captured settings only when both flags are true.
int getLoadDecision() const noexcept
Returns the load decision.
bool getRestoreRequested() const noexcept
bool getUnfreezePlayerRequested() const noexcept
Returns the unfreeze player requested.
uint64_t getRevision() const noexcept
Result< std::string > workingJson() const
Encode the currently selected working profile.
Result< void > begin(const std::string &capturedJson, const std::string &savedJson, bool loadSaved, bool savedEver, int currentPipeline, int savedPipeline, const std::string &sceneName, int lightingProfile)
Begin from captured engine values and optionally select a compatible saved profile.
Complete typed value set from Pcg PhotoModeProfile with exact defaults.
Result< bool > getBool(const std::string &name) const
Read a typed boolean field.
Result< void > restoreJson(const std::string &json)
Atomically restore schema 1 JSON; unknown or missing fields are rejected.
Result< std::string > snapshotJson() const
Encode schema 1 JSON containing every field.
Result< int64_t > getInt(const std::string &name) const
Read a typed integer field.
Result< std::string > getString(const std::string &name) const
Read a typed string field.
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.
void exposePcgPhotoModeSessionBindings(ssq::Table &table)
Register Pcg photo-mode session bindings.