add covenant

This commit is contained in:
2021-05-30 17:49:54 +02:00
parent d0e5824d40
commit 5b3da08707
29 changed files with 157 additions and 9 deletions

View File

@@ -2,7 +2,7 @@
class WowCharactersController < ProtectedController
def index
@wow_characters = current_user.wow_characters.includes(:wow_realm, :wow_race, :wow_class, :wow_character_medium, :wow_guild)
@wow_characters = current_user.wow_characters.includes(:wow_realm, :wow_race, :wow_class, :wow_character_medium, :wow_guild, :wow_covenant)
end
def show

View File

@@ -10,10 +10,12 @@ class WowCharacter < ApplicationRecord
belongs_to :wow_race
belongs_to :wow_character_title, optional: true
belongs_to :wow_guild, optional: true
has_one :wow_covenant_progress, dependent: :destroy
has_one :wow_covenant, through: :wow_covenant_progress
belongs_to :last_position, class_name: 'WowGeoPosition', optional: true
belongs_to :bind_position, class_name: 'WowGeoPosition', optional: true
has_one :wow_character_medium, dependent: :nullify
has_many :wow_standings, dependent: :nullify
has_one :wow_character_medium, dependent: :destroy
has_many :wow_standings, dependent: :destroy
has_many :wow_reputations, through: :wow_standings
validates :name, presence: true

View File

@@ -0,0 +1,10 @@
class WowCovenant < ApplicationRecord
extend Mobility
translates :name, :description
has_many :wow_covenant_progresses, dependent: :nullify
has_many :wow_characters, through: :wow_covenant_progresses
validates :name, presence: true
validates :covenant_id, presence: true, uniqueness: true
end

View File

@@ -0,0 +1,4 @@
class WowCovenantProgress < ApplicationRecord
belongs_to :wow_character
belongs_to :wow_covenant
end

View File

@@ -10,6 +10,7 @@
<th scope="col"><%= t('wow_characters.character_list.race') %></th>
<th scope="col"><%= t('wow_characters.character_list.class') %></th>
<th scope="col"><%= t('wow_characters.character_list.faction') %></th>
<th scope="col"><%= t('wow_characters.character_list.covenant') %></th>
<th scope="col"><%= t('wow_characters.character_list.level') %></th>
</tr>
</thead>
@@ -25,6 +26,7 @@
<td><%= gender_race_name(character.gender, character.wow_race) %></td>
<td><%= gender_class_name(character.gender, character.wow_class) %></td>
<td><%= character.translated_faction %></td>
<td><%= character.wow_covenant&.name %></td>
<td><%= character.level %></td>
</tr>
<% end %>

View File

@@ -24,6 +24,8 @@ class WowCharacterDetailWorker < WowSidekiqWorker
wow_character.wow_guild = find_or_create_wow_guild(result.guild) if result.guild
wow_character.save
update_covenant_progress(wow_character, result.covenant_progress) if result.covenant_progress
end
def find_or_create_wow_guild(guild)
@@ -36,4 +38,13 @@ class WowCharacterDetailWorker < WowSidekiqWorker
wow_guild.persisted? ? wow_guild : nil
end
def update_covenant_progress(wow_character, covenant_progress)
wow_covenant_progress = wow_character.wow_covenant_progress || WowCovenantProgress.new(wow_character: wow_character)
wow_covenant_progress.renown_level = covenant_progress.renown_level
wow_covenant_progress.wow_covenant = WowCovenant.find_by(covenant_id: covenant_progress.chosen_covenant.id)
wow_covenant_progress.save
end
end

View File

@@ -23,7 +23,7 @@ class WowCharactersWorker < WowSidekiqWorker
wow_char.wow_class = WowClass.where(class_id: character.playable_class.id).first
wow_char.wow_race = WowRace.where(race_id: character.playable_race.id).first
wow_char.user = user
wow_char.account_id = account.map_id
wow_char.account_id = account.id
locales.each do |locale|
Mobility.with_locale(locale[0]) do

View File

@@ -0,0 +1,23 @@
# frozen_string_literal: true
class WowCovenantDetailWorker < WowSidekiqWorker
def perform(covenant_id)
return unless (wow_covenant = WowCovenant.find_by(covenant_id: covenant_id))
RBattlenet.set_options(locale: 'all')
result = RBattlenet::Wow::Covenant.find(covenant_id)
return unless result.status_code == 200
wow_covenant.media_id = result.media.id
# Localisation data
locales.each do |locale|
Mobility.with_locale(locale[0]) do
wow_covenant.description = result.description[locale[1]]
end
end
wow_covenant.save
end
end

View File

@@ -0,0 +1,24 @@
# frozen_string_literal: true
class WowCovenantsWorker < WowSidekiqWorker
def perform
RBattlenet.authenticate(client_id: ENV['BLIZZARD_API_CLIENT_ID'], client_secret: ENV['BLIZZARD_API_CLIENT_SECRET'])
RBattlenet.set_options(locale: 'all')
result = RBattlenet::Wow::Covenant.all
return unless result.status_code == 200
result.covenants.each do |covenant|
wow_covenant = WowCovenant.find_or_initialize_by(covenant_id: covenant.id)
# Localisation data
locales.each do |locale|
Mobility.with_locale(locale[0]) { wow_covenant.name = covenant.name[locale[1]] }
end
wow_covenant.save
WowCovenantDetailWorker.perform_async(wow_covenant.covenant_id) if wow_covenant.persisted?
end
end
end