@@ -119,15 +119,35 @@ func convert_type_to_media_path(type: int) -> String:
119
119
_ :
120
120
return "unknown"
121
121
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
+
122
142
func _load_media (media : RetroHubGameMediaData , game_data : RetroHubGameData , types : Type ):
123
143
var media_path := RetroHubConfig .get_gamemedia_dir ().path_join (game_data .system_path )
124
144
var game_path := game_data .path .get_file ().get_basename ()
125
145
126
146
var path : String
127
147
# 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 ( ):
131
151
var image := Image .load_from_file (path )
132
152
image .generate_mipmaps ()
133
153
var image_texture := ImageTexture .create_from_image (image )
@@ -137,9 +157,9 @@ func _load_media(media: RetroHubGameMediaData, game_data: RetroHubGameData, type
137
157
media .logo = image_texture
138
158
139
159
# 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 ( ):
143
163
var image := Image .load_from_file (path )
144
164
image .generate_mipmaps ()
145
165
var image_texture := ImageTexture .create_from_image (image )
@@ -149,9 +169,9 @@ func _load_media(media: RetroHubGameMediaData, game_data: RetroHubGameData, type
149
169
media .screenshot = image_texture
150
170
151
171
# 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 ( ):
155
175
var image := Image .load_from_file (path )
156
176
image .generate_mipmaps ()
157
177
var image_texture := ImageTexture .create_from_image (image )
@@ -161,9 +181,9 @@ func _load_media(media: RetroHubGameMediaData, game_data: RetroHubGameData, type
161
181
media .title_screen = image_texture
162
182
163
183
# 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 ( ):
167
187
var image := Image .load_from_file (path )
168
188
image .generate_mipmaps ()
169
189
var image_texture := ImageTexture .create_from_image (image )
@@ -173,9 +193,9 @@ func _load_media(media: RetroHubGameMediaData, game_data: RetroHubGameData, type
173
193
media .box_render = image_texture
174
194
175
195
# 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 ( ):
179
199
var image := Image .load_from_file (path )
180
200
image .generate_mipmaps ()
181
201
var image_texture := ImageTexture .create_from_image (image )
@@ -185,9 +205,9 @@ func _load_media(media: RetroHubGameMediaData, game_data: RetroHubGameData, type
185
205
media .box_texture = image_texture
186
206
187
207
# 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 ( ):
191
211
var image := Image .load_from_file (path )
192
212
image .generate_mipmaps ()
193
213
var image_texture := ImageTexture .create_from_image (image )
@@ -197,9 +217,9 @@ func _load_media(media: RetroHubGameMediaData, game_data: RetroHubGameData, type
197
217
media .support_render = image_texture
198
218
199
219
# 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 ( ):
203
223
var image := Image .load_from_file (path )
204
224
image .generate_mipmaps ()
205
225
var image_texture := ImageTexture .create_from_image (image )
@@ -209,9 +229,9 @@ func _load_media(media: RetroHubGameMediaData, game_data: RetroHubGameData, type
209
229
media .support_texture = image_texture
210
230
211
231
# 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 ( ):
215
235
var video_stream := VideoStreamFFMPEG .new ()
216
236
video_stream .set_file (path )
217
237
media .video = video_stream
0 commit comments