Files
sijcdusmode/scripts/level_skip.gd
T
sijcdu 44e4c3a751 Add a debug-only level skip overlay so testing level 3 does not require beating levels 1 and 2
Registered as an autoload so every scene gets it for free. Top-right shows a row of buttons generated from the levels array (main, level2, level3) plus keyboard shortcuts 1/2/3, and it runs with PROCESS_MODE_ALWAYS at layer 30 so it still works while the tree is paused on a death or level-clear screen. Hidden in exported release builds, same rule as the debug flight.
2026-10-07 23:02:57 +08:00

60 lines
1.4 KiB
GDScript

extends CanvasLayer
## 测试用跳关:右上角一排数字按钮,点一下直接跳到对应关卡;
## 键盘上按 1 / 2 / 3 也一样。
## 只在编辑器 / 调试版里显示,导出的正式版会自动隐藏(和飞行一个规矩)。
@export var levels: Array[String] = [
"res://scenes/main.tscn",
"res://scenes/level2.tscn",
"res://scenes/level3.tscn",
]
## 强制在正式版里也显示(一般别开)
@export var always_show: bool = false
func _ready() -> void:
visible = always_show or OS.is_debug_build()
if not visible:
set_process_unhandled_input(false)
return
var box := get_node_or_null("Buttons")
if box == null:
return
var index := 1
for path in levels:
var btn := Button.new()
btn.text = str(index)
btn.custom_minimum_size = Vector2(24.0, 24.0)
btn.focus_mode = Control.FOCUS_NONE
btn.add_theme_font_size_override("font_size", 12)
btn.pressed.connect(jump_to.bind(path))
box.add_child(btn)
index += 1
func _unhandled_input(event: InputEvent) -> void:
var key := event as InputEventKey
if key == null or not key.pressed or key.echo:
return
var n := 0
match key.physical_keycode:
KEY_1, KEY_KP_1:
n = 1
KEY_2, KEY_KP_2:
n = 2
KEY_3, KEY_KP_3:
n = 3
KEY_4, KEY_KP_4:
n = 4
KEY_5, KEY_KP_5:
n = 5
if n >= 1 and n <= levels.size():
jump_to(levels[n - 1])
func jump_to(path: String) -> void:
get_tree().paused = false
get_tree().change_scene_to_file(path)