Add cry import
This commit is contained in:
parent
b65e6b39f2
commit
ad28672093
|
|
@ -18,6 +18,7 @@ extends Resource
|
||||||
@export var model_scene : PackedScene
|
@export var model_scene : PackedScene
|
||||||
@export var shiny_albedo : Texture2D
|
@export var shiny_albedo : Texture2D
|
||||||
@export var learnset : Array[LearnedMove] = []
|
@export var learnset : Array[LearnedMove] = []
|
||||||
|
@export var cry_latest : AudioStream
|
||||||
|
|
||||||
func get_display_name() -> String:
|
func get_display_name() -> String:
|
||||||
return L10n.pick(names, api_name.capitalize())
|
return L10n.pick(names, api_name.capitalize())
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ 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())
|
||||||
|
DirAccess.make_dir_recursive_absolute(PokeApiSettings.cries_dir())
|
||||||
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()):
|
||||||
|
|
@ -74,31 +75,38 @@ func _fetch_pokemon(token : Variant) -> void:
|
||||||
var sprite_url = art.get("front_default", sprites.get("front_default"))
|
var sprite_url = art.get("front_default", sprites.get("front_default"))
|
||||||
var shiny_url = art.get("front_shiny", sprites.get("front_shiny"))
|
var shiny_url = art.get("front_shiny", sprites.get("front_shiny"))
|
||||||
var dir := PokeApiSettings.sprites_dir()
|
var dir := PokeApiSettings.sprites_dir()
|
||||||
|
|
||||||
|
var cries : Dictionary = j.get("cries", {})
|
||||||
|
var cry_path := await _client.download_file(cries.get("latest"), PokeApiSettings.cries_dir() + stem + ".ogg")
|
||||||
|
|
||||||
_pending.append({
|
_pending.append({
|
||||||
"data": d, "path": path, "moves": j["moves"],
|
"data": d, "path": path, "moves": j["moves"],
|
||||||
"png": await _client.download_file(sprite_url, dir + stem + ".png"),
|
"png": await _client.download_file(sprite_url, dir + stem + ".png"),
|
||||||
"shiny_png": await _client.download_file(shiny_url, dir + stem + "_shiny.png"),
|
"shiny_png": await _client.download_file(shiny_url, dir + stem + "_shiny.png"),
|
||||||
|
"cry": cry_path,
|
||||||
})
|
})
|
||||||
|
|
||||||
func _save_all() -> void:
|
func _save_all() -> void:
|
||||||
var pngs := PackedStringArray()
|
var to_reimport := PackedStringArray()
|
||||||
for p in _pending:
|
for p in _pending:
|
||||||
for key in ["png", "shiny_png"]:
|
for key in ["png", "shiny_png", "cry"]:
|
||||||
if p[key] != "": pngs.append(p[key])
|
if p[key] != "": to_reimport.append(p[key])
|
||||||
if !pngs.is_empty():
|
if !to_reimport.is_empty():
|
||||||
_fs.scan()
|
_fs.scan()
|
||||||
while _fs.is_scanning():
|
while _fs.is_scanning():
|
||||||
await _client.get_tree().process_frame
|
await _client.get_tree().process_frame
|
||||||
_fs.reimport_files(pngs)
|
_fs.reimport_files(to_reimport)
|
||||||
|
|
||||||
|
var saved : Array[PokemonData] = []
|
||||||
for p in _pending:
|
for p in _pending:
|
||||||
var d : PokemonData = p["data"]
|
var d : PokemonData = p["data"]
|
||||||
d.menu_sprite = _load_texture(p["png"])
|
d.menu_sprite = _load_texture(p["png"])
|
||||||
d.shiny_menu_sprite = _load_texture(p["shiny_png"])
|
d.shiny_menu_sprite = _load_texture(p["shiny_png"])
|
||||||
|
d.cry_latest = _load_audio(p["cry"])
|
||||||
_link_models(d)
|
_link_models(d)
|
||||||
d.learnset = _build_learnset(p["moves"])
|
d.learnset = _build_learnset(p["moves"])
|
||||||
ResourceSaver.save(d, p["path"])
|
ResourceSaver.save(d, p["path"])
|
||||||
|
saved.append(d)
|
||||||
message.emit("OK : %s (%d capacités)" % [d.get_display_name(), d.learnset.size()])
|
message.emit("OK : %s (%d capacités)" % [d.get_display_name(), d.learnset.size()])
|
||||||
|
|
||||||
_fs.scan()
|
_fs.scan()
|
||||||
|
|
@ -107,6 +115,10 @@ func _load_texture(path : String) -> Texture2D:
|
||||||
if path.is_empty(): return null
|
if path.is_empty(): return null
|
||||||
return ResourceLoader.load(path, "Texture2D", ResourceLoader.CACHE_MODE_REPLACE) as Texture2D
|
return ResourceLoader.load(path, "Texture2D", ResourceLoader.CACHE_MODE_REPLACE) as Texture2D
|
||||||
|
|
||||||
|
func _load_audio(path : String) -> AudioStream:
|
||||||
|
if path.is_empty(): return null
|
||||||
|
return ResourceLoader.load(path, "AudioStream", ResourceLoader.CACHE_MODE_REPLACE) as AudioStream
|
||||||
|
|
||||||
func _link_models(d : PokemonData) -> void:
|
func _link_models(d : PokemonData) -> void:
|
||||||
var dir := PokeApiSettings.models_dir()
|
var dir := PokeApiSettings.models_dir()
|
||||||
if dir.is_empty(): return
|
if dir.is_empty(): return
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ static func max_concurrent() -> int:
|
||||||
static func moves_dir() -> String: return data_dir() + "/moves/"
|
static func moves_dir() -> String: return data_dir() + "/moves/"
|
||||||
static func pokemon_dir() -> String: return data_dir() + "/pokemon/"
|
static func pokemon_dir() -> String: return data_dir() + "/pokemon/"
|
||||||
static func sprites_dir() -> String: return data_dir() + "/sprites/"
|
static func sprites_dir() -> String: return data_dir() + "/sprites/"
|
||||||
|
static func cries_dir() -> String: return data_dir() + "/cries/"
|
||||||
static func types_dir() -> String: return data_dir() + "/types/"
|
static func types_dir() -> String: return data_dir() + "/types/"
|
||||||
static func abilities_dir() -> String: return data_dir() + "/abilities/"
|
static func abilities_dir() -> String: return data_dir() + "/abilities/"
|
||||||
static func evolution_dir() -> String: return data_dir() + "/evolution/"
|
static func evolution_dir() -> String: return data_dir() + "/evolution/"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue