增加pause_counter_arr、sign interact/cancel、各类entity等日志记录点

This commit is contained in:
cakipaul 2025-07-11 23:33:43 +08:00
parent 3b1822810f
commit a29f0fca79
15 changed files with 47 additions and 55 deletions

View File

@ -332,7 +332,9 @@ func _jump_back_to_index_and_quit_main() -> void:
await get_tree().process_frame
get_tree().change_scene_to_packed(packed_index_page)
# 防止游戏卡死 reset pause counter
pause_counter = 0
if pause_counter_arr.size() > 0:
printerr("checkout_index_page: pause_counter_arr is not empty, resetting pause counter")
pause_counter_arr.clear()
get_tree().paused = false
@ -344,7 +346,9 @@ func enter_main_scene() -> void:
await get_tree().process_frame
get_tree().change_scene_to_packed.call_deferred(main_scene)
# get_tree().change_scene_to_file.call_deferred("uid://dygvcmykn02n8")
pause_counter = 0
if pause_counter_arr.size() > 0:
printerr("enter_main_scene: pause_counter_arr is not empty, resetting pause counter")
pause_counter_arr.clear()
get_tree().paused = false
@ -386,16 +390,20 @@ func show_settings() -> void:
#### 游戏场景树暂停计数器设置、memory、bag 等菜单都会导致 pause
var pause_counter := 0
## 目前有(5类): settings, panel, bag, note, memory
var pause_counter_arr: Array[String] = []
var pause_counter_mutex := Mutex.new()
func toggle_pause_counter(plus := true) -> void:
func toggle_pause_counter(plus := true, from := "") -> void:
# 若不 lock会导致快速切换菜单时出现并发问题pause_counter 成为负数)
pause_counter_mutex.lock()
pause_counter += 1 if plus else -1
print("SceneTree pause_counter: ", pause_counter)
get_tree().paused = pause_counter > 0
if plus:
pause_counter_arr.append(from)
else:
pause_counter_arr.erase(from)
print("SceneTree pause_counter_arr: ", pause_counter_arr)
get_tree().paused = len(pause_counter_arr) > 0
pause_counter_mutex.unlock()

View File

@ -279,8 +279,7 @@ func _on_freeze_changed(count: int, is_add: bool):
# 非首次 freeze 不改变动画状态,因为在动画演出中可能多次 freeze 与 release
func _on_first_frozen() -> void:
if GlobalConfig.DEBUG:
print("player _on_first_frozen. current_status=", current_status)
print("player _on_first_frozen. current_status=", current_status)
# reset status to idle or stay
velocity = Vector2.ZERO
current_status = PlayerAnimationConfig.MOVEMENT_IDLE
@ -372,8 +371,7 @@ func walk_to_x(global_pos_x: float) -> Tween:
func walk_to(global_pos: Vector2) -> Tween:
var tween = create_tween()
velocity = Vector2.ZERO
if GlobalConfig.DEBUG:
print("walk_to:", global_pos, " from:", global_position)
print("player walk_to:", global_pos, " from:", global_position)
# 不同距离下,行走时长略做自适应
var time_cost = absf(global_pos.distance_to(global_position) / 50.0)
# 忽略过小的位移
@ -406,8 +404,7 @@ func toggle_pause_state(pause := true) -> void:
func _after_walk_to() -> void:
current_status = PlayerAnimationConfig.MOVEMENT_IDLE
_play_animation()
if GlobalConfig.DEBUG:
print("walk_to end. unlock player")
print("player walk_to end. unlock player")
SceneManager.unlock_player()

View File

@ -206,7 +206,7 @@ func apply_dialogue_line() -> void:
if audio_stream_player.playing:
audio_stream_player.stop()
if GlobalConfig.DEBUG:
printerr("Dialogue no audio found! audio_path = %s audio_import_path = %s" % [audio_path, audio_import_path])
print_rich("[color=orange]Dialogue no audio found! audio_path = %s audio_import_path = %s" % [audio_path, audio_import_path])
# if dialogue_label.is_typing:
# await dialogue_label.finished_typing

View File

@ -33,7 +33,7 @@ func display() -> void:
if current_child.has_signal("exit"):
current_child.connect("exit", _exit)
elif GlobalConfig.DEBUG:
print("[特写界面] no exit signal, packed_scene:", packed_scene)
print_rich("[color=orange][特写界面] no exit signal, packed_scene:", packed_scene)
func _exit(arg = null):

