hero-mark-2/menus/file_select_panel.gd
2024-07-14 03:30:05 -04:00

83 lines
2.5 KiB
GDScript

extends Panel
signal file_loaded()
const FileCreate = preload("res://menus/file_create.tscn")
export var number = 1
var file: Save.SaveFile = null
onready var splatter = $DeathSplatter
func _ready():
$FileNumber.text = "FILE%d" % number
refresh()
func select() -> void:
if get_parent().kill_mode == false:
# if a file exists, load and play it!
if file:
# set current file and difficulty
Save.current_file = file
Game.difficulty = file.difficulty
Game.current_palette = file.palette
# update last-played file for continue button
Options.last_file = number
Options.save_options()
# let file select scene know a file has been loaded
emit_signal("file_loaded")
# empty file, so go to file creation screen
else:
# wait for fade
Fade.fade_out(Options.transition_speed_secs)
yield(Fade, "fade_finished")
# create new file and give it to the file create screen
var file_create = FileCreate.instance()
file_create.file = Save.SaveFile.new("user://file%d.pr" % number)
SceneManager.current_scene = file_create
else:
#Delete file
if file:
var dir = Directory.new()
dir.remove(file.file_path)
splatter.emitting = true
Audio.play_sound(Audio.a_die,Audio.ac_die)
file = null
refresh()
func refresh():
# check if the file exists
if File.new().file_exists("user://file%d.pr" % number):
# load file and fill in information
file = Save.load_file("user://file%d.pr" % number)
$"%Name".text = file.name
$"%ShardCounter".text = "%02d" % file.get_total_shards()
$"%KeyCounter".text = "%03d" % file.get_total_keys()
$"%DeathCounter".text = "%04d" % file.get_total_deaths()
$"%TimeCounter".text = "%02d:%02d" % [file.play_time / 3600.0, fmod(file.play_time / 60.0, 60.0)]
$"%Difficulty".text = Game.DIFFICULTY_NAMES[file.difficulty]
var palette = load("res://graphics/player/palettes/%s.tex" % file.palette)
$"%Palette".material.set_shader_param("palette", palette)
if file.palette == "super_player":
$"%Sparkles".visible = true
else:
$"%Sparkles".visible = false
$"%MoriMarkGameComplete".visible = false
$"%MoriMark100Complete".visible = false
$"%MoriMarkNoDeath".visible = false
if file.levels["boss3"].completed:
$"%MoriMarkGameComplete".visible = true
if file.get_total_shards() >= 72:
$"%MoriMark100Complete".visible = true
if file.get_total_deaths() <= 0:
$"%MoriMarkNoDeath".visible = true
else:
file = null
$FileExists.visible = false
$FileDoesNotExist.visible = true