Files
zombie-fps/tools/test_fullscreen_shortcut.gd
T
enne2 4af402f8bf Add Alt+F to toggle fullscreen and window mode
New remappable action `toggle_fullscreen` (Alt+F) handled in main.gd::_input(),
so it works in the menu, during a match with the pointer captured and in the boss
sandbox; the event is marked handled so the key does not reach the rest of the game.

toggle_fullscreen() switches between WINDOW_MODE_FULLSCREEN and WINDOW_MODE_WINDOWED;
the state lives in main.fullscreen (initialised from the real window mode) instead of
querying the driver on every press, so the toggle is deterministic and testable. On
Web it is a no-op because fullscreen belongs to the page.

Desktop HUD hint updated. New tools/test_fullscreen_shortcut.gd: 8 checks (action and
key mapping, alternation, bare F inert, works mid-match without freeing the cursor).
Verified on a real display: window_get_mode 0 -> 3 -> 0.
2026-10-24 12:55:15 +02:00

95 lines
3.6 KiB
GDScript

extends SceneTree
## Verifica la scorciatoia Alt+F (finestra <-> schermo intero):
## - l'azione "toggle_fullscreen" esiste nella mappa dei comandi ed e' Alt+F;
## - ogni pressione alterna lo stato, anche a partita avviata e a cursore catturato;
## - l'evento viene marcato come gestito (il tasto non arriva al gioco);
## - Alt+F senza Alt (o F da solo) NON cambia nulla.
## Avviare con: --headless --path . --script res://tools/test_fullscreen_shortcut.gd
## Con un display reale si usa: --rendering-method gl_compatibility
const ACTIONS := ["toggle_fullscreen"]
var world: Node3D
var failures := 0
var checks := 0
func _initialize() -> void:
call_deferred("run_test")
func check(label: String, condition: bool, detail: String = "") -> void:
checks += 1
if condition:
print("PASS: " + label)
else:
failures += 1
print("FAIL: %s %s" % [label, detail])
func run_test() -> void:
# --- mappa dei comandi ---
check("l'azione toggle_fullscreen esiste nella mappa", InputMap.has_action("toggle_fullscreen"))
var alt_f := false
for event in InputMap.action_get_events("toggle_fullscreen"):
if event is InputEventKey and event.alt_pressed \
and (event.physical_keycode == KEY_F or event.keycode == KEY_F):
alt_f = true
check("l'azione corrisponde ad Alt+F", alt_f, str(InputMap.action_get_events("toggle_fullscreen")))
world = load("res://scenes/main.tscn").instantiate()
root.add_child(world)
await process_frame
await process_frame
var start_state: bool = world.fullscreen
_press_f(true)
await process_frame
check("Alt+F capovolge lo stato dello schermo intero",
world.fullscreen != start_state, "prima=%s dopo=%s" % [str(start_state), str(world.fullscreen)])
_press_f(true)
await process_frame
check("una seconda pressione riporta allo stato iniziale",
world.fullscreen == start_state, "dopo=%s atteso=%s" % [str(world.fullscreen), str(start_state)])
# F senza Alt non deve cambiare nulla
var before: bool = world.fullscreen
_press_f(false)
await process_frame
check("F da solo (senza Alt) non cambia lo schermo", world.fullscreen == before,
"prima=%s dopo=%s" % [str(before), str(world.fullscreen)])
# --- in partita, a cursore catturato ---
var screen = world.start_screen
var gioca: Button = null
if screen != null:
for button in screen.find_children("*", "Button", true, false):
if button.text == "GIOCA":
gioca = button
if screen != null and screen.get("name_field") != null:
screen.name_field.text = "AltF"
if gioca != null:
gioca.pressed.emit()
await process_frame
await process_frame
check("la partita e' iniziata (il cursore e' catturato o headless)",
world.player.playing == true, "playing=%s" % str(world.player.playing))
var during_play: bool = world.fullscreen
_press_f(true)
await process_frame
check("Alt+F funziona anche in partita, a cursore catturato",
world.fullscreen != during_play, "prima=%s dopo=%s" % [str(during_play), str(world.fullscreen)])
check("Alt+F non interrompe la partita ne' libera il cursore",
world.player.playing == true and world.player.death_started == false,
"playing=%s morte=%s" % [str(world.player.playing), str(world.player.death_started)])
print("%d controlli superati, %d falliti" % [checks - failures, failures])
quit(1 if failures > 0 else 0)
## Pressione + rilascio di F, con o senza Alt: stesso percorso di un tasto reale.
func _press_f(alt: bool) -> void:
for pressed in [true, false]:
var event := InputEventKey.new()
event.physical_keycode = KEY_F
event.keycode = KEY_F
event.alt_pressed = alt
event.pressed = pressed
Input.parse_input_event(event)
Input.flush_buffered_events()