View File

@ -121,8 +121,7 @@ func _interacted():
else:
SceneManager.enable_prop_item(prop_key)
triggered.emit()
if GlobalConfig.DEBUG:
print("pickable triggered! name=", name)
print("pickable triggered! prop_key=", prop_key, ",as_important_item=", as_important_item)
_check_display()

View File

@ -95,8 +95,7 @@ func _ready() -> void:
ground_archive = ArchiveManager.archive.ground_archive()
icount = ground_archive.get_value(name, "icount", 0)
status = ground_archive.get_value(name, "status", status)
if GlobalConfig.DEBUG:
print("Portal read status [", name, "] status=", status)
print("Portal read status [", name, "] status=", status)
_check_sign_mark_and_texture()
area2d.body_entered.connect(_reset)
area2d.body_exited.connect(_on_cancel)
@ -198,8 +197,7 @@ func _on_interacted() -> void:
before_pre_transport_wait.emit()
if pre_transport_wait_time > 0.0:
await get_tree().create_timer(pre_transport_wait_time).timeout
if GlobalConfig.DEBUG:
print("传送前往", target_scene, target_portal, " immediately=", immediately)
prints("[portal] transition to scene:", target_scene, target_portal, "immediately=", immediately)
var ground_loader = SceneManager.get_ground_loader() as GroundLoader
if ground_loader:
if immediately:

View File

@ -34,10 +34,7 @@ var pass_unhandled_input = false
# var shadow_texture = preload("res://asset/art/ui/action_mark/探索空心ui.png") as Texture2D
# 同时只能有一个物品被激活交互态,其他物品进入等待队列
static var occupied: NodePath:
set(val):
occupied = val
print("[Sign] occupied:", Sign.get_name_from_path(occupied))
static var occupied: NodePath
# touching 状态改变时就要擦除
static var _touching_sign_arr: Array[NodePath] = []
# 使用互斥锁保证线程安全。在操作 occupied 或 _touching_sign_arr 时需要先锁定,操作完成后解锁
@ -228,8 +225,7 @@ func _unhandled_input(event: InputEvent) -> void:
if activated:
if event.is_action_pressed("interact"):
get_viewport().set_input_as_handled()
if GlobalConfig.DEBUG:
print("Sign interacted:", get_parent().name)
print("Sign interacted:", get_parent().name)
interacted.emit()
if is_inside_tree():
# grab focus 放在 emit 后面,避免在 emit 时 prop hud 失去 focus
@ -238,8 +234,7 @@ func _unhandled_input(event: InputEvent) -> void:
grab_focus()
elif event.is_action_pressed("cancel"):
get_viewport().set_input_as_handled()
if GlobalConfig.DEBUG:
print("Sign cancel:", get_parent().name)
print("Sign cancel:", get_parent().name)
cancel.emit()
release_focus()

View File

@ -180,8 +180,7 @@ func move_player_to_portal(portal_name: String) -> void:
elif portal_name == "right":
mov_player.set_facing_direction(Vector2.LEFT)
reset_player_y()
if GlobalConfig.DEBUG:
print("move player to portal:", portal_name, portal_node.global_position)
print("[ground] move player to portal:", portal_name, portal_node.global_position)
elif mov_player:
printerr(scene_name, " portal not found: ", node_path)
else:

View File

@ -122,9 +122,8 @@ func transition_to_scene(scene_name: String, portal: String, wait_time := 1.4) -
# 先发送,再暂停,允许 sfx 等节点执行 ease out
SceneManager.ground_transition_pre_paused.emit()
ground.process_mode = Node.PROCESS_MODE_DISABLED
if GlobalConfig.DEBUG:
# print reenter lock status
print("GroundLoader transition_to_scene: reenter lock status: ", ground.reenter_lock)
# print reenter lock status
print("GroundLoader transition_to_scene: reenter lock status: ", ground.reenter_lock)
var scene_path = GROUND_SCENE_PATH_DICT.get(scene_name)
if scene_path:
current_scene = scene_name
@ -208,14 +207,13 @@ func _add_ground():
else:
# move player to portal
ground.move_player_to_portal(entrance_portal)
if GlobalConfig.DEBUG:
print(
"GroundLoader add_ground finished:",
ground.scene_name,
" player.pos=",
ground.get_player().global_position
)
add_child(ground)
print(
"GroundLoader add_ground finished:",
ground.scene_name,
" player.pos=",
ground.get_player().global_position
)
# ready 后,再整体重置 camera 位置
if not Engine.is_editor_hint():
ground.get_camera().reset_position_immediately()

