mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-15 08:42:34 +00:00
Updated server browser to order servers by player count, then by ping.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
class W3DHub
|
||||
class Api
|
||||
class ServerListServer
|
||||
NO_OR_BAD_PING = 1_000_000
|
||||
|
||||
attr_reader :id, :game, :address, :port, :region, :channel, :ping, :status
|
||||
|
||||
def initialize(hash)
|
||||
@@ -12,7 +14,7 @@ class W3DHub
|
||||
@port = @data[:port]
|
||||
@region = @data[:region]
|
||||
@channel = @data[:channel] || "release"
|
||||
@ping = -1
|
||||
@ping = NO_OR_BAD_PING
|
||||
|
||||
@status = Status.new(@data[:status])
|
||||
|
||||
@@ -55,7 +57,7 @@ class W3DHub
|
||||
end
|
||||
end
|
||||
|
||||
@ping = -1 if @ping.zero?
|
||||
@ping = NO_OR_BAD_PING if @ping.zero?
|
||||
|
||||
@ping
|
||||
end,
|
||||
|
||||
@@ -196,11 +196,11 @@ class W3DHub
|
||||
|
||||
def ping_icon(server)
|
||||
case server.ping
|
||||
when 0..160
|
||||
when 0..150
|
||||
@ping_icons[:good]
|
||||
when 161..250
|
||||
when 151..200
|
||||
@ping_icons[:fair]
|
||||
when 251..1_000
|
||||
when 201..1_000
|
||||
@ping_icons[:poor]
|
||||
when 1_001..5_000
|
||||
@ping_icons[:bad]
|
||||
@@ -210,7 +210,7 @@ class W3DHub
|
||||
end
|
||||
|
||||
def ping_tip(server)
|
||||
server.ping.negative? ? "Ping failed" : "Ping #{server.ping}ms"
|
||||
server.ping == W3DHub::Api::ServerListServer::NO_OR_BAD_PING ? "Ping failed" : "Ping #{server.ping}ms"
|
||||
end
|
||||
|
||||
def find_element_by_tag(container, tag, list = [])
|
||||
@@ -292,7 +292,7 @@ class W3DHub
|
||||
@server_list_container.children.sort_by! do |child|
|
||||
s = Store.server_list.find { |s| s.id == child.style.tag }
|
||||
|
||||
[s.status.player_count, s.id]
|
||||
[s.status.player_count, -s.ping]
|
||||
end.reverse!.each_with_index do |child, i|
|
||||
next if @selected_server_container && child == @selected_server_container
|
||||
|
||||
|
||||
Reference in New Issue
Block a user