Skip to content

Commit

Permalink
Fixes for post-import error message (#126)
Browse files Browse the repository at this point in the history
* Fix Output error after importing room

* Fix error message after closing room import popup

The problem was caused because the popup was being added to the Room
tree. Now it is added to Popochiu's main dock.

* Temporary fix for bad row naming after import

* Imported prop image is placed in the prop's folder
  • Loading branch information
mapedorr authored Dec 13, 2023
1 parent a7ab2b2 commit 51736d7
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
5 changes: 4 additions & 1 deletion addons/popochiu/editor/factories/factory_popochiu_prop.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ class_name PopochiuPropFactory
# ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ PUBLIC ░░░░
func _init(_main_dock: Panel) -> void:
super(_main_dock)

_type = Constants.Types.PROP
_type_label = 'prop'
_obj_room_group = 'Props'
_path_template = '/props/%s/prop_%s'


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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func _load_config(cfg):

func _save_config():
_update_tags_cache()

var cfg := {
"source": _source,
"tags": _tags_cache,
Expand Down Expand Up @@ -172,15 +173,15 @@ func _on_rescan_pressed():
func _on_import_pressed():
if _importing:
return

_importing = true

_root_node = get_tree().get_edited_scene_root()

if _source == "":
_show_message("Aseprite file not selected")
_importing = false
return

_options = {
"source": ProjectSettings.globalize_path(_source),
"tags": _tags_cache,
Expand All @@ -191,7 +192,7 @@ func _on_import_pressed():
"only_visible_layers": get_node('%VisibleLayersCheckButton').is_pressed(),
"wipe_old_animations": get_node('%WipeOldAnimationsCheckButton').is_pressed(),
}

_save_config()


Expand Down Expand Up @@ -260,6 +261,7 @@ func _empty_tags_container():
get_node('%Tags').remove_child(tl)
tl.queue_free()


func _update_tags_cache():
_tags_cache = _get_tags_from_ui()

Expand Down Expand Up @@ -309,22 +311,24 @@ func _show_message(
message: String, title: String = "", object: Object = null, method := ""
):
var _warning_dialog = AcceptDialog.new()
get_parent().add_child(_warning_dialog)

if title != "":
_warning_dialog.title = title

_warning_dialog.dialog_text = message
_warning_dialog.popup_window = true
_warning_dialog.popup_centered()

var callback := Callable(_warning_dialog, "queue_free")

if is_instance_valid(object) and not method.is_empty():
callback = func():
_warning_dialog.queue_free()
object.call_deferred(method)
object.call(method)

_warning_dialog.confirmed.connect(callback)
_warning_dialog.close_requested.connect(callback)

main_dock.add_child(_warning_dialog)
_warning_dialog.popup_centered()


func _show_confirmation(message: String, title: String = ""):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func _on_import_pressed():
if not prop.has_meta("ANIM_NAME"): continue
# TODO: check if animation player exists in prop, if not add it
# same for Sprite2D even if it should be there...

# Make the output folder match the prop's folder
_options.output_folder = prop.scene_file_path.get_base_dir()

# Import a single tag animation
result = await _animation_creator.create_prop_animations(
prop,
Expand All @@ -70,6 +74,7 @@ func _on_import_pressed():
_show_message("Some errors occurred. Please check output panel.", "Warning!")
else:
await get_tree().create_timer(0.1).timeout

# Once the popup is closed, call _clean_props()
_show_message(
"%d animation tags processed." % [_tags_cache.size()],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
extends EditorInspectorPlugin ## TODO: create a base class with pointer variables

const INSPECTOR_DOCK = preload("res://addons/popochiu/editor/importers/aseprite/docks/aseprite_importer_inspector_dock.tscn")
const DOCKS_PATH := "res://addons/popochiu/editor/importers/aseprite/docks/"
const INSPECTOR_DOCK = preload(DOCKS_PATH + "aseprite_importer_inspector_dock.tscn")
const CONFIG_SCRIPT = preload("res://addons/popochiu/editor/config/config.gd")
const INSPECTOR_DOCK_CHARACTER := DOCKS_PATH + "aseprite_importer_inspector_dock_character.gd"
const INSPECTOR_DOCK_ROOM := DOCKS_PATH + "aseprite_importer_inspector_dock_room.gd"


var ei: EditorInterface
Expand All @@ -21,16 +24,17 @@ func _can_handle(object):
func _parse_begin(object):
_target_node = object


func _parse_category(object, category):
if category == 'Aseprite':
# Instanciate and configure the dock
var dock = INSPECTOR_DOCK.instantiate()

# Load the specific script in the dock
if object is PopochiuCharacter:
dock.set_script(load("res://addons/popochiu/editor/importers/aseprite/docks/aseprite_importer_inspector_dock_character.gd"))
dock.set_script(load(INSPECTOR_DOCK_CHARACTER))
if object is PopochiuRoom:
dock.set_script(load("res://addons/popochiu/editor/importers/aseprite/docks/aseprite_importer_inspector_dock_room.gd"))
dock.set_script(load(INSPECTOR_DOCK_ROOM))

dock.target_node = object
dock.config = config
Expand Down
7 changes: 7 additions & 0 deletions addons/popochiu/editor/main_dock/tab_room.gd
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,14 @@ func scene_changed(scene_root: Node) -> void:
var row: PopochiuObjectRow = _create_object_row(
t, c.name, row_path, node_path
)

_types[t].group.add(row)

# NOTE: Temporary fix for incorrect row naming after importing
# the props from Aseprite
if row.name != c.name:
row.name = c.name
row._label.text = str(c.name)

if _types[t].has('popup'):
_types[t].popup.room_opened(opened_room)
Expand Down
1 change: 1 addition & 0 deletions popochiu/rooms/house/room_house.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ outlines = Array[PackedVector2Array]([PackedVector2Array(-88, 16, -40, 7, 81, 12

[node name="RoomHouse" type="Node2D"]
script = ExtResource("1_5s51l")
script_name = "House"
popochiu_placeholder = null

[node name="WalkableAreas" type="Node2D" parent="."]
Expand Down

0 comments on commit 51736d7

Please sign in to comment.