Show estimate of game balance based on score

This commit is contained in:
2021-11-29 21:18:29 -06:00
parent 13103a7380
commit 1a71d1274f
3 changed files with 27 additions and 2 deletions

View File

@@ -262,12 +262,16 @@ class W3DHub
end end
end end
game_balance_icon = server_game_balance_icon(server)
flow(width: 1.0, height: 0.05) do flow(width: 1.0, height: 0.05) do
stack(width: 0.5, height: 1.0) do stack(width: 0.465, height: 1.0) do
para "<b>#{server.status.teams[0].name}</b>", width: 1.0, text_align: :center para "<b>#{server.status.teams[0].name}</b>", width: 1.0, text_align: :center
end end
stack(width: 0.5, height: 1.0) do image game_balance_icon, height: 1.0, tip: "Estimate of game balance based on score"
stack(width: 0.46, height: 1.0) do
para "<b>#{server.status.teams[1].name}</b>", width: 1.0, text_align: :center para "<b>#{server.status.teams[1].name}</b>", width: 1.0, text_align: :center
end end
end end
@@ -348,6 +352,27 @@ class W3DHub
Store.applications.games.detect { |g| g.id == game }&.name Store.applications.games.detect { |g| g.id == game }&.name
end end
def server_game_balance_icon(server)
# team 0 is left side
team_0_score = server.status.players.select { |ply| ply.team == 0 }.map(&:score).sum.to_f
# team 1 is right side
team_1_score = server.status.players.select { |ply| ply.team == 1 }.map(&:score).sum.to_f
ratio = 1.0 / (team_0_score / team_1_score)
ratio = 1.0 if ratio.to_s == "NaN"
if team_0_score + team_1_score < 2_500
"#{GAME_ROOT_PATH}/media/ui_icons/question.png"
elsif ratio.between?(0.75, 1.25)
"#{GAME_ROOT_PATH}/media/ui_icons/checkmark.png"
elsif ratio < 0.75
"#{GAME_ROOT_PATH}/media/ui_icons/arrowRight.png"
else
"#{GAME_ROOT_PATH}/media/ui_icons/arrowLeft.png"
end
end
def prompt_for_nickname(accept_callback: nil, cancel_callback: nil) def prompt_for_nickname(accept_callback: nil, cancel_callback: nil)
push_state( push_state(
W3DHub::States::PromptDialog, W3DHub::States::PromptDialog,

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB