45 lines
1.3 KiB
GDScript
45 lines
1.3 KiB
GDScript
# editor/ability_importer.gd
|
|
@tool
|
|
class_name PokeApiAbilityImporter
|
|
extends RefCounted
|
|
|
|
signal message(text : String)
|
|
|
|
var _client : PokeApiClient
|
|
var _overwrite : bool
|
|
var _languages : PackedStringArray
|
|
var _dir : String
|
|
|
|
func _init(client : PokeApiClient, overwrite : bool) -> void:
|
|
_client = client
|
|
_overwrite = overwrite
|
|
_languages = PokeApiSettings.languages()
|
|
_dir = PokeApiSettings.abilities_dir()
|
|
|
|
func run() -> void:
|
|
DirAccess.make_dir_recursive_absolute(_dir)
|
|
var list = await _client.get_json(PokeApiClient.API + "ability?limit=1000")
|
|
if list == null:
|
|
message.emit("[color=red]Impossible de récupérer la liste des talents.[/color]")
|
|
return
|
|
|
|
message.emit("%d talents à traiter..." % list["results"].size())
|
|
await _client.run_parallel(list["results"], _import_ability)
|
|
message.emit("Talents terminés.")
|
|
|
|
func _import_ability(entry : Dictionary) -> void:
|
|
var path : String = _dir + entry["name"] + ".tres"
|
|
if !_overwrite and FileAccess.file_exists(path): return
|
|
|
|
var j = await _client.get_json(entry["url"])
|
|
if j == null:
|
|
message.emit("[color=red]Échec : %s[/color]" % entry["name"])
|
|
return
|
|
|
|
var a := AbilityData.new()
|
|
a.id = j["id"]
|
|
a.api_name = j["name"]
|
|
a.names = PokeApiText.names(j["names"], _languages)
|
|
a.descriptions = PokeApiText.flavors(j["flavor_text_entries"], _languages)
|
|
ResourceSaver.save(a, path)
|