Make accessing application extended data easyish, dynamicify game page game play/import/install buttons

This commit is contained in:
2026-09-03 13:27:15 -05:00
parent 60672ef9c3
commit 8dd9b44cb0
2 changed files with 76 additions and 11 deletions

View File

@@ -46,6 +46,22 @@ module W3DHubLauncher
@current_app = game @current_app = game
@current_channel = game&.channels&.first @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_games_list
populate_game_info populate_game_info
populate_game_event populate_game_event
@@ -69,6 +85,10 @@ module W3DHubLauncher
end end
def populate_game_info 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 @game_info_container.clear do
# logo # 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 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
end end
flow(width: 1.0, height: 60) do flow(width: 1.0, height: 60) do
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 if application
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 "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/gear.png"), tip: "Options", image_height: 1.0, background_nine_slice: NINE_SLICE_ROUNDED_RIGHT, **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 end
# FIXME: the reported version should be the _installed_ version, not the current channel version # 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
end end

View File

@@ -12,15 +12,28 @@ module W3DHubLauncher
@name = data["name"] @name = data["name"]
@type = data["type"] @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 @extended_data = data["extended-data"]&.map { |d| ExtendedData.new(d) } || nil
@web_links = data["web-links"]&.map { |d| WebLink.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 end
# libgosu friendly color # libgosu friendly color
def 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 end
def to_json(context = nil) def to_json(context = nil)
@@ -36,13 +49,31 @@ module W3DHubLauncher
end end
class Channel 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"] @id = data["id"]
@name = data["name"] @name = data["name"]
@user_level = data["user-level"] @user_level = data["user-level"]
@version = Gem::Version.new(data["current-version"]) @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 end
def to_json(context = nil) def to_json(context = nil)
@@ -50,7 +81,8 @@ module W3DHubLauncher
"id": @id, "id": @id,
"name": @name, "name": @name,
"user-level": @user_level, "user-level": @user_level,
"current-version": @version.to_s "current-version": @version.to_s,
"extended-data": @extended_data
}.to_json(context) }.to_json(context)
end end
end end
@@ -59,8 +91,13 @@ module W3DHubLauncher
attr_reader :name, :value attr_reader :name, :value
def initialize(data) def initialize(data)
@name = data["name"] if data.is_a?(Hash)
@value = data["value"] @name = data["name"]
@value = data["value"]
else
@name = data[0]
@value = data[1]
end
end end
def to_json(context = nil) def to_json(context = nil)