载入中...
搜索中...
未找到
ActionComboWindowState.cpp
浏览该文件的文档.
2
3#include "common/Capability.h"
4
5#include <algorithm>
6#include <utility>
7
8namespace eve::action::input {
9namespace {
10
11} // namespace
12
14
15ActionComboWindowState::~ActionComboWindowState() { cap::removeListener<IActionStateWindowSink>(this); }
16
18 for (std::size_t index = 0; index < cap::listenerCount<IActionStateWindowSink>(); ++index)
19 if (cap::listenerAt<IActionStateWindowSink>(index) == this) return true;
20 return false;
21}
22
24 const bool current = enabled();
25 if (value && !current)
26 cap::addListener<IActionStateWindowSink>(this);
27 else if (!value && current)
28 cap::removeListener<IActionStateWindowSink>(this);
29}
30
34
36 const ActionTimelineEvent& event,
38 if (!supports(binding.kind))
40 Diagnostic::error(DiagnosticCode::Unsupported, "input adapter does not own this window kind", "kind"));
41 if (!resolver_)
43 Diagnostic::error(DiagnosticCode::NotFound, "combo subject resolver is unavailable", "resolver"));
44 std::optional<ecs::EntityHandle> handle;
45 if (binding.targetIndex) {
46 if (*binding.targetIndex >= context.targets.size())
48 Diagnostic::error(DiagnosticCode::NotFound, "combo target index is unavailable", "targetIndex"));
49 handle = context.targets[*binding.targetIndex];
50 } else {
51 handle = context.source;
52 }
53 if (!handle)
55 Diagnostic::error(DiagnosticCode::NotFound, "combo window has no source or target", "subject"));
56 auto subject = resolver_(*handle);
57 if (!subject) return Result<void>::failure(subject.status());
58 if (!subject.value().isValid())
60 Diagnostic::error(DiagnosticCode::InvalidArgument, "combo-window subject is nil", "subject"));
61
62 ActiveKey key{context.executionId, event.itemId.format()};
63 const auto found = active_.find(key);
64 if (found != active_.end()) {
65 if (found->second.subject == subject.value() && found->second.input == binding.resource)
68 Diagnostic::error(DiagnosticCode::Conflict, "combo-window key has different active data", "itemId"));
69 }
70 active_.emplace(std::move(key), ActiveCombo{event.itemId, subject.value(), binding.resource});
72}
73
75 const ActionTimelineEvent& event,
77 if (!supports(binding.kind))
79 Diagnostic::error(DiagnosticCode::Unsupported, "input adapter does not own this window kind", "kind"));
80 const ActiveKey key{context.executionId, event.itemId.format()};
81 const auto found = active_.find(key);
82 if (found == active_.end()) return Result<void>::success(Status::success(StatusCode::NoOp));
83 active_.erase(found);
85}
86
88 std::vector<std::string> result;
89 for (const auto& [key, combo] : active_) {
90 (void)key;
91 if (combo.subject == subject) result.push_back(combo.input);
92 }
93 std::sort(result.begin(), result.end());
94 result.erase(std::unique(result.begin(), result.end()), result.end());
95 return result;
96}
97
99 if (!subject.isValid())
101 Diagnostic::error(DiagnosticCode::InvalidArgument, "combo subject is nil", "subject"));
102 if (input.empty())
104 Diagnostic::error(DiagnosticCode::InvalidArgument, "combo input is empty", "input"));
105 for (const auto& [key, combo] : active_) {
106 if (combo.subject == subject && combo.input == input)
108 ActionComboMatch{key.first, combo.itemId, combo.subject, combo.input});
109 }
111 Diagnostic::error(DiagnosticCode::NotFound, "no active combo window accepts the input", "input"));
112}
113
114} // namespace eve::action::input
Semantic input matching for active Montage combo windows.
double value
int subject
Definition AnimSmr.cpp:163
EvpackChunkInput input
Definition Evpack.cpp:170
std::uint32_t key
TokenKind kind
eve::action::ActionVfxBinding binding
PrimitiveHandle handle
bool found
double current
uint32_t index
const VegetationPresetContext & context
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
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
Strong, domain-neutral reference to a runtime subject.
Definition SubjectRef.h:26
Result< ActionComboMatch > match(SubjectRef subject, std::string_view input) const
Resolve the first deterministic active window accepting an input.
ActionComboWindowState(ComboSubjectResolver resolver)
Construct with a synchronous stable-subject resolver.
Result< void > exit(const ActionStateWindowBinding &binding, const ActionTimelineEvent &event, const ActionNotifyContext &context) override
Exit one previously entered window by execution and item identity.
void setEnabled(bool enabled)
Opt this state owner into or out of Action window dispatch.
std::vector< std::string > availableInputs(SubjectRef subject) const
Return sorted unique semantic inputs currently accepted for a subject.
~ActionComboWindowState() override
Action combo window state.
Result< void > enter(const ActionStateWindowBinding &binding, const ActionTimelineEvent &event, const ActionNotifyContext &context) override
Enter one validated window or idempotently observe the same active key.
bool supports(ActionStateWindowKind kind) const noexcept override
Whether this sink owns the supplied semantic window kind.
bool enabled() const
Return whether this exact owner is registered.
std::function< Result< SubjectRef >(ecs::EntityHandle)> ComboSubjectResolver
Resolves an owning stable subject from a generation-qualified ECS handle.
ActionStateWindowKind
Stable semantic kind for one built-in state window.
Context linking a routed event to its action execution.
Owning validated state-window request authored on an action timeline.
Owning event projection returned by the runtime sampler.
Owning deterministic match between one semantic input and an active combo window.