Skip to content

Commit afdf544

Browse files
committed
Support JPEG files in media
1 parent d9eab6a commit afdf544

File tree

2 files changed

+46
-28
lines changed

2 files changed

+46
-28
lines changed

addons/godot-accessibility/ScreenReader.gd

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func try_to_get_text_in_theme(theme, texture):
127127
if theme == null:
128128
return ""
129129

130-
for type in theme.get_type_list(""):
130+
for type in theme.get_type_list():
131131
for icon in theme.get_icon_list(type):
132132
var icon_texture = theme.get_icon(icon, type)
133133
if icon_texture == texture:
@@ -137,15 +137,13 @@ func try_to_get_text_in_theme(theme, texture):
137137

138138

139139
func _get_graphical_button_text(texture):
140-
var default_theme_copy = Theme.new()
141-
default_theme_copy.copy_default_theme()
142140
var current = node
143141
while current != null:
144142
var text = try_to_get_text_in_theme(current.theme, texture)
145143
if text != "":
146144
return text
147145
current = current.get_parent_control()
148-
return try_to_get_text_in_theme(default_theme_copy, texture)
146+
return ""
149147

150148

151149
func _texturebutton_focused():

source/Media.gd

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,35 @@ func convert_type_to_media_path(type: int) -> String:
119119
_:
120120
return "unknown"
121121

122+
func _find_image_path(path: String) -> String:
123+
var extensions : Array[String] = [
124+
".png", ".jpg"
125+
]
126+
for ext in extensions:
127+
var full_path := path + ext
128+
if FileAccess.file_exists(full_path):
129+
return full_path
130+
return ""
131+
132+
func _find_video_path(path: String) -> String:
133+
var extensions : Array[String] = [
134+
".mp4"
135+
]
136+
for ext in extensions:
137+
var full_path := path + ext
138+
if FileAccess.file_exists(full_path):
139+
return full_path
140+
return ""
141+
122142
func _load_media(media: RetroHubGameMediaData, game_data: RetroHubGameData, types: Type):
123143
var media_path := RetroHubConfig.get_gamemedia_dir().path_join(game_data.system_path)
124144
var game_path := game_data.path.get_file().get_basename()
125145

126146
var path : String
127147
# Logo
128-
if not media.logo:
129-
path = media_path + "/logo/" + game_path + ".png"
130-
if types & Type.LOGO and FileAccess.file_exists(path):
148+
if not media.logo and types & Type.LOGO:
149+
path = _find_image_path(media_path.path_join("logo").path_join(game_path))
150+
if not path.is_empty():
131151
var image := Image.load_from_file(path)
132152
image.generate_mipmaps()
133153
var image_texture := ImageTexture.create_from_image(image)
@@ -137,9 +157,9 @@ func _load_media(media: RetroHubGameMediaData, game_data: RetroHubGameData, type
137157
media.logo = image_texture
138158

139159
# Screenshot
140-
if not media.screenshot:
141-
path = media_path + "/screenshot/" + game_path + ".png"
142-
if types & Type.SCREENSHOT and FileAccess.file_exists(path):
160+
if not media.screenshot and types & Type.SCREENSHOT:
161+
path = _find_image_path(media_path.path_join("screenshot").path_join(game_path))
162+
if not path.is_empty():
143163
var image := Image.load_from_file(path)
144164
image.generate_mipmaps()
145165
var image_texture := ImageTexture.create_from_image(image)
@@ -149,9 +169,9 @@ func _load_media(media: RetroHubGameMediaData, game_data: RetroHubGameData, type
149169
media.screenshot = image_texture
150170

151171
# Title screen
152-
if not media.title_screen:
153-
path = media_path + "/title-screen/" + game_path + ".png"
154-
if types & Type.TITLE_SCREEN and FileAccess.file_exists(path):
172+
if not media.title_screen and types & Type.TITLE_SCREEN:
173+
path = _find_image_path(media_path.path_join("title-screen").path_join(game_path))
174+
if not path.is_empty():
155175
var image := Image.load_from_file(path)
156176
image.generate_mipmaps()
157177
var image_texture := ImageTexture.create_from_image(image)
@@ -161,9 +181,9 @@ func _load_media(media: RetroHubGameMediaData, game_data: RetroHubGameData, type
161181
media.title_screen = image_texture
162182

163183
# Box render
164-
if not media.box_render:
165-
path = media_path + "/box-render/" + game_path + ".png"
166-
if types & Type.BOX_RENDER and FileAccess.file_exists(path):
184+
if not media.box_render and types & Type.BOX_RENDER:
185+
path = _find_image_path(media_path.path_join("box-render").path_join(game_path))
186+
if not path.is_empty():
167187
var image := Image.load_from_file(path)
168188
image.generate_mipmaps()
169189
var image_texture := ImageTexture.create_from_image(image)
@@ -173,9 +193,9 @@ func _load_media(media: RetroHubGameMediaData, game_data: RetroHubGameData, type
173193
media.box_render = image_texture
174194

175195
# Box texture
176-
if not media.box_texture:
177-
path = media_path + "/box-texture/" + game_path + ".png"
178-
if types & Type.BOX_TEXTURE and FileAccess.file_exists(path):
196+
if not media.box_texture and types & Type.BOX_TEXTURE:
197+
path = _find_image_path(media_path.path_join("box-texture").path_join(game_path))
198+
if not path.is_empty():
179199
var image := Image.load_from_file(path)
180200
image.generate_mipmaps()
181201
var image_texture := ImageTexture.create_from_image(image)
@@ -185,9 +205,9 @@ func _load_media(media: RetroHubGameMediaData, game_data: RetroHubGameData, type
185205
media.box_texture = image_texture
186206

187207
# Support render
188-
if not media.support_render:
189-
path = media_path + "/support-render/" + game_path + ".png"
190-
if types & Type.SUPPORT_RENDER and FileAccess.file_exists(path):
208+
if not media.support_render and types & Type.SUPPORT_RENDER:
209+
path = _find_image_path(media_path.path_join("support-render").path_join(game_path))
210+
if not path.is_empty():
191211
var image := Image.load_from_file(path)
192212
image.generate_mipmaps()
193213
var image_texture := ImageTexture.create_from_image(image)
@@ -197,9 +217,9 @@ func _load_media(media: RetroHubGameMediaData, game_data: RetroHubGameData, type
197217
media.support_render = image_texture
198218

199219
# Support texture
200-
if not media.support_texture:
201-
path = media_path + "/support-texture/" + game_path + ".png"
202-
if types & Type.SUPPORT_TEXTURE and FileAccess.file_exists(path):
220+
if not media.support_texture and types & Type.SUPPORT_TEXTURE:
221+
path = _find_image_path(media_path.path_join("support-texture").path_join(game_path))
222+
if not path.is_empty():
203223
var image := Image.load_from_file(path)
204224
image.generate_mipmaps()
205225
var image_texture := ImageTexture.create_from_image(image)
@@ -209,9 +229,9 @@ func _load_media(media: RetroHubGameMediaData, game_data: RetroHubGameData, type
209229
media.support_texture = image_texture
210230

211231
# Video
212-
if not media.video:
213-
path = media_path + "/video/" + game_path + ".mp4"
214-
if types & Type.VIDEO and FileAccess.file_exists(path):
232+
if not media.video and types & Type.VIDEO:
233+
path = _find_video_path(media_path.path_join("video").path_join(game_path))
234+
if not path.is_empty():
215235
var video_stream := VideoStreamFFMPEG.new()
216236
video_stream.set_file(path)
217237
media.video = video_stream

0 commit comments

Comments
 (0)