2026-03-08 13:28:00 -05:00
|
|
|
extends PanelContainer
|
|
|
|
|
|
2026-03-10 10:25:17 -05:00
|
|
|
var _offline_color := Color.html("d36dff4e")
|
|
|
|
|
var _offline_no_thumbnail := preload("res://assets/bootstrap/twitch_large.svg")
|
|
|
|
|
|
2026-03-08 13:28:00 -05:00
|
|
|
var chatter: Chatter:
|
|
|
|
|
set(value):
|
|
|
|
|
chatter = value
|
|
|
|
|
if not chatter:
|
|
|
|
|
live = null
|
2026-03-10 10:25:17 -05:00
|
|
|
clear()
|
2026-03-08 13:28:00 -05:00
|
|
|
return
|
|
|
|
|
live = Globals.live_streamers[chatter.twitch_id] if chatter.twitch_id in Globals.live_streamers.keys() else null
|
|
|
|
|
_populate_view()
|
|
|
|
|
|
|
|
|
|
var live: TwitchStream
|
|
|
|
|
|
|
|
|
|
var _ticks: int = 0
|
|
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
%StreamTitle.pressed.connect(_open_stream)
|
|
|
|
|
%RaidCurrentUser.pressed.connect(_raid_stream)
|
2026-03-10 10:25:17 -05:00
|
|
|
if not chatter:
|
|
|
|
|
clear()
|
|
|
|
|
return
|
2026-03-08 13:28:00 -05:00
|
|
|
if not live and chatter.twitch_id in Globals.live_streamers.keys():
|
|
|
|
|
live = Globals.live_streamers[chatter.twitch_id]
|
|
|
|
|
_populate_view()
|
2026-03-10 10:25:17 -05:00
|
|
|
elif not live:
|
|
|
|
|
clear()
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
func clear() -> void:
|
|
|
|
|
%StreamTitle.text = "Not Live"
|
|
|
|
|
%StreamViewerCount.text = "0"
|
|
|
|
|
%StreamTime.text = "00:00:00"
|
|
|
|
|
%StreamThumbnail.visible = false
|
|
|
|
|
%OfflineThumbnail.visible = true
|
|
|
|
|
%NoThumbText.visible = true
|
|
|
|
|
if chatter:
|
|
|
|
|
if chatter.user.offline_image_url != "":
|
|
|
|
|
%OfflineThumbnail.texture = await ImageLoader.load_image(chatter.user.offline_image_url)
|
|
|
|
|
%OfflineThumbnail.self_modulate = Color.WHITE
|
|
|
|
|
%NoThumbText.visible = false
|
|
|
|
|
return
|
|
|
|
|
%OfflineThumbnail.texture = _offline_no_thumbnail
|
|
|
|
|
%OfflineThumbnail.self_modulate = _offline_color
|
2026-03-08 13:28:00 -05:00
|
|
|
|
|
|
|
|
func _populate_view() -> void:
|
|
|
|
|
if not live:
|
|
|
|
|
set_process(false)
|
2026-03-10 10:25:17 -05:00
|
|
|
clear()
|
2026-03-08 13:28:00 -05:00
|
|
|
return
|
|
|
|
|
set_process(true)
|
|
|
|
|
%StreamTitle.text = live.title
|
|
|
|
|
%StreamViewerCount.text = str(live.viewer_count)
|
|
|
|
|
var url := live.thumbnail_url.format({"width": 640, "height": 360})
|
2026-03-10 10:25:17 -05:00
|
|
|
%StreamThumbnail.texture = await ImageLoader.load_image(url)
|
|
|
|
|
%StreamThumbnail.visible = true
|
|
|
|
|
%OfflineThumbnail.visible = false
|
2026-03-08 13:28:00 -05:00
|
|
|
|
|
|
|
|
func _process(_d: float) -> void:
|
|
|
|
|
if not live:
|
|
|
|
|
set_process(false)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
_ticks += 1
|
|
|
|
|
if _ticks < 30: return
|
|
|
|
|
_ticks = 0
|
|
|
|
|
|
|
|
|
|
var system_unix = Time.get_unix_time_from_system()
|
|
|
|
|
var stream_start_unix = Time.get_unix_time_from_datetime_string(live.started_at)
|
|
|
|
|
var elapsed = Time.get_datetime_string_from_unix_time((system_unix - stream_start_unix), true)
|
|
|
|
|
|
|
|
|
|
%StreamTime.text = elapsed.split(" ")[1]
|
|
|
|
|
|
|
|
|
|
func _open_stream() -> void:
|
|
|
|
|
if not live: return
|
|
|
|
|
OS.shell_open("https://twitch.tv/%s" % live.user_login)
|
|
|
|
|
|
|
|
|
|
func _raid_stream() -> void:
|
|
|
|
|
if not live: return
|
|
|
|
|
pass
|