载入中...
搜索中...
未找到
CardTypes.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
11#include "card/CardEffects.h"
12#include "common/Condition.h"
13#include "common/ECS.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;
71 float flipSpeed = 0.18f;
73 float flipLift = 28.f;
78 int flipAxis = 0;
80 float disabledAlpha = 0.35f;
82 bool showZones = true;
84 float deckX = 360.f;
85 float deckY = 640.f;
87 float dragThreshold = 64.f;
88};
89
92 std::string id;
93 std::string name;
94 std::string kind = "creature"; // "creature" | "spell" | ...
95 int cost = 0;
96 int attack = 0;
97 int health = 0;
98 glm::vec3 tint{0.62f, 0.50f, 0.40f};
102 std::vector<std::string> tags;
103};
104
106class EVENGINE_API_WORLD CardData : public ecs::Entity {
107public:
109 ENTITY(CardData, ecs::Entity)
110
111
112 void release() override { ecs::DestroyEntity(this); }
113
115 struct Identity {
117 std::string id;
119 std::string definitionId;
120 std::string name;
121 std::string kind = "creature";
122 };
124 struct Stats {
125 int cost = 0;
126 int attack = 0;
127 int health = 0;
128 };
144 struct Visual {
146 bool faceUp = true;
152 float flip = 0.f;
153 bool disabled = false;
154 glm::vec3 tint{0.62f, 0.50f, 0.40f};
156 };
158 struct Layout {
159 float x = 0.f;
160 float y = 0.f;
161 float w = 0.f;
162 float h = 0.f;
163 float angle = 0.f;
164 float scale = 1.f;
165 float alpha = 1.f;
166 };
168 struct State {
169 CardState phase = CardState::Deck;
170 bool hovered = false;
171 bool dragging = false;
172 };
173
187
188 COMPONENT(Identity, identity)
189 COMPONENT(Stats, stats)
190 COMPONENT(Attributes, attributes)
191 COMPONENT(Effects, effects)
192 COMPONENT(Visual, visual)
193 COMPONENT(Layout, layout)
194 COMPONENT(State, state)
195 COMPONENT(DefinitionBinding, definitionBinding)
196
197
198 static CardData *createCard();
199
201 bool hit(float px, float py);
203 std::string describe();
204};
205
207class EVENGINE_API_WORLD Deck : public ecs::Entity {
208public:
210 ENTITY(Deck, ecs::Entity)
211
212
213 void release() override { ecs::DestroyEntity(this); }
214
216 struct Membership {
217 std::vector<CardData *> cards;
218 };
219
220 COMPONENT(Membership, membership)
221
222
223 static Deck *createDeck();
224
226 void push(CardData *c) { membership()->cards.push_back(c); }
228 CardData *draw();
230 CardData *peek();
232 void clear() { membership()->cards.clear(); }
234 void shuffle();
236 int count() { return static_cast<int>(membership()->cards.size()); }
237 bool isEmpty() { return membership()->cards.empty(); }
238 CardData *get(int index);
239};
240
242class EVENGINE_API_WORLD Zone : public ecs::Entity {
243public:
245 ENTITY(Zone, ecs::Entity)
246
247
248 void release() override { ecs::DestroyEntity(this); }
249
251 struct Rect {
252 std::string id;
253 std::string label;
254 float x = 0.f, y = 0.f, w = 0.f, h = 0.f;
255 glm::vec3 color{0.30f, 0.60f, 0.30f};
256 float alpha = 0.16f;
257 bool enabled = true;
258 };
260 struct Filter {
261 std::vector<std::string> acceptKinds;
262 };
263
264 COMPONENT(Rect, rect)
265 COMPONENT(Filter, filter)
266
267
268 static Zone *createZone();
269
271 bool contains(float px, float py);
273 bool accepts(CardData *card);
275 void render(graphics::Graphics *gfx, bool showLabel);
276};
277
279struct CardEvent {
281 std::string type;
283 std::string hand;
285 std::string zoneId;
286 std::string cardId;
288 std::string reason;
289};
290
292class EVENGINE_API_WORLD Hand : public ecs::Entity {
293public:
295 ENTITY(Hand, ecs::Entity)
296
297
298 void release() override { ecs::DestroyEntity(this); }
299
301 struct Meta {
302 std::string owner = "player";
303 LayoutConfig *config = nullptr;
304 bool faceDown = false;
305 bool peek = false;
306 bool interactive = true;
307 };
309 struct Membership {
310 std::vector<CardData *> cards;
311 };
313 struct Drag {
314 CardData *card = nullptr;
315 CardData *press = nullptr;
316 float ox = 0.f, oy = 0.f;
317 float pressX = 0.f, pressY = 0.f;
318 bool wasDown = false;
319 };
320
321 COMPONENT(Meta, meta)
322 COMPONENT(Membership, membership)
323 COMPONENT(Drag, drag)
324
325
326 static Hand *createHand();
327
329 void addCard(CardData *c);
330 bool removeCard(CardData *c);
331 void clear();
332 int count() { return static_cast<int>(membership()->cards.size()); }
333 CardData *get(int index);
334 CardData *find(const std::string &id);
336 CardData *pick(float px, float py);
337
339 void slotTransform(int i, int n, float &ox, float &oy, float &angle);
340
342 void update(float dt, float mx, float my, bool down, const std::vector<Zone *> &zones,
343 std::vector<CardEvent> &out);
344
346 void render(graphics::Graphics *gfx);
347};
348
356 float progress = 0.f;
357 float angleRadians = 0.f;
358 float angleDegrees = 0.f;
359 float lift = 0.f;
360 float axisScale = 1.f;
361 bool showingFront = true;
362};
363
368EVENGINE_API_WORLD CardFlipPose evaluateCardFlip(float flipProgress, float liftPeak);
369
371EVENGINE_API_WORLD void advanceCardFlip(float &flip, float targetFaceDown, float speed, float dt);
372
379EVENGINE_API_WORLD bool resolveCardWantFaceUp(bool cardFaceUp, bool handFaceDown, bool handPeek);
380
382void printCentered(graphics::Graphics *gfx, const std::string &text, float cx, float cy, float scale,
383 const glm::vec4 &color);
385void renderCardBack(graphics::Graphics *gfx, float x, float y, float w, float h, float angle, float a);
387void renderCard(graphics::Graphics *gfx, const CardData &card, const LayoutConfig &cfg, bool back);
388
389} // namespace eve::card
double y
double x
bool & active
float w
Definition AnimClip.cpp:738
Owner-aware canonical attribute state shared by gameplay adapters.
Card-domain effect adapter and executor.
float cx
Definition CardTypes.cpp:36
float cy
Definition CardTypes.cpp:37
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::array< float, 3 > scale
MeleePoint3 a
Definition MeleeHit.cpp:40
MeshVfxBatchedDraw draw
const std::string * accepts
std::shared_ptr< OceanGpuSpectrum > owner
double dt
Texture * texture
bool hit
std::map< std::string, double > attributes
std::vector< EquipmentStat > stats
std::string filter
std::string text
ScriptStructure out
std::string kind
float phase
uint32_t index
double oy
double ox
uint64_t identity
Canonical selected-attribute storage with owner and revision checks.
单张卡牌:ECS 实体,数据拆成 Identity / Stats / Visual / Layout / State。
Definition CardTypes.h:106
Card adapter composing the common lifecycle container with CardEffectExecutor.
Definition CardEffects.h:90
牌库(栈顶在末尾)。
Definition CardTypes.h:207
void push(CardData *c)
将卡牌压入栈顶(末尾)。
Definition CardTypes.h:226
void clear()
清空牌库。
Definition CardTypes.h:232
int count()
牌库数量/是否为空/按下标取牌。
Definition CardTypes.h:236
手牌:扇形布局 + 悬浮 + 拖拽 + 落区判定 + 渲染。
Definition CardTypes.h:292
落牌区(手牌区 / 出牌区 / 弃牌区),用于拖放命中判定。
Definition CardTypes.h:242
Immutable condition AST node.
Definition Condition.h:199
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:15
void renderCardBack(graphics::Graphics *gfx, float x, float y, float w, float h, float angle, float a)
绘制牌背。
void advanceCardFlip(float &flip, float targetFaceDown, float speed, float dt)
Advance animated flip toward a face-down target with frame-rate-normalized speed.
Definition CardTypes.cpp:85
bool resolveCardWantFaceUp(bool cardFaceUp, bool handFaceDown, bool handPeek)
Resolve whether a card should read as face-up under hand faceDown/peek rules.
Definition CardTypes.cpp:92
const char * cardStateName(CardState state)
状态枚举的字符串名(用于脚本/调试)。
Definition CardTypes.cpp:15
CardState
单张卡牌的运行时状态。
Definition CardTypes.h:31
CardFlipPose evaluateCardFlip(float flipProgress, float liftPeak)
Evaluate face-down progress into an adapter-facing flip pose.
Definition CardTypes.cpp:74
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)
绘制单张卡牌(正面或牌背;back 强制牌背,忽略 flip)。
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:136
eve::attributes::AttributeProjection values
Definition CardTypes.h:137
Definition link and reload policy for this card instance.
Definition CardTypes.h:182
eve::definition::InstanceIdentity identity
Definition CardTypes.h:183
Canonical effect lifecycle and card combat target state.
Definition CardTypes.h:140
CardEffectAdapter values
Definition CardTypes.h:141
稳定实例 id、显示名、种类。
Definition CardTypes.h:115
std::string definitionId
Registered definition identifier used to construct this instance.
Definition CardTypes.h:119
std::string id
Stable runtime instance identifier, unique within the owning Card module.
Definition CardTypes.h:117
运行时布局(由 Hand 维护):中心坐标与变换。
Definition CardTypes.h:158
运行时交互状态。
Definition CardTypes.h:168
费用 / 攻击 / 生命。
Definition CardTypes.h:124
朝向、禁用、色调、卡图。
Definition CardTypes.h:144
卡牌类型定义(registerCardsFromJson 注册)。
Definition CardTypes.h:91
eve::condition::Condition playCondition
Side-effect-free condition tree required before this card can play.
Definition CardTypes.h:100
std::vector< std::string > tags
Definition tags available to HasTag nodes.
Definition CardTypes.h:102
一次交互事件。
Definition CardTypes.h:279
std::string hand
来源手牌 owner。
Definition CardTypes.h:283
std::string type
事件类型:"click" | "drop"。
Definition CardTypes.h:281
std::string reason
dropRejected 时为拒绝原因。
Definition CardTypes.h:288
std::string cardId
Definition CardTypes.h:286
std::string zoneId
drop 目标的落牌区 id(click 为空)。
Definition CardTypes.h:285
Evaluated flip pose for external 2D/3D adapters (graphics-independent).
Definition CardTypes.h:355
有序牌堆;栈顶在 vector 末尾。
Definition CardTypes.h:216
std::vector< CardData * > cards
Definition CardTypes.h:217
拖拽内部状态(勿直接修改)。
Definition CardTypes.h:313
有序手牌列表。
Definition CardTypes.h:309
std::vector< CardData * > cards
Definition CardTypes.h:310
所有者与布局/交互开关。
Definition CardTypes.h:301
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 flipLift
Peak lift (logical pixels) at the edge-on midpoint of a flip.
Definition CardTypes.h:73
float disabledAlpha
禁用牌透明度。
Definition CardTypes.h:80
float handX
手牌扇形中心 X / 基准高度 Y。
Definition CardTypes.h:53
float motionSpeed
通用归位运动速度。
Definition CardTypes.h:66
float flipSpeed
Face flip lerp speed (same 60fps-normalized units as motionSpeed). Drives the animated 0....
Definition CardTypes.h:71
int flipAxis
Flip hinge: 0 = vertical (width foreshortens / rotate about local up), 1 = horizontal (height foresho...
Definition CardTypes.h:78
float deckX
牌库堆绘制位置。
Definition CardTypes.h:84
float spacing
手牌水平间距。
Definition CardTypes.h:51
float hoverScale
悬浮缩放/上移像素/运动速度。
Definition CardTypes.h:62
bool showZones
是否绘制落牌区。
Definition CardTypes.h:82
float rotationAngle
手牌两端最大旋转角(度)。
Definition CardTypes.h:58
float dragThreshold
拖拽触发距离(像素)。
Definition CardTypes.h:87
接受的卡牌 kind;空 = 接受任意 kind。
Definition CardTypes.h:260
std::vector< std::string > acceptKinds
Definition CardTypes.h:261
区域矩形与绘制参数。
Definition CardTypes.h:251
Canonical identity carried by every typed runtime instance.
glm::vec4 color