combine code entry with debug, add code visual, fix non-symbol keys in cheat codes

This commit is contained in:
Haze Weathers 2023-01-12 01:22:09 -05:00
parent 349a46b8fa
commit fa58ac21a1
6 changed files with 61 additions and 44 deletions

View file

@ -1,17 +1,25 @@
extends CanvasLayer
#Console by hazel
#Const
const ENTRY_SEQUENCE = ["4", "1", "5"]
#Export
export var max_lines: int = 10
export var opacity: float = 0.5
#Onready
onready var console: Label = $Console
onready var console = $Console
onready var code_label = get_parent().get_node("Main/Control/ViewportContainer/Viewport/CheatLayer/CheatLabel")
##Runtime
var lines: int = 0
var time: float = 0.0
var n: int = 0
var debug = false
# cheat code entry
var entry_index = 0
var entry = false
var code = ""
func _ready():
#Auto do debug when playtesting
@ -26,7 +34,7 @@ func _ready():
func _physics_process(delta):
#DEBUG
if debug == true && !CodeEntry.entry && !CodeEntry.entry_index > 0:
if debug == true && !entry && !entry_index > 0:
#Show console
if Input.is_action_just_pressed("debug_show"):
console.visible = !console.visible
@ -67,9 +75,44 @@ func print(text):
else:
console.text += str(text)
func _on_visible_toggled(button_pressed):
if button_pressed:
console.visible = true
else:
console.visible = false
func _input(event):
if event is InputEventKey && event.is_pressed():
var character = OS.get_scancode_string(event.scancode)
if character.length() > 1:
character = ""
if entry:
if event.scancode == KEY_ENTER:
_enter_code()
entry = false
code = ""
elif event.scancode == KEY_BACKSPACE:
code.erase(code.length() - 1, 1)
else:
code += character
code_label.text = code
else:
if character == ENTRY_SEQUENCE[entry_index]:
entry_index += 1
if entry_index >= ENTRY_SEQUENCE.size():
entry = true
entry_index = 0
_on_entry()
func _on_entry():
Game.play_sound(Game.a_star, Game.ac_cheat)
func _enter_code():
match code:
"30385":
Debug.print("Woohoo crystals!")
"1989":
Game.play_sound(Game.a_die, Game.ac_die)
for enemy in get_tree().get_nodes_in_group("enemy"):
enemy.queue_free()