From b65e6b39f293c2d02fc30a4154303f75f42b877f Mon Sep 17 00:00:00 2001 From: TheThomaas Date: Wed, 30 Sep 2026 14:25:15 +0200 Subject: [PATCH] Pokemon types from imported types and not strings --- data/pokemon_data.gd | 2 +- editor/pokemon_importer.gd | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/data/pokemon_data.gd b/data/pokemon_data.gd index 9c092f8..d0af3f4 100644 --- a/data/pokemon_data.gd +++ b/data/pokemon_data.gd @@ -7,7 +7,7 @@ extends Resource @export var api_name : String @export var names : Dictionary = {} @export var descriptions : Dictionary = {} -@export var types : PackedStringArray +@export var types : Array[TypeData] = [] @export var abilities : Array[PokemonAbility] = [] # remplace l'ancien PackedStringArray @export var evolution_chain : EvolutionNode @export var base_stats : Dictionary = {} diff --git a/editor/pokemon_importer.gd b/editor/pokemon_importer.gd index 49534bd..1814003 100644 --- a/editor/pokemon_importer.gd +++ b/editor/pokemon_importer.gd @@ -22,12 +22,12 @@ func _init(client : PokeApiClient, fs : EditorFileSystem, overwrite : bool) -> v func run(tokens : Array) -> void: DirAccess.make_dir_recursive_absolute(PokeApiSettings.pokemon_dir()) DirAccess.make_dir_recursive_absolute(PokeApiSettings.sprites_dir()) - if !DirAccess.dir_exists_absolute(PokeApiSettings.moves_dir()): - message.emit("[color=orange]Aucune capacité importée : les learnsets seront vides.[/color]") if !DirAccess.dir_exists_absolute(PokeApiSettings.moves_dir()): message.emit("[color=orange]Aucune capacité importée : les learnsets seront vides.[/color]") if !DirAccess.dir_exists_absolute(PokeApiSettings.abilities_dir()): message.emit("[color=orange]Aucun talent importé : les talents des pokémon seront vides.[/color]") + if !DirAccess.dir_exists_absolute(PokeApiSettings.types_dir()): + message.emit("[color=orange]Aucun type importé : les types des pokémon seront vides.[/color]") _pending.clear() await _client.run_parallel(tokens, _fetch_pokemon) # phase 1 : téléchargement @@ -56,7 +56,7 @@ func _fetch_pokemon(token : Variant) -> void: d.height = j["height"] / 10.0 d.weight = j["weight"] / 10.0 for t in j["types"]: - d.types.append(t["type"]["name"]) + d.types = _resolve_types(j["types"]) for a in j["abilities"]: d.abilities = _build_abilities(j["abilities"]) for s in j["stats"]: @@ -142,3 +142,14 @@ func _build_abilities(raw_abilities : Array) -> Array[PokemonAbility]: pa.is_hidden = a["is_hidden"] result.append(pa) return result + +func _resolve_types(raw_types : Array) -> Array[TypeData]: + var result : Array[TypeData] = [] + for t in raw_types: + var name : String = t["type"]["name"] + var path : String = PokeApiSettings.types_dir() + name + ".tres" + if !FileAccess.file_exists(path): + message.emit("[color=orange]Type introuvable : %s (importe les types d'abord)[/color]" % name) + continue + result.append(load(path) as TypeData) + return result