49 lines
1.6 KiB
GDScript
49 lines
1.6 KiB
GDScript
extends Panel
|
|
|
|
signal start_game(game_path:String)
|
|
|
|
@onready var game_name_edit: TextEdit = %GameNameEdit
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
pass # Replace with function body.
|
|
|
|
func sanitize_game_name(value:String) -> String:
|
|
push_warning("Warning: sanitize_game_name not yet implemented!")
|
|
return value
|
|
|
|
func create_game_directory() -> String:
|
|
var dir_access = DirAccess.open("user://")
|
|
|
|
if not dir_access.dir_exists("game_profiles"):
|
|
dir_access.make_dir("game_profiles")
|
|
|
|
var game_base_directory = DirAccess.open("user://game_profiles")
|
|
if game_base_directory == null:
|
|
push_warning(DirAccess.get_open_error())
|
|
|
|
var sanitized_name = sanitize_game_name(game_name_edit.text)
|
|
if game_base_directory.dir_exists(sanitized_name):
|
|
var free_name_counter:int = 0
|
|
var sanitized_name_with_counter = sanitized_name + "_" + str(free_name_counter)
|
|
|
|
while game_base_directory.dir_exists(sanitized_name_with_counter):
|
|
free_name_counter = free_name_counter + 1
|
|
sanitized_name_with_counter = sanitized_name + "_" + str(free_name_counter)
|
|
|
|
sanitized_name = sanitized_name_with_counter
|
|
|
|
game_base_directory.make_dir(sanitized_name)
|
|
|
|
var game_profile = GameProfileResource.new()
|
|
game_profile.game_name = game_name_edit.text
|
|
game_profile.created = Time.get_datetime_string_from_system()
|
|
game_profile.last_played = Time.get_datetime_string_from_system()
|
|
ResourceSaver.save(game_profile, "user://game_profiles/" + sanitized_name + "/game.tres")
|
|
|
|
return sanitized_name
|
|
|
|
|
|
func _on_start_game_button_pressed() -> void:
|
|
start_game.emit("user://game_profiles/" + create_game_directory() + "/game.tres")
|