载入中...
搜索中...
未找到
ClimbingEventValue.cpp
浏览该文件的文档.
2
3#include <array>
4#include <string>
5#include <utility>
6
7namespace eve::climbing {
8namespace {
9
10struct EventKindName {
12 const char* name;
13};
14
19constexpr std::array<EventKindName, kClimbingEventKindCount> kEventKindNames = {{
20 {ClimbingEventKind::Started, "started"},
21 {ClimbingEventKind::AnchorTransitionStarted, "anchor_transition_started"},
22 {ClimbingEventKind::AnchorReached, "anchor_reached"},
23 {ClimbingEventKind::ContactLeftHand, "contact_left_hand"},
24 {ClimbingEventKind::ContactRightHand, "contact_right_hand"},
25 {ClimbingEventKind::Landed, "landed"},
26 {ClimbingEventKind::Hanging, "hanging"},
27 {ClimbingEventKind::Dropped, "dropped"},
28 {ClimbingEventKind::Completed, "completed"},
29 {ClimbingEventKind::Cancelled, "cancelled"},
30 {ClimbingEventKind::Failed, "failed"},
31}};
32
33} // namespace
34
36 for (const EventKindName& entry : kEventKindNames) {
37 if (entry.kind == kind) return entry.name;
38 }
39 return "failed";
40}
41
43 for (const EventKindName& entry : kEventKindNames) {
44 if (name == entry.name) {
45 out = entry.kind;
47 }
48 }
50}
51
53 Value::Array metadata;
54 metadata.reserve(event.metadata.size());
55 for (const std::string& value : event.metadata) metadata.emplace_back(value);
56 return Value::object({
57 {"kind", std::string(climbingEventKindName(event.kind))},
58 {"actionId", event.actionId},
59 {"tick", std::to_string(event.tick.value())},
60 {"executionId", std::to_string(event.executionId.value())},
61 {"metadata", Value(std::move(metadata))},
62 });
63}
64
65Value climbingEventArrayValue(std::span<const ClimbingEvent> events) {
67 values.reserve(events.size());
68 for (const ClimbingEvent& event : events) values.push_back(climbingEventValue(event));
69 return Value(std::move(values));
70}
71
72} // namespace eve::climbing
攀爬事件 ↔ eve::Value 的**唯一**映射。
std::string name
Definition ECS.cpp:154
std::vector< particles::ParticleRecordEvent > events
std::set< std::string > values
Object::Ptr value
ScriptStructure out
std::string kind
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
std::vector< Value > Array
Definition Value.h:33
static Value object(Object value)
Compatibility factory for an object value.
Definition Value.cpp:129
constexpr std::uint64_t value() const noexcept
Returns the underlying value at an explicit protocol boundary.
Value climbingEventArrayValue(std::span< const ClimbingEvent > events)
一批事件 → Value 数组,顺序与传入一致。
std::string_view climbingEventKindName(ClimbingEventKind kind)
事件种类的稳定脚本名(snake_case,例如 "anchor_transition_started")。
EventKindParse
事件种类名的解析结果。
@ Unknown
不认识这个名字;out 未被改动(不猜默认值)。
@ Parsed
name 认识,out 已写入。
EventKindParse parseClimbingEventKind(std::string_view name, ClimbingEventKind &out)
名字 → ClimbingEventKind(climbingEventKindName 的严格逆)。
ClimbingEventKind
Stable semantic event emitted by the authoritative climbing lifecycle.
Definition Climbing.h:488
Value climbingEventValue(const ClimbingEvent &event)
一个事件 → {kind, actionId, tick, executionId, metadata}。
Owning event record; dispatch to scripts only after the simulation phase.
Definition Climbing.h:513
std::vector< std::string > metadata
Owning immutable action metadata copied when the event is enqueued.
Definition Climbing.h:519
ClimbingEventKind kind
Definition Climbing.h:514
eve::SimulationTick tick
Definition Climbing.h:516
ClimbingExecutionId executionId
Definition Climbing.h:517