fetch custom sprites list from github

This commit is contained in:
infinitefusion
2023-04-23 12:19:17 -04:00
parent 67e8e4511f
commit 521e9a410f
25 changed files with 58224 additions and 22 deletions

View File

@@ -28,7 +28,10 @@ module Settings
DEFAULT_SPRITE_PATH = "Graphics/Battlers/Special/000.png"
CREDITS_FILE_PATH = "Data/SPRITE_CREDS"
VERSION_FILE_PATH = "Data/VERSION"
CUSTOM_SPRITES_FILE_PATH = "Data/CUSTOM_SPRITES"
CREDITS_FILE_URL = "https://raw.githubusercontent.com/infinitefusion/sprites/main/Sprite Credits.csv"
SPRITES_FILE_URL = "https://raw.githubusercontent.com/infinitefusion/infinitefusion-e18/main/Data/CUSTOM_SPRITES"
VERSION_FILE_URL = "https://raw.githubusercontent.com/infinitefusion/infinitefusion-e18/main/Data/VERSION"
FRONTSPRITE_POSITION_OFFSET = 20

View File

@@ -837,7 +837,8 @@ end
def pbReceiveItem(item, quantity = 1, item_name = "", music = nil, canRandom=true)
#item_name -> pour donner un autre nom à l'item. Pas encore réimplémenté et surtout là pour éviter que ça plante quand des events essaient de le faire
canRandom = false if !$game_switches[SWITCH_RANDOM_ITEMS_GENERAL]
if canRandom && ($game_switches[SWITCH_RANDOM_GIVEN_ITEMS] || $game_switches[SWITCH_RANDOM_GIVEN_TMS])
original_item = GameData::Item.get(item).is_TM
if canRandom && ((!original_item.is_TM? && $game_switches[SWITCH_RANDOM_GIVEN_ITEMS]) || (original_item.is_TM? && $game_switches[SWITCH_RANDOM_GIVEN_TMS]))
item = pbGetRandomItem(item) if canRandom #fait rien si pas activé
else
item = GameData::Item.get(item)

View File

@@ -360,7 +360,8 @@ def Kernel.pbShuffleTrainersCustom(bst_range = 50)
bst_range = pbGet(VAR_RANDOMIZER_TRAINER_BST)
Kernel.pbMessage(_INTL("Parsing custom sprites folder"))
customsList = getCustomSpeciesList()
customsList = getCustomSpeciesList(true )
p customsList
Kernel.pbMessage(_INTL("{1} sprites found", customsList.length.to_s))
if customsList.length == 0
@@ -368,7 +369,11 @@ def Kernel.pbShuffleTrainersCustom(bst_range = 50)
Kernel.pbMessage(_INTL("Trainer Pokémon will include auto-generated sprites."))
return Kernel.pbShuffleTrainers(bst_range)
elsif customsList.length < 200
if Kernel.pbConfirmMessage(_INTL("Too few custom sprites were found. This will result in a very low Pokémon variety for trainers. Continue anyway?"))
if Kernel.pbConfirmMessage(_INTL("Too few custom sprites were found. This will result in a very low Pokémon variety for trainers. Would you like to disable the Custom Sprites only option?"))
Kernel.pbMessage(_INTL("Trainer Pokémon will include auto-generated sprites."))
return Kernel.pbShuffleTrainers(bst_range) ##use regular shuffle if not enough sprites
end
if Kernel.pbConfirmMessage(_INTL("This will result in a very low Pokémon variety for trainers. Continue anyway?"))
bst_range = 999
else
Kernel.pbMessage(_INTL("Trainer Pokémon will include auto-generated sprites."))
@@ -408,7 +413,7 @@ end
#end
def getCustomSpeciesList(allowOnline=true)
def getCustomSpeciesList(allowOnline=false)
speciesList = []
for num in 1..NB_POKEMON
@@ -429,25 +434,33 @@ def getCustomSpeciesList(allowOnline=true)
if speciesList.length <= 200 && allowOnline
Kernel.pbMessage(_INTL("Not enough local sprites found, attempting to fetch list from the internet."))
#try to get list from github
online_list = list_online_custom_sprites
return nil if !online_list
online_list = list_online_custom_sprites(true)
return speciesList if !online_list
species_id_list = []
for file in online_list
species_id_list << getDexNumFromFilename(file)
dexnum = getDexNumFromFilename(file)
species_id_list << dexnum if dexnum && dexnum <= maxDexNumber && dexnum > 0
end
return species_id_list
end
return speciesList
end
def is_file_alt(file)
filename = file.split(".")[0]
return filename.match(/[a-zA-Z]/)
end
#input: ex: 10.10.png
def getDexNumFromFilename(filename)
splitPoke = filename.split(".")
head = splitPoke[0].to_i
body = splitPoke[1].to_i
return nil if (body * NB_POKEMON) + head > (NB_POKEMON*NB_POKEMON)+420
return (body * NB_POKEMON) + head
end

View File

@@ -85,6 +85,9 @@ def Kernel.pbShuffleDex(range = 50, type = 0)
# create hash
pokemon_list = only_customs ? getCustomSpeciesList() : get_pokemon_list(should_include_fusions)
if !pokemon_list #when not enough custom sprites
pokemon_list = get_pokemon_list(should_include_fusions)
end
$PokemonGlobal.psuedoBSTHash = get_randomized_bst_hash(pokemon_list,range,should_include_fusions)
end

View File

@@ -22,7 +22,7 @@ def download_file(url, saveLocation)
return saveLocation
end
return nil
rescue MKXPError => error
rescue MKXPError, Errno::ENOENT => error
echo error
return nil
end
@@ -42,7 +42,7 @@ def download_sprite(base_path, head_id, body_id, saveLocation = "Graphics/temp")
return downloaded_file_name
end
return nil
rescue MKXPError
rescue MKXPError,Errno::ENOENT
return nil
end
end
@@ -71,17 +71,58 @@ end
# 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
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'] }
# def fetch_online_custom_sprites
# page_start =1
# page_end =2
#
# repo = "infinitefusion/sprites"
# folder = "CustomBattlers"
# api_url = "https://api.github.com/repos/#{repo}/contents/#{folder}"
#
# files = []
# page = page_start
#
# File.open(Settings::CUSTOM_SPRITES_FILE_PATH, "wb") do |csv|
# loop do
# break if page > page_end
# response = HTTPLite.get(api_url, {'page' => page.to_s})
# response_files = HTTPLite::JSON.parse(response[:body])
# break if response_files.empty?
# response_files.each do |file|
# csv << [file['name']].to_s
# csv << "\n"
# end
# page += 1
# end
# end
#
#
# write_custom_sprites_csv(files)
# end
# Too many file to get everything without getting
# rate limited by github, so instead we're getting the
# files list from a csv file that will be manually updated
# with each new spritepack
def updateOnlineCustomSpritesFile
return if $PokemonSystem.download_sprites != 0
download_file(Settings::SPRITES_FILE_URL,Settings::CUSTOM_SPRITES_FILE_PATH)
end
def list_online_custom_sprites(updateList=false)
updateOnlineCustomSpritesFile if updateList
sprites_list= []
File.foreach(Settings::CUSTOM_SPRITES_FILE_PATH) do |line|
sprites_list << line
end
return sprites_list
end
GAME_VERSION_FORMAT_REGEX = /\A\d+(\.\d+)*\z/
def fetch_latest_game_version
begin