Skip to content

Commit

Permalink
teams: speed/power can now be modified and reset
Browse files Browse the repository at this point in the history
  • Loading branch information
dulvui committed Oct 27, 2024
1 parent e2b70e5 commit 63b0964
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 61 deletions.
74 changes: 54 additions & 20 deletions game/src/global/Global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -81,6 +82,7 @@ var round_limit:int = 5
func _ready() -> void:
randomize()


func set_up() -> void:
load_data()

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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"
Expand All @@ -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:
Expand All @@ -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"
Expand All @@ -265,7 +274,7 @@ func toggle_music() -> void:
save()



func save() -> void:
config.save("user://settings.cfg")

Expand Down Expand Up @@ -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"])
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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?
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -514,41 +525,61 @@ 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
coins -= less
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 = []
Expand All @@ -573,21 +604,22 @@ 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:
if a["points"] > b["points"] or (a["points"] == b["points"] and a["goal_difference"] > b["goal_difference"]):
return true
return false


func _get_team_from_name(name:String) -> Dictionary:
if is_worldcup:
for group in groups:
Expand All @@ -600,3 +632,5 @@ func _get_team_from_name(name:String) -> Dictionary:
if name == team["name"]:
return team
return {}


3 changes: 1 addition & 2 deletions game/src/global/Teams.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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},
]
Expand Down
86 changes: 63 additions & 23 deletions game/src/ui/championship/team-picker/TeamPicker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
Expand All @@ -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]

Expand All @@ -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()
Expand Down Expand Up @@ -92,7 +93,6 @@ func _on_PrevLeague_pressed() -> void:
team_index = 0
_set_team()


league_label.text = Teams.leagues[league_index].name


Expand Down Expand Up @@ -263,25 +263,65 @@ 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)
for team in teams:
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()

Loading

0 comments on commit 63b0964

Please sign in to comment.