View File

@ -11,8 +11,7 @@ extends Control
func _ready():
if GlobalConfig.DEBUG:
print("Index Page Ready")
print("Index Page Ready")
newgame_btn.pressed.connect(_on_newgame_pressed)
resume_btn.pressed.connect(_on_resume_pressed)
quit_btn.pressed.connect(_on_quit_pressed)
@ -37,8 +36,7 @@ func _on_newgame_pressed():
func _on_resume_pressed():
sfx_click.global_play()
# 继续一号存档
if GlobalConfig.DEBUG:
print("Resume")
print("Resume Game")
if ArchiveManager.archives.has(1):
# 设置 current_selected_archive_id 后,存档会自动加载
GlobalConfigManager.config.current_selected_archive_id = 1

View File

@ -91,7 +91,7 @@ func _ready():
# navigation
return_btn.pressed.connect(_on_return_btn_pressed)
return_btn.grab_focus()
SceneManager.toggle_pause_counter(true)
SceneManager.toggle_pause_counter(true, "settings")
# open
$"Sfx打开".play()
# # resize
@ -192,5 +192,5 @@ func _unhandled_key_input(event: InputEvent) -> void:
func exit_settings() -> void:
$"Sfx关闭".global_play()
SceneManager.toggle_pause_counter(false)
SceneManager.toggle_pause_counter(false, "settings")
queue_free()

View File

@ -8,7 +8,7 @@ extends CanvasLayer
func _ready():
layer = GlobalConfig.CANVAS_LAYER_UX_PANEL
SceneManager.toggle_pause_counter(true)
SceneManager.toggle_pause_counter(true, "bag")
_load_item_buttons()
# fisplay first item
var hud = SceneManager.get_prop_hud()
@ -76,5 +76,5 @@ func _unhandled_input(event: InputEvent) -> void:
func quit() -> void:
SceneManager.toggle_pause_counter(false)
SceneManager.toggle_pause_counter(false, "bag")
queue_free()

View File

@ -3,7 +3,7 @@ class_name Memory extends CanvasLayer
func _ready() -> void:
layer = GlobalConfig.CANVAS_LAYER_UX_PANEL
SceneManager.toggle_pause_counter(true)
SceneManager.toggle_pause_counter(true, "memory")
update_display()
@ -19,7 +19,7 @@ func _unhandled_input(event: InputEvent) -> void:
func quit() -> void:
SceneManager.toggle_pause_counter(false)
SceneManager.toggle_pause_counter(false, "memory")
queue_free()

View File

@ -3,7 +3,7 @@ extends CanvasLayer
func _ready() -> void:
layer = GlobalConfig.CANVAS_LAYER_UX_PANEL
SceneManager.toggle_pause_counter(true)
SceneManager.toggle_pause_counter(true, "note")
func _unhandled_input(event: InputEvent) -> void:
@ -18,5 +18,5 @@ func _unhandled_input(event: InputEvent) -> void:
func quit() -> void:
SceneManager.toggle_pause_counter(false)
SceneManager.toggle_pause_counter(false, "note")
queue_free()

View File

@ -11,7 +11,7 @@ extends CanvasLayer
func _ready() -> void:
$SfxOpen.play()
layer = GlobalConfig.CANVAS_LAYER_UX_PANEL
SceneManager.toggle_pause_counter(true)
SceneManager.toggle_pause_counter(true, "panel")
continue_btn.pressed.connect(_continue)
note_btn.pressed.connect(SceneManager.show_note)
settings_btn.pressed.connect(SceneManager.show_settings)
@ -27,7 +27,7 @@ func _quit_game() -> void:
func _continue():
$SfxClose.global_play()
SceneManager.toggle_pause_counter(false)
SceneManager.toggle_pause_counter(false, "panel")
queue_free()