mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 09:12:35 +00:00
Games page back to semi-functional; games are out of order however
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
*.json
|
||||||
|
data/cache/*
|
||||||
|
!data/cache/.gitkeep
|
||||||
0
data/cache/.gitkeep
vendored
Normal file
0
data/cache/.gitkeep
vendored
Normal file
11
lib/api.rb
11
lib/api.rb
@@ -76,6 +76,17 @@ class W3DHub
|
|||||||
# Client requests news for a specific application/game e.g.: data={"category":"ia"}
|
# Client requests news for a specific application/game e.g.: data={"category":"ia"}
|
||||||
# Response is a JSON hash with a "highlighted" and "news" keys; the "news" on seems to be the desired one
|
# Response is a JSON hash with a "highlighted" and "news" keys; the "news" on seems to be the desired one
|
||||||
def self.news(category)
|
def self.news(category)
|
||||||
|
response = W3DHUB_API_CONNECTION.post(
|
||||||
|
path: "apis/w3dhub/1/get-news",
|
||||||
|
headers: DEFAULT_HEADERS.merge({"Content-Type": "application/x-www-form-urlencoded"}),
|
||||||
|
body: "data=#{JSON.dump({category: category})}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if response.status == 200
|
||||||
|
News.new(response.body)
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Downloading games
|
# Downloading games
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ class W3DHub
|
|||||||
@studio_id = @data[:"studio-id"]
|
@studio_id = @data[:"studio-id"]
|
||||||
|
|
||||||
# TODO: Do processing
|
# TODO: Do processing
|
||||||
@channels = @data[:channels]
|
@channels = @data[:channels].map { |channel| Channel.new(channel) }
|
||||||
@web_links = @data[:"web-links"]
|
@web_links = @data[:"web-links"]&.map { |link| WebLink.new(link) } || []
|
||||||
@extended_data = @data[:"extended-data"]
|
@extended_data = @data[:"extended-data"]
|
||||||
|
|
||||||
color = @data[:"extended-data"].find { |h| h[:name] == "colour" }[:value].sub("#", "")
|
color = @data[:"extended-data"].find { |h| h[:name] == "colour" }[:value].sub("#", "")
|
||||||
@@ -38,6 +38,8 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Channel
|
class Channel
|
||||||
|
attr_reader :id, :name, :user_level, :current_version
|
||||||
|
|
||||||
def initialize(hash)
|
def initialize(hash)
|
||||||
@data = hash
|
@data = hash
|
||||||
|
|
||||||
|
|||||||
32
lib/api/news.rb
Normal file
32
lib/api/news.rb
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
class W3DHub
|
||||||
|
class Api
|
||||||
|
class News
|
||||||
|
attr_reader :items
|
||||||
|
|
||||||
|
def initialize(response)
|
||||||
|
@data = JSON.parse(response, symbolize_names: true)
|
||||||
|
|
||||||
|
@items = @data[:news].map { |item| Item.new(item) }
|
||||||
|
end
|
||||||
|
|
||||||
|
class Item
|
||||||
|
attr_reader :topic_id, :title, :blurb, :image, :uri, :author, :author_uri, :timestamp, :date, :time
|
||||||
|
|
||||||
|
def initialize(hash)
|
||||||
|
@data = hash
|
||||||
|
|
||||||
|
@topic_id = Integer(@data[:"topic-id"])
|
||||||
|
@title = @data[:title]
|
||||||
|
@blurb = @data[:blurb]
|
||||||
|
@image = @data[:image].strip
|
||||||
|
@uri = @data[:uri].strip
|
||||||
|
@author = @data[:author]
|
||||||
|
@author_uri = @data[:"author-uri"].strip
|
||||||
|
@timestamp = Time.at(Integer(@data[:timestamp]))
|
||||||
|
@date = @data[:date]
|
||||||
|
@time = @data[:time]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -3,7 +3,7 @@ class W3DHub
|
|||||||
class Games < Page
|
class Games < Page
|
||||||
def setup
|
def setup
|
||||||
@@game_news ||= {}
|
@@game_news ||= {}
|
||||||
@focused_game ||= W3DHub::Game.games.first
|
@focused_game ||= @host.applications.games.first
|
||||||
|
|
||||||
body.clear do
|
body.clear do
|
||||||
# Games List
|
# Games List
|
||||||
@@ -15,7 +15,7 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
populate_game_page(W3DHub::Game.games.first)
|
populate_game_page(@host.applications.games.first)
|
||||||
populate_games_list
|
populate_games_list
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -23,17 +23,17 @@ class W3DHub
|
|||||||
@games_list_container.clear do
|
@games_list_container.clear do
|
||||||
background 0xff_121920
|
background 0xff_121920
|
||||||
|
|
||||||
W3DHub::Game.games.each do |game|
|
@host.applications.games.each do |game|
|
||||||
selected = game == @focused_game
|
selected = game == @focused_game
|
||||||
|
|
||||||
game_button = stack(width: 1.0, border_thickness_left: 4,
|
game_button = stack(width: 1.0, border_thickness_left: 4,
|
||||||
border_color_left: selected ? 0xff_00acff : 0x00_000000, hover: { background: 0xff_444444 },
|
border_color_left: selected ? 0xff_00acff : 0x00_000000, hover: { background: 0xff_444444 },
|
||||||
padding_top: 4, padding_bottom: 4) do
|
padding_top: 4, padding_bottom: 4) do
|
||||||
background game.background_color if selected
|
background game.color if selected
|
||||||
|
|
||||||
flow(width: 1.0, height: 48) do
|
flow(width: 1.0, height: 48) do
|
||||||
stack(width: 0.3)
|
stack(width: 0.3)
|
||||||
image game.icon, height: 48
|
image "#{GAME_ROOT_PATH}/media/icons/#{game.id}.png", height: 48
|
||||||
end
|
end
|
||||||
inscription game.name, width: 1.0, text_align: :center
|
inscription game.name, width: 1.0, text_align: :center
|
||||||
end
|
end
|
||||||
@@ -54,27 +54,39 @@ class W3DHub
|
|||||||
@focused_game = game
|
@focused_game = game
|
||||||
|
|
||||||
@game_page_container.clear do
|
@game_page_container.clear do
|
||||||
background game.background_color
|
background game.color
|
||||||
|
|
||||||
# Release channel
|
# Release channel
|
||||||
flow(width: 1.0, height: 0.03) do
|
flow(width: 1.0, height: 0.03) do
|
||||||
# background 0xff_444411
|
# background 0xff_444411
|
||||||
|
|
||||||
inscription "Release"
|
game.channels.each do |channel|
|
||||||
|
button "#{channel.name}", text_size: 14, padding_top: 2, padding_bottom: 2, padding_left: 4, padding_right: 4
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Game Stuff
|
# Game Stuff
|
||||||
flow(width: 1.0, height: 0.89) do
|
flow(width: 1.0, height: 0.89) do
|
||||||
# background 0xff_9999ff
|
# background 0xff_9999ff
|
||||||
|
|
||||||
# Gane options
|
# Game options
|
||||||
stack(width: 0.25, height: 1.0, padding: 8) do
|
stack(width: 0.25, height: 1.0, padding: 8) do
|
||||||
# background 0xff_550055
|
# background 0xff_550055
|
||||||
|
|
||||||
game.menu_items.each do |item|
|
# TODO: Show links for managing game install
|
||||||
|
# game.menu_items.each do |item|
|
||||||
|
# flow(width: 1.0, height: 22, margin_bottom: 8) do
|
||||||
|
# image item.image, width: 0.11
|
||||||
|
# link item.label, text_size: 18
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
|
game.web_links.each do |item|
|
||||||
flow(width: 1.0, height: 22, margin_bottom: 8) do
|
flow(width: 1.0, height: 22, margin_bottom: 8) do
|
||||||
image item.image, width: 0.11
|
image EMPTY_IMAGE, width: 0.11
|
||||||
link item.label, text_size: 18
|
link item.name, text_size: 18 do
|
||||||
|
Launchy.open(item.uri)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -89,15 +101,20 @@ class W3DHub
|
|||||||
flow(width: 1.0, height: 0.08) do
|
flow(width: 1.0, height: 0.08) do
|
||||||
# background 0xff_551100
|
# background 0xff_551100
|
||||||
|
|
||||||
game.play_items.each do |item|
|
# TODO: Determine if game is installed or not and show apporpiante options ["Play Now" and "Single Player", "Install" and "Import"]
|
||||||
button "<b>#{item.label}</b>", margin_left: 24 do
|
# game.play_items.each do |item|
|
||||||
item.block&.call(game)
|
# button "<b>#{item.label}</b>", margin_left: 24 do
|
||||||
end
|
# item.block&.call(game)
|
||||||
end
|
# end
|
||||||
|
# end
|
||||||
|
button "<b>Install</b>", margin_left: 24
|
||||||
|
button "<b>Import</b>", margin_left: 24
|
||||||
|
button "<b>Play Now</b>", margin_left: 24
|
||||||
|
button "<b>Single Player</b>", margin_left: 24
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
unless @@game_news[game.slot]
|
unless @@game_news[game.id]
|
||||||
Thread.new do
|
Thread.new do
|
||||||
fetch_game_news(game)
|
fetch_game_news(game)
|
||||||
main_thread_queue << proc { populate_game_news(game) }
|
main_thread_queue << proc { populate_game_news(game) }
|
||||||
@@ -112,42 +129,57 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fetch_game_news(game)
|
def fetch_game_news(game)
|
||||||
feed_uri = Excon.get(
|
news = Api.news(game.id)
|
||||||
game.news_feed,
|
|
||||||
headers: {
|
|
||||||
"User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0",
|
|
||||||
"Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
|
|
||||||
"Accept-Encoding" => "deflate",
|
|
||||||
"Accept-Language" => "en-US,en;q=0.5",
|
|
||||||
"Host" => "w3dhub.com",
|
|
||||||
"DNT" => "1"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
@@game_news[game.slot] = RSS::Parser.parse(feed_uri.body) if feed_uri.status == 200
|
if news
|
||||||
|
news.items[0..9].each do |item|
|
||||||
|
# Cache Image
|
||||||
|
ext = File.basename(item.image).split(".").last
|
||||||
|
path = "#{CACHE_PATH}/#{Digest::SHA2.hexdigest(item.image)}.#{ext}"
|
||||||
|
|
||||||
|
next if File.exist?(path)
|
||||||
|
|
||||||
|
response = Excon.get(item.image)
|
||||||
|
|
||||||
|
if response.status == 200
|
||||||
|
File.open(path, "wb") do |f|
|
||||||
|
f.write(response.body)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@@game_news[game.id] = news
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def populate_game_news(game)
|
def populate_game_news(game)
|
||||||
return unless @focused_game == game
|
return unless @focused_game == game
|
||||||
|
|
||||||
if (feed = @@game_news[game.slot])
|
if (feed = @@game_news[game.id])
|
||||||
@game_news_container.clear do
|
@game_news_container.clear do
|
||||||
feed.items.sort_by { |i| i.pubDate }.reverse[0..9].each do |item|
|
feed.items.sort_by { |i| i.timestamp }.reverse[0..9].each do |item|
|
||||||
flow(width: 0.5, height: 128, margin: 4) do
|
flow(width: 0.5, height: 128, margin: 4) do
|
||||||
# background 0x88_000000
|
# background 0x88_000000
|
||||||
|
|
||||||
image game.icon, width: 0.4, padding: 4
|
ext = File.basename(item.image).split(".").last
|
||||||
|
path = "#{CACHE_PATH}/#{Digest::SHA2.hexdigest(item.image)}.#{ext}"
|
||||||
|
|
||||||
|
if File.exist?(path)
|
||||||
|
image path, width: 0.4, padding: 4
|
||||||
|
else
|
||||||
|
image BLACK_IMAGE, width: 0.4, padding: 4
|
||||||
|
end
|
||||||
|
|
||||||
stack(width: 0.6, height: 1.0) do
|
stack(width: 0.6, height: 1.0) do
|
||||||
stack(width: 1.0, height: 112) do
|
stack(width: 1.0, height: 112) do
|
||||||
para "<b>#{item.title}</b>"
|
para "<b>#{item.title}</b>"
|
||||||
inscription "#{Sanitize.fragment(item.description[0...180]).strip}"
|
inscription "#{item.blurb.strip[0..180]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
flow(width: 1.0) do
|
flow(width: 1.0) do
|
||||||
inscription item.pubDate.strftime("%Y-%m-%d"), width: 0.5
|
inscription item.timestamp.strftime("%Y-%m-%d"), width: 0.5
|
||||||
link "Read More", width: 0.5, text_align: :right, text_size: 14 do
|
link "Read More", width: 0.5, text_align: :right, text_size: 14 do
|
||||||
Launchy.open(item.link)
|
Launchy.open(item.uri)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -50,28 +50,30 @@ class W3DHub
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
send(:"#{@tasks.keys[@task_index]}") if @tasks.dig(@tasks.keys[@task_index], :complete) == false
|
if @tasks.dig(@tasks.keys[@task_index], :started) == false
|
||||||
|
p @tasks.keys[@task_index]
|
||||||
|
@tasks[@tasks.keys[@task_index]][:started] = true
|
||||||
|
|
||||||
|
send(:"#{@tasks.keys[@task_index]}")
|
||||||
|
end
|
||||||
|
|
||||||
@task_index += 1 if @tasks.dig(@tasks.keys[@task_index], :complete)
|
@task_index += 1 if @tasks.dig(@tasks.keys[@task_index], :complete)
|
||||||
end
|
end
|
||||||
|
|
||||||
def refresh_user_token
|
def refresh_user_token
|
||||||
@tasks[:refresh_user_token][:started] = true
|
|
||||||
@tasks[:refresh_user_token][:complete] = true
|
@tasks[:refresh_user_token][:complete] = true
|
||||||
|
|
||||||
@refresh_token = nil
|
@refresh_token = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def service_status
|
def service_status
|
||||||
@tasks[:service_status][:started] = true
|
|
||||||
|
|
||||||
Thread.new do
|
Thread.new do
|
||||||
@service_status = Api.service_status
|
@service_status = Api.service_status
|
||||||
|
|
||||||
if service_status
|
if @service_status
|
||||||
if !service_status.authentication? || !service_status.package_download?
|
if !@service_status.authentication? || !@service_status.package_download?
|
||||||
# FIXME: MAIN THREAD!
|
# FIXME: MAIN THREAD!
|
||||||
@status_label.value = "Authentication is #{service_status.authentication? ? 'Okay' : 'Down'}. Package Download is #{service_status.package_download? ? 'Okay' : 'Down'}."
|
@status_label.value = "Authentication is #{@service_status.authentication? ? 'Okay' : 'Down'}. Package Download is #{@service_status.package_download? ? 'Okay' : 'Down'}."
|
||||||
end
|
end
|
||||||
|
|
||||||
@tasks[:service_status][:complete] = true
|
@tasks[:service_status][:complete] = true
|
||||||
@@ -85,19 +87,13 @@ class W3DHub
|
|||||||
def applications
|
def applications
|
||||||
@status_label.value = "Checking for updates..."
|
@status_label.value = "Checking for updates..."
|
||||||
|
|
||||||
warn "ALREADY STARTED APPLICATIONS!!!" if @tasks[:applications][:started]
|
|
||||||
|
|
||||||
return if @tasks[:applications][:started]
|
|
||||||
|
|
||||||
@tasks[:applications][:started] = true
|
|
||||||
|
|
||||||
Thread.new do
|
Thread.new do
|
||||||
@applications = Api.applications
|
@applications = Api.applications
|
||||||
|
|
||||||
if applications
|
if @applications
|
||||||
pp applications.games.first
|
|
||||||
|
|
||||||
@tasks[:applications][:complete] = true
|
@tasks[:applications][:complete] = true
|
||||||
|
else
|
||||||
|
# FIXME: Failed to retreive!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ class W3DHub
|
|||||||
|
|
||||||
button(
|
button(
|
||||||
get_image("#{GAME_ROOT_PATH}/media/ui_icons/import.png"),
|
get_image("#{GAME_ROOT_PATH}/media/ui_icons/import.png"),
|
||||||
|
enabled: false,
|
||||||
tip: "Download Manager",
|
tip: "Download Manager",
|
||||||
image_height: 1.0,
|
image_height: 1.0,
|
||||||
padding_left: 4,
|
padding_left: 4,
|
||||||
|
|||||||
22
w3dhub.rb
22
w3dhub.rb
@@ -1,12 +1,14 @@
|
|||||||
require "cyberarm_engine"
|
require "cyberarm_engine"
|
||||||
require "sanitize"
|
require "digest"
|
||||||
require "rss"
|
|
||||||
require "zlib"
|
require "zlib"
|
||||||
require "launchy"
|
require "launchy"
|
||||||
|
|
||||||
|
class W3DHub
|
||||||
GAME_ROOT_PATH = File.expand_path(".", __dir__)
|
GAME_ROOT_PATH = File.expand_path(".", __dir__)
|
||||||
|
CACHE_PATH = "#{GAME_ROOT_PATH}/data/cache"
|
||||||
EMPTY_IMAGE = Gosu::Image.from_blob(1, 1)
|
EMPTY_IMAGE = Gosu::Image.from_blob(1, 1)
|
||||||
BLACK_IMAGE = Gosu::Image.from_blob(1, 1, "\x00\x00\x00\xff")
|
BLACK_IMAGE = Gosu::Image.from_blob(1, 1, "\x00\x00\x00\xff")
|
||||||
|
end
|
||||||
|
|
||||||
require_relative "lib/version"
|
require_relative "lib/version"
|
||||||
require_relative "lib/window"
|
require_relative "lib/window"
|
||||||
@@ -16,13 +18,15 @@ require_relative "lib/states/interface"
|
|||||||
require_relative "lib/api"
|
require_relative "lib/api"
|
||||||
require_relative "lib/api/service_status"
|
require_relative "lib/api/service_status"
|
||||||
require_relative "lib/api/applications"
|
require_relative "lib/api/applications"
|
||||||
|
require_relative "lib/api/news"
|
||||||
|
|
||||||
require_relative "lib/game"
|
# require_relative "lib/game"
|
||||||
require_relative "lib/games/renegade"
|
# require_relative "lib/games/renegade"
|
||||||
require_relative "lib/games/expansive_civilian_warfare"
|
# require_relative "lib/games/expansive_civilian_warfare"
|
||||||
require_relative "lib/games/interim_apex"
|
# require_relative "lib/games/interim_apex"
|
||||||
require_relative "lib/games/ra_a_path_beyond"
|
# require_relative "lib/games/ra_a_path_beyond"
|
||||||
require_relative "lib/games/ts_reborn"
|
# require_relative "lib/games/ts_reborn"
|
||||||
|
# W3DHub::Game.load_games
|
||||||
|
|
||||||
require_relative "lib/page"
|
require_relative "lib/page"
|
||||||
require_relative "lib/pages/games"
|
require_relative "lib/pages/games"
|
||||||
@@ -35,6 +39,4 @@ require_relative "lib/pages/download_manager"
|
|||||||
require_relative "lib/renegade_server"
|
require_relative "lib/renegade_server"
|
||||||
require_relative "lib/renegade_player"
|
require_relative "lib/renegade_player"
|
||||||
|
|
||||||
W3DHub::Game.load_games
|
|
||||||
|
|
||||||
W3DHub::Window.new(width: 980, height: 720, borderless: false).show
|
W3DHub::Window.new(width: 980, height: 720, borderless: false).show
|
||||||
|
|||||||
Reference in New Issue
Block a user