100 lines
3 KiB
GDScript
100 lines
3 KiB
GDScript
extends PanelContainer
|
|
class_name GameEntry
|
|
|
|
const PROMOTE_ALERT_SCENE = preload("res://UI/Shoutouts/promote.tscn")
|
|
enum Type {STEAM, ITCHIO}
|
|
var type: Type
|
|
|
|
var steam_app_id: int
|
|
var itchio_app_url: String
|
|
|
|
var chatter: Chatter
|
|
|
|
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
|
|
var inst: Alert = PROMOTE_ALERT_SCENE.instantiate()
|
|
inst.chatter = chatter
|
|
match type:
|
|
Type.STEAM:
|
|
title = steam_data.name
|
|
developer = steam_data.developers.front()
|
|
description = steam_data.short_description
|
|
link = steam_data.s_team_url
|
|
inst.steam = steam_data
|
|
Type.ITCHIO:
|
|
title = itchio_data.title
|
|
developer = itchio_data.authors.front()["name"]
|
|
description = itchio_data.description.left(200) + "..."
|
|
link = itchio_data.url
|
|
inst.itch = itchio_data
|
|
msg = msg.format({
|
|
"title": title,
|
|
"developer": developer,
|
|
"description": description,
|
|
"link": link
|
|
})
|
|
Globals.twitcher.send_message(msg)
|
|
EventManager.add_alert(inst)
|
|
|
|
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)
|