hensei-api/lib/granblue/downloaders/elemental_weapon_downloader.rb
Justin Edmund 0d5d4d5f59
Jedmund/import (#167)
* Move app/helpers/granblue_wiki to lib/parsers/wiki

This clears up the namespace beginning with "Granblue"

* Removed some top-level Granblue libs

DataImporter and DownloadManager exist inside of the PostDeployment namespace now so these files are redundant

* Fix Downloaders namespace

Our namespace was singular Downloader, now it is plural Downloaders to match the folder name

* Fix import paths

* DownloadManager was moved to downloaders/
* import_data task now uses the PostDeployment version of DataImporter

* Update application.rb

Eager-Load/Autoload the lib/ folder

* Update cors.rb

Add Granblue website and Extension ID to CORS

* Add transformers

Transformers take raw data from Granblue Fantasy and transforms them into hensei-compatible JSON. Transformers heavily borrow from vazkii/hensei-transfer.

* Add ImportController and route

This adds the controller that handles creating a full party from transformed Granblue Fantasy data
2025-01-17 12:02:12 -08:00

47 lines
1.3 KiB
Ruby

# frozen_string_literal: true
require_relative 'weapon_downloader'
module Granblue
module Downloaders
class ElementalWeaponDownloader < WeaponDownloader
SUFFIXES = [2, 3, 4, 1, 6, 5].freeze
def initialize(id_base)
@id_base = id_base.to_i
end
def download
(1..6).each do |i|
id = @id_base + (i - 1) * 100
suffix = SUFFIXES[i - 1]
puts "Elemental Weapon #{id}_#{suffix}"
SIZES.each do |size|
path = download_path(size)
url = build_url_for_id(id, size)
filename = "#{id}_#{suffix}.jpg"
download_elemental_image(url, size, path, filename)
end
progress_reporter(count: i, total: 6, result: "Elemental Weapon #{id}_#{suffix}")
end
end
private
def build_url_for_id(id, size)
directory = directory_for_size(size)
"#{base_url}/#{directory}/#{id}.jpg"
end
def progress_reporter(count:, total:, result:, bar_len: 40)
filled_len = (bar_len * count / total).round
status = result
percents = (100.0 * count / total).round(1)
bar = '=' * filled_len + '-' * (bar_len - filled_len)
print("\n[#{bar}] #{percents}% ...#{' ' * 14}#{status}\n")
end
end
end
end