Skip to content

Commit

Permalink
fix(card.gd): 修复交换导致的通关可能引起震动的 bug
Browse files Browse the repository at this point in the history
将 P [P] [=] 交换为 P [=] [P] 时,会引起文字变红并震动。

原因是 entered_block 和 self.last_block 的 set_card() 的顺序出了问题,
在原代码中先调用 self.last_block.set_card(entered_block.occupied_card)
会使得 P [P] [=] 变为 P [P] [P],并发送信号 occupied_card_changed(),
导致 BaseLevel 引起文字变红并震动。

解决方法是调换二者顺序。
  • Loading branch information
cutekibry committed Feb 15, 2024
1 parent c1a40fc commit 1b20ad9
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions objects/card/card.gd
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ func put_down():
self.z_index -= 1
var entered_block := get_top_prior_entered_block()
if entered_block != null:
if not entered_block.is_empty(): # 若 entered_block 非空,则进行交换
var old_card = entered_block.occupied_card
entered_block.set_card(self)

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

entered_block.set_card(self)
old_card.queue_free()

self.current_block = entered_block
self.position = entered_block.position
Expand Down

0 comments on commit 1b20ad9

Please sign in to comment.