Add rake tasks for exporting URL lists
This commit is contained in:
parent
8273af0f82
commit
c9c52fbf15
4 changed files with 156 additions and 0 deletions
38
lib/tasks/export_all.rake
Normal file
38
lib/tasks/export_all.rake
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
namespace :granblue do
|
||||
namespace :export do
|
||||
desc 'Exports files of URLs for every object at every size'
|
||||
task :all do
|
||||
# Run character tasks
|
||||
Rake::Task['granblue:export:character'].invoke('main')
|
||||
Rake::Task['granblue:export:character'].reenable
|
||||
|
||||
Rake::Task['granblue:export:character'].invoke('grid')
|
||||
Rake::Task['granblue:export:character'].reenable
|
||||
|
||||
Rake::Task['granblue:export:character'].invoke('square')
|
||||
Rake::Task['granblue:export:character'].reenable
|
||||
|
||||
# Run weapon tasks
|
||||
Rake::Task['granblue:export:weapon'].invoke('main')
|
||||
Rake::Task['granblue:export:weapon'].reenable
|
||||
|
||||
Rake::Task['granblue:export:weapon'].invoke('grid')
|
||||
Rake::Task['granblue:export:weapon'].reenable
|
||||
|
||||
Rake::Task['granblue:export:weapon'].invoke('square')
|
||||
Rake::Task['granblue:export:weapon'].reenable
|
||||
|
||||
# Run summon tasks
|
||||
Rake::Task['granblue:export:summon'].invoke('main')
|
||||
Rake::Task['granblue:export:summon'].reenable
|
||||
|
||||
Rake::Task['granblue:export:summon'].invoke('grid')
|
||||
Rake::Task['granblue:export:summon'].reenable
|
||||
|
||||
Rake::Task['granblue:export:summon'].invoke('square')
|
||||
Rake::Task['granblue:export:summon'].reenable
|
||||
|
||||
puts 'Exported 9 files'
|
||||
end
|
||||
end
|
||||
end
|
||||
41
lib/tasks/export_character.rake
Normal file
41
lib/tasks/export_character.rake
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
namespace :granblue do
|
||||
namespace :export do
|
||||
def build_chara_url(id, size)
|
||||
# Set up URL
|
||||
base_url = 'http://gbf.game-a.mbga.jp/assets/img/sp/assets/npc'
|
||||
extension = '.jpg'
|
||||
|
||||
directory = 'f' if size.to_s == 'main'
|
||||
directory = 'm' if size.to_s == 'grid'
|
||||
directory = 's' if size.to_s == 'square'
|
||||
|
||||
"#{base_url}/#{directory}/#{id}#{extension}"
|
||||
end
|
||||
|
||||
desc 'Exports a list of character URLs for a given size'
|
||||
task :character, [:size] => :environment do |_t, args|
|
||||
# Set up options
|
||||
size = args[:size]
|
||||
|
||||
# Include character model
|
||||
Dir.glob("#{Rails.root}/app/models/character.rb").each { |file| require file }
|
||||
|
||||
# Set up filepath
|
||||
dir = "#{Rails.root}/export/"
|
||||
FileUtils.mkdir(dir) unless Dir.exist?(dir)
|
||||
|
||||
unless File.exist?("#{dir}/character-#{size}.txt")
|
||||
File.open("#{dir}/character-#{size}.txt", 'w') do |f|
|
||||
Character.all.each do |c|
|
||||
f.write("#{build_chara_url("#{c.granblue_id}_01", size)} \n")
|
||||
f.write("#{build_chara_url("#{c.granblue_id}_02", size)} \n")
|
||||
f.write("#{build_chara_url("#{c.granblue_id}_03", size)} \n") if c.flb
|
||||
f.write("#{build_chara_url("#{c.granblue_id}_04", size)} \n") if c.ulb
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
puts "Wrote #{Character.count} character URLs for \"#{size}\" size"
|
||||
end
|
||||
end
|
||||
end
|
||||
39
lib/tasks/export_summon.rake
Normal file
39
lib/tasks/export_summon.rake
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
namespace :granblue do
|
||||
namespace :export do
|
||||
def build_summon_url(id, size)
|
||||
# Set up URL
|
||||
base_url = 'http://gbf.game-a.mbga.jp/assets/img/sp/assets/summon'
|
||||
extension = '.jpg'
|
||||
|
||||
directory = 'party_main' if size.to_s == 'main'
|
||||
directory = 'party_sub' if size.to_s == 'grid'
|
||||
directory = 's' if size.to_s == 'square'
|
||||
|
||||
"#{base_url}/#{directory}/#{id}#{extension}"
|
||||
end
|
||||
|
||||
desc 'Exports a list of summon URLs for a given size'
|
||||
task :summon, [:size] => :environment do |_t, args|
|
||||
# Set up options
|
||||
size = args[:size]
|
||||
|
||||
# Include character model
|
||||
Dir.glob("#{Rails.root}/app/models/summon.rb").each { |file| require file }
|
||||
|
||||
# Set up filepath
|
||||
dir = "#{Rails.root}/export/"
|
||||
FileUtils.mkdir(dir) unless Dir.exist?(dir)
|
||||
|
||||
unless File.exist?("#{dir}/summon-#{size}.txt")
|
||||
File.open("#{dir}/summon-#{size}.txt", 'w') do |f|
|
||||
Summon.all.each do |s|
|
||||
f.write("#{build_summon_url("#{s.granblue_id}_01", size)} \n")
|
||||
f.write("#{build_summon_url("#{s.granblue_id}_02", size)} \n") if (s.series == 3 || s.series == 0) && s.ulb
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
puts "Wrote #{Summon.count} summon URLs for \"#{size}\" size"
|
||||
end
|
||||
end
|
||||
end
|
||||
38
lib/tasks/export_weapon.rake
Normal file
38
lib/tasks/export_weapon.rake
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
namespace :granblue do
|
||||
namespace :export do
|
||||
def build_weapon_url(id, size)
|
||||
# Set up URL
|
||||
base_url = 'http://gbf.game-a.mbga.jp/assets/img/sp/assets/weapon'
|
||||
extension = '.jpg'
|
||||
|
||||
directory = 'ls' if size.to_s == 'main'
|
||||
directory = 'm' if size.to_s == 'grid'
|
||||
directory = 's' if size.to_s == 'square'
|
||||
|
||||
"#{base_url}/#{directory}/#{id}#{extension}"
|
||||
end
|
||||
|
||||
desc 'Exports a list of weapon URLs for a given size'
|
||||
task :weapon, [:size] => :environment do |_t, args|
|
||||
# Set up options
|
||||
size = args[:size]
|
||||
|
||||
# Include weapon model
|
||||
Dir.glob("#{Rails.root}/app/models/weapon.rb").each { |file| require file }
|
||||
|
||||
# Set up filepath
|
||||
dir = "#{Rails.root}/export/"
|
||||
FileUtils.mkdir(dir) unless Dir.exist?(dir)
|
||||
|
||||
unless File.exist?("#{dir}/weapon-#{size}.txt")
|
||||
File.open("#{dir}/weapon-#{size}.txt", 'w') do |f|
|
||||
Weapon.all.each do |w|
|
||||
f.write("#{build_weapon_url(w.granblue_id.to_s, size)} \n")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
puts "Wrote #{Weapon.count} weapon URLs for \"#{size}\" size"
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue