122 lines
3.2 KiB
GDScript
122 lines
3.2 KiB
GDScript
# 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
|
|
|
|
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)
|
|
|
|
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 _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")
|