载入中...
搜索中...
未找到
CardDefinitionRuntime.cpp
浏览该文件的文档.
15eve::Result<eve::definition::DefinitionHandle> currentHandle(eve::definitions::DefinitionRegistry& registry,
29 if (*integer < std::numeric_limits<int>::min() || *integer > std::numeric_limits<int>::max()) return false;
44 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "card definition payload must be an object",
52 return eve::Result<CardRuntimeState>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
60 return eve::Result<CardRuntimeState>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
68 eve::DiagnosticCode::InvalidArgument, "card cost, attack and health must be Int64 fields", "stats", {},
71 return eve::Result<CardRuntimeState>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
80 eve::DiagnosticCode::InvalidArgument, "card tint must contain three numeric channels", "tint", {},
97 return eve::Result<CardRuntimeState>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
104 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "card tag must be a non-empty string",
132 eve::Value::Array tint{eve::Value(static_cast<double>(state.tint.r)), eve::Value(static_cast<double>(state.tint.g)),
151 return eve::Result<CardRuntimeState>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
160 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "unknown card runtime state field",
166 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "card runtime state is missing a field",
181 if (name == nullptr || kind == nullptr || tags == nullptr || tint == nullptr || tint->size() != 3 ||
183 !readIntField("currentHealth", result.currentHealth) || !readIntField("maxHealth", result.maxHealth))
184 return eve::Result<CardRuntimeState>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
192 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "card runtime health/stat values are invalid",
216eve::Result<CardDefinitionRuntime> CardDefinitionRuntime::create(eve::definitions::DefinitionRegistry& registry,
222 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "card definition reference is invalid", {}, {},
239const CardRuntimeState& CardDefinitionRuntime::state() const noexcept { return runtime_.state(); }
281eve::Result<eve::definition::ReloadOutcome> CardDefinitionRuntime::reload(eve::definition::ReloadPolicy policy) {
284 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "card definition registry is not bound",
291 auto rebuild = [defaultState](const CardRuntimeState& oldState, const eve::definition::InstanceIdentity&,
303 eve::Revision revision, eve::SimulationTick tick, const eve::SnapshotHashProvider& hashProvider) const {
304 const eve::definition::RuntimeStateEncoder<CardRuntimeState> encoder = [](const CardRuntimeState& value) {
307 return eve::definition::snapshotRuntimeInstance(runtime_, "card.runtime", cardSchema(), eve::SchemaVersion(1),
332 return eve::definition::restoreRuntimeInstance(runtime_, snapshotValue, "card.runtime", cardSchema(),
std::map< std::string, std::vector< Key >, std::less<> > channels
Definition AnimCurveLibrary.cpp:19
Strongly typed CardDefinition to CardData runtime adapter.
Owning, renderer-independent dynamic values.
const LogicalId & id() const noexcept
Return the stable logical definition identity.
Definition ResourceRef.h:97
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
Human-readable, scoped identifier in the form namespace:name.
Definition Identity.h:411
static std::optional< LogicalId > parse(std::string_view text)
Parses a scoped logical name.
Definition Identity.cpp:36
std::string_view name() const noexcept
Returns the name component as a view into this object.
Definition Identity.cpp:63
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:57
单张卡牌:ECS 实体,数据拆成 Identity / Stats / Visual / Layout / State。
Definition CardTypes.h:94
Binds a typed card runtime to one Definitions registry incarnation.
Definition CardDefinitionRuntime.h:48
eve::Result< eve::definition::ReloadOutcome > reload(eve::definition::ReloadPolicy policy)
Reload from the registry's current generation and execute policy.
Definition CardDefinitionRuntime.cpp:281
const CardRuntimeState & state() const noexcept
Borrow the strongly typed card runtime state.
Definition CardDefinitionRuntime.cpp:239
const eve::definition::InstanceIdentity & identity() const noexcept
Borrow the unified instance identity.
Definition CardDefinitionRuntime.cpp:235
eve::Result< std::string > snapshotJson(eve::Revision revision, eve::SimulationTick tick, const eve::SnapshotHashProvider &hashProvider) const
Serialize snapshot() as canonical JSON.
Definition CardDefinitionRuntime.cpp:311
eve::Result< void > applyTo(CardData *card) const
Apply the typed state and common identity to an ECS CardData.
Definition CardDefinitionRuntime.cpp:251
bool isActive() const noexcept
Return whether RejectWhileActive currently treats the instance as active.
Definition CardDefinitionRuntime.cpp:249
static eve::Result< CardDefinitionRuntime > create(eve::definitions::DefinitionRegistry ®istry, eve::DefinitionRef definition, eve::PersistentId instanceId, eve::definition::ReloadPolicy policy=eve::definition::ReloadPolicy::KeepInstanceValues)
Create a card runtime from the current typed definition.
Definition CardDefinitionRuntime.cpp:216
void setActive(bool active) noexcept
Mark the instance active/inactive for RejectWhileActive.
Definition CardDefinitionRuntime.cpp:247
eve::Result< eve::SnapshotEnvelope > snapshot(eve::Revision revision, eve::SimulationTick tick, const eve::SnapshotHashProvider &hashProvider) const
Capture card instance state in the common SnapshotEnvelope.
Definition CardDefinitionRuntime.cpp:302
eve::definition::DefinitionHandle definitionHandle() const noexcept
Borrow the exact generation-qualified definition handle.
Definition CardDefinitionRuntime.cpp:243
eve::Result< void > restore(const eve::SnapshotEnvelope &snapshot, const eve::SnapshotHashProvider &hashProvider)
Verify and atomically restore a same-generation card snapshot.
Definition CardDefinitionRuntime.cpp:319
static eve::Result< RuntimeInstance > create(eve::PersistentId instanceId, eve::DefinitionRef definition, eve::Generation definitionGeneration, State state, bool active=true)
Construct a runtime instance after validating its identity.
Definition DefinitionRuntime.h:321
Deterministic registry of topic-neutral, versioned JSON definitions.
Definition Definitions.h:58
eve::ResultRef< const Definition > resolveHandle(const DefinitionHandle &handle) const
Resolves a generation-qualified handle and reports stale identities.
Definition Definitions.cpp:319
eve::Result< DefinitionHandle > handle(const std::string &type, const std::string &id) const
Returns the current generation-qualified handle through Result.
Definition Definitions.cpp:325
Definition Card.cpp:19
eve::Result< eve::SnapshotEnvelope > snapshotRuntimeInstance(const RuntimeInstance< State > &runtime, std::string type, eve::LogicalId schema, eve::SchemaVersion schemaVersion, eve::Revision revision, eve::SimulationTick tick, const eve::SnapshotHashProvider &hashProvider, const RuntimeStateEncoder< State > &encode)
Capture a typed runtime instance in the common snapshot envelope.
Definition RuntimeSnapshot.h:96
eve::Result< void > restoreRuntimeInstance(RuntimeInstance< State > &runtime, const eve::SnapshotEnvelope &snapshot, std::string_view expectedType, const eve::LogicalId &expectedSchema, eve::SchemaVersion expectedVersion, const eve::SnapshotHashProvider &hashProvider, const RuntimeStateDecoder< State > &decode)
Verify and atomically restore a typed runtime instance.
Definition RuntimeSnapshot.h:135
std::function< eve::Result< State >(const eve::Value &)> RuntimeStateDecoder
Decodes one domain-owned runtime state from an owning Value.
Definition RuntimeSnapshot.h:31
std::function< eve::Result< eve::Value >(const State &)> RuntimeStateEncoder
Converts one domain-owned runtime state into an owning Value.
Definition RuntimeSnapshot.h:27
const EditorValue * field(const EditorValue &value, const char *name)
Definition RoadNetworkEditTarget.cpp:15
@ InvalidArgument
@ StaleHandle
Result< std::string > serializeSnapshotEnvelope(const SnapshotEnvelope &snapshot)
Serialize an envelope as deterministic compact JSON.
Definition Snapshot.cpp:184
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
Definition link and reload policy for this card instance.
Definition CardTypes.h:163
eve::definition::ReloadPolicy reloadPolicy
Definition CardTypes.h:165
Typed mutable values owned by one card definition instance.
Definition CardDefinitionRuntime.h:28
A generation-qualified reference to one definition incarnation.
Definition DefinitionRuntime.h:69
Canonical identity carried by every typed runtime instance.
Definition DefinitionRuntime.h:87
eve::DefinitionRef definition
Definition DefinitionRuntime.h:89
One immutable view of a registered versioned JSON definition.
Definition Definitions.h:31