Skip to content

Commit

Permalink
fix: 修复卡牌交换时位置可能重合的 bug
Browse files Browse the repository at this point in the history
引起该 bug 的原因是 Card.put_down 中没有设置 old_card.current_block 为
self.last_block。

为了避免之后再次遗忘,从现在开始 Block.set_card 会自动设置 card 的
position 和 current_block。
  • Loading branch information
cutekibry committed Feb 28, 2024
1 parent ce83c1e commit 732f587
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 3 additions & 0 deletions objects/block/block.gd
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func set_card(card: Card) -> void:
assert(not self.is_fixed, "void Block::set_card(card: Card) should only be called when is_fixed is false.")
if self.occupied_card != card:
self.occupied_card = card
if card != null:
card.position = self.position
card.current_block = self
occupied_card_changed.emit(self)


Expand Down
5 changes: 2 additions & 3 deletions objects/card/card.gd
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,16 @@ func put_down():

if old_card != null: # 若原来占有的卡非空,则进行交换
if self.last_block != null: # 若当前 Card 之前占用了 Block,则将该 Block 占用的 Card 放置在原先的位置上
old_card.position = self.last_block.position
self.last_block.set_card(old_card)
else: # 若当前 Card 是由 CardBase 生成的,则将该 Block 占用的 Card 释放
old_card.queue_free()

self.current_block = entered_block
self.position = entered_block.position
self.is_dragging = false

self.last_block = null

$SFXPutDown.play()


else:
queue_free()
Expand Down

0 comments on commit 732f587

Please sign in to comment.