79 lines
2.2 KiB
GDScript
79 lines
2.2 KiB
GDScript
@tool
|
|
extends Node
|
|
|
|
@export var generate_playlist_now = false
|
|
@export var load_playlist_from_file = false
|
|
@export var maps_in_rotation : Array[String] = []
|
|
@export var gamemodes_in_rotation : Array[gamemode]= []
|
|
@export var levels_per_round : int = 5
|
|
@export var rounds : int = 3
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
pass # Replace with function body.
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
if generate_playlist_now == true:
|
|
generate_playlist()
|
|
|
|
if load_playlist_from_file == true:
|
|
load_playlist()
|
|
|
|
|
|
func generate_playlist() -> void:
|
|
var playlist_name = only_valid_chars(GameGlobals.leaderboard_name)
|
|
var playlist = []
|
|
print("PLAYLIST CREATED FOR THE : ",playlist_name)
|
|
for i in rounds:
|
|
var round = []
|
|
for x in levels_per_round:
|
|
var level_details = {
|
|
"map" : maps_in_rotation.pick_random(),
|
|
"gamemode" : gamemodes_in_rotation.pick_random()
|
|
}
|
|
round.append(level_details)
|
|
|
|
playlist.append(round)
|
|
print("PLAYLIST : ", playlist[0][0])
|
|
|
|
save_playlist(playlist)
|
|
generate_playlist_now = false
|
|
|
|
|
|
func only_valid_chars(input_string: String) -> String:
|
|
var valid_chars = ""
|
|
|
|
for char in input_string:
|
|
if char.is_valid_identifier():
|
|
valid_chars += char
|
|
elif char == " ":
|
|
valid_chars += "_"
|
|
|
|
return valid_chars
|
|
|
|
func save_playlist(playlist):
|
|
var playlist_path : String = "user://" + str(only_valid_chars(GameGlobals.leaderboard_name)) + "_playlist.save"
|
|
var file = FileAccess.open(playlist_path, FileAccess.WRITE)
|
|
file.store_var(only_valid_chars(GameGlobals.leaderboard_name))
|
|
file.store_var(playlist)
|
|
file.close()
|
|
|
|
func load_playlist():
|
|
var playlist_path : String = "user://" + str(only_valid_chars(GameGlobals.leaderboard_name)) + "_playlist.save"
|
|
if FileAccess.file_exists(playlist_path):
|
|
var file = FileAccess.open(playlist_path, FileAccess.READ)
|
|
var key = file.get_var()
|
|
var playlist = file.get_var()
|
|
print("KEY : ",key)
|
|
GameGlobals.playlist_test = playlist
|
|
file.close()
|
|
print("PLAYLIST: ")
|
|
print("------------------------------------------------------------------------------------")
|
|
print(playlist)
|
|
else:
|
|
print("no data saved, generating new playlist...")
|
|
generate_playlist()
|
|
|