Skip to content

Commit

Permalink
Migration tool (#246)
Browse files Browse the repository at this point in the history
* add initial migration framework support

* update files to have less then 100 characters

* in progress work pushed for others to look at

* Migration tool for Popochiu release.

Change spaces to tabs

Progress on formating code

Refactor some code to make it cleaner

Create migration scripts for new migration steps

- Migration 2 is intended to update changes between beta 1 and beta 2 to
beta 3.
- Migration 3 is intended to update changes between beta 3 to 2.0
release.
- **upd** Minor refactor of the PopochiuMigration class.

Finish code for PopochiuMigration1

This allows to update the project structure and file/folder naming from
versions prior to Beta 1.

It also assigns the SimpleClick as the default GUI template.

- **upd** Setup popup resizes each time a template button is clicked.

Add PopochiuCharacter voices update

Progress on making a Popup window to show the migration progress.

Fix scene linking in Props created in alpha 1

Assign script for non clickable props (which didn't have one prior to
beta 1).

- **upd** Migration 1 also updates the radius of WalkableArea's
Perimeter node.

Update prop update task to store interaction polygon's polygon

Refactor code to take into account Hotspots and Regions.

Update props and hotspots in Migration 1

Finish migration of PopochiuRegion and PopochiuWalkableArea objects

Replace calls to old methods in scripts.

Add Migrations popup to show migration progress

Closing the Migrations popup will restart the engine.

Update InventoryItem root nodes to PascalCase

Update visual style of Migrations popup.

Finish Migration 1 with node additions to PopochiuCharacter

Now this migration doesn't stops if the `res://popochiu/` folder doesn't
exists in the project.
- **fea** AnimationPlayer and ScalingPolygon nodes are added to
PopochiuCharacter scenes if needed.
- **upd** Refactor code to make it simplier and clearer.
- **upd** Now MigrationTab shows the steps and the migration progress
using CheckBox buttons instead of BBcode.

Update the way migrations notify their steps completion

Now a migration step can be completed as: FAILED, DONE or IGNORED

- **upd** Ignored migration steps are rendered different in the
Migrations dialog.
- **fix** Check if a PopochiuProp or PopochiuHotspot has an
InteractionPolygon or InteractionPolygon2 node before trying to store
its `polygon` property.

Progress on improving Migration 1 behavior for projects in beta

Can run Migration 1 in projects made in beta-3

A new function was added to **PopochiuUtils** in order to perform an
improved `Array.any()` that doesn't stops early.

- **fix** Don't update `PopochiuClickable.interaction_polygon` value if
the object already has a scene with an **InteractionPolygon** child.

Start coding for Migration 2

Now the process of adding the ScalingPolygon node to PopochiuCharacters
is done by Migration 2.

- **upd** Rename Migrations to MigrationsPanel for better understanding.
- **upd** Add comments to some functions in PopochiuMigrationHelper.
- **upd** Add constants and sample code to
popochiu_migration_template.gd.

Fix on checking if migrations are needed

The version in PopochiuMigrationHelper is no longer needed since we're
gonna take into account the number of files (migrations) in the
migration_files folder.

- **upd** Migration 2 first step working.

Make each migration to ask for an Engine reload

Instead of assuming an Engine reload is required each time a Migration
is executed, each Migration can set to `true` the
`PopochiuMigrationHelper.is_reload_required` property in order to make
the popup restart the Engine when clicking OK.

Progress on fixing and improving Migration 1

Moving values from old popochiu_settings.tres to Project Settings will
need extra steps since the PopochiuSettings script changed since beta-3.

Fix PopochiuSettings issue for Migration 2

Migration 1 now iterates through all possible children of each group to
obtain objects of that type, instead of assuming that each group only
has children of its specific type (e.g., if there are props grouped
within a node).

Migration 2 deletes helper nodes in PopochiuClickables

Update Migration 2 with changes done to SettingsBar

In beta-3 the SettingsBar GUI component changed to improve how the text
speed options are defined.

- **fix** Ignore room objects that already have a scene and a script in
the step that updates the room in Migration 1 so devs don't lose their
changes.

Add step to update DialogMenu component in Migration 2

Add code update step for deprecated properties and methods

Add step to update properties from the old popochiu_settings.tres into
InventoryBar and SettingsBar GUI components.

Fix on deprecated camera functions replacement

Calls to functions in PopochiuMainCamera changed their names compared to
those used before in the **E** autoload.

- **fix** On moving inventory items on start from old
popochiu_settings.tres to Popochiu Project Settings.
- **upd** Inventory items on start are now stored as an array of String
in Project Settings.

Create Markers scenes in Migration 1

Update Migrations process to be started by the user

Instead of triggering the migrations automatically, the Migrations popup
asks devs to start the migrations by pressing the Run migrations button.

- **fix** Updating room objects wasn't working properly due to an issue
in Godot when appending elements to an Array inside a Dictionary.

Fix an issue found when running migration 2 in Alpha projects

- **upd** Execution pauses in popochiu_plugin.gd if Migrations are
required until dev run the migrations.
- **fix** Other issues found when running migrations in alpha projects
after adding Migration 2.

Update Migration 1 and 2 related to PopochiuCharacter

In Migration 1, now the "Sprite2D:texture" track is removed from
AnimationPlayer nodes (something that affected characters imported from
Aseprite prior Beta 1). In Migration 2 the coordinates of the
**DialogPos** node are stored in the `dialog_pos` property before
deleting the node.

- **fix** Enable the Remove button in Room objects context menu in Room
tab.

Fix issue after snake_case renaming

Changing file and folder names in the snake_case renaming process
required to update the references to the new names inside .gd, .tscn,
.tres, and .cfg files.

Restore code that shows the confirmation dialog in Setup popup

- **upd** Rename function to more descriptive name.

Fix PopochiuDialog deletion (after refactor)

Update Migration 2 to take into account the changes made to autoloads
after refactor

Fix setting PC character in Create character popup

Improve visual feedback of migrations progress

- **fix** Closing the Migrations tool popup doesn't stops the execution
in `popochiu_plugin.gd`.

* Remove not needed nodes in PopochiuRegion and PopochiuWalkableArea

This is because in the release version these objects won't need a node
in the room to define their InteractionPolygon and Perimeter nodes.

- **upd** Remove the old DialogPos node in PopochiuCharacter and store
its position in the new `@export var dialog_pos` property.

* Add check for lacking nodes in room objects

Ignore "graphic_interface" folder in code updates for Migration 1.

* Fix for WalkableAreas not working until room save

- **fix** Send `hint_string` parameter when creating settings in
  config.gd.
- **upd** Minor refactor in **PopochiuWalkableArea** to avoid duplicated
  code.

* Apply suggestions from code review

Co-authored-by: Paolo Pustorino <[email protected]>

* Make changes based in PR comments

* Enable gizmos plugin when Popochiu dock is ready

This happens only if the plugin is not already enabled.

- **upd** Add comments to some functions with the help of Copilot.

* Add lacking comments to Migration 2 functions

* Check custom script in Room object

If a room object created during migration has a script attached that is not in
the "addons" folder, assume it is a custom script and copy its
properties to the new instance of the object.

* Add comments for better understanding

Co-authored-by: Paolo Pustorino <[email protected]>

* Fix getting custom vars in walkable area

- **upd** Add a $Sprite2D check in PopochiuProp.
- **upd** Set specific steps in Migration 1 to ask for an engine
  restart.

* Fix polygon assignation when adding nodes to Walkable Area

- **fix** Change code order to first assign custom script properties on
  Migration 1.

* Move room objects update to Migration 2

- **upd** Add validation to ignore Migration 1 in project done since
  beta 1.

---------

Co-authored-by: Anthony Irwin <[email protected]>
Co-authored-by: Paolo Pustorino <[email protected]>
  • Loading branch information
3 people authored Aug 1, 2024
1 parent 39af850 commit d45d954
Show file tree
Hide file tree
Showing 51 changed files with 3,258 additions and 239 deletions.
20 changes: 10 additions & 10 deletions addons/popochiu/editor/config/config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const SKIP_CUTSCENE_TIME = "popochiu/gui/skip_cutscene_time"
const TEXT_SPEED = "popochiu/dialogs/text_speed"
const AUTO_CONTINUE_TEXT = "popochiu/dialogs/auto_continue_text"
const USE_TRANSLATIONS = "popochiu/dialogs/use_translations"
const DIALOG_STYLE = "popochiu/gui/dialog_style"
const DIALOG_STYLE = "popochiu/dialogs/dialog_style"

# ---- Inventory -----------------------------------------------------------------------------------
const INVENTORY_LIMIT = "popochiu/inventory/inventory_limit"
Expand Down Expand Up @@ -99,7 +99,7 @@ static func initialize_project_settings():
INVENTORY_ITEMS_ON_START,
TYPE_ARRAY,
PROPERTY_HINT_TYPE_STRING,
"%d/%d:%s" % [TYPE_STRING, PROPERTY_HINT_FILE, "*tscn"]
"%d:" % [TYPE_STRING]
)

