added playlist generator

This commit is contained in:
derek
2025-02-26 09:13:00 -06:00
parent c87f22d9e8
commit 1c342ecda7
13 changed files with 257 additions and 3 deletions

View File

@@ -1,3 +1,4 @@
@tool
extends Node
## ANGLES
@@ -34,3 +35,12 @@ func weighted_random(choices):
print("----------------------------------------------------------------")
return i
random_number -= choices[i]
func only_valid_chars(input_string: String) -> String:
var valid_chars = ""
for char in input_string:
if char.is_valid_identifier():
valid_chars += char
return valid_chars

View File

@@ -13,6 +13,10 @@ var loading_gamemode
var current_level
var current_gamemode
#Leaderboard
var leaderboard_name = "Test"
var playlist_test
#Player Stats

View File

@@ -2,14 +2,24 @@ extends Node
var last_scene
@onready var playlist_generator: Node = $PlaylistGenerator
@onready var leaderboard_name: TextEdit = $MarginContainer/VBoxContainer/leaderboard_name
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
SaveLoad.load_persistent_data()
leaderboard_name.text = GameGlobals.leaderboard_name
playlist_generator.load_playlist()
func _on_continue_pressed() -> void:
var level
var load_to_gamemode
if GameGlobals.leaderboard_name != leaderboard_name.text:
GameGlobals.leaderboard_name = leaderboard_name.text
playlist_generator.load_playlist()
if GameGlobals.current_level == null:
level = "res://scenes/HUBWORLD.tscn"
load_to_gamemode = "res://GameModes/hubworld.tres"

View File

@@ -0,0 +1,78 @@
@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()

View File

@@ -35,6 +35,7 @@ func save_persistent_data():
print("LAST HIT PATH " + str(last_hit_path))
file.store_var(last_hit_path)
file.store_var(player.velocity)
file.store_var(GameGlobals.leaderboard_name)
file.store_var(get_tree().current_scene.scene_file_path)
file.store_var(get_tree().current_scene.gamemode.resource_path)
file.store_var(GameGlobals.money)
@@ -59,6 +60,7 @@ func load_persistent_data():
var file = FileAccess.open(persistent_save_path, FileAccess.READ)
last_hit_path = file.get_var()
player_velocity_cache = file.get_var()
GameGlobals.leaderboard_name = file.get_var()
GameGlobals.current_level = str(file.get_var())
GameGlobals.current_gamemode = file.get_var()
GameGlobals.money = set_nulls_zero(file.get_var())