Skip to content

Commit

Permalink
fixed icon cache and disconnects (thanks to trgKai)
Browse files Browse the repository at this point in the history
  • Loading branch information
issork committed Dec 19, 2023
1 parent 39f9fd5 commit 9180cfa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions addons/gift/icon_downloader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ func _init(twitch_api : TwitchAPIConnection, disk_cache_enabled : bool = false)

func poll() -> void:
jtvnw_client.poll()
if (jtvnw_client.get_status() == HTTPClient.STATUS_BODY):
var conn_status = jtvnw_client.get_status()
if (conn_status == HTTPClient.STATUS_BODY):
jtvnw_response += jtvnw_client.read_response_body_chunk()
elif (!jtvnw_response.is_empty()):
var img := Image.new()
Expand All @@ -34,8 +35,11 @@ func poll() -> void:
texture.set_image(img)
texture.take_over_path(path)
fetched.emit(texture)
elif (jtvnw_client.get_status() == HTTPClient.STATUS_CONNECTED && !jtvnw_queue.is_empty()):
jtvnw_client.request(HTTPClient.METHOD_GET, jtvnw_queue.front(), ["Accept: image/png"])
elif (!jtvnw_queue.is_empty()):
if (conn_status == HTTPClient.STATUS_CONNECTED):
jtvnw_client.request(HTTPClient.METHOD_GET, jtvnw_queue.front(), ["Accept: image/png"])
elif (conn_status == HTTPClient.STATUS_DISCONNECTED || conn_status == HTTPClient.STATUS_CONNECTION_ERROR):
jtvnw_client.connect_to_host(JTVNW_URL)

func get_badge(badge_id : String, channel_id : String = "_global", scale : String = "1x") -> Texture2D:
var badge_data : PackedStringArray = badge_id.split("/", true, 1)
Expand Down Expand Up @@ -78,5 +82,5 @@ func wait_for_fetched(path : String, filepath : String) -> ImageTexture:
var last_fetched : ImageTexture = null
while (last_fetched == null || last_fetched.resource_path != path):
last_fetched = await(fetched)
last_fetched.take_over_path(filepath)
return load(filepath)
last_fetched.take_over_path(path)
return load(path)
2 changes: 1 addition & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ config_version=5

config/name="GIFT"
run/main_scene="res://example/Example.tscn"
config/features=PackedStringArray("4.1")
config/features=PackedStringArray("4.2")

[debug]

Expand Down

0 comments on commit 9180cfa

Please sign in to comment.