# ---- Aseprite Importing ----------------------------------------------------------------------
Expand All @@ -126,6 +126,11 @@ static func initialize_project_settings():
ProjectSettings.save()


static func set_project_setting(key: String, value) -> void:
ProjectSettings.set_setting(key, value)
ProjectSettings.save()


# ---- GUI -----------------------------------------------------------------------------------------
static func is_scale_gui() -> bool:
return _get_project_setting(SCALE_GUI)
Expand Down Expand Up @@ -162,7 +167,7 @@ static func get_inventory_limit() -> int:


static func set_inventory_items_on_start(items: Array) -> void:
_set_project_setting(INVENTORY_ITEMS_ON_START, items)
set_project_setting(INVENTORY_ITEMS_ON_START, items)


static func get_inventory_items_on_start() -> Array:
Expand Down Expand Up @@ -192,7 +197,7 @@ static func is_default_wipe_old_anims_enabled() -> bool:

# ---- Pixel game ----------------------------------------------------------------------------------
static func set_pixel_art_textures(use_pixel_art_textures: bool) -> void:
_set_project_setting(PIXEL_ART_TEXTURES, use_pixel_art_textures)
set_project_setting(PIXEL_ART_TEXTURES, use_pixel_art_textures)


static func is_pixel_art_textures() -> bool:
Expand Down Expand Up @@ -242,7 +247,7 @@ static func _initialize_project_setting(
static func _initialize_advanced_project_setting(
key: String, type: int, hint := PROPERTY_HINT_NONE, hint_string := ""
) -> void:
_create_setting(key, type, hint)
_create_setting(key, type, hint, hint_string)


static func _create_setting(
Expand All @@ -263,9 +268,4 @@ static func _get_project_setting(key: String):
return p if p != null else defaults[key]


static func _set_project_setting(key: String, value) -> void:
ProjectSettings.set_setting(key, value)
ProjectSettings.save()


#endregion
19 changes: 18 additions & 1 deletion addons/popochiu/editor/factories/factory_base_popochiu_obj.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var _path_script := ""
var _type := -1
var _type_label := ""
var _type_target := ""
var _type_method: Callable
# The following variables are references to the elements generated for the creation of the new
# Popochiu object, such as resources, scenes, scripts, state scripts, etc
var _scene: Node
Expand All @@ -34,6 +35,10 @@ func get_obj_scene() -> Node:
return _scene


func get_snake_name() -> String:
return _snake_name


func get_obj_resource() -> Resource:
return _resource

Expand All @@ -45,6 +50,19 @@ func get_state_resource() -> Resource:
func get_obj_script() -> Resource:
return _script


func get_scene_path() -> String:
return _path_scene


func get_type() -> int:
return _type


func get_type_method() -> Callable:
return _type_method


#endregion

#region Private ####################################################################################
Expand Down Expand Up @@ -159,7 +177,6 @@ func _save_obj_scene(obj: Node) -> int:
[_type_label, _path_script]
)
return ResultCodes.ERR_CANT_SAVE_OBJ_SCENE

# Load the scene to be get by the calling code
# Instancing the created .tscn file fixes #58
_scene = (load(_path_scene) as PackedScene).instantiate(PackedScene.GEN_EDIT_STATE_INSTANCE)
Expand Down
46 changes: 46 additions & 0 deletions addons/popochiu/editor/factories/factory_base_popochiu_room_obj.gd
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class_name PopochiuRoomObjFactory
extends "res://addons/popochiu/editor/factories/factory_base_popochiu_obj.gd"

const CHILD_VISIBLE_IN_ROOM_META = "_popochiu_obj_factory_child_visible_in_room_"
Expand All @@ -11,6 +12,32 @@ var _room_path := ""
var _room_dir := ""


#region Public #####################################################################################
func get_group() -> String:
return _obj_room_group


func create_from(node: Node, room: PopochiuRoom) -> int:
_setup_room(room)
_setup_name(node.name)

var param := _get_param(node)
param.room = room
param.obj_name = node.name
param.is_visible = node.visible
param.should_setup_room_and_name = false
param.should_add_to_room = false
param.should_create_script = !FileAccess.file_exists(_path_script)

return call("create", param)


func get_new_instance() -> PopochiuRoomObjFactory:
return new()


#endregion

#region Private ####################################################################################
func _setup_room(room: PopochiuRoom) -> void:
_room = room
Expand Down Expand Up @@ -49,4 +76,23 @@ func _add_resource_to_room() -> void:
EditorInterface.save_scene()


func _get_param(_node: Node) -> PopochiuRoomObjFactoryParam:
return PopochiuRoomObjFactoryParam.new()


#endregion

#region Subclass ###################################################################################
class PopochiuRoomObjFactoryParam extends RefCounted:
var obj_name: String
var room: PopochiuRoom
var is_visible := true
var should_setup_room_and_name := true
var should_create_script := true
var should_add_to_room := true
## Property used to store the vectors stored in the [member CollisionPolygon2D.polygon] for
## [PopochiuProp], [PopochiuHotspot], and [PopochiuRegion].
var interaction_polygon := PackedVector2Array()


#endregion
43 changes: 33 additions & 10 deletions addons/popochiu/editor/factories/factory_popochiu_hostspot.gd
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
class_name PopochiuHotspotFactory
extends "res://addons/popochiu/editor/factories/factory_base_popochiu_room_obj.gd"
extends PopochiuRoomObjFactory


#region Godot ######################################################################################
func _init() -> void:
_type = PopochiuResources.Types.HOTSPOT
_type_label = "hotspot"
_type_method = PopochiuEditorHelper.is_hotspot
_obj_room_group = "Hotspots"
_path_template = "/hotspots/%s/hotspot_%s"


#endregion

#region Public #####################################################################################
func create(obj_name: String, room: PopochiuRoom) -> int:
func create(param: PopochiuHotspotFactoryParam) -> int:
# If everything goes well, this won't change.
var result_code := ResultCodes.SUCCESS

_setup_room(room)
_setup_name(obj_name)

if param.should_setup_room_and_name:
_setup_room(param.room)
_setup_name(param.obj_name)

# Create the folder
result_code = _create_obj_folder()
if result_code != ResultCodes.SUCCESS: return result_code

# Create the script
result_code = _copy_script_template()
if result_code != ResultCodes.SUCCESS: return result_code
if param.should_create_script:
result_code = _copy_script_template()
if result_code != ResultCodes.SUCCESS: return result_code

# ---- LOCAL CODE ------------------------------------------------------------------------------
# Create the instance
Expand All @@ -38,16 +41,36 @@ func create(obj_name: String, room: PopochiuRoom) -> int:
new_obj.script_name = _pascal_name
new_obj.description = _snake_name.capitalize()
new_obj.cursor = PopochiuResources.CURSOR_TYPE.ACTIVE
new_obj.interaction_polygon = param.interaction_polygon

# Save the hostspot scene (.tscn) and put it into _scene class property
result_code = _save_obj_scene(new_obj)
if result_code != ResultCodes.SUCCESS: return result_code
# ---- END OF LOCAL CODE -----------------------------------------------------------------------

# Add the object to its room
_add_resource_to_room()

if param.should_add_to_room:
# Add the object to its room
_add_resource_to_room()

return result_code


#endregion

#region Private ####################################################################################
func _get_param(node: Node) -> PopochiuRoomObjFactoryParam:
var param := PopochiuHotspotFactoryParam.new()
param.is_interactive = node.clickable
# TODO: Remove this line once the last gizmos PR is merged
param.interaction_polygon = node.interaction_polygon
return param


#endregion

#region Subclass ###################################################################################
class PopochiuHotspotFactoryParam extends PopochiuRoomObjFactory.PopochiuRoomObjFactoryParam:
var is_interactive := true


#endregion
19 changes: 11 additions & 8 deletions addons/popochiu/editor/factories/factory_popochiu_marker.gd
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
class_name PopochiuMarkerFactory
extends "res://addons/popochiu/editor/factories/factory_base_popochiu_room_obj.gd"
extends PopochiuRoomObjFactory

#region Godot ######################################################################################
func _init() -> void:
_type = PopochiuResources.Types.MARKER
_type_label = "marker"
_type_method = PopochiuEditorHelper.is_marker
_obj_room_group = "Markers"
_path_template = "/markers/%s/marker_%s"


#endregion
#region Public #####################################################################################
func create(obj_name: String, room: PopochiuRoom) -> int:
func create(param: PopochiuRoomObjFactoryParam) -> int:
# If everything goes well, this won't change.
var result_code := ResultCodes.SUCCESS

_setup_room(room)
_setup_name(obj_name)

if param.should_setup_room_and_name:
_setup_room(param.room)
_setup_name(param.obj_name)

# Create the folder
result_code = _create_obj_folder()
Expand All @@ -31,9 +33,10 @@ func create(obj_name: String, room: PopochiuRoom) -> int:
result_code = _save_obj_scene(new_obj)
if result_code != ResultCodes.SUCCESS: return result_code
# ---- END OF LOCAL CODE -----------------------------------------------------------------------

# Add the object to its room
_add_resource_to_room()

if param.should_add_to_room:
# Add the object to its room
_add_resource_to_room()

return result_code

Expand Down
49 changes: 35 additions & 14 deletions addons/popochiu/editor/factories/factory_popochiu_prop.gd
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
class_name PopochiuPropFactory
extends "res://addons/popochiu/editor/factories/factory_base_popochiu_room_obj.gd"
extends PopochiuRoomObjFactory


#region Godot ######################################################################################
func _init() -> void:
_type = PopochiuResources.Types.PROP
_type_label = "prop"
_type_method = PopochiuEditorHelper.is_prop
_obj_room_group = "Props"
_path_template = "/props/%s/prop_%s"


#endregion

#region Public #####################################################################################
func create(
obj_name: String, room: PopochiuRoom, is_interactive:bool = false, is_visible:bool = true
) -> int:
func create(param: PopochiuPropFactoryParam) -> int:
# If everything goes well, this won't change.
var result_code := ResultCodes.SUCCESS

_setup_room(room)
_setup_name(obj_name)

if param.should_setup_room_and_name:
_setup_room(param.room)
_setup_name(param.obj_name)

# Create the folder
result_code = _create_obj_folder()
if result_code != ResultCodes.SUCCESS: return result_code

# Create the script (if the prop is interactive)
result_code = _copy_script_template()
if result_code != ResultCodes.SUCCESS: return result_code
if param.should_create_script:
result_code = _copy_script_template()
if result_code != ResultCodes.SUCCESS: return result_code

# ---- LOCAL CODE ------------------------------------------------------------------------------
# Create the instance
Expand All @@ -40,8 +41,9 @@ func create(
new_obj.script_name = _pascal_name
new_obj.description = _snake_name.capitalize()
new_obj.cursor = PopochiuResources.CURSOR_TYPE.ACTIVE
new_obj.clickable = is_interactive
new_obj.visible = is_visible
new_obj.clickable = param.is_interactive
new_obj.visible = param.is_visible
new_obj.interaction_polygon = param.interaction_polygon

if PopochiuConfig.is_pixel_art_textures():
new_obj.get_node("Sprite2D").texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
Expand All @@ -55,11 +57,30 @@ func create(
result_code = _save_obj_scene(new_obj)
if result_code != ResultCodes.SUCCESS: return result_code
# ---- END OF LOCAL CODE -----------------------------------------------------------------------

if param.should_add_to_room:
# Add the object to its room
_add_resource_to_room()

return result_code

# Add the object to its room
_add_resource_to_room()

return result_code
#endregion

#region Private ####################################################################################
func _get_param(node: Node) -> PopochiuRoomObjFactoryParam:
var param := PopochiuPropFactoryParam.new()
param.is_interactive = node.clickable
# TODO: Remove this line once the last gizmos PR is merged
param.interaction_polygon = node.interaction_polygon
return param


#endregion

#region Subclass ###################################################################################
class PopochiuPropFactoryParam extends PopochiuRoomObjFactory.PopochiuRoomObjFactoryParam:
var is_interactive := false


#endregion
Loading

0 comments on commit d45d954

Please sign in to comment.