Pokemon types from imported types and not strings
This commit is contained in:
parent
df7ca58c5e
commit
b65e6b39f2
|
|
@ -7,7 +7,7 @@ extends Resource
|
||||||
@export var api_name : String
|
@export var api_name : String
|
||||||
@export var names : Dictionary = {}
|
@export var names : Dictionary = {}
|
||||||
@export var descriptions : 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 abilities : Array[PokemonAbility] = [] # remplace l'ancien PackedStringArray
|
||||||
@export var evolution_chain : EvolutionNode
|
@export var evolution_chain : EvolutionNode
|
||||||
@export var base_stats : Dictionary = {}
|
@export var base_stats : Dictionary = {}
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,12 @@ func _init(client : PokeApiClient, fs : EditorFileSystem, overwrite : bool) -> v
|
||||||
func run(tokens : Array) -> void:
|
func run(tokens : Array) -> void:
|
||||||
DirAccess.make_dir_recursive_absolute(PokeApiSettings.pokemon_dir())
|
DirAccess.make_dir_recursive_absolute(PokeApiSettings.pokemon_dir())
|
||||||
DirAccess.make_dir_recursive_absolute(PokeApiSettings.sprites_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()):
|
if !DirAccess.dir_exists_absolute(PokeApiSettings.moves_dir()):
|
||||||
message.emit("[color=orange]Aucune capacité importée : les learnsets seront vides.[/color]")
|
message.emit("[color=orange]Aucune capacité importée : les learnsets seront vides.[/color]")
|
||||||
if !DirAccess.dir_exists_absolute(PokeApiSettings.abilities_dir()):
|
if !DirAccess.dir_exists_absolute(PokeApiSettings.abilities_dir()):
|
||||||
message.emit("[color=orange]Aucun talent importé : les talents des pokémon seront vides.[/color]")
|
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()
|
_pending.clear()
|
||||||
await _client.run_parallel(tokens, _fetch_pokemon) # phase 1 : téléchargement
|
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.height = j["height"] / 10.0
|
||||||
d.weight = j["weight"] / 10.0
|
d.weight = j["weight"] / 10.0
|
||||||
for t in j["types"]:
|
for t in j["types"]:
|
||||||
d.types.append(t["type"]["name"])
|
d.types = _resolve_types(j["types"])
|
||||||
for a in j["abilities"]:
|
for a in j["abilities"]:
|
||||||
d.abilities = _build_abilities(j["abilities"])
|
d.abilities = _build_abilities(j["abilities"])
|
||||||
for s in j["stats"]:
|
for s in j["stats"]:
|
||||||
|
|
@ -142,3 +142,14 @@ func _build_abilities(raw_abilities : Array) -> Array[PokemonAbility]:
|
||||||
pa.is_hidden = a["is_hidden"]
|
pa.is_hidden = a["is_hidden"]
|
||||||
result.append(pa)
|
result.append(pa)
|
||||||
return result
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue