mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2026-09-19 23:03:53 +00:00
Make accessing application extended data easyish, dynamicify game page game play/import/install buttons
This commit is contained in:
@@ -46,6 +46,22 @@ module W3DHubLauncher
|
||||
@current_app = game
|
||||
@current_channel = game&.channels&.first
|
||||
|
||||
# This shouldn't be possible, but you never know...
|
||||
unless @current_app
|
||||
@games_list_container.clear
|
||||
@game_info_container.clear
|
||||
|
||||
@event_container.clear
|
||||
@event_container.hide
|
||||
|
||||
@news_container.clear do
|
||||
title "Something has gone wrong somewhere."
|
||||
tagline "No games to display... ¯\\_(-|-)_/¯"
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
populate_games_list
|
||||
populate_game_info
|
||||
populate_game_event
|
||||
@@ -69,6 +85,10 @@ module W3DHubLauncher
|
||||
end
|
||||
|
||||
def populate_game_info
|
||||
# FIXME: We should be able to query an api to figure out the installation state, instead of explictly writing it out like this...
|
||||
application = MemCache[:settings].applications.find { |app| app.id == @current_app.id }
|
||||
pp application
|
||||
|
||||
@game_info_container.clear do
|
||||
# logo
|
||||
img = image safe_get_image("#{ROOT_PATH}/data/cache/logo_#{@current_app.id}.png"), tag: :"image_logo_#{@current_app.id}", width: 1.0, max_height: 124
|
||||
@@ -92,12 +112,20 @@ module W3DHubLauncher
|
||||
end
|
||||
end
|
||||
flow(width: 1.0, height: 60) do
|
||||
if application
|
||||
button "JOIN", tip: "Join most populated or lowest ping server", fill: true, height: 1.0, background_nine_slice: NINE_SLICE_ROUNDED_LEFT, **CTA_BUTTON_THEME
|
||||
button safe_get_image("#{ROOT_PATH}/media/icons/singleplayer.png"), tip: "Single player", image_height: 1.0, background_nine_slice: NINE_SLICE_SQUARE, **CTA_BUTTON_THEME
|
||||
button safe_get_image("#{ROOT_PATH}/media/icons/gear.png"), tip: "Options", image_height: 1.0, background_nine_slice: NINE_SLICE_ROUNDED_RIGHT, **CTA_BUTTON_THEME
|
||||
elsif @current_app.servicable?
|
||||
pp @current_app
|
||||
button "Import", tip: "Import existing application installation", fill: true, height: 1.0, background_nine_slice: NINE_SLICE_ROUNDED_LEFT, **CTA_BUTTON_THEME
|
||||
button "Download", tip: "Download and install application", fill: true, height: 1.0, background_nine_slice: NINE_SLICE_ROUNDED_RIGHT, **CTA_BUTTON_THEME
|
||||
else
|
||||
button "Import", tip: "Import existing application installation", fill: true, height: 1.0, **CTA_BUTTON_THEME
|
||||
end
|
||||
end
|
||||
# FIXME: the reported version should be the _installed_ version, not the current channel version
|
||||
inscription "Version: #{@current_channel.version}", margin_top: PADDING, tip: "Installed version"
|
||||
inscription "Version: #{@current_channel.version}", margin_top: PADDING, tip: "Installed version" if application
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -12,15 +12,28 @@ module W3DHubLauncher
|
||||
@name = data["name"]
|
||||
@type = data["type"]
|
||||
|
||||
@channels = data["channels"]&.map { |c| Channel.new(c) } || []
|
||||
@channels = data["channels"]&.map { |c| Channel.new(c, self) } || []
|
||||
|
||||
@extended_data = data["extended-data"]&.map { |d| ExtendedData.new(d) } || nil
|
||||
@web_links = data["web-links"]&.map { |d| WebLink.new(d) } || nil
|
||||
|
||||
@servicable = extended_data("application.isservicable", "true").strip.downcase == "true"
|
||||
end
|
||||
|
||||
def extended_data(key, default)
|
||||
v = @extended_data&.find { |d| d.name == key }&.value
|
||||
return default if v.nil?
|
||||
|
||||
v
|
||||
end
|
||||
|
||||
# libgosu friendly color
|
||||
def color
|
||||
"ff_#{(@extended_data["colour"] || "#000000").sub("#", "")}".to_i(16)
|
||||
"ff_#{extended_data("colour","#000000").sub("#", "")}".to_i(16)
|
||||
end
|
||||
|
||||
def servicable?
|
||||
@servicable
|
||||
end
|
||||
|
||||
def to_json(context = nil)
|
||||
@@ -36,13 +49,31 @@ module W3DHubLauncher
|
||||
end
|
||||
|
||||
class Channel
|
||||
attr_reader :id, :name, :user_level, :version
|
||||
attr_reader :id, :name, :user_level, :version, :extended_data
|
||||
|
||||
def initialize(data, app)
|
||||
@_app = app
|
||||
|
||||
def initialize(data)
|
||||
@id = data["id"]
|
||||
@name = data["name"]
|
||||
@user_level = data["user-level"]
|
||||
@version = Gem::Version.new(data["current-version"])
|
||||
@extended_data = data["extended-data"]&.map { |d| ExtendedData.new(d) } || nil
|
||||
end
|
||||
|
||||
def extended_data(key, default)
|
||||
v = @extended_data&.find { |d| d.name == key }&.value
|
||||
if v.nil?
|
||||
v = @_app.extended_data(key, value)
|
||||
|
||||
return default if v.nil?
|
||||
end
|
||||
|
||||
v
|
||||
end
|
||||
|
||||
def server_channel
|
||||
extended_data("serverchannel", @id)
|
||||
end
|
||||
|
||||
def to_json(context = nil)
|
||||
@@ -50,7 +81,8 @@ module W3DHubLauncher
|
||||
"id": @id,
|
||||
"name": @name,
|
||||
"user-level": @user_level,
|
||||
"current-version": @version.to_s
|
||||
"current-version": @version.to_s,
|
||||
"extended-data": @extended_data
|
||||
}.to_json(context)
|
||||
end
|
||||
end
|
||||
@@ -59,8 +91,13 @@ module W3DHubLauncher
|
||||
attr_reader :name, :value
|
||||
|
||||
def initialize(data)
|
||||
if data.is_a?(Hash)
|
||||
@name = data["name"]
|
||||
@value = data["value"]
|
||||
else
|
||||
@name = data[0]
|
||||
@value = data[1]
|
||||
end
|
||||
end
|
||||
|
||||
def to_json(context = nil)
|
||||
|
||||
Reference in New Issue
Block a user