extends Node @export var generate_playlist_now = false @export var checksum_test = false @export var load_playlist_from_file = false @export var maps_in_rotation : Array[level_resource] = [] @export var gamemodes_in_rotation : Array[gamemode]= [] @export var levels_per_round : int = 5 @export var rounds_per_match : int = 3 @export var matches_per_year : int = 52 func generate_playlist() -> void: var playlist_name = only_valid_chars(GameGlobals.all_user_leaderboards[GameGlobals.user_id][GameGlobals.last_leaderboard_id]) var playlist = [] print("PLAYLIST CREATED FOR THE : ",playlist_name) for h in matches_per_year: var matches = [] for i in rounds_per_match: var round = [] for x in levels_per_round: var gamemode_path = gamemodes_in_rotation.pick_random().resource_path var level_selection = maps_in_rotation.pick_random() var level_details = { "level_path" : level_selection.level_path, "level_name" : level_selection.level_name, "gamemode_path" : gamemode_path } round.append(level_details) matches.append(round) playlist.append(matches) 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_name = str(only_valid_chars(GameGlobals.all_user_leaderboards[GameGlobals.user_id][GameGlobals.last_leaderboard_id])) var playlist_path : String = "user://"+ playlist_name + "_playlist.save" var file = FileAccess.open(playlist_path, FileAccess.WRITE) file.store_var(only_valid_chars(GameGlobals.all_user_leaderboards[GameGlobals.user_id][GameGlobals.last_leaderboard_id])) file.store_var(playlist) file.close() func load_playlist(): var playlist_path : String = "user://" + str(GameGlobals.all_user_leaderboards[GameGlobals.user_id][GameGlobals.last_leaderboard_id]) + "_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 GameGlobals.current_match = playlist[0] file.close() else: print("no data saved, generating new playlist...") generate_playlist()