Skip to content

Commit

Permalink
Add more specific error messages for player count
Browse files Browse the repository at this point in the history
  • Loading branch information
Atlinx committed Sep 19, 2023
1 parent fd7c0ac commit 6706983
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions CogsPartyLauncher/scripts/game_entry.gd
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,32 @@ func construct(_game_data: Dictionary):
else:
errors.append("Missing builds")

var player_bounds_valid = true
if not (game_data.has("min_players") and game_data.min_players is float):
errors.append("Missing min players")
player_bounds_valid = false
elif game_data.min_players <= 1:
player_bounds_valid = false
errors.append("Cannot have singleplayer only games. min_players >= 2")

if not (game_data.has("max_players") and game_data.max_players is float):
player_bounds_valid = false
errors.append("Missing max players")
elif game_data.max_players <= 1:
player_bounds_valid = false
errors.append("Cannot have singleplayer only games. max_players >= 2")

if player_bounds_valid and game_data.max_players < game_data.min_players:
player_bounds_valid = false
errors.append("max_players must be >= min_players")

if game_data.has("min_players") and game_data.has("max_players"):
player_count_label.text = "%d - %d Players" % [game_data.min_players, game_data.max_players]
if player_bounds_valid and game_data.has("min_players") and game_data.has("max_players"):
if game_data.min_players == game_data.max_players:
player_count_label.text = "%d Players" % [game_data.min_players]
else:
player_count_label.text = "%d - %d Players" % [game_data.min_players, game_data.max_players]
else:
player_count_label.text = "N/A"

_update_ui()


Expand Down Expand Up @@ -120,7 +136,6 @@ func _update_ui():

if display_mode:
enabled_checkbox.visible = false
error_panel.visible = false


func _on_enabled_checbox_toggled(toggled: bool):
Expand Down
2 changes: 1 addition & 1 deletion CogsPartyLauncher/scripts/game_library_display.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var games: Array[Dictionary]
var allowed_games # Array[Dictionary] | Null


func update(_games: Array[Dictionary], _allowed_games = null,):
func update(_games: Array[Dictionary], _allowed_games = null):
games = _games
allowed_games = _allowed_games

Expand Down

0 comments on commit 6706983

Please sign in to comment.