# editor/importer_dock.gd (interface uniquement) @tool extends VBoxContainer var editor_filesystem : EditorFileSystem var _client : PokeApiClient var _input : LineEdit var _overwrite : CheckBox var _buttons : Array[Button] = [] var _progress : ProgressBar var _log : RichTextLabel var _busy : bool = false var _item_importer_ref : PokeApiItemImporter var _category_list : ItemList var _btn_load_categories : Button var _btn_import_items : Button func _ready() -> void: custom_minimum_size = Vector2(260, 0) _client = PokeApiClient.new() _client.progress.connect(_on_progress) add_child(_client) _add_button("Importer toutes les capacités", _on_import_moves) _add_button("Importer les types", _on_import_types) _add_button("Importer les talents", _on_import_abilities) add_child(HSeparator.new()) var label := Label.new() label.text = "Pokémon (ids, noms, plages) :" add_child(label) _input = LineEdit.new() _input.placeholder_text = "25, eevee, 1-9, mr-mime" add_child(_input) _overwrite = CheckBox.new() _overwrite.text = "Écraser les fichiers existants" add_child(_overwrite) _add_button("Importer les pokémon", _on_import_pokemon) _progress = ProgressBar.new() add_child(_progress) _log = RichTextLabel.new() _log.custom_minimum_size = Vector2(0, 200) _log.size_flags_vertical = Control.SIZE_EXPAND_FILL _log.scroll_following = true _log.selection_enabled = true add_child(_log) add_child(HSeparator.new()) var item_label := Label.new() item_label.text = "Objets, par catégorie :" add_child(item_label) _btn_load_categories = Button.new() _btn_load_categories.text = "Lister les catégories" _btn_load_categories.pressed.connect(_on_load_categories) add_child(_btn_load_categories) _category_list = ItemList.new() _category_list.custom_minimum_size = Vector2(0, 150) _category_list.select_mode = ItemList.SELECT_MULTI add_child(_category_list) _add_button("Importer les objets sélectionnés", _on_import_items) func _add_button(text : String, callback : Callable) -> void: var b := Button.new() b.text = text b.pressed.connect(callback) add_child(b) _buttons.append(b) func _on_import_moves() -> void: if _busy: return _set_busy(true) var importer := PokeApiMoveImporter.new(_client, _overwrite.button_pressed) importer.message.connect(_print) await importer.run() editor_filesystem.scan() _set_busy(false) func _on_import_types() -> void: if _busy: return _set_busy(true) var importer := PokeApiTypeImporter.new(_client, _overwrite.button_pressed) importer.message.connect(_print) await importer.run() editor_filesystem.scan() _set_busy(false) func _on_import_abilities() -> void: if _busy: return _set_busy(true) var importer := PokeApiAbilityImporter.new(_client, _overwrite.button_pressed) importer.message.connect(_print) await importer.run() editor_filesystem.scan() _set_busy(false) func _on_import_pokemon() -> void: if _busy: return var tokens := _parse_input(_input.text) if tokens.is_empty(): _print("Rien à importer.") return _set_busy(true) var importer := PokeApiPokemonImporter.new(_client, editor_filesystem, _overwrite.button_pressed) importer.message.connect(_print) await importer.run(tokens) _set_busy(false) func _on_load_categories() -> void: if _busy: return _set_busy(true) var importer := PokeApiItemImporter.new(_client, editor_filesystem, _overwrite.button_pressed) var categories := await importer.list_categories() _category_list.clear() for c in categories: _category_list.add_item("%s (%d)" % [c["name"], c["count"]]) _category_list.set_item_metadata(_category_list.item_count - 1, c["name"]) _print("%d catégories chargées." % categories.size()) _set_busy(false) func _on_import_items() -> void: if _busy: return var selected : Array = [] for idx in _category_list.get_selected_items(): selected.append(_category_list.get_item_metadata(idx)) # nom brut, sans le "(N)" if selected.is_empty(): _print("Sélectionne au moins une catégorie.") return _set_busy(true) var importer := PokeApiItemImporter.new(_client, editor_filesystem, _overwrite.button_pressed) importer.message.connect(_print) await importer.run(selected) _set_busy(false) func _parse_input(text : String) -> Array: var out : Array = [] for tok in text.split(",", false): var t : String = tok.strip_edges().to_lower() if t.is_empty(): continue var parts := t.split("-") if parts.size() == 2 and parts[0].is_valid_int() and parts[1].is_valid_int(): for i in range(int(parts[0]), int(parts[1]) + 1): out.append(i) elif t.is_valid_int(): out.append(int(t)) else: out.append(t) return out func _on_progress(done : int, total : int) -> void: _progress.max_value = total _progress.value = done func _set_busy(value : bool) -> void: _busy = value for b in _buttons: b.disabled = value func _print(msg : String) -> void: _log.append_text(msg + "\n")