2024-04-25 01:22:27 +03:00
|
|
|
extends Node3D
|
|
|
|
|
|
|
|
signal on_select_entity(entity_id)
|
|
|
|
signal on_back()
|
|
|
|
|
2024-04-25 14:19:12 +03:00
|
|
|
const EntityScene = preload ("entity.tscn")
|
2024-04-25 01:22:27 +03:00
|
|
|
|
2024-04-25 14:19:12 +03:00
|
|
|
@onready var entity_container = $FlexContainer3D
|
2024-04-25 01:22:27 +03:00
|
|
|
@onready var pagination = $Pagination3D
|
|
|
|
@onready var back_button = $Button
|
2024-04-26 16:23:18 +03:00
|
|
|
@onready var search_input: Input3D = $Input
|
2024-04-25 01:22:27 +03:00
|
|
|
|
|
|
|
var page = R.state(0)
|
2024-04-25 14:19:12 +03:00
|
|
|
var page_size = 5.0
|
2024-04-25 01:22:27 +03:00
|
|
|
var selected_device = R.state(null)
|
2024-04-26 16:23:18 +03:00
|
|
|
var search = R.state("")
|
2024-04-25 01:22:27 +03:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
var entities = R.computed(func(_arg):
|
|
|
|
var devices=Store.devices.state.devices
|
|
|
|
|
2024-04-26 16:23:18 +03:00
|
|
|
var entities=[]
|
|
|
|
|
2024-04-25 01:22:27 +03:00
|
|
|
for device in devices:
|
|
|
|
if device.keys()[0] == selected_device.value:
|
2024-04-26 16:23:18 +03:00
|
|
|
entities=device.values()[0]["entities"]
|
|
|
|
break
|
|
|
|
|
|
|
|
if search.value != "":
|
|
|
|
return entities.filter(func(entity):
|
|
|
|
return entity.to_lower().find(search.value.to_lower()) != - 1
|
|
|
|
)
|
2024-04-25 01:22:27 +03:00
|
|
|
|
2024-04-26 16:23:18 +03:00
|
|
|
return entities
|
2024-04-25 01:22:27 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var pages = R.computed(func(_arg):
|
|
|
|
return ceil(entities.value.size() / page_size)
|
|
|
|
)
|
|
|
|
|
|
|
|
var visible_entities = R.computed(func(_arg):
|
|
|
|
return entities.value.slice(page.value * page_size, page.value * page_size + page_size)
|
|
|
|
)
|
|
|
|
|
|
|
|
R.bind(pagination, "pages", pages)
|
|
|
|
R.bind(pagination, "page", page, pagination.on_page_changed)
|
2024-04-26 16:23:18 +03:00
|
|
|
R.bind(search_input, "text", search, search_input.on_text_changed)
|
|
|
|
|
|
|
|
search_input.on_text_changed.connect(func(_arg):
|
|
|
|
page.value=0
|
|
|
|
)
|
2024-04-25 01:22:27 +03:00
|
|
|
|
|
|
|
back_button.on_button_up.connect(func():
|
|
|
|
on_back.emit()
|
|
|
|
)
|
|
|
|
|
|
|
|
R.effect(func(_arg):
|
2024-04-25 14:19:12 +03:00
|
|
|
for child in entity_container.get_children():
|
|
|
|
entity_container.remove_child(child)
|
|
|
|
child.queue_free()
|
2024-04-25 01:22:27 +03:00
|
|
|
|
|
|
|
for entity in visible_entities.value:
|
2024-04-25 14:19:12 +03:00
|
|
|
var entity_node=EntityScene.instantiate()
|
|
|
|
entity_node.icon=EntityFactory.get_entity_icon(entity.split(".")[0])
|
|
|
|
entity_node.text=entity
|
|
|
|
entity_node.on_select.connect(func():
|
2024-04-25 01:22:27 +03:00
|
|
|
on_select_entity.emit(entity)
|
|
|
|
)
|
2024-04-25 14:19:12 +03:00
|
|
|
entity_container.add_child(entity_node)
|
|
|
|
|
|
|
|
entity_container._update()
|
2024-04-25 01:22:27 +03:00
|
|
|
|
|
|
|
)
|