diff --git a/src/modules/building/building_option/building_option.gd b/src/modules/building/building_option/building_option.gd index d6e812c..dbe57ab 100644 --- a/src/modules/building/building_option/building_option.gd +++ b/src/modules/building/building_option/building_option.gd @@ -13,12 +13,17 @@ var option_button: OptionButton; var selected_option: BuildingOptionItem = null var options: Array[BuildingOptionItem] = [] -func select(selected_id: int): - option_button.selected = option_button.get_item_index(selected_id) +func _select_option_by_id(building_id): for option in options: - if option.id == selected_id: + if option.id == building_id: + selected_id = building_id selected_option = option selected.emit(option) + break + +func select(building_id: int): + option_button.selected = option_button.get_item_index(building_id) + _select_option_by_id(building_id) func _enter_tree(): option_button = $OptionButton; @@ -37,10 +42,5 @@ func _ready(): func _on_option_button_item_selected(index): - var selected_id = option_button.get_item_id(index) - for option in options: - if option.id == selected_id: - print("selected item: %s (id: %s, energy: %s)" % [option.label, option.id, option.energy]) - selected_option = option - selected.emit(option) - break + var building_id = option_button.get_item_id(index) + _select_option_by_id(building_id)