载入中...
搜索中...
未找到
Card.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
12#include "card/CardPlay.h"
13#include "card/CardTypes.h"
14#include "common/ECS.h"
15#include "common/Module.h"
16#include "common/Result.h"
17
18#include <cstddef>
19#include <memory>
20#include <string>
21#include <string_view>
22#include <unordered_map>
23#include <vector>
24namespace eve::graphics {
25class Graphics;
26}
27
28namespace eve::resource {
29class IResourceAccount;
30}
31
33class AtomicBatch;
34}
35
36namespace eve::card {
37
38class CardControl;
39
42 std::string instanceId;
43 std::string definitionId;
44 std::string state;
45 float x = 0.f;
46 float y = 0.f;
47 float width = 0.f;
48 float height = 0.f;
49 float angle = 0.f;
50 float scale = 1.f;
51 float alpha = 1.f;
52 bool hovered = false;
53 bool dragging = false;
54 bool disabled = false;
56 bool faceUp = true;
58 float flip = 0.f;
60 float flipAngle = 0.f;
62 float flipLift = 0.f;
64 float flipAxisScale = 1.f;
66 bool showingFront = true;
68 int flipAxis = 0;
69};
70
73public:
75 void setLogicalRect(float x, float y, float width, float height);
77 void setPlane(float ox, float oy, float oz, float ux, float uy, float uz,
78 float vx, float vy, float vz);
80 bool mapRay(float ox, float oy, float oz, float dx, float dy, float dz);
82 bool mapLayout(float x, float y);
95 [[nodiscard]] eve::Result<void> mapCardPose(float x, float y, float layoutAngleDeg, float flipProgress,
96 float liftPeak, int flipAxis);
98 float getLogicalX() const { return resultLogicalX_; }
100 float getLogicalY() const { return resultLogicalY_; }
102 float getWorldX() const { return resultWorld_.x; }
104 float getWorldY() const { return resultWorld_.y; }
106 float getWorldZ() const { return resultWorld_.z; }
108 float getBasisUX() const { return resultBasisU_.x; }
110 float getBasisUY() const { return resultBasisU_.y; }
112 float getBasisUZ() const { return resultBasisU_.z; }
114 float getBasisVX() const { return resultBasisV_.x; }
116 float getBasisVY() const { return resultBasisV_.y; }
118 float getBasisVZ() const { return resultBasisV_.z; }
120 float getBasisNX() const { return resultBasisN_.x; }
122 float getBasisNY() const { return resultBasisN_.y; }
124 float getBasisNZ() const { return resultBasisN_.z; }
126 bool isShowingFront() const { return resultShowingFront_; }
127
128private:
129 glm::vec3 origin_{0.f};
130 glm::vec3 axisU_{1.f, 0.f, 0.f};
131 glm::vec3 axisV_{0.f, 0.f, 1.f};
132 glm::vec3 resultWorld_{0.f};
133 glm::vec3 resultBasisU_{1.f, 0.f, 0.f};
134 glm::vec3 resultBasisV_{0.f, 0.f, 1.f};
135 glm::vec3 resultBasisN_{0.f, 1.f, 0.f};
136 float logicalX_ = 0.f;
137 float logicalY_ = 0.f;
138 float logicalWidth_ = 1.f;
139 float logicalHeight_ = 1.f;
140 float resultLogicalX_ = 0.f;
141 float resultLogicalY_ = 0.f;
142 bool resultShowingFront_ = true;
143};
144
147public:
152 ~Card() override;
153
154 // The two `vector<unique_ptr<...>>` members make the implicit copy operations
155 // ill-formed (C2280) the moment a class-level dllexport instantiates them;
156 // spell the four out so the export surface stays defined. Semantics unchanged:
157 // a module instance was never copyable or assignable in practice.
158 Card(const Card &) = delete;
159 Card &operator=(const Card &) = delete;
160 // Out of line for the same reason as the constructor and destructor above: a
161 // defaulted move in the class body instantiates the move of every member,
162 // including the deleter of the incomplete `CardControl`.
164 Card(Card &&) noexcept;
166 Card &operator=(Card &&) noexcept;
167
169 int registerCardsFromJson(const std::string &json);
171 void clearCardDefinitions();
173 int getCardDefinitionCount();
178 std::string getCardDefinitionId(int index) const;
180 bool hasCardDefinition(const std::string &id);
193 bool setCardDefinition(const std::string &id, const std::string &name, const std::string &kind,
194 int cost, int attack, int health, float tintR, float tintG, float tintB);
199 bool removeCardDefinition(const std::string &id);
206 [[nodiscard]] eve::Result<void> setCardPlayCondition(const std::string& id, condition::Condition condition);
207 std::string getCardDefinitionName(const std::string &id);
209 std::string getCardDefinitionKind(const std::string &id);
211 int getCardDefinitionCost(const std::string &id);
213 int getCardDefinitionAttack(const std::string &id);
215 int getCardDefinitionHealth(const std::string &id);
217 float getCardDefinitionTintR(const std::string &id);
219 float getCardDefinitionTintG(const std::string &id);
221 float getCardDefinitionTintB(const std::string &id);
222
224 LayoutConfig *newConfig();
226 CardData *newCard(const std::string &defId);
228 Deck *newDeck();
230 Zone *newZone(const std::string &id, const std::string &label, float x, float y, float w, float h);
232 Hand *newHand(LayoutConfig *cfg);
234 CardPlaneMapper *newPlaneMapper();
235
237 void setConfig(LayoutConfig *cfg);
239 LayoutConfig *getConfig() const;
241 int handCount() const;
243 Hand *getHand(int index) const;
245 Hand *findHand(const std::string &owner) const;
247 int zoneCount() const;
249 Zone *getZone(int index) const;
251 Deck *getDeck() const;
253 CardData *drawCard(const std::string &handOwner);
254
261 [[nodiscard]] condition::ConditionResult evaluatePlay(const CardData* card,
262 CardPlayConditionQueries queries = {}) const;
268 [[nodiscard]] Result<std::optional<resource::CostSpec>> playCost(CardData &card) const;
281 [[nodiscard]] Result<void> stagePlay(transaction::AtomicBatch &batch, CardData &card) const;
282 [[nodiscard]] Result<std::unique_ptr<transaction::ITransactionParticipant>> prepareHandConsumption(
283 CardData &card) const;
284
291 [[nodiscard]] eve::Result<double> getCardAttribute(CardData &card, std::string_view attribute) const;
292
300 [[nodiscard]] eve::Result<void> setCardAttribute(CardData &card, std::string_view attribute, double value) const;
301
309 [[nodiscard]] eve::Result<effects::EffectHandle> applyEffect(CardData &card, const CardEffectDefinition &definition,
311
318
328 eve::resource::IResourceAccount &playerAccount,
329 CardPlayComposition composition = {},
330 std::string transactionId = {});
331
333 int capturePresentation();
335 int getPresentationCount() const;
337 CardPresentationSnapshot *getPresentation(int index);
338
340 void update(float dt, float mx, float my, bool down);
342 void render(graphics::Graphics *gfx);
344 void renderDeck(graphics::Graphics *gfx);
345
347 void setBuiltInVisuals(bool enabled) { builtInVisuals_ = enabled; }
349 bool getBuiltInVisuals() const { return builtInVisuals_; }
350
368 [[nodiscard]] eve::Result<void> publishGameplay(const std::string &instanceId, const std::string &ownerId,
371 [[nodiscard]] eve::Result<void> unpublishGameplay(const std::string &instanceId);
373 void clearGameplayControls();
375 [[nodiscard]] int gameplayControlCount() const;
377 [[nodiscard]] std::vector<std::string> gameplayInstances() const;
378
379private:
381 std::unique_ptr<CardControl> gameplay_;
382
384 void beginTargeting(const std::string &sourceId, float x, float y);
386 void updateTargeting(float x, float y, const std::string &targetId, bool valid);
388 void cancelTargeting();
390 void renderTargeting(graphics::Graphics *gfx);
392 bool isTargeting() const { return targetingActive_; }
394 bool isTargetValid() const { return targetingValid_; }
396 std::string getTargetSource() const { return targetingSource_; }
398 std::string getTargetId() const { return targetingId_; }
399
401 void clearEvents();
402 int getEventCount() const;
403 std::string getEventType(int index) const;
404 std::string getEventHand(int index) const;
405 std::string getEventZone(int index) const;
406 std::string getEventCardId(int index) const;
407 std::string getEventReason(int index) const;
408
409private:
410 const CardDefinition *findDef(const std::string &id) const;
411
412 std::unordered_map<std::string, CardDefinition> defs_;
413 mutable std::vector<std::string> definitionView_;
414 mutable bool definitionViewDirty_ = true;
415 std::vector<std::unique_ptr<LayoutConfig>> configs_;
416 std::vector<std::unique_ptr<CardPlaneMapper>> planeMappers_;
417 std::vector<CardEvent> events_;
418 std::vector<ecs::EntityHandle> cards_;
419 std::vector<ecs::EntityHandle> decks_;
420 std::vector<ecs::EntityHandle> zones_;
421 std::vector<ecs::EntityHandle> hands_;
422 std::vector<CardPresentationSnapshot> presentation_;
423
424 LayoutConfig *activeConfig_ = nullptr;
425 Deck *activeDeck_ = nullptr;
426 int nextInstance_ = 1;
427 bool builtInVisuals_ = true;
428 bool targetingActive_ = false;
429 bool targetingValid_ = false;
430 float targetingStartX_ = 0.f;
431 float targetingStartY_ = 0.f;
432 float targetingX_ = 0.f;
433 float targetingY_ = 0.f;
434 std::string targetingSource_;
435 std::string targetingId_;
436};
437
438} // namespace eve::card
double y
double x
float w
Definition AnimClip.cpp:738
int subject
Definition AnimSmr.cpp:163
Card Play adapter for the renderer-independent decision protocol.
eve::resource::CostSpec cost
eve::resource::IResourceAccount * account
eve::Value condition
std::string name
Definition ECS.cpp:154
EnvironmentTest definition
int instanceId
std::uint64_t sourceId
#define EVENGINE_API_WORLD
Definition Export.h:109
int h
std::uint32_t height
std::uint32_t width
std::string label
bool valid
std::shared_ptr< OceanGpuSpectrum > owner
glm::dvec3 dx
glm::dvec3 dz
double dt
std::uint32_t targetId
Object::Ptr value
std::string attribute
Move-only, checked operation results for the common layer.
std::string kind
float dy
Definition Shadow.cpp:151
float step
Definition TreeMesh.cpp:451
uint32_t index
double oy
double ox
EVENGINE_API_FOUNDATION public API.
Definition Module.h:48
Move-only operation result carrying either a value or Status.
Definition Result.h:176
Strong, domain-neutral reference to a runtime subject.
Definition SubjectRef.h:26
单张卡牌:ECS 实体,数据拆成 Identity / Stats / Visual / Layout / State。
Definition CardTypes.h:106
Maps a logical card canvas to a 3D parallelogram without depending on graphics.
Definition Card.h:72
float getBasisUX() const
Local card right axis after layout rotation and flip (world space).
Definition Card.h:108
float getBasisUY() const
Basis U Y.
Definition Card.h:110
float getBasisNZ() const
Basis N Z.
Definition Card.h:124
float getWorldZ() const
Return the most recently mapped world Z coordinate.
Definition Card.h:106
float getBasisNX() const
Card facing normal after flip (world space).
Definition Card.h:120
float getBasisVZ() const
Basis V Z.
Definition Card.h:118
float getLogicalY() const
Return the most recently mapped logical Y coordinate.
Definition Card.h:100
float getWorldY() const
Return the most recently mapped world Y coordinate.
Definition Card.h:104
float getBasisVX() const
Local card up axis after layout rotation and flip (world space).
Definition Card.h:114
bool isShowingFront() const
Whether the most recent mapCardPose should bind the front face.
Definition Card.h:126
float getBasisNY() const
Basis N Y.
Definition Card.h:122
float getBasisUZ() const
Basis U Z.
Definition Card.h:112
float getBasisVY() const
Basis V Y.
Definition Card.h:116
float getLogicalX() const
Return the most recently mapped logical X coordinate.
Definition Card.h:98
float getWorldX() const
Return the most recently mapped world X coordinate.
Definition Card.h:102
卡牌模块入口(eve.Card):定义注册、对象工厂与每帧 update/render。
Definition Card.h:146
Card()
Declared out of line so the incomplete CardControl member needs no deleter here.
void setBuiltInVisuals(bool enabled)
Enable or disable the built-in card visuals while retaining layout and interaction.
Definition Card.h:347
Card & operator=(const Card &)=delete
bool getBuiltInVisuals() const
Return whether Card::render draws the built-in card faces.
Definition Card.h:349
Card(Card &&) noexcept
Card.
Card(const Card &)=delete
牌库(栈顶在末尾)。
Definition CardTypes.h:207
手牌:扇形布局 + 悬浮 + 拖拽 + 落区判定 + 渲染。
Definition CardTypes.h:292
落牌区(手牌区 / 出牌区 / 弃牌区),用于拖放命中判定。
Definition CardTypes.h:242
Provider-neutral resource account contract.
Single-use composition of domain participants and one payer's costs. Owns staged participants,...
Definition AtomicBatch.h:19
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
bool enabled
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158
Strong card definition projected into the common effect definition.
Definition CardEffects.h:40
Optional cross-domain operations that belong to one card play.
Definition CardPlay.h:144
Read-only extension points used while evaluating a card play.
Definition CardPlay.h:30
Immutable presentation data captured from one card for external 2D/3D adapters.
Definition Card.h:41
bool faceUp
Effective face target after hand faceDown/peek resolution.
Definition Card.h:56
float flipLift
Lift above the resting plane/layout at the current flip pose.
Definition Card.h:62
float flip
Animated face-down progress in [0, 1] (0 = up, 1 = down).
Definition Card.h:58
float flipAngle
Flip rotation about the configured hinge, in degrees (0..180).
Definition Card.h:60
int flipAxis
Hinge used to produce this pose: 0 = vertical, 1 = horizontal.
Definition Card.h:68
bool showingFront
Which face texture to bind right now (swaps at the edge-on pinch).
Definition Card.h:66
float flipAxisScale
Absolute cosine foreshortening for the hinge axis (0 at edge-on).
Definition Card.h:64
UiCard 风格的布局配置(脚本可实时修改,对应 UiCard 的 Configs 面板)。
Definition CardTypes.h:46