file select and file creation, menus glued together

This commit is contained in:
Haze Weathers 2023-07-20 18:19:20 -04:00
parent 13708b4046
commit f7496c5e6f
18 changed files with 754 additions and 47 deletions

View file

@ -1,16 +1,48 @@
extends Panel
signal file_loaded()
const FileCreate = preload("res://menus/file_create.tscn")
export var number = 1
var file: Save.SaveFile
var file: Save.SaveFile = null
func _ready():
$FileNumber.text = "FILE%d" % number
# 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)]
else:
$FileExists.visible = false
$FileDoesNotExist.visible = true
func select() -> void:
# if a file exists, load and play it!
if file:
# set current file and difficulty
Save.current_file = file
Game.difficulty = file.difficulty
# 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(0.4)
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