mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 09:12:35 +00:00
Updated gems, added server events to games page
This commit is contained in:
15
lib/api.rb
15
lib/api.rb
@@ -207,6 +207,21 @@ class W3DHub
|
||||
Cache.fetch_package(package, block)
|
||||
end
|
||||
|
||||
# /apis/w3dhub/1/get-events
|
||||
#
|
||||
# clients requests events: data={"serverPath":"apb"}
|
||||
def self.events(app_id)
|
||||
body = URI.encode_www_form("data": JSON.dump({ serverPath: app_id }))
|
||||
response = post("#{ENDPOINT}/apis/w3dhub/1/get-server-events", FORM_ENCODED_HEADERS, body)
|
||||
|
||||
if response.success?
|
||||
array = JSON.parse(response.read, symbolize_names: true)
|
||||
array.map { |e| Event.new(e) }
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
#! === Server List API === !#
|
||||
|
||||
SERVER_LIST_ENDPOINT = "https://gsh.w3dhub.com".freeze
|
||||
|
||||
33
lib/api/event.rb
Normal file
33
lib/api/event.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
class W3DHub
|
||||
class Api
|
||||
class Event
|
||||
def initialize(data)
|
||||
@data = data
|
||||
end
|
||||
|
||||
def server
|
||||
@data[:server]
|
||||
end
|
||||
|
||||
def title
|
||||
@data[:title]
|
||||
end
|
||||
|
||||
def start_time
|
||||
@start_time ||= Time.parse(@data[:starttime]).localtime
|
||||
end
|
||||
|
||||
def end_time
|
||||
@end_time ||= Time.parse(@data[:endtime]).localtime
|
||||
end
|
||||
|
||||
def date_time
|
||||
@data[:dateTime]
|
||||
end
|
||||
|
||||
def image
|
||||
@data[:image]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,6 +3,7 @@ class W3DHub
|
||||
class Games < Page
|
||||
def setup
|
||||
@game_news ||= {}
|
||||
@game_events ||= {}
|
||||
|
||||
# unless Store.offline_mode
|
||||
@focused_game ||= Store.applications.games.find { |g| g.id == Store.settings[:last_selected_app] }
|
||||
@@ -212,6 +213,10 @@ class W3DHub
|
||||
end
|
||||
end
|
||||
|
||||
# Game Events
|
||||
@game_events_container = flow(width: 1.0, height: 128, padding: 8, visible: false) do
|
||||
end
|
||||
|
||||
# Game News
|
||||
@game_news_container = flow(width: 1.0, fill: true, padding: 8, scroll: true) do
|
||||
# background 0xff_005500
|
||||
@@ -220,24 +225,40 @@ class W3DHub
|
||||
end
|
||||
end
|
||||
|
||||
return if Cache.net_lock?("game_news_#{game.id}")
|
||||
|
||||
if @game_news[game.id]
|
||||
populate_game_news(game)
|
||||
else
|
||||
@game_news_container.clear do
|
||||
title I18n.t(:"games.fetching_news"), padding: 8
|
||||
end
|
||||
|
||||
BackgroundWorker.foreground_job(
|
||||
-> { fetch_game_news(game) },
|
||||
lambda do |result|
|
||||
if result
|
||||
populate_game_news(game)
|
||||
Cache.release_net_lock(result)
|
||||
unless Cache.net_lock?("game_news_#{game.id}")
|
||||
if @game_events[game.id]
|
||||
populate_game_events(game)
|
||||
else
|
||||
BackgroundWorker.foreground_job(
|
||||
-> { fetch_game_events(game) },
|
||||
lambda do |result|
|
||||
if result
|
||||
populate_game_events(game)
|
||||
Cache.release_net_lock(result)
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
unless Cache.net_lock?("game_events_#{game.id}")
|
||||
if @game_news[game.id]
|
||||
populate_game_news(game)
|
||||
else
|
||||
@game_news_container.clear do
|
||||
title I18n.t(:"games.fetching_news"), padding: 8
|
||||
end
|
||||
)
|
||||
|
||||
BackgroundWorker.foreground_job(
|
||||
-> { fetch_game_news(game) },
|
||||
lambda do |result|
|
||||
if result
|
||||
populate_game_news(game)
|
||||
Cache.release_net_lock(result)
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -344,6 +365,41 @@ class W3DHub
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_game_events(game)
|
||||
lock = Cache.acquire_net_lock("game_events_#{game.id}")
|
||||
return false unless lock
|
||||
|
||||
events = Api.events(game.id)
|
||||
Cache.release_net_lock("game_events_#{game.id}") unless events
|
||||
|
||||
return false unless events
|
||||
|
||||
@game_events[game.id] = events
|
||||
|
||||
"game_events_#{game.id}"
|
||||
end
|
||||
|
||||
def populate_game_events(game)
|
||||
return unless @focused_game == game
|
||||
|
||||
if (events = @game_events[game.id])
|
||||
@game_events_container.show unless events.empty?
|
||||
@game_events_container.hide if events.empty?
|
||||
|
||||
@game_events_container.clear do
|
||||
events.flatten.each do |event|
|
||||
stack(width: 300, height: 1.0, margin_left: 8, margin_right: 8, border_thickness: 1, border_color: lighten(Gosu::Color.new(game.color))) do
|
||||
background 0xaa_222222
|
||||
|
||||
title event.title, width: 1.0, text_align: :center
|
||||
tagline event.start_time.strftime("%A"), text_size: 36, width: 1.0, text_align: :center
|
||||
caption event.start_time.strftime("%B %e, %Y %l:%M %p"), width: 1.0, text_align: :center
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def populate_game_modifications(application, channel)
|
||||
@game_news_container.clear do
|
||||
([
|
||||
|
||||
Reference in New Issue
Block a user