ccf9813c80
Alle Texte stehen in einer Tabelle mit Deutsch und Englisch, die das Spiel zur Laufzeit liest. Die Tasten werden in Code angelegt, nach physischer Position. SaveStore verwaltet den Spielerschlüssel dieser Installation, schreibt den Speicherstand über eine temporäre Datei, legt unbrauchbare Stände beiseite und behält die zehn neuesten Aufzeichnungen. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
36 lines
1.1 KiB
GDScript
36 lines
1.1 KiB
GDScript
class_name InputSetup
|
|
extends RefCounted
|
|
## Registers the game's input actions in code, so that project.godot holds no
|
|
## serialized input events. Keys are physical positions, so WASD stays in
|
|
## place on German keyboards too.
|
|
|
|
|
|
static func install() -> void:
|
|
_add_keys("move_up", [KEY_W, KEY_UP])
|
|
_add_keys("move_down", [KEY_S, KEY_DOWN])
|
|
_add_keys("move_left", [KEY_A, KEY_LEFT])
|
|
_add_keys("move_right", [KEY_D, KEY_RIGHT])
|
|
_add_keys("save_game", [KEY_F5])
|
|
_add_keys("load_game", [KEY_F9])
|
|
_add_keys("toggle_pause", [KEY_ESCAPE])
|
|
_add_mouse_button("dig", MOUSE_BUTTON_LEFT)
|
|
|
|
|
|
static func _add_keys(action: StringName, keys: Array[Key]) -> void:
|
|
if InputMap.has_action(action):
|
|
return
|
|
InputMap.add_action(action)
|
|
for key in keys:
|
|
var event := InputEventKey.new()
|
|
event.physical_keycode = key
|
|
InputMap.action_add_event(action, event)
|
|
|
|
|
|
static func _add_mouse_button(action: StringName, button: MouseButton) -> void:
|
|
if InputMap.has_action(action):
|
|
return
|
|
InputMap.add_action(action)
|
|
var event := InputEventMouseButton.new()
|
|
event.button_index = button
|
|
InputMap.action_add_event(action, event)
|