Created GameEntry
Created GameEntry item for Game lists in User Panel
This commit is contained in:
parent
7aa064fe24
commit
f5aeb44cfd
3 changed files with 182 additions and 0 deletions
93
UI/Controls/game_entry.gd
Normal file
93
UI/Controls/game_entry.gd
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
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 = ImageTexture.create_from_image(await Globals.twitcher.media.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 = ImageTexture.create_from_image(await Globals.twitcher.media.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.developer
|
||||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue