Files
net-gunner/scripts/decompile_hack_modal.gd

114 lines
3.2 KiB
GDScript

class_name DecompileHackModal extends Control
const action_value : Dictionary[String, int] = {
"detonate" : 0,
"install" : 1,
"detect" : 2,
"attack" : 3
}
const icon_textures : Array = [
{
"normal" : preload("res://visuals/images/icons/button-detonate.png"),
"pressed" : preload("res://visuals/images/icons/button-detonate-hit.png")
},
{
"normal" : preload("res://visuals/images/icons/button-hack.png"),
"pressed" : preload("res://visuals/images/icons/button-hack-hit.png")
},
{
"normal" : preload("res://visuals/images/icons/button-detect.png"),
"pressed" : preload("res://visuals/images/icons/button-detect-hit.png")
},
{
"normal" : preload("res://visuals/images/icons/button-attack.png"),
"pressed" : preload("res://visuals/images/icons/button-attack-hit.png")
},
]
const decompile_icon_template = preload("res://templates/decompile_icon.tscn")
const success_sound = preload("res://audio/sounds/TomWinandySFX_UI_ScifiTech_Notification_13.wav")
const fail_sound = preload("res://audio/sounds/TomWinandySFX_UI_ScifiTech_Cancel_05.wav")
const progress_sound = preload("res://audio/sounds/metal_tiny_hit_impact_01.wav")
@onready var confirmation_dialog : ConfirmationDialog = %ConfirmationDialog
@onready var decompile_window : PanelContainer = %DecompileWindow
@onready var decompile_button_container : HBoxContainer = %DecompileContainer
@onready var timer : Timer = %Timer
@onready var timer_label : Label = %TimerLabel
var square : Vector3i
var decompile_icons : Array[TextureButton]
var decompile_buttons : Array[int]
var progress : int
var decompiling : bool
var failed : bool
var difficulty : int = 1
func _process(_delta: float) -> void:
timer_label.text = "%02f.3" % timer.time_left
func start_decompiling() -> void:
decompiling = true
progress = 0
decompile_icons = []
decompile_buttons = []
for i in range(Game.level.difficulty):
var btn = randi_range(0,3)
var icon : TextureButton = decompile_icon_template.instantiate()
icon.texture_normal = icon_textures[btn].normal
icon.texture_pressed = icon_textures[btn].pressed
decompile_buttons.append(btn)
decompile_icons.append(icon)
decompile_button_container.add_child(icon)
confirmation_dialog.visible = false
decompile_window.visible = true
timer.start(2 + (len(decompile_buttons) * randf_range(.75, 1.25) ))
func try_advance(btn : int) -> void:
if btn == decompile_buttons[progress]:
decompile_icons[progress].button_pressed = true
progress += 1
if progress >= len(decompile_buttons):
succeed()
else:
Game.oneshot(progress_sound)
else:
fail()
func button_pressed(event : String) -> void:
if decompiling:
try_advance(action_value[event])
else:
match(event):
"detonate":
start_decompiling()
"attack":
var hack = Game.level.get_square_hack(square)
hack.decompiling = false
Game.player.close_modal()
_: return
func fail() -> void:
if failed:
return
failed = true
Game.player.close_modal()
Game.oneshot(fail_sound)
Game.level.activate_hack(square)
func succeed() -> void:
Game.player.close_modal()
Game.oneshot(success_sound)
Game.level.decompile_hack(square)
func _on_hack_failed() -> void:
fail()
func _on_hack_removed(_type : Hack.Type) -> void:
Game.player.close_modal()