StreamOverlay/UI/Controls/game_entry.gd
Mario Steele 23fdd1e972 Updated GameEntry
Switched to using ImageLoader.load_image()
Fixed bug in developer, to use itchio_data.authors
2026-03-10 10:16:33 -05:00

93 lines
2.7 KiB
GDScript

extends PanelContainer
class_name GameEntry
enum Type {STEAM, ITCHIO}
var type: Type
var steam_app_id: int
var itchio_app_url: String
var steam_data: SteamAppData
var itchio_data: ItchIOAppData
signal game_info_steam_pressed(steam_data: SteamAppData)
signal game_info_itchio_pressesd(itchio_data: ItchIOAppData)
signal entry_deleted(entry: GameEntry)
func _ready() -> void:
populate()
%Refresh.pressed.connect(_reload_data)
%GameName.pressed.connect(_select_game)
%Promote.pressed.connect(_promote_game)
%SteamLink.pressed.connect(_launch_game_site)
%ItchLink.pressed.connect(_launch_game_site)
%Delete.pressed.connect(entry_deleted.emit.bind(self))
func populate() -> void:
%SteamLink.visible = type == Type.STEAM
%ItchLink.visible = type == Type.ITCHIO
match type:
Type.STEAM:
if not steam_data:
steam_data = await %SteamService.get_steam_app_data(steam_app_id)
%GameName.text = steam_data.name
%GameName.tooltip_text = steam_data.name
var url_no_query: String = steam_data.header_image.split("?")[0]
%Background.texture = await ImageLoader.load_image(url_no_query)
Type.ITCHIO:
if not itchio_data:
itchio_data = await %ItchIOService.get_itch_app_data(itchio_app_url)
%GameName.text = itchio_data.title
var url: String = itchio_data.cover_image
%Background.texture = await ImageLoader.load_image(url)
func _reload_data() -> void:
match type:
Type.STEAM:
steam_data = await %SteamService.get_steam_app_data(steam_app_id)
populate()
game_info_steam_pressed.emit(steam_data)
Type.ITCHIO:
itchio_data = await %ItchIOService.get_itch_app_data(itchio_app_url)
populate()
game_info_itchio_pressesd.emit(itchio_data)
func _select_game() -> void:
if type == Type.STEAM: game_info_steam_pressed.emit(steam_data)
elif type == Type.ITCHIO: game_info_itchio_pressesd.emit(itchio_data)
func _promote_game() -> void:
var msg: String = "Check out {title} by {developer}! {description} {link}"
var title: String
var developer: String
var description: String
var link: String
match type:
Type.STEAM:
title = steam_data.name
developer = steam_data.developers.front()
description = steam_data.short_description
link = steam_data.s_team_url
pass
Type.ITCHIO:
title = itchio_data.title
developer = itchio_data.authors.front()["name"]
description = itchio_data.description.left(200) + "..."
link = itchio_data.url
msg = msg.format({
"title": title,
"developer": developer,
"description": description,
"link": link
})
Globals.twitcher.send_message(msg)
func _launch_game_site() -> void:
var link: String
match type:
Type.STEAM: link = "https://s.team/a/%d" % steam_app_id
Type.ITCHIO: link = itchio_app_url
_:
link = "https://google.com"
OS.shell_open(link)