58 lines
1.5 KiB
GDScript3
58 lines
1.5 KiB
GDScript3
|
|
extends PanelContainer
|
||
|
|
|
||
|
|
var chatter: Chatter:
|
||
|
|
set(value):
|
||
|
|
chatter = value
|
||
|
|
if not chatter:
|
||
|
|
live = null
|
||
|
|
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)
|
||
|
|
if not chatter: return
|
||
|
|
if not live and chatter.twitch_id in Globals.live_streamers.keys():
|
||
|
|
live = Globals.live_streamers[chatter.twitch_id]
|
||
|
|
_populate_view()
|
||
|
|
|
||
|
|
func _populate_view() -> void:
|
||
|
|
if not live:
|
||
|
|
set_process(false)
|
||
|
|
return
|
||
|
|
set_process(true)
|
||
|
|
%StreamTitle.text = live.title
|
||
|
|
%StreamViewerCount.text = str(live.viewer_count)
|
||
|
|
var url := live.thumbnail_url.format({"width": 640, "height": 360})
|
||
|
|
var img = await Globals.twitcher.media.load_image(url)
|
||
|
|
%StreamThumbnail.texture = ImageTexture.create_from_image(img)
|
||
|
|
|
||
|
|
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
|