167 lines
5 KiB
GDScript
167 lines
5 KiB
GDScript
@tool
|
|
extends PanelContainer
|
|
class_name ItchIOAppInfo
|
|
|
|
@export var enable_logger: bool = true
|
|
@warning_ignore("unused_private_class_variable")
|
|
@export_tool_button("Search", "Button") var _search = tool_search
|
|
@export var tool_app_url: String
|
|
|
|
#region Test Apps
|
|
enum ItchIOGames{
|
|
RIDICULOUS_SHOPPING,
|
|
THE_MAZE_AND_THE_BEAST,
|
|
THE_SUNNYSIDE_MOTEL_IN_HUTTSVILLE_ARKANSAS,
|
|
VOID_DRIVE_THROUGH,
|
|
POTION_QUEST,
|
|
SUPER_ROLL_OUT,
|
|
COVINOS_ROTTEN_FRUIT,
|
|
AUTENTIC_ITALIAN_PIZZA,
|
|
}
|
|
const ITCHIO_APP_URLS: Dictionary[ItchIOGames, String] = {
|
|
ItchIOGames.RIDICULOUS_SHOPPING: "https://uff.itch.io/ridiculous-shopping",
|
|
ItchIOGames.THE_MAZE_AND_THE_BEAST: "https://uff.itch.io/the-maze-and-the-beast",
|
|
ItchIOGames.THE_SUNNYSIDE_MOTEL_IN_HUTTSVILLE_ARKANSAS: "https://fgaha56.itch.io/the-sunnyside-motel-in-huttsville-arkansas",
|
|
ItchIOGames.VOID_DRIVE_THROUGH: "https://fgaha56.itch.io/void-drive-through",
|
|
ItchIOGames.POTION_QUEST: "https://vex667.itch.io/potion-quest",
|
|
ItchIOGames.SUPER_ROLL_OUT: "https://seano4d.itch.io/super-roll-out",
|
|
ItchIOGames.COVINOS_ROTTEN_FRUIT: "https://jerem-watts.itch.io/gorley-cleans-up-covinos-rotten-fruit",
|
|
ItchIOGames.AUTENTIC_ITALIAN_PIZZA: "https://trevron.itch.io/authentic-italian-pizza",
|
|
}
|
|
@export var selected_itchio_game: ItchIOGames:
|
|
set(val):
|
|
selected_itchio_game = val
|
|
if is_node_ready(): get_app_info(ITCHIO_APP_URLS[selected_itchio_game])
|
|
@export var test_data: ItchIOAppData
|
|
#endregion
|
|
|
|
const IMG_VALID_FORMATS = ["png", "jpeg", "jpg", "bmp", "webp", "svg"]
|
|
|
|
static var _log: TwitchLogger = TwitchLogger.new(&"ItchAppInfo")
|
|
var data: ItchIOAppData:
|
|
set(val):
|
|
data = val
|
|
if is_node_ready():
|
|
%VisitPage.disabled = data == null
|
|
|
|
var _save_data: ItchIOAppData
|
|
|
|
func _ready() -> void:
|
|
%Clear.pressed.connect(clear)
|
|
if Engine.is_editor_hint():
|
|
return
|
|
clear()
|
|
|
|
func tool_search() -> void:
|
|
if !Engine.is_editor_hint():
|
|
return
|
|
if tool_app_url:
|
|
get_app_info(tool_app_url)
|
|
|
|
func get_app_info(app_url: String) -> ItchIOAppData:
|
|
var _data: ItchIOAppData = await %ItchIOService.get_itch_app_data(app_url)
|
|
if not _data:
|
|
return null
|
|
|
|
display_app_info(_data)
|
|
if Engine.is_editor_hint():
|
|
test_data = _data
|
|
return _data
|
|
|
|
func display_app_info(_data: ItchIOAppData) -> void:
|
|
clear()
|
|
data = _data
|
|
if not data: return
|
|
%AppSearch.text = str(data.url)
|
|
%AppId.text = str(data.id)
|
|
%GameName.text = data.title
|
|
|
|
var authors_string: String = ""
|
|
for i: int in data.authors.size():
|
|
var author_dic: Dictionary = data.authors[i]
|
|
authors_string += "[b][url={url}]{name}[/url][/b]".format(author_dic)
|
|
if i+1 < data.authors.size():
|
|
authors_string += ", "
|
|
|
|
%AuthorName.text = "[i]by %s[/i]" % authors_string
|
|
if data.cover_image:
|
|
%CapsuleImage.texture = await load_texture_from_url(data.cover_image)
|
|
if not data.screenshots_thumbnails.is_empty():
|
|
var texture := await load_texture_from_url(data.screenshots_thumbnails.front())
|
|
if texture:
|
|
%Background.texture = texture
|
|
|
|
%lb_price_desc.visible = !data.is_free
|
|
if data.is_free:
|
|
%GamePrice.text = "[color=green][wave][b]Free to play![/b][/wave][/color]"
|
|
else:
|
|
%GamePrice.text = "[color=green][b]%s[/b][/color]" % data.price
|
|
|
|
%Description.text = data.description
|
|
|
|
func clear() -> void:
|
|
data = null
|
|
%AppSearch.text = ""
|
|
%GameName.text = ""
|
|
%AuthorName.text = ""
|
|
%CapsuleImage.texture = null
|
|
%Background.texture = null
|
|
%ReleaseDate.text = ""
|
|
%GamePrice.text = ""
|
|
%h_price.hide()
|
|
%Description.text = ""
|
|
|
|
func load_texture_from_url(url: String) -> ImageTexture:
|
|
var http := HTTPRequest.new()
|
|
add_child(http)
|
|
var url_no_query: String = url.split("?")[0]
|
|
var file_type = url_no_query.get_extension()
|
|
if not file_type in ["png", "jpeg", "jpg", "bmp", "webp", "svg"]:
|
|
file_type = "webp"
|
|
|
|
var _err = http.request(url)
|
|
if _err != OK:
|
|
print("_err != OK")
|
|
return
|
|
|
|
var result: Array = await http.request_completed
|
|
var _result: int = result[0]
|
|
var response_code: int = result[1]
|
|
var _headers: PackedStringArray = result[2]
|
|
var buffer: PackedByteArray = result[3]
|
|
if response_code != HTTPClient.RESPONSE_OK:
|
|
print("response_code != HTTPClient.RESPONSE_OK")
|
|
return
|
|
|
|
var tex_image := Image.new()
|
|
match file_type:
|
|
"png": tex_image.load_png_from_buffer(buffer)
|
|
"jpeg", "jpg": tex_image.load_jpg_from_buffer(buffer)
|
|
"bmp": tex_image.load_bmp_from_buffer(buffer)
|
|
"webp": tex_image.load_webp_from_buffer(buffer)
|
|
"svg": tex_image.load_svg_from_buffer(buffer)
|
|
_:
|
|
_log.e("%s format not recognized." % file_type)
|
|
return null
|
|
|
|
var tex = ImageTexture.create_from_image(tex_image)
|
|
http.queue_free()
|
|
return tex
|
|
|
|
|
|
func _notification(what: int) -> void:
|
|
if not Engine.is_editor_hint(): return
|
|
match what:
|
|
NOTIFICATION_EDITOR_PRE_SAVE:
|
|
_save_data = data
|
|
#_save_capsule_texture = %CapsuleImage.texture
|
|
#_save_bg_texture = %Background.texture
|
|
#test_data = null
|
|
clear()
|
|
NOTIFICATION_EDITOR_POST_SAVE:
|
|
test_data = _save_data
|
|
display_app_info.call_deferred(_save_data)
|
|
#%CapsuleImage.texture = _save_capsule_texture
|
|
#%Background.texture = _save_bg_texture
|
|
#_save_capsule_texture = null
|
|
#_save_bg_texture = null
|