-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheater.gd
40 lines (35 loc) · 856 Bytes
/
cheater.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
extends Node
var cur_code = ""
var codes = Dictionary()
var signals = Dictionary()
func _input(event):
if event is InputEventKey and event.pressed:
cur_code += String.chr(event.unicode).to_upper()
var found = false
for code in codes.keys():
if code.begins_with(cur_code):
found = true
break
if found:
if cur_code in codes:
for sig in codes[cur_code]:
sig.emit(cur_code)
cur_code = ""
else:
cur_code = ""
func register(code : String, thing : Node):
var sig
if thing in signals:
sig = signals[thing]
else:
thing.add_user_signal("cheat", [{"name": "code", "type": TYPE_STRING}])
sig = Signal(thing, "cheat")
sig.connect(thing.cheat)
signals[thing] = sig
if code in codes:
codes[code].appemd(sig)
else:
codes[code] = [sig]
func unregister(code : String):
if code in codes:
codes.erase(code)