From 1c342ecda7a14423d124763128802d2a1781ff8a Mon Sep 17 00:00:00 2001 From: derek Date: Wed, 26 Feb 2025 09:13:00 -0600 Subject: [PATCH] added playlist generator --- GameModes/cookie_mode.tres | 6 ++- GameModes/do_not_get_hit.tres | 8 ++- GameModes/standard.tres | 1 + GameModes/standard_stam_regen.tres | 38 +++++++++++++++ Mai48CD.tmp | 59 ++++++++++++++++++++++ MainMenu.tscn | 15 +++++- Tools/playlist_generator.tscn | 28 +++++++++++ gamemode.gd | 1 + scripts/HelperFuncs.gd | 10 ++++ scripts/game_globals.gd | 4 ++ scripts/main_menu.gd | 10 ++++ scripts/playlist_generator.gd | 78 ++++++++++++++++++++++++++++++ scripts/save_load.gd | 2 + 13 files changed, 257 insertions(+), 3 deletions(-) create mode 100644 GameModes/standard_stam_regen.tres create mode 100644 Mai48CD.tmp create mode 100644 Tools/playlist_generator.tscn create mode 100644 scripts/playlist_generator.gd diff --git a/GameModes/cookie_mode.tres b/GameModes/cookie_mode.tres index e80802c..bd4fb95 100644 --- a/GameModes/cookie_mode.tres +++ b/GameModes/cookie_mode.tres @@ -5,8 +5,12 @@ [resource] script = ExtResource("1_8tp85") gamemode_name = "Cookie Mode" +estimated_difficulty = 4 win_conditions = 0 survival_time = 160.0 +money_lost_multiplier = 0.5 +weapon_penalty = 0 +weapon_drop_percentage = 0.5 walk_speed = 5.0 jump_velocity = 5 dash_speed = 5 @@ -17,7 +21,7 @@ max_stamina = 100.0 stamina_drain = 20.0 air_dash_max = 1 load_save = true -money = 0 +money_multiplier = 3.0 start_health = 3 drop_chance_minimum = 0.1 random_drops = false diff --git a/GameModes/do_not_get_hit.tres b/GameModes/do_not_get_hit.tres index d00268d..2563a0d 100644 --- a/GameModes/do_not_get_hit.tres +++ b/GameModes/do_not_get_hit.tres @@ -5,6 +5,12 @@ [resource] script = ExtResource("1_lcpua") gamemode_name = "DO NOT GET HIT" +estimated_difficulty = 0 +win_conditions = 2 +survival_time = 160.0 +money_lost_multiplier = 0.5 +weapon_penalty = 0 +weapon_drop_percentage = 0.5 walk_speed = 12.0 jump_velocity = 5 dash_speed = 40 @@ -15,7 +21,7 @@ max_stamina = 100.0 stamina_drain = 20.0 air_dash_max = 1 load_save = true -money = 250 +money_multiplier = 1.0 start_health = 1 drop_chance_minimum = 0.1 random_drops = false diff --git a/GameModes/standard.tres b/GameModes/standard.tres index b045b2b..f91101a 100644 --- a/GameModes/standard.tres +++ b/GameModes/standard.tres @@ -5,6 +5,7 @@ [resource] script = ExtResource("1_litni") gamemode_name = "Standard" +estimated_difficulty = 2 win_conditions = 0 survival_time = 160.0 money_lost_multiplier = 0.5 diff --git a/GameModes/standard_stam_regen.tres b/GameModes/standard_stam_regen.tres new file mode 100644 index 0000000..e2e7279 --- /dev/null +++ b/GameModes/standard_stam_regen.tres @@ -0,0 +1,38 @@ +[gd_resource type="Resource" script_class="gamemode" load_steps=2 format=3 uid="uid://u32xafejp3rq"] + +[ext_resource type="Script" path="res://gamemode.gd" id="1_2sia6"] + +[resource] +script = ExtResource("1_2sia6") +gamemode_name = "Standard" +estimated_difficulty = 0 +win_conditions = 0 +survival_time = 160.0 +money_lost_multiplier = 0.5 +weapon_penalty = 0 +weapon_drop_percentage = 0.5 +walk_speed = 12.0 +jump_velocity = 5 +dash_speed = 40 +gravity = -9.8 +time_slowed_speed = 0.1 +stamina_regen = false +max_stamina = 100.0 +stamina_drain = 20.0 +air_dash_max = 1 +load_save = false +money_multiplier = 1.0 +start_health = 10 +drop_chance_minimum = 0.1 +random_drops = false +ammo_drop_enabled = true +expected_ammo = { +"heavy": 25, +"light": 200, +"medium": 50, +"rocket": 3, +"shotgun": 20 +} +stamina_drop_enabled = true +health_drop_enabled = true +money_drop_enabled = true diff --git a/Mai48CD.tmp b/Mai48CD.tmp new file mode 100644 index 0000000..b1ab7b8 --- /dev/null +++ b/Mai48CD.tmp @@ -0,0 +1,59 @@ +[gd_scene load_steps=5 format=3 uid="uid://sa1d1rftyn87"] + +[ext_resource type="Script" path="res://scripts/main_menu.gd" id="1_haaol"] +[ext_resource type="Theme" uid="uid://clek42ofxr45f" path="res://DefaultTheme.tres" id="2_3fflq"] +[ext_resource type="FontFile" uid="uid://d2h2tjhxiv5wo" path="res://assets/fonts/White On Black.ttf" id="2_ac165"] +[ext_resource type="Script" path="res://scripts/playlist_generator.gd" id="4_pbhnf"] + +[node name="MainMenu" type="Control" groups=["ui"]] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_haaol") + +[node name="MarginContainer" type="MarginContainer" parent="."] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -277.018 +offset_top = -174.68 +offset_right = 277.018 +offset_bottom = 174.68 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 + +[node name="leaderboard_name" type="TextEdit" parent="MarginContainer/VBoxContainer"] +custom_minimum_size = Vector2(0, 75) +layout_mode = 2 +theme = ExtResource("2_3fflq") +theme_override_font_sizes/font_size = 51 +placeholder_text = "Leaderboard name" + +[node name="Continue" type="Button" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +theme_override_fonts/font = ExtResource("2_ac165") +theme_override_font_sizes/font_size = 150 +text = "Continue" + +[node name="Exit" type="Button" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +theme_override_fonts/font = ExtResource("2_ac165") +theme_override_font_sizes/font_size = 150 +text = "exit" + +[node name="PlaylistGenerator" type="Node" parent="."] +script = ExtResource("4_pbhnf") + +[connection signal="pressed" from="MarginContainer/VBoxContainer/Continue" to="." method="_on_continue_pressed"] +[connection signal="pressed" from="MarginContainer/VBoxContainer/Exit" to="." method="_on_exit_pressed"] diff --git a/MainMenu.tscn b/MainMenu.tscn index 4b04204..e7f9519 100644 --- a/MainMenu.tscn +++ b/MainMenu.tscn @@ -1,6 +1,8 @@ -[gd_scene load_steps=3 format=3 uid="uid://sa1d1rftyn87"] +[gd_scene load_steps=5 format=3 uid="uid://sa1d1rftyn87"] [ext_resource type="Script" path="res://scripts/main_menu.gd" id="1_haaol"] +[ext_resource type="PackedScene" uid="uid://dpootbr7qgac1" path="res://Tools/playlist_generator.tscn" id="2_2rg1o"] +[ext_resource type="Theme" uid="uid://clek42ofxr45f" path="res://DefaultTheme.tres" id="2_3fflq"] [ext_resource type="FontFile" uid="uid://d2h2tjhxiv5wo" path="res://assets/fonts/White On Black.ttf" id="2_ac165"] [node name="MainMenu" type="Control" groups=["ui"]] @@ -12,6 +14,10 @@ grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_haaol") +[node name="PlaylistGenerator" parent="." instance=ExtResource("2_2rg1o")] +visible = false +layout_mode = 1 + [node name="MarginContainer" type="MarginContainer" parent="."] layout_mode = 1 anchors_preset = 8 @@ -31,6 +37,13 @@ layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 4 +[node name="leaderboard_name" type="TextEdit" parent="MarginContainer/VBoxContainer"] +custom_minimum_size = Vector2(0, 75) +layout_mode = 2 +theme = ExtResource("2_3fflq") +theme_override_font_sizes/font_size = 51 +placeholder_text = "Leaderboard name" + [node name="Continue" type="Button" parent="MarginContainer/VBoxContainer"] layout_mode = 2 theme_override_fonts/font = ExtResource("2_ac165") diff --git a/Tools/playlist_generator.tscn b/Tools/playlist_generator.tscn new file mode 100644 index 0000000..e91080e --- /dev/null +++ b/Tools/playlist_generator.tscn @@ -0,0 +1,28 @@ +[gd_scene load_steps=7 format=3 uid="uid://dpootbr7qgac1"] + +[ext_resource type="Script" path="res://scripts/playlist_generator.gd" id="1_qvqs2"] +[ext_resource type="Resource" uid="uid://dn3t7wcoumlm3" path="res://GameModes/standard.tres" id="2_85uje"] +[ext_resource type="Script" path="res://gamemode.gd" id="2_hoyqc"] +[ext_resource type="Resource" uid="uid://bs8yvpq65yh3w" path="res://GameModes/cookie_mode.tres" id="3_t0mxh"] +[ext_resource type="Resource" uid="uid://dlvhtdmtln3bb" path="res://GameModes/do_not_get_hit.tres" id="4_8wht4"] +[ext_resource type="Resource" uid="uid://u32xafejp3rq" path="res://GameModes/standard_stam_regen.tres" id="6_vu1w7"] + +[node name="Playlist Generator" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_qvqs2") +generate_playlist_now = null +maps_in_rotation = Array[String](["res://assets/blockout_2.tscn", "res://scenes/enemy_working_scene.tscn", "res://scenes/test_level_2v2.tscn", "res://scenes/Arena of Money.tscn"]) +gamemodes_in_rotation = Array[ExtResource("2_hoyqc")]([ExtResource("2_85uje"), ExtResource("3_t0mxh"), ExtResource("4_8wht4"), ExtResource("6_vu1w7")]) + +[node name="Button" type="Button" parent="."] +layout_mode = 0 +offset_right = 8.0 +offset_bottom = 8.0 +text = "Generate Random Playlist" + +[connection signal="pressed" from="Button" to="." method="_on_button_pressed"] diff --git a/gamemode.gd b/gamemode.gd index 77acbab..b5e96ae 100644 --- a/gamemode.gd +++ b/gamemode.gd @@ -2,6 +2,7 @@ extends Resource class_name gamemode @export var gamemode_name : String = "My Custom Game Mode" +@export_range(1,5) var estimated_difficulty : int @export_enum("Kill 'em All","Extraction","Survival_Time") var win_conditions @export_group("Win Conditions") @export var survival_time : float = 160 #in seconds diff --git a/scripts/HelperFuncs.gd b/scripts/HelperFuncs.gd index ea6a800..d9df3c8 100644 --- a/scripts/HelperFuncs.gd +++ b/scripts/HelperFuncs.gd @@ -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 diff --git a/scripts/game_globals.gd b/scripts/game_globals.gd index d1c5278..b7f7821 100644 --- a/scripts/game_globals.gd +++ b/scripts/game_globals.gd @@ -13,6 +13,10 @@ var loading_gamemode var current_level var current_gamemode +#Leaderboard +var leaderboard_name = "Test" +var playlist_test + #Player Stats diff --git a/scripts/main_menu.gd b/scripts/main_menu.gd index ac13251..d977424 100644 --- a/scripts/main_menu.gd +++ b/scripts/main_menu.gd @@ -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" diff --git a/scripts/playlist_generator.gd b/scripts/playlist_generator.gd new file mode 100644 index 0000000..a01dabf --- /dev/null +++ b/scripts/playlist_generator.gd @@ -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() + diff --git a/scripts/save_load.gd b/scripts/save_load.gd index 1603d83..0c24484 100644 --- a/scripts/save_load.gd +++ b/scripts/save_load.gd @@ -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())