Update download and export scripts

This commit is contained in:
Justin Edmund 2023-06-04 22:57:32 -07:00
parent fc8cd43de2
commit 85379b0dea
2 changed files with 52 additions and 9 deletions

View file

@ -106,7 +106,7 @@ namespace :granblue do
puts "Summon #{id}"
sizes.each do |size|
path = "#{Rails.root}/download/character-#{size}"
path = "#{Rails.root}/download/summon-#{size}"
download_images(url[size.to_sym], size, path)
end
end
@ -125,7 +125,10 @@ namespace :granblue do
elsif object == 'weapon'
download_weapon_images(id)
elsif object == 'summon'
download_summon_images(id)
download_summon_images("#{id}")
download_summon_images("#{id}_02")
download_summon_images("#{id}_03")
download_summon_images("#{id}_04")
end
end
end

View file

@ -1,33 +1,73 @@
namespace :granblue do
namespace :export do
def build_job_icon_url(id)
# Set up URL
base_url = 'https://prd-game-a-granbluefantasy.akamaized.net/assets_en/img/sp/ui/icon/job'
extension = '.png'
"#{base_url}/#{id}#{extension}"
end
desc 'Exports a list of weapon URLs for a given size'
task :job do |_t, _args|
# Include weapon model
def build_job_portrait_url(id, proficiency, gender)
base_url = 'https://prd-game-a1-granbluefantasy.akamaized.net/assets_en/img/sp/assets/leader/quest'
extension = '.jpg'
prefix = ""
case proficiency
when 1
prefix = "sw"
when 2
prefix = "kn"
when 3
prefix = "ax"
when 4
prefix = "sp"
when 5
prefix = "bw"
when 6
prefix = "wa"
when 7
prefix = "me"
when 8
prefix = "mc"
when 9
prefix = "gu"
when 10
prefix = "kt"
end
"#{base_url}/#{id}_#{prefix}_#{gender}_01#{extension}"
end
# job-icon
def write_urls(size)
# Include model
Dir.glob("#{Rails.root}/app/models/job.rb").each { |file| require file }
# Set up filepath
dir = "#{Rails.root}/export/"
filename = "#{dir}/job-icon.txt"
filename = "#{dir}job-#{size}.txt"
FileUtils.mkdir(dir) unless Dir.exist?(dir)
# Write to file
File.open(filename, 'w') do |f|
Job.all.each do |w|
f.write("#{build_job_icon_url(w.granblue_id.to_s)} \n")
if size == 'icon'
f.write("#{build_job_icon_url(w.granblue_id.to_s)} \n")
elsif size == 'portrait'
f.write("#{build_job_portrait_url(w.granblue_id.to_s, w.proficiency1, 0)} \n")
f.write("#{build_job_portrait_url(w.granblue_id.to_s, w.proficiency1, 1)} \n")
end
end
end
# CLI output
count = `wc -l #{filename}`.split.first.to_i
puts "Wrote #{count} job URLs for icon size"
puts "Wrote #{count} job URLs for #{size} size"
end
desc 'Exports a list of job URLs for a given size'
task :job, [:size] => :environment do |_t, args|
write_urls(args[:size])
end
end
end