@@ -372,3 +372,51 @@ func compute_blurhash(game_data: RetroHubGameData) -> void:
372
372
FileUtils .ensure_path (file_path )
373
373
JSONUtils .save_json_file (json_data , file_path )
374
374
375
+ func get_box_texture_region (data : RetroHubGameData , media : RetroHubGameMediaData , type : RetroHubGameData .BoxTextureRegions , rotate : bool = true ) -> Texture2D :
376
+ if not data .box_texture_regions .has (type ) or not media .box_texture :
377
+ return null
378
+
379
+ var coords_raw : Rect2 = data .box_texture_regions [type ]
380
+ var _offset_1 := coords_raw .position
381
+ var _offset_2 := coords_raw .size
382
+
383
+ var offset : Vector2
384
+ var size : Vector2
385
+ var rotation : int = 0
386
+
387
+ # Coords embed text direction. We infer it by the xy ordering of both coords.
388
+ # 90 degrees (text up-to-down)
389
+ if _offset_1 .x >= _offset_2 .x and _offset_1 .y < _offset_2 .y :
390
+ offset = Vector2 (_offset_2 .x , _offset_1 .y )
391
+ size = Vector2 (_offset_1 .x , _offset_2 .y ) - offset
392
+ rotation = 90
393
+ # 180 degrees (text right-to-left)
394
+ elif _offset_1 .x >= _offset_2 .x and _offset_1 .y >= _offset_2 .y :
395
+ offset = Vector2 (_offset_2 .x , _offset_2 .y )
396
+ size = Vector2 (_offset_1 .x , _offset_1 .y ) - offset
397
+ rotation = 180
398
+ # -90 degrees (text down-to-up)
399
+ elif _offset_1 .x < _offset_2 .x and _offset_1 .y >= _offset_2 .y :
400
+ offset = Vector2 (_offset_1 .x , _offset_2 .y )
401
+ size = Vector2 (_offset_2 .x , _offset_1 .y ) - offset
402
+ rotation = - 90
403
+ else :
404
+ offset = Vector2 (_offset_1 .x , _offset_1 .y )
405
+ size = Vector2 (_offset_2 .x , _offset_2 .y ) - offset
406
+
407
+ var image := media .box_texture .get_image ()
408
+ var image_size := Vector2 (image .get_width (), image .get_height ())
409
+ var offset_i := Vector2i ((offset * image_size ).round ())
410
+ var size_i := Vector2i ((size * image_size ).round ())
411
+ var blit_image := Image .create (size_i .x , size_i .y , false , image .get_format ())
412
+ blit_image .blit_rect (image , Rect2i (offset_i , size_i ), Vector2i .ZERO )
413
+ if rotate :
414
+ match rotation :
415
+ - 90 :
416
+ blit_image .rotate_90 (CLOCKWISE )
417
+ 90 :
418
+ blit_image .rotate_90 (COUNTERCLOCKWISE )
419
+ 180 :
420
+ blit_image .rotate_180 ()
421
+
422
+ return ImageTexture .create_from_image (blit_image )
0 commit comments