载入中...
搜索中...
未找到
CardTypes.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
11#include "card/CardEffects.h"
12#include "common/ECS.h"
14#include "decision/Condition.h"
15
16#include <glm/vec3.hpp>
17#include <glm/vec4.hpp>
18
19#include <cstdint>
20#include <string>
21#include <vector>
22
23namespace eve::graphics {
24class Graphics;
25class Texture;
26} // namespace eve::graphics
27
28namespace eve::card {
29
31enum class CardState : uint8_t {
32 Deck,
33 Hand,
34 Hovered,
37 Played,
40};
41
44
48 float cardW = 110.f;
49 float cardH = 150.f;
51 float spacing = 26.f;
53 float handX = 640.f;
54 float handY = 640.f;
56 float arcHeight = 46.f;
58 float rotationAngle = 14.f;
60 bool hoverRotation = true;
62 float hoverScale = 1.22f;
63 float hoverLift = 46.f;
64 float hoverSpeed = 0.18f;
66 float motionSpeed = 0.12f;
68 float disabledAlpha = 0.35f;
70 bool showZones = true;
72 float deckX = 360.f;
73 float deckY = 640.f;
75 float dragThreshold = 64.f;
76};
77
80 std::string id;
81 std::string name;
82 std::string kind = "creature"; // "creature" | "spell" | ...
83 int cost = 0;
84 int attack = 0;
85 int health = 0;
86 glm::vec3 tint{0.62f, 0.50f, 0.40f};
90 std::vector<std::string> tags;
91};
92
94class EVENGINE_API_WORLD CardData : public ecs::Entity {
95public:
97 ENTITY(CardData, ecs::Entity)
98
99
100 void release() override { ecs::DestroyEntity(this); }
101
103 struct Identity {
105 std::string id;
107 std::string definitionId;
108 std::string name;
109 std::string kind = "creature";
110 };
112 struct Stats {
113 int cost = 0;
114 int attack = 0;
115 int health = 0;
116 };
132 struct Visual {
133 bool faceUp = true;
134 bool disabled = false;
135 glm::vec3 tint{0.62f, 0.50f, 0.40f};
136 graphics::Texture *texture = nullptr;
137 };
139 struct Layout {
140 float x = 0.f;
141 float y = 0.f;
142 float w = 0.f;
143 float h = 0.f;
144 float angle = 0.f;
145 float scale = 1.f;
146 float alpha = 1.f;
147 };
149 struct State {
150 CardState phase = CardState::Deck;
151 bool hovered = false;
152 bool dragging = false;
153 };
154
168
169 COMPONENT(Identity, identity)
170 COMPONENT(Stats, stats)
171 COMPONENT(Attributes, attributes)
172 COMPONENT(Effects, effects)
173 COMPONENT(Visual, visual)
174 COMPONENT(Layout, layout)
175 COMPONENT(State, state)
176 COMPONENT(DefinitionBinding, definitionBinding)
177
178
179 static CardData *createCard();
180
182 bool hit(float px, float py);
184 std::string describe();
185};
186
188class EVENGINE_API_WORLD Deck : public ecs::Entity {
189public:
191 ENTITY(Deck, ecs::Entity)
192
193
194 void release() override { ecs::DestroyEntity(this); }
195
197 struct Membership {
198 std::vector<CardData *> cards;
199 };
200
201 COMPONENT(Membership, membership)
202
203
204 static Deck *createDeck();
205
207 void push(CardData *c) { membership()->cards.push_back(c); }
209 CardData *draw();
211 CardData *peek();
213 void clear() { membership()->cards.clear(); }
215 void shuffle();
217 int count() { return static_cast<int>(membership()->cards.size()); }
218 bool isEmpty() { return membership()->cards.empty(); }
219 CardData *get(int index);
220};
221
223class EVENGINE_API_WORLD Zone : public ecs::Entity {
224public:
226 ENTITY(Zone, ecs::Entity)
227
228
229 void release() override { ecs::DestroyEntity(this); }
230
232 struct Rect {
233 std::string id;
234 std::string label;
235 float x = 0.f, y = 0.f, w = 0.f, h = 0.f;
236 glm::vec3 color{0.30f, 0.60f, 0.30f};
237 float alpha = 0.16f;
238 bool enabled = true;
239 };
241 struct Filter {
242 std::vector<std::string> acceptKinds;
243 };
244
245 COMPONENT(Rect, rect)
246 COMPONENT(Filter, filter)
247
248
249 static Zone *createZone();
250
252 bool contains(float px, float py);
254 bool accepts(CardData *card);
256 void render(graphics::Graphics *gfx, bool showLabel);
257};
258
260struct CardEvent {
262 std::string type;
264 std::string hand;
266 std::string zoneId;
267 std::string cardId;
269 std::string reason;
270};
271
273class EVENGINE_API_WORLD Hand : public ecs::Entity {
274public:
276 ENTITY(Hand, ecs::Entity)
277
278
279 void release() override { ecs::DestroyEntity(this); }
280
282 struct Meta {
283 std::string owner = "player";
284 LayoutConfig *config = nullptr;
285 bool faceDown = false;
286 bool peek = false;
287 bool interactive = true;
288 };
290 struct Membership {
291 std::vector<CardData *> cards;
292 };
294 struct Drag {
295 CardData *card = nullptr;
296 CardData *press = nullptr;
297 float ox = 0.f, oy = 0.f;
298 float pressX = 0.f, pressY = 0.f;
299 bool wasDown = false;
300 };
301
302 COMPONENT(Meta, meta)
303 COMPONENT(Membership, membership)
304 COMPONENT(Drag, drag)
305
306
307 static Hand *createHand();
308
310 void addCard(CardData *c);
311 bool removeCard(CardData *c);
312 void clear();
313 int count() { return static_cast<int>(membership()->cards.size()); }
314 CardData *get(int index);
315 CardData *find(const std::string &id);
317 CardData *pick(float px, float py);
318
320 void slotTransform(int i, int n, float &ox, float &oy, float &angle);
321
323 void update(float dt, float mx, float my, bool down, const std::vector<Zone *> &zones,
324 std::vector<CardEvent> &out);
325
327 void render(graphics::Graphics *gfx);
328};
329
331void printCentered(graphics::Graphics *gfx, const std::string &text, float cx, float cy, float scale,
332 const glm::vec4 &color);
334void renderCardBack(graphics::Graphics *gfx, float x, float y, float w, float h, float angle, float a);
336void renderCard(graphics::Graphics *gfx, const CardData &card, const LayoutConfig &cfg, bool back);
337
338} // namespace eve::card
bool & active
float w
Definition AnimClip.cpp:738
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
Owner-aware canonical attribute state shared by gameplay adapters.
Card-domain effect adapter and executor.
float cx
Definition CardTypes.cpp:33
float cy
Definition CardTypes.cpp:34
float phase
Definition CaveMesh.cpp:58
float py
Pure, explainable condition trees shared by gameplay domains.
Common identity and hot-reload contract for typed runtime instances.
eve::resource::CostSpec cost
#define EVENGINE_API_WORLD
Definition Export.h:109
std::string layout
glm::vec4 tint
glm::vec3 n
Definition Grass.cpp:63
std::int32_t c
int h
std::vector< Colorf > px
std::string text
TokenKind kind
std::array< float, 3 > scale
MeleePoint3 a
Definition MeleeHit.cpp:40
MeshVfxBatchedDraw draw
const std::string * accepts
OnnxTransferStats stats
Definition OnnxGpgpu.cpp:56
bool hit
std::function< eve::Result< void >()> release
Definition Procgen.cpp:86
std::string filter
uint32_t index
double oy
double ox
float angle
Canonical selected-attribute storage with owner and revision checks.
单张卡牌:ECS 实体,数据拆成 Identity / Stats / Visual / Layout / State。
Definition CardTypes.h:94
Card adapter composing the common lifecycle container with CardEffectExecutor.
Definition CardEffects.h:90
牌库(栈顶在末尾)。
Definition CardTypes.h:188
void push(CardData *c)
将卡牌压入栈顶(末尾)。
Definition CardTypes.h:207
void clear()
清空牌库。
Definition CardTypes.h:213
int count()
牌库数量/是否为空/按下标取牌。
Definition CardTypes.h:217
手牌:扇形布局 + 悬浮 + 拖拽 + 落区判定 + 渲染。
Definition CardTypes.h:273
落牌区(手牌区 / 出牌区 / 弃牌区),用于拖放命中判定。
Definition CardTypes.h:223
Immutable condition AST node.
Definition Condition.h:195
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:18
void renderCardBack(graphics::Graphics *gfx, float x, float y, float w, float h, float angle, float a)
绘制牌背。
const char * cardStateName(CardState state)
状态枚举的字符串名(用于脚本/调试)。
Definition CardTypes.cpp:12
CardState
单张卡牌的运行时状态。
Definition CardTypes.h:31
void printCentered(graphics::Graphics *gfx, const std::string &text, float cx, float cy, float scale, const glm::vec4 &color)
渲染辅助(也供 Zone / Deck 复用)。
void renderCard(graphics::Graphics *gfx, const CardData &cardRef, const LayoutConfig &cfg, bool back)
绘制单张卡牌(正面或牌背)。
ReloadPolicy
Policy used when a live definition is replaced.
@ KeepInstanceValues
Replace the definition generation and preserve all instance values.
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
bool enabled
Canonical selected card stats backed by the attributes module.
Definition CardTypes.h:124
eve::attributes::AttributeProjection values
Definition CardTypes.h:125
Definition link and reload policy for this card instance.
Definition CardTypes.h:163
eve::definition::InstanceIdentity identity
Definition CardTypes.h:164
Canonical effect lifecycle and card combat target state.
Definition CardTypes.h:128
CardEffectAdapter values
Definition CardTypes.h:129
稳定实例 id、显示名、种类。
Definition CardTypes.h:103
std::string definitionId
Registered definition identifier used to construct this instance.
Definition CardTypes.h:107
std::string id
Stable runtime instance identifier, unique within the owning Card module.
Definition CardTypes.h:105
运行时布局(由 Hand 维护):中心坐标与变换。
Definition CardTypes.h:139
运行时交互状态。
Definition CardTypes.h:149
费用 / 攻击 / 生命。
Definition CardTypes.h:112
朝向、禁用、色调、卡图。
Definition CardTypes.h:132
卡牌类型定义(registerCardsFromJson 注册)。
Definition CardTypes.h:79
eve::decision::Condition playCondition
Side-effect-free condition tree required before this card can play.
Definition CardTypes.h:88
std::vector< std::string > tags
Definition tags available to HasTag nodes.
Definition CardTypes.h:90
一次交互事件。
Definition CardTypes.h:260
std::string hand
来源手牌 owner。
Definition CardTypes.h:264
std::string type
事件类型:"click" | "drop"。
Definition CardTypes.h:262
std::string reason
dropRejected 时为拒绝原因。
Definition CardTypes.h:269
std::string cardId
Definition CardTypes.h:267
std::string zoneId
drop 目标的落牌区 id(click 为空)。
Definition CardTypes.h:266
有序牌堆;栈顶在 vector 末尾。
Definition CardTypes.h:197
std::vector< CardData * > cards
Definition CardTypes.h:198
拖拽内部状态(勿直接修改)。
Definition CardTypes.h:294
有序手牌列表。
Definition CardTypes.h:290
std::vector< CardData * > cards
Definition CardTypes.h:291
所有者与布局/交互开关。
Definition CardTypes.h:282
UiCard 风格的布局配置(脚本可实时修改,对应 UiCard 的 Configs 面板)。
Definition CardTypes.h:46
float cardW
卡牌宽/高(像素)。
Definition CardTypes.h:48
bool hoverRotation
悬浮时是否恢复为水平。
Definition CardTypes.h:60
float arcHeight
扇形弧度(两端上翘高度)。
Definition CardTypes.h:56
float disabledAlpha
禁用牌透明度。
Definition CardTypes.h:68
float handX
手牌扇形中心 X / 基准高度 Y。
Definition CardTypes.h:53
float motionSpeed
通用归位运动速度。
Definition CardTypes.h:66
float deckX
牌库堆绘制位置。
Definition CardTypes.h:72
float spacing
手牌水平间距。
Definition CardTypes.h:51
float hoverScale
悬浮缩放/上移像素/运动速度。
Definition CardTypes.h:62
bool showZones
是否绘制落牌区。
Definition CardTypes.h:70
float rotationAngle
手牌两端最大旋转角(度)。
Definition CardTypes.h:58
float dragThreshold
拖拽触发距离(像素)。
Definition CardTypes.h:75
接受的卡牌 kind;空 = 接受任意 kind。
Definition CardTypes.h:241
std::vector< std::string > acceptKinds
Definition CardTypes.h:242
区域矩形与绘制参数。
Definition CardTypes.h:232
Canonical identity carried by every typed runtime instance.
glm::vec4 color