Skip to content

Commit

Permalink
Fix Array Validation and Casting (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelipemartins authored Oct 1, 2023
1 parent 22f2558 commit 56f1c54
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
7 changes: 6 additions & 1 deletion addons/pandora/ui/components/array_editor/array_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ func close():

func is_empty(item: Variant):
var array_type = _property.get_setting(ArrayType.SETTING_ARRAY_TYPE)
if array_type == 'reference' or array_type == 'resource':
if array_type == 'reference':
return item == null
if array_type == 'resource':
return is_instance_valid(item) == false
elif array_type == 'string':
return item == ""
Expand Down Expand Up @@ -67,6 +69,9 @@ func _load_items():
var value = _items[i]
if array_type == 'resource':
value = load(value)
elif array_type == 'reference':
if value is Dictionary:
value = Pandora.get_entity(value["_entity_id"])
item_property.set_default_value(value)
_add_property_control(control, item_property, i)

Expand Down
38 changes: 38 additions & 0 deletions test/ui/components/array_editor/array_editor_test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,41 @@ func test_array_window_opening() -> void:
scene.array_window._on_close_requested()

await assert_signal(signal_monitor).wait_until(500).is_emitted('about_to_popup')

func test_create_reference_array() -> void:
var root = Pandora.create_category("Root")
var items = Pandora.create_category("Items", root)
var item = Pandora.create_entity("Item 1", items)
var npcs = Pandora.create_category("NPCs", root)
var items_prop: PandoraProperty = Pandora.create_property(npcs, "Items", "array")
items_prop.set_setting_override("Array Type", "reference")
var npc = Pandora.create_entity("Npc 1", npcs)
items_prop.set_setting_override("Array Type", "reference")
items_prop.set_setting_override("Category Filter", items.get_entity_id())
var ref = PandoraReference.new(item.get_entity_id(), PandoraReference.Type.ENTITY).save_data()
npc.get_entity_property("Items").set_default_value([ref])

Pandora.save_data()
Pandora._clear()
Pandora.load_data()

var scene = auto_free(load(__source).instantiate())
var runner = scene_runner(scene)
var signal_monitor = monitor_signals(scene.array_window)
await runner.simulate_frames(1)

scene.set_property(npc.get_entity_property("Items"))

await runner.simulate_frames(10, 5)

runner.set_mouse_pos(scene.edit_button.position + Vector2(10, 10))
runner.simulate_mouse_button_pressed(MOUSE_BUTTON_LEFT)

await runner.simulate_frames(10, 5)

runner.set_mouse_pos(scene.array_window.array_manager.close_button.position + Vector2(10, 10))
runner.simulate_mouse_button_pressed(MOUSE_BUTTON_LEFT)

scene.array_window._on_close_requested()

await assert_signal(signal_monitor).wait_until(500).is_not_emitted('item_removed', [ref])

0 comments on commit 56f1c54

Please sign in to comment.