Sprites now get downloaded to battlers folder instead of temp folder

This commit is contained in:
infinitefusion
2023-03-04 17:06:25 -05:00
parent c29e428f90
commit 33065a8f45
17 changed files with 21 additions and 17 deletions

View File

@@ -36,7 +36,8 @@ end
def pbGetBTPokemon(challenge_id)
customsOnly = !$game_switches[SWITCH_BATTLE_FACTORY_INCLUDE_ALL]
if customsOnly
return getCustomSpeciesList()
customsList = getCustomSpeciesList()
return customsList if customsList
end
return listAllPokemon

View File

@@ -406,7 +406,7 @@ def customSpriteExists(species)
return download_custom_sprite(head, body) != nil
end
def customSpriteExistsBase(head,body)
def customSpriteExistsBase(body,head)
pathCustom = getCustomSpritePath(body,head)
return true if pbResolveBitmap(pathCustom) != nil
return download_custom_sprite(head, body) != nil

View File

@@ -12,10 +12,9 @@ def downloadCustomSprite(head_id,body_id)
end
def download_sprite(base_path, head_id, body_id)
def download_sprite(base_path, head_id, body_id, saveLocation="Graphics/temp")
begin
temp_sprites_folder = "Graphics/temp"
downloaded_file_name = _INTL("{1}/{2}.{3}.png",temp_sprites_folder,head_id,body_id)
downloaded_file_name = _INTL("{1}/{2}.{3}.png",saveLocation,head_id,body_id)
return downloaded_file_name if pbResolveBitmap(downloaded_file_name)
url = _INTL(base_path,head_id,body_id)
response = HTTPLite.get(url)
@@ -23,6 +22,7 @@ def download_sprite(base_path, head_id, body_id)
File.open(downloaded_file_name, "wb") do |file|
file.write(response[:body])
end
echo _INTL("\nDownloaded file {1} to {2}",downloaded_file_name,saveLocation)
return downloaded_file_name
end
return nil
@@ -33,8 +33,9 @@ end
def download_autogen_sprite(head_id, body_id)
return nil if $PokemonSystem.download_sprites != 0
base_path = "https://raw.githubusercontent.com/Aegide/autogen-fusion-sprites/master/Battlers/{1}/{1}.{2}.png"
sprite = download_sprite(_INTL(base_path,head_id,body_id),head_id,body_id)
url = "https://raw.githubusercontent.com/Aegide/autogen-fusion-sprites/master/Battlers/{1}/{1}.{2}.png"
destPath = _INTL("{1}/{2}",Settings::BATTLERS_FOLDER,head_id)
sprite = download_sprite(_INTL(url,head_id,body_id),head_id,body_id,destPath)
return sprite if sprite
return nil
end
@@ -42,8 +43,9 @@ end
def download_custom_sprite(head_id, body_id)
return nil if $PokemonSystem.download_sprites != 0
#base_path = "https://raw.githubusercontent.com/Aegide/custom-fusion-sprites/main/CustomBattlers/{1}.{2}.png"
base_path = "https://raw.githubusercontent.com/infinitefusion/sprites/main/CustomBattlers/{1}.{2}.png"
sprite = download_sprite(_INTL(base_path,head_id,body_id),head_id,body_id)
url = "https://raw.githubusercontent.com/infinitefusion/sprites/main/CustomBattlers/{1}.{2}.png"
destPath= _INTL("{1}/{2}",Settings::CUSTOM_BATTLERS_FOLDER_INDEXED,head_id)
sprite = download_sprite(_INTL(url,head_id,body_id),head_id,body_id,destPath)
return sprite if sprite
return nil
end
@@ -52,13 +54,14 @@ end
# https://api.github.com/repos/infinitefusion/contents/sprites/CustomBattlers
# repo = "Aegide/custom-fusion-sprites"
# folder = "CustomBattlers"
#
# todo: github api returns a maximum of 1000 files. Need to find workaround.
# Possibly using git trees https://docs.github.com/fr/rest/git/trees?apiVersion=2022-11-28#get-a-tree
def list_online_custom_sprites
# repo = "infinitefusion/sprites"
# folder = "CustomBattlers"
repo = "Aegide/custom-fusion-sprites"
folder = "CustomBattlers"
api_url = "https://api.github.com/repos/#{repo}/contents/#{folder}"
response = HTTPLite.get(api_url)
return HTTPLite::JSON.parse(response[:body]).map { |file| file['name'] }
return nil
# repo = "infinitefusion/sprites"
# folder = "CustomBattlers"
# api_url = "https://api.github.com/repos/#{repo}/contents/#{folder}"
# response = HTTPLite.get(api_url)
# return HTTPLite::JSON.parse(response[:body]).map { |file| file['name'] }
end