summaryrefslogtreecommitdiff
path: root/addons/escoria-core/editor
diff options
context:
space:
mode:
Diffstat (limited to 'addons/escoria-core/editor')
-rw-r--r--addons/escoria-core/editor/migration_4_6_4_7/acceptdialog_migrate_4_6_4_7.gd80
-rw-r--r--addons/escoria-core/editor/migration_4_6_4_7/acceptdialog_migrate_4_6_4_7.gd.uid1
-rw-r--r--addons/escoria-core/editor/migration_4_6_4_7/acceptdialog_migrate_4_6_4_7.tscn57
-rw-r--r--addons/escoria-core/editor/migration_4_6_4_7/migrator_4_6_4_7.gd107
-rw-r--r--addons/escoria-core/editor/migration_4_6_4_7/migrator_4_6_4_7.gd.uid1
5 files changed, 246 insertions, 0 deletions
diff --git a/addons/escoria-core/editor/migration_4_6_4_7/acceptdialog_migrate_4_6_4_7.gd b/addons/escoria-core/editor/migration_4_6_4_7/acceptdialog_migrate_4_6_4_7.gd
new file mode 100644
index 0000000..d89519d
--- /dev/null
+++ b/addons/escoria-core/editor/migration_4_6_4_7/acceptdialog_migrate_4_6_4_7.gd
@@ -0,0 +1,80 @@
+@tool
+class_name AcceptDialogMigrate4647
+extends Window
+
+signal confirmed
+signal canceled
+
+var migrator: Migrator4647
+var required_migration: bool = false
+
+@onready var label: Label = $FlowContainer/Label
+@onready var mark_this_as_done: CheckButton = $FlowContainer/mark_this_as_done
+@onready var confirm_button: Button = $FlowContainer/HBoxContainer/confirm
+@onready var cancel_button: Button = $FlowContainer/HBoxContainer/cancel
+
+
+func _ready() -> void:
+ migrator = Migrator4647.new()
+ var action: Migrator4647.MigrationAction = migrator.check_need_upgrade_or_downgrade_scripts()
+ match action:
+ Migrator4647.MigrationAction.UPGRADE_4_7:
+ title = "Auto-upgrade Escoria-core scripts for Godot Engine 4.7.x"
+ label.text = \
+"""The version of Godot Engine you appear to be running is newer
+than the one this version of Escoria relies on (4.6.x) or this is the first time
+you run this version of Escoria.\n
+Godot Engine 4.6 and 4.7 APIs have some differences in methods that Escoria makes use of.
+Escoria can now automatically revert its impacted core scripts to makes them compatible
+with Godot Engine 4.7.\n
+Here is the list of the impacted files:
+- res://addons/escoria-core/game/core-scripts/esc_item.gd\n
+⚠️IMPORTANT⚠️: the editor will restart after this action is done.\n
+If you wish to let Escoria proceed, choose 'OK'.
+If you wish to upgrade to a newer version of Godot, choose 'Cancel'.
+If you have edited these files for your own needs, you'll need to manually fix them:
+choose 'Cancel' (see README; existing files will be backuped anyway)."""
+ required_migration = true
+ Migrator4647.MigrationAction.DOWNGRADE_4_6:
+ title = "Auto-downgrade Escoria-core scripts for Godot Engine 4.6.x"
+ label.text = \
+"""The version of Godot Engine you appear to be running is older
+than the one this version of Escoria relies on (4.7.x) or this is the first time
+you run this version of Escoria.\n
+Godot Engine 4.6 and 4.7 APIs have some differences in methods that Escoria makes use of.
+Escoria can now automatically revert its impacted core scripts to makes them compatible
+with Godot Engine 4.6.\n
+Here is the list of the impacted files:
+- res://addons/escoria-core/game/core-scripts/esc_item.gd\n
+⚠️IMPORTANT⚠️: the editor will restart after this action is done.\n
+If you wish to let Escoria proceed, choose 'OK' (a backup of the existing file will be created).
+If you wish to upgrade to a newer version of Godot, choose 'Cancel' (nothing will be done,
+but this tool will happen next time you open the editor).
+If you have edited these files for your own needs, you'll need to manually fix them:
+choose 'Cancel' (see README; existing files will be backuped anyway)."""
+ required_migration = true
+
+ _:
+ required_migration = false
+
+
+func _on_confirm_pressed() -> void:
+ if mark_this_as_done.button_pressed:
+ await migrator.save_migration_file($FlowContainer/mark_this_as_done.button_pressed)
+ else:
+ migrator.prepare_specific_godot_version(Engine.get_version_info().hex)
+ confirmed.emit()
+ hide()
+
+
+func _on_cancel_pressed() -> void:
+ await migrator.save_migration_file($FlowContainer/mark_this_as_done.button_pressed)
+ canceled.emit()
+ hide()
+
+
+func _on_mark_this_as_done_toggled(toggled_on: bool) -> void:
+ if toggled_on:
+ cancel_button.hide()
+ else:
+ cancel_button.show()
diff --git a/addons/escoria-core/editor/migration_4_6_4_7/acceptdialog_migrate_4_6_4_7.gd.uid b/addons/escoria-core/editor/migration_4_6_4_7/acceptdialog_migrate_4_6_4_7.gd.uid
new file mode 100644
index 0000000..2cf55d3
--- /dev/null
+++ b/addons/escoria-core/editor/migration_4_6_4_7/acceptdialog_migrate_4_6_4_7.gd.uid
@@ -0,0 +1 @@
+uid://cxx10dv5352wk
diff --git a/addons/escoria-core/editor/migration_4_6_4_7/acceptdialog_migrate_4_6_4_7.tscn b/addons/escoria-core/editor/migration_4_6_4_7/acceptdialog_migrate_4_6_4_7.tscn
new file mode 100644
index 0000000..128c980
--- /dev/null
+++ b/addons/escoria-core/editor/migration_4_6_4_7/acceptdialog_migrate_4_6_4_7.tscn
@@ -0,0 +1,57 @@
+[gd_scene format=3 uid="uid://ydte1xndp6p1"]
+
+[ext_resource type="Script" uid="uid://cxx10dv5352wk" path="res://addons/escoria-core/editor/migration_4_6_4_7/acceptdialog_migrate_4_6_4_7.gd" id="1_ogeh4"]
+
+[node name="AcceptDialogMigrate4647" type="Window" unique_id=1453257784]
+oversampling_override = 1.0
+position = Vector2i(0, 36)
+size = Vector2i(720, 530)
+script = ExtResource("1_ogeh4")
+
+[node name="FlowContainer" type="VBoxContainer" parent="." unique_id=726240657]
+offset_left = 8.0
+offset_top = 8.0
+offset_right = 712.0
+offset_bottom = 517.0
+
+[node name="Label" type="Label" parent="FlowContainer" unique_id=1668065635]
+layout_mode = 2
+text = "The version of Godot Engine you appear to be running is older
+ than the one this version of Escoria relies on (4.7.x) or this is the first time
+ you run this version of Escoria.
+
+ Godot Engine 4.6 and 4.7 APIs have some differences in methods that Escoria makes use of.
+ Escoria can now automatically revert its impacted core scripts to makes them compatible
+ with Godot Engine 4.6.
+
+ Here is the list of the impacted files:
+ - res://addons/escoria-core/game/core-scripts/esc_item.gd
+
+ ⚠️IMPORTANT⚠️: the editor will restart after this action is done.
+
+ If you wish to let Escoria proceed, choose 'OK'.
+ If you wish to upgrade to a newer version of Godot, choose 'Cancel'.
+ If you have edited these files for your own needs, you'll need to manually fix them:
+ choose 'Cancel' (see README; existing files will be backuped anyway)."
+autowrap_mode = 3
+
+[node name="mark_this_as_done" type="CheckButton" parent="FlowContainer" unique_id=99402283]
+layout_mode = 2
+text = "Mark this as already done"
+
+[node name="HBoxContainer" type="HBoxContainer" parent="FlowContainer" unique_id=1123299495]
+layout_mode = 2
+theme_override_constants/separation = 55
+alignment = 1
+
+[node name="confirm" type="Button" parent="FlowContainer/HBoxContainer" unique_id=1563226882]
+layout_mode = 2
+text = "Ok"
+
+[node name="cancel" type="Button" parent="FlowContainer/HBoxContainer" unique_id=2075346076]
+layout_mode = 2
+text = "Cancel"
+
+[connection signal="toggled" from="FlowContainer/mark_this_as_done" to="." method="_on_mark_this_as_done_toggled"]
+[connection signal="pressed" from="FlowContainer/HBoxContainer/confirm" to="." method="_on_confirm_pressed"]
+[connection signal="pressed" from="FlowContainer/HBoxContainer/cancel" to="." method="_on_cancel_pressed"]
diff --git a/addons/escoria-core/editor/migration_4_6_4_7/migrator_4_6_4_7.gd b/addons/escoria-core/editor/migration_4_6_4_7/migrator_4_6_4_7.gd
new file mode 100644
index 0000000..45e480a
--- /dev/null
+++ b/addons/escoria-core/editor/migration_4_6_4_7/migrator_4_6_4_7.gd
@@ -0,0 +1,107 @@
+class_name Migrator4647
+extends Node
+
+enum MigrationAction {
+ UPGRADE_4_7,
+ DOWNGRADE_4_6,
+ DO_NOTHING
+}
+
+const MIGRATION_DONE = "migration_done"
+const GODOT_4_7_HEX = 0x040700
+
+
+func check_need_upgrade_or_downgrade_scripts(engine_version: Dictionary = Engine.get_version_info()) -> MigrationAction:
+ var data: Dictionary = read_migration_file()
+ var current_version_hex: int = engine_version["hex"]
+ var current_is_4_7_or_newer: bool = current_version_hex >= GODOT_4_7_HEX
+ if data.is_empty(): # No existing file : initiate migration
+ if current_is_4_7_or_newer:
+ return MigrationAction.UPGRADE_4_7
+ return MigrationAction.DOWNGRADE_4_6
+
+ if not data[MIGRATION_DONE]:
+ if data["last_engine_version_hex"] >= GODOT_4_7_HEX:
+ return MigrationAction.UPGRADE_4_7
+ return MigrationAction.DOWNGRADE_4_6
+
+ var last_migration_version = data["last_engine_version_hex"]
+ var last_is_4_7_or_newer: bool = last_migration_version >= GODOT_4_7_HEX
+ if last_is_4_7_or_newer == current_is_4_7_or_newer:
+ return MigrationAction.DO_NOTHING
+ if last_is_4_7_or_newer:
+ return MigrationAction.DOWNGRADE_4_6
+ return MigrationAction.UPGRADE_4_7
+
+
+func prepare_specific_godot_version(target_hex: int) -> void:
+ var dir = DirAccess.open("res://addons/escoria-core/game/core-scripts/")
+ print("Preparing Escoria for Godot version %s" % [target_hex])
+ if dir == null:
+ print("Failed opening folder res://addons/escoria-core/game/core-scripts/")
+ return
+
+ # Backup existing files, just in case they were edited by gamedev (and so, different from
+ # origin).
+ var datetime: String = Time.get_datetime_string_from_system().replace(":", ".")
+ var res: Error = dir.copy(
+ "res://addons/escoria-core/game/core-scripts/esc_item.gd",
+ "res://addons/escoria-core/game/core-scripts/pre-4.7/esc_item.gd.%s.bak" % datetime
+ )
+ if res != OK:
+ print("Failed backup of existing file res://addons/escoria-core/game/core-scripts/esc_item.gd")
+ return
+
+ # Then remove
+ res = dir.remove("res://addons/escoria-core/game/core-scripts/esc_item.gd")
+ if res != OK:
+ print("Failed removing file res://addons/escoria-core/game/core-scripts/esc_item.gd")
+ return
+
+ if target_hex < GODOT_4_7_HEX: # < 4.7.0
+ # Copy 4.6 files
+ res = DirAccess.copy_absolute(
+ "res://addons/escoria-core/game/core-scripts/pre-4.7/esc_item.4.6.gd",
+ "res://addons/escoria-core/game/core-scripts/esc_item.gd"
+ )
+ if res != OK:
+ print("Failed copying file res://addons/escoria-core/game/core-scripts/pre-4.7/esc_item.4.6.gd")
+ return
+ else: # >= 4.7.x
+ # Copy 4.7 files
+ res = DirAccess.copy_absolute(
+ "res://addons/escoria-core/game/core-scripts/pre-4.7/esc_item.4.7.gd",
+ "res://addons/escoria-core/game/core-scripts/esc_item.gd"
+ )
+ if res != OK:
+ print("Failed copying file res://addons/escoria-core/game/core-scripts/pre-4.7/esc_item.4.7.gd")
+ return
+
+ # Lastly, store the last used engine version in a file
+ save_migration_file(true)
+
+ EditorInterface.restart_editor()
+
+
+func save_migration_file(migration_done: bool):
+ var new_last_version_used_file = FileAccess.open("res://addons/escoria-core/game/core-scripts/pre-4.7/last_version_used.json", FileAccess.WRITE)
+ var version = Engine.get_version_info()
+ var data: Dictionary = {
+ "last_engine_version": version.string,
+ "last_engine_version_hex": version.hex,
+ "migration_done": migration_done
+ }
+ new_last_version_used_file.store_string(JSON.stringify(data))
+ new_last_version_used_file.close()
+
+
+func read_migration_file() -> Dictionary:
+ var new_last_version_used_file = FileAccess.open("res://addons/escoria-core/game/core-scripts/pre-4.7/last_version_used.json", FileAccess.READ)
+ if new_last_version_used_file == null:
+ return {}
+ var parsed: Variant = JSON.parse_string(new_last_version_used_file.get_as_text())
+ new_last_version_used_file.close()
+ if not (parsed is Dictionary):
+ push_error("Error reading file res://addons/escoria-core/game/core-scripts/pre-4.7/last_version_used.json")
+ return {}
+ return parsed
diff --git a/addons/escoria-core/editor/migration_4_6_4_7/migrator_4_6_4_7.gd.uid b/addons/escoria-core/editor/migration_4_6_4_7/migrator_4_6_4_7.gd.uid
new file mode 100644
index 0000000..e2eb44a
--- /dev/null
+++ b/addons/escoria-core/editor/migration_4_6_4_7/migrator_4_6_4_7.gd.uid
@@ -0,0 +1 @@
+uid://rdo2ddvl7csi