-
Notifications
You must be signed in to change notification settings - Fork 0
/
Global.gd
50 lines (40 loc) · 1.21 KB
/
Global.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
extends Node
onready var keybinds_menu = load("res://menu/keybind_menu/KeybindsMenu.tscn")
var filepath = "keybinds.ini"
var configfile
var keybinds = {}
func _input(event):
if Input.is_key_pressed(KEY_ESCAPE):
add_child(keybinds_menu.instance())
get_tree().paused = true
func _ready():
configfile = ConfigFile.new()
if configfile.load(filepath) == OK:
for key in configfile.get_section_keys("keybinds"):
var key_value = configfile.get_value("keybinds", key)
if str(key_value) != "":
keybinds[key] = key_value
else:
keybinds[key] = null
else:
print("CONFIG FILE NOT FOUND")
get_tree().quit()
set_game_binds()
func set_game_binds():
for key in keybinds.keys():
var value = keybinds[key]
var actionlist = InputMap.get_action_list(key)
if !actionlist.empty():
InputMap.action_erase_event(key, actionlist[0])
if value != null:
var new_key = InputEventKey.new()
new_key.set_scancode(value)
InputMap.action_add_event(key, new_key)
func write_config():
for key in keybinds.keys():
var key_value = keybinds[key]
if key_value != null:
configfile.set_value("keybinds", key, key_value)
else:
configfile.set_value("keybinds", key, "")
configfile.save(filepath)