57 lines
1.9 KiB
GDScript
57 lines
1.9 KiB
GDScript
# editor/move_importer.gd
|
|
@tool
|
|
class_name PokeApiMoveImporter
|
|
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.moves_dir()
|
|
|
|
func run() -> void:
|
|
DirAccess.make_dir_recursive_absolute(_dir)
|
|
var list = await _client.get_json(PokeApiClient.API + "move?limit=2000")
|
|
if list == null:
|
|
message.emit("[color=red]Impossible de récupérer la liste des capacités.[/color]")
|
|
return
|
|
|
|
var entries : Array = []
|
|
for r in list["results"]:
|
|
var id : int = int(String(r["url"]).trim_suffix("/").get_file())
|
|
if id < 10000: entries.append(r) # ignore les capacités "shadow" (Colosseum/XD)
|
|
|
|
message.emit("%d capacités à traiter..." % entries.size())
|
|
await _client.run_parallel(entries, _import_move)
|
|
message.emit("Capacités terminées.")
|
|
|
|
func _import_move(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 m := MoveData.new()
|
|
m.id = PokeApiJson.get_int(j, "id")
|
|
m.api_name = PokeApiJson.get_str(j, "name", entry["name"])
|
|
m.names = PokeApiText.names(PokeApiJson.get_array(j, "names"), _languages)
|
|
m.descriptions = PokeApiText.flavors(PokeApiJson.get_array(j, "flavor_text_entries"), _languages)
|
|
m.type = PokeApiJson.get_dict_name(j, "type")
|
|
m.category = PokeApiJson.get_dict_name(j, "damage_class")
|
|
m.power = PokeApiJson.get_int(j, "power")
|
|
m.accuracy = PokeApiJson.get_int(j, "accuracy")
|
|
m.pp = PokeApiJson.get_int(j, "pp")
|
|
m.priority = PokeApiJson.get_int(j, "priority")
|
|
m.target = PokeApiJson.get_dict_name(j, "target")
|
|
ResourceSaver.save(m, path)
|