refactor: more regicide stuff
This commit is contained in:
@@ -14,7 +14,9 @@ export class CardView {
|
||||
private readonly valueText: Phaser.GameObjects.Text;
|
||||
private readonly card: Card;
|
||||
private isHovering = false;
|
||||
private isSelected = false;
|
||||
private baseY: number;
|
||||
private selectedBorderColor = 0xfbbf24; // 金色边框表示选中
|
||||
|
||||
constructor(scene: GameScene, card: Card, x: number, y: number) {
|
||||
this.card = card;
|
||||
@@ -73,7 +75,7 @@ export class CardView {
|
||||
const scene = this.container.scene as Phaser.Scene;
|
||||
scene.tweens.add({
|
||||
targets: this.container,
|
||||
y: this.baseY + offset,
|
||||
y: this.baseY + offset + (this.isSelected ? -15 : 0),
|
||||
duration: 100,
|
||||
ease: 'Power2',
|
||||
});
|
||||
@@ -86,13 +88,37 @@ export class CardView {
|
||||
const scene = this.container.scene as Phaser.Scene;
|
||||
scene.tweens.add({
|
||||
targets: this.container,
|
||||
y: this.baseY,
|
||||
y: this.baseY + (this.isSelected ? -15 : 0),
|
||||
duration: 100,
|
||||
ease: 'Power2',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setSelected(selected: boolean, scene: GameScene): void {
|
||||
if (this.isSelected === selected) return;
|
||||
this.isSelected = selected;
|
||||
|
||||
// 更新边框颜色
|
||||
const color = selected ? this.selectedBorderColor : getSuitColor(this.card.suit);
|
||||
this.bg.setStrokeStyle(3, Phaser.Display.Color.HexStringToColor(
|
||||
selected ? '#fbbf24' : getSuitColor(this.card.suit)
|
||||
).color);
|
||||
|
||||
// 更新位置
|
||||
const targetY = this.baseY + (selected ? -15 : 0);
|
||||
scene.tweens.add({
|
||||
targets: this.container,
|
||||
y: targetY,
|
||||
duration: 100,
|
||||
ease: 'Power2',
|
||||
});
|
||||
}
|
||||
|
||||
getSelected(): boolean {
|
||||
return this.isSelected;
|
||||
}
|
||||
|
||||
getCard(): Card {
|
||||
return this.card;
|
||||
}
|
||||
@@ -114,7 +140,11 @@ export class CardView {
|
||||
if (scene.state.phase === 'playerTurn') {
|
||||
scene.gameHost.tryAnswerPrompt(prompts.playerAction, 'play', [this.card.id]);
|
||||
} else if (scene.state.phase === 'enemyCounterattack') {
|
||||
scene.gameHost.tryAnswerPrompt(prompts.counterattack, [this.card.id]);
|
||||
// 切换选中状态
|
||||
const newSelected = !this.isSelected;
|
||||
this.setSelected(newSelected, scene);
|
||||
// 通知 GameScene 更新选中状态
|
||||
scene.onCardClicked(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user