载入中...
搜索中...
未找到
CardDefinitionRuntime.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
10#include "card/CardTypes.h"
11#include "common/Snapshot.h"
15
16#include <string>
17#include <vector>
18
19namespace eve::card {
20
29 std::string name;
30 std::string kind = "creature";
31 int cost = 0;
32 int attack = 0;
33 int maxHealth = 0;
35 glm::vec3 tint{0.62f, 0.50f, 0.40f};
36 std::vector<std::string> tags;
37};
38
49public:
57 [[nodiscard]] static eve::Result<CardDefinitionRuntime> create(
60
64 CardDefinitionRuntime& operator=(CardDefinitionRuntime&&) noexcept = default;
68 CardDefinitionRuntime& operator=(const CardDefinitionRuntime&) = delete;
71
73 [[nodiscard]] const eve::definition::InstanceIdentity& identity() const noexcept;
75 [[nodiscard]] const CardRuntimeState& state() const noexcept;
77 [[nodiscard]] CardRuntimeState& state() noexcept;
79 [[nodiscard]] eve::definition::DefinitionHandle definitionHandle() const noexcept;
81 [[nodiscard]] eve::definition::ReloadPolicy reloadPolicy() const noexcept { return policy_; }
83 void setActive(bool active) noexcept;
85 [[nodiscard]] bool isActive() const noexcept;
86
92 [[nodiscard]] eve::Result<void> applyTo(CardData* card) const;
93
100 [[nodiscard]] eve::Result<eve::definition::ReloadOutcome> reload(eve::definition::ReloadPolicy policy);
101
104 const eve::SnapshotHashProvider& hashProvider) const;
106 [[nodiscard]] eve::Result<std::string> snapshotJson(eve::Revision revision, eve::SimulationTick tick,
107 const eve::SnapshotHashProvider& hashProvider) const;
109 [[nodiscard]] eve::Result<void> restore(const eve::SnapshotEnvelope& snapshot,
110 const eve::SnapshotHashProvider& hashProvider);
111
112private:
113 CardDefinitionRuntime(eve::definitions::DefinitionRegistry& registry,
114 eve::definition::RuntimeInstance<CardRuntimeState> runtime,
115 eve::definition::ReloadPolicy policy)
116 : registry_(&registry), runtime_(std::move(runtime)), policy_(policy) {}
117
118 eve::definitions::DefinitionRegistry* registry_ = nullptr; // borrowed
121};
122
123} // namespace eve::card
bool & active
Common identity and hot-reload contract for typed runtime instances.
#define EVENGINE_API_WORLD
Definition Export.h:109
std::uint64_t revision
Shared SnapshotEnvelope codec for typed definition runtime instances.
Versioned, integrity-checked persistence envelopes.
LogicalId definition
SimulationTick tick
const std::map< std::string, Value > & definitions
Stable definition reference backed by LogicalId.
Definition ResourceRef.h:85
Move-only operation result carrying either a value or Status.
Definition Result.h:155
单张卡牌:ECS 实体,数据拆成 Identity / Stats / Visual / Layout / State。
Definition CardTypes.h:94
Binds a typed card runtime to one Definitions registry incarnation.
CardDefinitionRuntime(CardDefinitionRuntime &&) noexcept=default
Move a card runtime while retaining its borrowed registry binding.
Owns one strongly typed runtime state and its definition identity.
Deterministic registry of topic-neutral, versioned JSON definitions.
Definition Definitions.h:58
Id128 public API.
Definition Identity.h:112
ReloadPolicy
Policy used when a live definition is replaced.
@ KeepInstanceValues
Replace the definition generation and preserve all instance values.
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
std::function< Result< ContentId >(std::string_view canonicalInput)> SnapshotHashProvider
Injected content-digest implementation used by snapshots.
Definition Snapshot.h:36
Stable outer format shared by persistence and cross-process snapshots.
Definition Snapshot.h:46
Typed mutable values owned by one card definition instance.
std::vector< std::string > tags