载入中...
搜索中...
未找到
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
32namespace eve::card {
33
34class CardControl;
35
38 std::string instanceId;
39 std::string definitionId;
40 std::string state;
41 float x = 0.f;
42 float y = 0.f;
43 float width = 0.f;
44 float height = 0.f;
45 float angle = 0.f;
46 float scale = 1.f;
47 float alpha = 1.f;
48 bool hovered = false;
49 bool dragging = false;
50 bool disabled = false;
51 bool faceUp = true;
52};
53
56public:
58 void setLogicalRect(float x, float y, float width, float height);
60 void setPlane(float ox, float oy, float oz, float ux, float uy, float uz,
61 float vx, float vy, float vz);
63 bool mapRay(float ox, float oy, float oz, float dx, float dy, float dz);
65 bool mapLayout(float x, float y);
67 float getLogicalX() const { return resultLogicalX_; }
69 float getLogicalY() const { return resultLogicalY_; }
71 float getWorldX() const { return resultWorld_.x; }
73 float getWorldY() const { return resultWorld_.y; }
75 float getWorldZ() const { return resultWorld_.z; }
76
77private:
78 glm::vec3 origin_{0.f};
79 glm::vec3 axisU_{1.f, 0.f, 0.f};
80 glm::vec3 axisV_{0.f, 0.f, 1.f};
81 glm::vec3 resultWorld_{0.f};
82 float logicalX_ = 0.f;
83 float logicalY_ = 0.f;
84 float logicalWidth_ = 1.f;
85 float logicalHeight_ = 1.f;
86 float resultLogicalX_ = 0.f;
87 float resultLogicalY_ = 0.f;
88};
89
92public:
97 ~Card() override;
98
99 // The two `vector<unique_ptr<...>>` members make the implicit copy operations
100 // ill-formed (C2280) the moment a class-level dllexport instantiates them;
101 // spell the four out so the export surface stays defined. Semantics unchanged:
102 // a module instance was never copyable or assignable in practice.
103 Card(const Card &) = delete;
104 Card &operator=(const Card &) = delete;
105 // Out of line for the same reason as the constructor and destructor above: a
106 // defaulted move in the class body instantiates the move of every member,
107 // including the deleter of the incomplete `CardControl`.
109 Card(Card &&) noexcept;
111 Card &operator=(Card &&) noexcept;
112
114 int registerCardsFromJson(const std::string &json);
116 void clearCardDefinitions();
118 int getCardDefinitionCount();
123 std::string getCardDefinitionId(int index) const;
125 bool hasCardDefinition(const std::string &id);
138 bool setCardDefinition(const std::string &id, const std::string &name, const std::string &kind,
139 int cost, int attack, int health, float tintR, float tintG, float tintB);
144 bool removeCardDefinition(const std::string &id);
151 [[nodiscard]] eve::Result<void> setCardPlayCondition(const std::string &id, decision::Condition condition);
152 std::string getCardDefinitionName(const std::string &id);
154 std::string getCardDefinitionKind(const std::string &id);
156 int getCardDefinitionCost(const std::string &id);
158 int getCardDefinitionAttack(const std::string &id);
160 int getCardDefinitionHealth(const std::string &id);
162 float getCardDefinitionTintR(const std::string &id);
164 float getCardDefinitionTintG(const std::string &id);
166 float getCardDefinitionTintB(const std::string &id);
167
169 LayoutConfig *newConfig();
171 CardData *newCard(const std::string &defId);
173 Deck *newDeck();
175 Zone *newZone(const std::string &id, const std::string &label, float x, float y, float w, float h);
177 Hand *newHand(LayoutConfig *cfg);
179 CardPlaneMapper *newPlaneMapper();
180
182 void setConfig(LayoutConfig *cfg);
184 LayoutConfig *getConfig() const;
186 int handCount() const;
188 Hand *getHand(int index) const;
190 Hand *findHand(const std::string &owner) const;
192 int zoneCount() const;
194 Zone *getZone(int index) const;
196 Deck *getDeck() const;
198 CardData *drawCard(const std::string &handOwner);
199
206 [[nodiscard]] decision::ConditionResult evaluatePlay(const CardData *card,
207 CardPlayConditionQueries queries = {}) const;
208
215 [[nodiscard]] eve::Result<double> getCardAttribute(CardData &card, std::string_view attribute) const;
216
224 [[nodiscard]] eve::Result<void> setCardAttribute(CardData &card, std::string_view attribute, double value) const;
225
233 [[nodiscard]] eve::Result<effects::EffectHandle> applyEffect(CardData &card, const CardEffectDefinition &definition,
235
242
252 eve::resource::IResourceAccount &playerAccount,
253 CardPlayComposition composition = {},
254 std::string transactionId = {});
255
257 int capturePresentation();
259 int getPresentationCount() const;
261 CardPresentationSnapshot *getPresentation(int index);
262
264 void update(float dt, float mx, float my, bool down);
266 void render(graphics::Graphics *gfx);
268 void renderDeck(graphics::Graphics *gfx);
269
271 void setBuiltInVisuals(bool enabled) { builtInVisuals_ = enabled; }
273 bool getBuiltInVisuals() const { return builtInVisuals_; }
274
292 [[nodiscard]] eve::Result<void> publishGameplay(const std::string &instanceId, const std::string &ownerId,
295 [[nodiscard]] eve::Result<void> unpublishGameplay(const std::string &instanceId);
297 void clearGameplayControls();
299 [[nodiscard]] int gameplayControlCount() const;
301 [[nodiscard]] std::vector<std::string> gameplayInstances() const;
302
303private:
305 std::unique_ptr<CardControl> gameplay_;
306
308 void beginTargeting(const std::string &sourceId, float x, float y);
310 void updateTargeting(float x, float y, const std::string &targetId, bool valid);
312 void cancelTargeting();
314 void renderTargeting(graphics::Graphics *gfx);
316 bool isTargeting() const { return targetingActive_; }
318 bool isTargetValid() const { return targetingValid_; }
320 std::string getTargetSource() const { return targetingSource_; }
322 std::string getTargetId() const { return targetingId_; }
323
325 void clearEvents();
326 int getEventCount() const;
327 std::string getEventType(int index) const;
328 std::string getEventHand(int index) const;
329 std::string getEventZone(int index) const;
330 std::string getEventCardId(int index) const;
331 std::string getEventReason(int index) const;
332
333private:
334 const CardDefinition *findDef(const std::string &id) const;
335
336 std::unordered_map<std::string, CardDefinition> defs_;
337 mutable std::vector<std::string> definitionView_;
338 mutable bool definitionViewDirty_ = true;
339 std::vector<std::unique_ptr<LayoutConfig>> configs_;
340 std::vector<std::unique_ptr<CardPlaneMapper>> planeMappers_;
341 std::vector<CardEvent> events_;
342 std::vector<ecs::EntityHandle> cards_;
343 std::vector<ecs::EntityHandle> decks_;
344 std::vector<ecs::EntityHandle> zones_;
345 std::vector<ecs::EntityHandle> hands_;
346 std::vector<CardPresentationSnapshot> presentation_;
347
348 LayoutConfig *activeConfig_ = nullptr;
349 Deck *activeDeck_ = nullptr;
350 int nextInstance_ = 1;
351 bool builtInVisuals_ = true;
352 bool targetingActive_ = false;
353 bool targetingValid_ = false;
354 float targetingStartX_ = 0.f;
355 float targetingStartY_ = 0.f;
356 float targetingX_ = 0.f;
357 float targetingY_ = 0.f;
358 std::string targetingSource_;
359 std::string targetingId_;
360};
361
362} // namespace eve::card
double value
float w
Definition AnimClip.cpp:738
float y
Definition AnimClip.cpp:738
float x
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
std::string label
eve::Value condition
std::uint64_t sourceId
#define EVENGINE_API_WORLD
Definition Export.h:109
int h
std::uint32_t height
std::uint32_t width
TokenKind kind
std::string name
bool valid
std::uint32_t targetId
Move-only, checked operation results for the common layer.
float dz
float dy
float dx
LogicalId definition
float step
Definition TreeMesh.cpp:314
uint32_t index
double oy
double ox
float vz
float vy
float vx
EVENGINE_API_FOUNDATION public API.
Definition Module.h:46
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Strong, domain-neutral reference to a runtime subject.
Definition SubjectRef.h:26
单张卡牌:ECS 实体,数据拆成 Identity / Stats / Visual / Layout / State。
Definition CardTypes.h:94
Maps a logical card canvas to a 3D parallelogram without depending on graphics.
Definition Card.h:55
float getWorldZ() const
Return the most recently mapped world Z coordinate.
Definition Card.h:75
float getLogicalY() const
Return the most recently mapped logical Y coordinate.
Definition Card.h:69
float getWorldY() const
Return the most recently mapped world Y coordinate.
Definition Card.h:73
float getLogicalX() const
Return the most recently mapped logical X coordinate.
Definition Card.h:67
float getWorldX() const
Return the most recently mapped world X coordinate.
Definition Card.h:71
卡牌模块入口(eve.Card):定义注册、对象工厂与每帧 update/render。
Definition Card.h:91
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:271
Card & operator=(const Card &)=delete
bool getBuiltInVisuals() const
Return whether Card::render draws the built-in card faces.
Definition Card.h:273
Card(Card &&) noexcept
Card.
Card(const Card &)=delete
牌库(栈顶在末尾)。
Definition CardTypes.h:188
手牌:扇形布局 + 悬浮 + 拖拽 + 落区判定 + 渲染。
Definition CardTypes.h:273
落牌区(手牌区 / 出牌区 / 弃牌区),用于拖放命中判定。
Definition CardTypes.h:223
Provider-neutral resource account contract.
卡牌游戏 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:147
Read-only extension points used while evaluating a card play.
Definition CardPlay.h:29
Immutable presentation data captured from one card for external 2D/3D adapters.
Definition Card.h:37
UiCard 风格的布局配置(脚本可实时修改,对应 UiCard 的 Configs 面板)。
Definition CardTypes.h:46