Skip to content

Commit

Permalink
Port to Godot 4 (#20)
Browse files Browse the repository at this point in the history
* Update addons to Godot 4 versions

* Automated and manual Godot 3-to-4 conversion

* Fix image colors and font loading

* Fix system icons position, default labels, and helptext

* Update helper addon
  • Loading branch information
rsubtil authored Jul 21, 2023
1 parent 11eeabe commit 841587d
Show file tree
Hide file tree
Showing 589 changed files with 8,152 additions and 11,513 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Godot 4+ specific ignores
.godot/

# Godot-specific ignores
.import/
export.cfg

# Imported translations (automatically generated from CSV files)
*.translation

# Mono-specific ignores
.mono/
data_*/

# RetroHub Theme Helper
addons/retrohub_theme_helper/config.json
62 changes: 30 additions & 32 deletions Logic.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tool
@tool
extends Node

export(String, DIR, GLOBAL) var path
@export_global_dir var path : String

var Wrapper = load("res://Wrapper.gd").new()

Expand All @@ -19,48 +19,48 @@ enum Mode {

var curr_mode = Mode.SYSTEM

onready var target_position_system : Vector2 = $System.rect_position
onready var target_position_game_view : Vector2 = $GameView.rect_position
@onready var target_position_system : Vector2 = $System.position
@onready var target_position_game_view : Vector2 = $GameView.position

# _ready function, called everytime the theme is loaded
func _ready():
if Engine.is_editor_hint():
return
# App related signals
#warning-ignore:return_value_discarded
RetroHub.connect("app_initializing", self, "_on_app_initializing")
RetroHub.app_initializing.connect(_on_app_initializing)
#warning-ignore:return_value_discarded
RetroHub.connect("app_closing", self, "_on_app_closing")
RetroHub.app_closing.connect(_on_app_closing)
#warning-ignore:return_value_discarded
RetroHub.connect("app_received_focus", self, "_on_app_received_focus")
RetroHub.app_received_focus.connect(_on_app_received_focus)
#warning-ignore:return_value_discarded
RetroHub.connect("app_lost_focus", self, "_on_app_lost_focus")
RetroHub.app_lost_focus.connect(_on_app_lost_focus)
#warning-ignore:return_value_discarded
RetroHub.connect("app_returning", self, "_on_app_returning")
RetroHub.app_returning.connect(_on_app_returning)

# Content related signals
#warning-ignore:return_value_discarded
RetroHub.connect("system_receive_start", self, "_on_system_receive_start")
RetroHub.system_receive_start.connect(_on_system_receive_start)
#warning-ignore:return_value_discarded
RetroHub.connect("system_received", self, "_on_system_received")
RetroHub.system_received.connect(_on_system_received)
#warning-ignore:return_value_discarded
RetroHub.connect("system_receive_end", self, "_on_system_receive_end")
RetroHub.system_receive_end.connect(_on_system_receive_end)


#warning-ignore:return_value_discarded
RetroHub.connect("game_receive_start", self, "_on_game_receive_start")
RetroHub.game_receive_start.connect(_on_game_receive_start)
#warning-ignore:return_value_discarded
RetroHub.connect("game_received", self, "_on_game_received")
RetroHub.game_received.connect(_on_game_received)
#warning-ignore:return_value_discarded
RetroHub.connect("game_receive_end", self, "_on_game_receive_end")
RetroHub.game_receive_end.connect(_on_game_receive_end)

# Config related signals
#warning-ignore:return_value_discarded
RetroHubConfig.connect("config_updated", self, "_on_config_updated")
RetroHubConfig.config_updated.connect(_on_config_updated)
#warning-ignore:return_value_discarded
RetroHubConfig.connect("theme_config_ready", self, "_on_theme_config_ready")
RetroHubConfig.theme_config_ready.connect(_on_theme_config_ready)
#warning-ignore:return_value_discarded
RetroHubConfig.connect("theme_config_updated", self, "_on_theme_config_updated")
RetroHubConfig.theme_config_updated.connect(_on_theme_config_updated)

if not RetroHub.is_main_app():
Wrapper.load_es_theme_file(path + "/theme.xml")
Expand All @@ -78,13 +78,13 @@ func set_node_enabled(node: Node, enabled: bool):
# use this function for input (not _input/_process) for proper behavior
func _unhandled_input(event):
if event.is_action_pressed("rh_accept") and curr_mode == Mode.SYSTEM:
get_tree().set_input_as_handled()
get_viewport().set_input_as_handled()
var system_data : RetroHubSystemData = $System.get_selected_system_data()
var game_view = gameview_map[system_data]
curr_mode = Mode.GAME_VIEW
move_ui(1, game_view)
if event.is_action_pressed("rh_back") and curr_mode == Mode.GAME_VIEW:
get_tree().set_input_as_handled()
get_viewport().set_input_as_handled()
curr_mode = Mode.SYSTEM
move_ui(-1)
RetroHub.set_curr_game_data(null)
Expand All @@ -105,17 +105,15 @@ func move_ui(dir: int, game_view: Node = null):
else:
set_node_enabled(child, false)
child.on_hide()
$Tween.interpolate_property(
$GameView, "rect_position",
null, target_position_game_view,
0.5, Tween.TRANS_QUART, Tween.EASE_OUT
var tween := create_tween()
tween.set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_QUART)
tween.set_parallel(true)
tween.tween_property(
$GameView, "position", target_position_game_view, 0.5
)
$Tween.interpolate_property(
$System, "rect_position",
null, target_position_system,
0.5, Tween.TRANS_QUART, Tween.EASE_OUT
tween.tween_property(
$System, "position", target_position_system, 0.5
)
$Tween.start()

## Called when RetroHub is initializing your theme.
## This can either happen when RetroHub is launching, or
Expand Down Expand Up @@ -207,9 +205,9 @@ func _on_game_receive_end():
for system_name in games:
var game_view
if games_metadata[system_name]:
game_view = load("res://views/detailed/Detailed.tscn").instance()
game_view = load("res://views/detailed/Detailed.tscn").instantiate()
else:
game_view = load("res://views/basic/Basic.tscn").instance()
game_view = load("res://views/basic/Basic.tscn").instantiate()
$GameView.add_child(game_view)

if systems.has(system_name):
Expand All @@ -233,7 +231,7 @@ func _on_config_updated(key: String, _old, _new):
func _on_theme_config_ready():
# Load theme XML info
path = RetroHubConfig.get_theme_config("path", "")
if not path.empty():
if not path.is_empty():
Wrapper.load_es_theme_file(path + "/theme.xml")
else:
print("No path selected")
Expand Down
15 changes: 8 additions & 7 deletions PropertyWrapper.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extends Object

var screen_width = 1024
var screen_height = 576
var screen_width = 1152
var screen_height = 648

func parse_normalized_pair(Wrapper, data: String, to_absolute: bool = true) -> Vector2:
data = parse_string(Wrapper, data)
Expand Down Expand Up @@ -44,11 +44,12 @@ func parse_bool(Wrapper, data: String) -> bool:

func parse_color(Wrapper, data: String) -> Color:
data = parse_string(Wrapper, data)
if data.length() == 8:
var color_str = data.substr(6) + data.substr(0, 6)
return Color(color_str)
else:
return Color(data)
return Color(data)
#if data.length() == 8:
# var color_str = data.substr(6) + data.substr(0, 6)
# return Color(color_str)
#else:
# return Color(data)

func parse_float(Wrapper, data: String) -> float:
data = parse_string(Wrapper, data)
Expand Down
15 changes: 7 additions & 8 deletions Theme.tscn
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=3 format=3 uid="uid://mspdxioy4gxu"]

[ext_resource path="res://Logic.gd" type="Script" id=1]
[ext_resource path="res://views/system/System.tscn" type="PackedScene" id=2]
[ext_resource type="Script" path="res://Logic.gd" id="1"]
[ext_resource type="PackedScene" uid="uid://741n1a4ffwjn" path="res://views/system/System.tscn" id="2"]

[node name="RetroHubTheme" type="Node"]
script = ExtResource( 1 )
path = "/home/ricardo/.emulationstation/themes/snes"
script = ExtResource("1")
path = "/home/ricardo/.emulationstation/themes/art-book-next-retropie-main"

[node name="System" parent="." instance=ExtResource( 2 )]
[node name="System" parent="." instance=ExtResource("2")]
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="GameView" type="Control" parent="."]
layout_mode = 3
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 2.0

[node name="Tween" type="Tween" parent="."]
10 changes: 5 additions & 5 deletions Wrapper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ func convert_system_name(system_name: String):
func load_es_theme_file(path: String):
# Load generic theme.xml, used when no themes are found
# Ensure file exists
if not Directory.new().file_exists(path):
if not FileAccess.file_exists(path):
return
var dict : Dictionary = xml2json.parse(path)
var root_path = path.get_base_dir()
if not dict.empty():
if not dict.is_empty():
xml_filemap[path] = dict["theme"]
map_xml_content(xml_filemap[path], root_path)
"""var file := File.new()
var dir := Directory.new()
var dir := DirAccess.new()
dir.make_dir_recursive("/tmp/rh/" + system_name)
var err = file.open("/tmp/rh/" + system_name + "/" + path.get_basename().get_file() + ".json", File.WRITE)
file.store_string(JSON.print(dict, " "))
file.store_string(JSON.stringify(dict, " "))
file.close()"""

func map_xml_content(dict: Dictionary, root_path: String):
Expand Down Expand Up @@ -57,7 +57,7 @@ func expand_file_path(path: String, root_path: String):
path = FileUtils.get_home_dir() + path.substr(1)
var back_idx = path.find("..")
while back_idx != -1:
var slash = path.substr(0, back_idx-1).find_last("/")
var slash = path.substr(0, back_idx-1).rfind("/")
assert(slash != -1)
path = path.substr(0, slash) + path.substr(back_idx+2)
back_idx = path.find("..")
Expand Down
6 changes: 3 additions & 3 deletions XML2JSON.gd
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static func _parse_xml(xml_raw: XMLParser, skip: bool = false) -> Dictionary:
if element_begin:
element_begin = false
_add_child_to_dict(ret, element_name, _parse_xml(xml_raw, true))
if not element_attr.empty():
if not element_attr.is_empty():
_get_child_from_dict(ret, element_name)["#attributes"] = element_attr
else:
element_begin = true
Expand Down Expand Up @@ -159,7 +159,7 @@ static func _parse_xml(xml_raw: XMLParser, skip: bool = false) -> Dictionary:
if element_begin:
element_begin = false
_add_child_to_dict(ret, element_name, _parse_xml(xml_raw, true))
if not element_attr.empty():
if not element_attr.is_empty():
_get_child_from_dict(ret, element_name)["#attributes"] = element_attr
else:
_add_child_to_dict(ret, "#comment", xml_raw.get_node_name())
Expand All @@ -185,4 +185,4 @@ static func _get_child_from_dict(dict: Dictionary, key: String):

# Internal, don't use
static func _is_text_empty(s: String):
return s.strip_edges().strip_escapes().empty()
return s.strip_edges().strip_escapes().is_empty()
Loading

0 comments on commit 841587d

Please sign in to comment.