From 63b096432bb4ce8f077283787673e24d3260f83c Mon Sep 17 00:00:00 2001 From: Simon Dalvai Date: Sun, 27 Oct 2024 20:31:48 +0100 Subject: [PATCH] teams: speed/power can now be modified and reset --- game/src/global/Global.gd | 74 +++++++++++----- game/src/global/Teams.gd | 3 +- .../ui/championship/team-picker/TeamPicker.gd | 86 ++++++++++++++----- .../championship/team-picker/TeamPicker.tscn | 68 ++++++++++++--- game/src/ui/settings/Settings.gd | 5 ++ game/src/ui/settings/Settings.tscn | 15 +++- game/translations/translations.csv | 1 + 7 files changed, 191 insertions(+), 61 deletions(-) diff --git a/game/src/global/Global.gd b/game/src/global/Global.gd index 0b1c0a4..5d77d41 100644 --- a/game/src/global/Global.gd +++ b/game/src/global/Global.gd @@ -46,6 +46,7 @@ var league_started:bool var teams:Array var matches:Array = [] var selected_squad:String +var teams_mods: Dictionary # worldcup var is_worldcup:bool @@ -81,6 +82,7 @@ var round_limit:int = 5 func _ready() -> void: randomize() + func set_up() -> void: load_data() @@ -129,6 +131,7 @@ func load_data() -> void: matches = config.get_value("league", "matches", []) match_day = config.get_value("league", "match_day", 0) unlocked_team_ids = config.get_value("league", "unlocked_team_ids", [1,2,-1,-2]) + teams_mods = config.get_value("league", "teams_mods", {}) #unlock india and germany, if not unlocked yet if not -1 in unlocked_team_ids: @@ -190,6 +193,7 @@ func save_all_data() -> void: config.set_value("league","matches", matches) config.set_value("league", "statistics", league_stats) config.set_value("league", "current_league_name", current_league_name) + config.set_value("league", "teams_mods", teams_mods) # arcade config.set_value("arcade", "highscore", arcade_highscore) @@ -210,7 +214,8 @@ func save_all_data() -> void: config.set_value("shop", "unlocked_" + type, ShopUtil.items[type]["unlocked"]) save() - + + func locale_to_lang(_locale:String) -> String: if "en" in _locale: return "en" @@ -221,6 +226,7 @@ func locale_to_lang(_locale:String) -> String: else: return "en" + func increase_stats() -> void: if is_worldcup: if final_teams[0]["name"] == selected_squad: @@ -237,15 +243,18 @@ func increase_stats() -> void: else: league_stats[current_league_name]["played"] += 1 + func fade_in_goals() -> void: $AnimationPlayer.play("FadeIn") - + + func _find_team(name:String) -> Dictionary: for team in teams: if team["name"] == name: return team return {} + func toggle_music() -> void: if music == "off": music = "chill" @@ -265,7 +274,7 @@ func toggle_music() -> void: save() - + func save() -> void: config.save("user://settings.cfg") @@ -374,7 +383,8 @@ func game_over(home_goals:int,away_goals:int, simulation:bool = false) -> void: save_all_data() - + + func _save_current_game(home_goals,away_goals) -> void: if "home" in current_league_game and "away" in current_league_game: var home_team = _get_team_from_name(current_league_game["home"]["name"]) @@ -396,7 +406,8 @@ func _save_current_game(home_goals,away_goals) -> void: current_league_game["result"] = str(home_goals) + " : " + str(away_goals) sort_table() - + + func sort_table() -> void: if is_worldcup: for group in groups: @@ -405,7 +416,8 @@ func sort_table() -> void: teams.sort_custom(PointsSorter, "sort") for i in range(0,teams.size()): teams[i]["position"] = i - + + func create_quarter_finals() -> void: # create final teams final_teams.append(groups[0][0]) # A1 @@ -432,7 +444,6 @@ func create_quarter_finals() -> void: break # finished for sure - func random_world_cup_results() -> void: var from:int = match_day * 8 # 8 because worlcup teams are 16? @@ -472,7 +483,7 @@ func random_world_cup_results() -> void: home_team["goal_difference"] += home_goals - away_goals matches[i]["result"] = str(home_goals) + " : " + str(away_goals) - + func random_results() -> void: var from:int = match_day * (teams.size() / 2) @@ -514,12 +525,12 @@ func random_results() -> void: matches[i]["result"] = str(home_goals) + " : " + str(away_goals) - func add_coins(more:int) -> void: coins += more config.set_value("coins","amount",coins) save() - + + func use_coins(less:int) -> bool: if coins - less < 0: return false @@ -527,28 +538,48 @@ func use_coins(less:int) -> bool: config.set_value("coins","amount",coins) save() return true - + + func set_home_team(team:Dictionary) -> void: if not team.empty(): home_team_name = team.name - home_team_power = team.power - home_team_speed = team.speed + home_team_power = get_team_power(team) + home_team_speed = get_team_speed(team) home_team_colors = team.colors home_team_icon = team.get("icon") else: home_team_icon = null - - + + func set_away_team(team:Dictionary) -> void: if not team.empty(): away_team_name = team.name - away_team_power = team.power - away_team_speed = team.speed + away_team_power = get_team_power(team) + away_team_speed = get_team_speed(team) away_team_colors = team.colors away_team_icon = team.get("icon") else: away_team_icon = null - + + +func get_team_speed(team: Dictionary) -> int: + if not team.id in teams_mods: + Global.teams_mods[team.id] = { + "speed": team.speed, + "power": team.power, + } + return teams_mods[team.id].speed + + +func get_team_power(team: Dictionary) -> int: + if not team.id in teams_mods: + Global.teams_mods[team.id] = { + "speed": team.speed, + "power": team.power, + } + return teams_mods[team.id].power + + func new_league() -> void: league_started = false teams = [] @@ -573,13 +604,14 @@ func click() -> void: if sfx: $Click.play() + # to save on close func _notification(event:int) -> void: if event == MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST or event == MainLoop.NOTIFICATION_WM_QUIT_REQUEST: # if current_league_game != null: # game_over(0,5) # game over a tavolino on exit save_all_data() - + class PointsSorter: static func sort(a:Dictionary, b:Dictionary) -> bool: @@ -587,7 +619,7 @@ class PointsSorter: return true return false - + func _get_team_from_name(name:String) -> Dictionary: if is_worldcup: for group in groups: @@ -600,3 +632,5 @@ func _get_team_from_name(name:String) -> Dictionary: if name == team["name"]: return team return {} + + diff --git a/game/src/global/Teams.gd b/game/src/global/Teams.gd index 6555496..a5b65ce 100644 --- a/game/src/global/Teams.gd +++ b/game/src/global/Teams.gd @@ -439,7 +439,6 @@ func _load_ontario_teams(): var mildmay_moose_icon = load("res://assets/teams/ontario-league/mildmay-moose.png") - ontario_teams = [ {"colors" : ["#E6D409", "#FEFEFE", "#e6eaee"], "short_name" : "TND","id" : 82, "name":"Thunder","position": 3, "points": 0 , "goal_diference": 0 , "wins" : 0, "speed" : 4, "power" : 4, @@ -459,7 +458,7 @@ func _load_ontario_teams(): {"colors" : ["#E1DBD1", "#55222B", "#e6eaee"], "short_name" : "BOY","id" : 91, "name":"Boys","position": 3, "points": 0 , "goal_diference": 0 , "wins" : 0, "speed" : 10, "power" : 9, "lost":0, "icon" : les_boys_icon, "goal_difference":0, "price":100000}, - {"colors" : ["#F6F6F6", "#fffff", "#060606"], "short_name" : "MMO","id" : 92, "name":"Mildmay Moose","position": 3, "points": 0 , + {"colors" : ["#F6F6F6", "#ffffff", "#060606"], "short_name" : "MMO","id" : 92, "name":"Mildmay Moose","position": 3, "points": 0 , "goal_diference": 0 , "wins" : 0, "speed" : 10, "power" : 9, "lost":0, "icon" : mildmay_moose_icon, "goal_difference":0, "price":100000}, ] diff --git a/game/src/ui/championship/team-picker/TeamPicker.gd b/game/src/ui/championship/team-picker/TeamPicker.gd index bb15c64..d5b1557 100644 --- a/game/src/ui/championship/team-picker/TeamPicker.gd +++ b/game/src/ui/championship/team-picker/TeamPicker.gd @@ -4,18 +4,19 @@ extends Control -onready var price_label:Label = $VBoxContainer/Price -onready var team_label:Label = $VBoxContainer/Team/TeamLabel -onready var league_label:Label = $VBoxContainer/League/LeagueLabel -onready var speed_bar:TextureProgress = $VBoxContainer/SpeedBar -onready var power_bar:TextureProgress = $VBoxContainer/PowerBar -onready var animation_player:AnimationPlayer = $AnimationPlayer -onready var select_button:Button = $VBoxContainer/Select -onready var locker:Node2D = $Locker - -var team_index:int -var league_index:int -var teams:Array +onready var price_label: Label = $VBoxContainer/Price +onready var team_label: Label = $VBoxContainer/Team/TeamLabel +onready var league_label: Label = $VBoxContainer/League/LeagueLabel +onready var speed_bar: TextureProgress = $VBoxContainer/Speed/SpeedBar +onready var power_bar: TextureProgress = $VBoxContainer/Power/PowerBar +onready var animation_player: AnimationPlayer = $AnimationPlayer +onready var select_button: Button = $VBoxContainer/Select +onready var locker: Node2D = $Locker + +var team_index: int +var league_index: int +var teams: Array + func _ready() -> void: team_index = 0 @@ -26,7 +27,7 @@ func _ready() -> void: _set_team_first_time() func _set_team() -> void: - var team = teams[team_index] + var team: Dictionary = teams[team_index] $Team.texture = team.icon team_label.text = team["name"] @@ -41,10 +42,10 @@ func _set_team() -> void: price_label.text = "" locker.hide() - - power_bar.value = team.power - speed_bar.value = team.speed - + power_bar.value = Global.get_team_power(team) + speed_bar.value = Global.get_team_speed(team) + + func _set_team_first_time() -> void: var team:Dictionary = teams[team_index] @@ -63,8 +64,8 @@ func _set_team_first_time() -> void: # $Team.modulate = Color(1,1,1,1) locker.hide() - power_bar.value = team.power - speed_bar.value = team.speed + power_bar.value = Global.get_team_power(team) + speed_bar.value = Global.get_team_speed(team) func _on_PrevTeam_pressed() -> void: Global.click() @@ -92,7 +93,6 @@ func _on_PrevLeague_pressed() -> void: team_index = 0 _set_team() - league_label.text = Teams.leagues[league_index].name @@ -263,21 +263,24 @@ func inizialize_worldcup_matches() -> void: print(Global.matches.size()) print(Global.matches.size()) - -func unlock_team(team:Dictionary) -> bool: + + +func unlock_team(team: Dictionary) -> bool: if Global.coins - team["price"] < 0: return false Global.coins -= team["price"] Global.unlocked_team_ids.append(team["id"]) Global.save_all_data() return true - + + func _shift_array(array:Array) -> void: var temp = array[0] for i in range(array.size() - 1): array[i] = array[i+1] array[array.size() - 1] = temp + func set_teams() -> void: Global.teams = Teams.leagues[league_index].teams.duplicate(true) teams = Teams.leagues[league_index].teams.duplicate(true) @@ -285,3 +288,40 @@ func set_teams() -> void: if team["id"] == 0: teams.erase(team) + +func _on_PowerMinus_pressed() -> void: + var team: Dictionary = teams[team_index] + _modify_team(team, "power", -1) + power_bar.value = Global.get_team_power(team) + + +func _on_PowerPlus_pressed() -> void: + var team: Dictionary = teams[team_index] + _modify_team(team, "power", +1) + power_bar.value = Global.get_team_power(team) + + +func _on_SpeedMinus_pressed() -> void: + var team: Dictionary = teams[team_index] + _modify_team(team, "speed", -1) + speed_bar.value = Global.get_team_speed(team) + + +func _on_SpeedPlus_pressed() -> void: + var team: Dictionary = teams[team_index] + _modify_team(team, "speed", +1) + speed_bar.value = Global.get_team_speed(team) + + +func _modify_team(team: Dictionary, key: String, value: int): + if not team.id in Global.teams_mods: + Global.teams_mods[team.id] = { + "speed": team.speed, + "power": team.power, + } + Global.teams_mods[team.id][key] += value + # make sure value is between 1 and 10 + Global.teams_mods[team.id][key] = max(1, Global.teams_mods[team.id][key]) + Global.teams_mods[team.id][key] = min(10, Global.teams_mods[team.id][key]) + Global.save_all_data() + diff --git a/game/src/ui/championship/team-picker/TeamPicker.tscn b/game/src/ui/championship/team-picker/TeamPicker.tscn index e926ba3..4ca06ab 100644 --- a/game/src/ui/championship/team-picker/TeamPicker.tscn +++ b/game/src/ui/championship/team-picker/TeamPicker.tscn @@ -83,8 +83,9 @@ alignment = 1 margin_top = 139.0 margin_right = 60.0 margin_bottom = 211.0 +rect_min_size = Vector2( 60, 0 ) size_flags_vertical = 4 -text = " < " +text = "<" [node name="LeagueLabel" type="Label" parent="VBoxContainer/League"] margin_left = 64.0 @@ -106,8 +107,9 @@ margin_left = 600.0 margin_top = 139.0 margin_right = 660.0 margin_bottom = 211.0 +rect_min_size = Vector2( 60, 0 ) size_flags_vertical = 4 -text = " > " +text = ">" [node name="HSeparator2" type="HSeparator" parent="VBoxContainer"] self_modulate = Color( 1, 1, 1, 0 ) @@ -137,8 +139,9 @@ alignment = 1 margin_top = 34.0 margin_right = 60.0 margin_bottom = 106.0 +rect_min_size = Vector2( 60, 0 ) size_flags_vertical = 4 -text = " < " +text = "<" [node name="TeamLabel" type="Label" parent="VBoxContainer/Team"] margin_left = 64.0 @@ -162,28 +165,65 @@ margin_left = 600.0 margin_top = 34.0 margin_right = 660.0 margin_bottom = 106.0 +rect_min_size = Vector2( 60, 0 ) size_flags_vertical = 4 -text = " > " +text = ">" -[node name="SpeedBar" parent="VBoxContainer" instance=ExtResource( 6 )] -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Speed" type="HBoxContainer" parent="VBoxContainer"] margin_top = 796.0 margin_right = 660.0 margin_bottom = 880.0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -text = "SPEED" +custom_constants/separation = 10 + +[node name="SpeedMinus" type="Button" parent="VBoxContainer/Speed"] +margin_right = 60.0 +margin_bottom = 84.0 +rect_min_size = Vector2( 60, 0 ) +text = "-" -[node name="PowerBar" parent="VBoxContainer" instance=ExtResource( 6 )] +[node name="SpeedBar" parent="VBoxContainer/Speed" instance=ExtResource( 6 )] anchor_right = 0.0 anchor_bottom = 0.0 +margin_left = 70.0 +margin_right = 590.0 +margin_bottom = 84.0 +size_flags_vertical = 1 +text = "SPEED" + +[node name="SpeedPlus" type="Button" parent="VBoxContainer/Speed"] +margin_left = 600.0 +margin_right = 660.0 +margin_bottom = 84.0 +rect_min_size = Vector2( 60, 0 ) +text = "+" + +[node name="Power" type="HBoxContainer" parent="VBoxContainer"] margin_top = 900.0 margin_right = 660.0 margin_bottom = 984.0 -size_flags_horizontal = 1 +custom_constants/separation = 10 + +[node name="PowerMinus" type="Button" parent="VBoxContainer/Power"] +margin_right = 60.0 +margin_bottom = 84.0 +rect_min_size = Vector2( 60, 0 ) +text = "-" + +[node name="PowerBar" parent="VBoxContainer/Power" instance=ExtResource( 6 )] +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 70.0 +margin_right = 590.0 +margin_bottom = 84.0 size_flags_vertical = 1 +[node name="PowerPlus" type="Button" parent="VBoxContainer/Power"] +margin_left = 600.0 +margin_right = 660.0 +margin_bottom = 84.0 +rect_min_size = Vector2( 60, 0 ) +text = "+" + [node name="HSeparator" type="HSeparator" parent="VBoxContainer"] self_modulate = Color( 1, 1, 1, 0 ) margin_top = 1004.0 @@ -218,5 +258,9 @@ anims/Unlock = SubResource( 4 ) [connection signal="pressed" from="VBoxContainer/League/NextLeague" to="." method="_on_NextLeague_pressed"] [connection signal="pressed" from="VBoxContainer/Team/PrevTeam" to="." method="_on_PrevTeam_pressed"] [connection signal="pressed" from="VBoxContainer/Team/NextTeam" to="." method="_on_NextTeam_pressed"] +[connection signal="pressed" from="VBoxContainer/Speed/SpeedMinus" to="." method="_on_SpeedMinus_pressed"] +[connection signal="pressed" from="VBoxContainer/Speed/SpeedPlus" to="." method="_on_SpeedPlus_pressed"] +[connection signal="pressed" from="VBoxContainer/Power/PowerMinus" to="." method="_on_PowerMinus_pressed"] +[connection signal="pressed" from="VBoxContainer/Power/PowerPlus" to="." method="_on_PowerPlus_pressed"] [connection signal="pressed" from="VBoxContainer/Select" to="." method="_on_Select_pressed"] [connection signal="pressed" from="VBoxContainer/GoBack" to="." method="_on_GoBack_pressed"] diff --git a/game/src/ui/settings/Settings.gd b/game/src/ui/settings/Settings.gd index a2b178d..becda99 100644 --- a/game/src/ui/settings/Settings.gd +++ b/game/src/ui/settings/Settings.gd @@ -161,3 +161,8 @@ func update_dynamic_labels(): func _on_Info_pressed(): Global.click() get_tree().change_scene("res://src/ui/info/Info.tscn") + + +func _on_ResetTeams_pressed(): + Global.teams_mods = {} + Global.save_all_data() diff --git a/game/src/ui/settings/Settings.tscn b/game/src/ui/settings/Settings.tscn index 9fe99c4..c598186 100644 --- a/game/src/ui/settings/Settings.tscn +++ b/game/src/ui/settings/Settings.tscn @@ -71,6 +71,12 @@ margin_bottom = 178.0 rect_scale = Vector2( 0.25, 0.25 ) texture = ExtResource( 4 ) +[node name="ResetTeams" type="Button" parent="VBoxContainer"] +margin_top = 400.0 +margin_right = 540.0 +margin_bottom = 472.0 +text = "RESET_TEAMS" + [node name="Join" type="Button" parent="VBoxContainer"] visible = false margin_top = 685.0 @@ -89,16 +95,16 @@ text = "INFO" [node name="HSeparator" type="HSeparator" parent="VBoxContainer"] modulate = Color( 1, 1, 1, 0 ) -margin_top = 400.0 +margin_top = 480.0 margin_right = 540.0 -margin_bottom = 420.0 +margin_bottom = 500.0 size_flags_horizontal = 3 custom_constants/separation = 20 [node name="GoBack" type="Button" parent="VBoxContainer"] -margin_top = 428.0 +margin_top = 508.0 margin_right = 540.0 -margin_bottom = 500.0 +margin_bottom = 580.0 text = "GO_BACK" [node name="EasterEgg" type="Button" parent="."] @@ -119,6 +125,7 @@ one_shot = true [connection signal="pressed" from="VBoxContainer/Sfx" to="." method="_on_Sfx_pressed"] [connection signal="pressed" from="VBoxContainer/MoreGames" to="." method="_on_MoreGames_pressed"] [connection signal="pressed" from="VBoxContainer/Language" to="." method="_on_Language_pressed"] +[connection signal="pressed" from="VBoxContainer/ResetTeams" to="." method="_on_ResetTeams_pressed"] [connection signal="pressed" from="VBoxContainer/Join" to="." method="_on_Join_pressed"] [connection signal="pressed" from="VBoxContainer/Info" to="." method="_on_Info_pressed"] [connection signal="pressed" from="VBoxContainer/GoBack" to="." method="_on_GoBack_pressed"] diff --git a/game/translations/translations.csv b/game/translations/translations.csv index 115e47e..d8261c0 100644 --- a/game/translations/translations.csv +++ b/game/translations/translations.csv @@ -84,3 +84,4 @@ BOT_1_WIN,Bot 1 wins!,Bot 1 gewinnt!,Bot 1 vince!,Bot 1 gagne!,Bot 1 gana! BOT_2_WIN,Bot 2 wins!,Bot 2 gewinnt!,Bot 2 vince!,Bot 2 gagne!,Bot 2 gana! YOU_WIN,You win!,Du gewinnst!,Hai vinto!,Vous avez gagné!,Has ganado! YOU_LOST,You loose...,Du verlierst...,Hai perso...,Vous avez perdu...,Has perdido... +RESET_TEAMS,Reset teams,Teams zurücksetzen,Ripristina squadre,Réinitialiser équipe,Reajustar equipos