add creature and base rp_world
This commit is contained in:
3
app/assets/stylesheets/rp_world.scss
Normal file
3
app/assets/stylesheets/rp_world.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the RpWorld controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: https://sass-lang.com/
|
||||
9
app/controllers/rp_worlds_controller.rb
Normal file
9
app/controllers/rp_worlds_controller.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class RpWorldsController < ApplicationController
|
||||
def index
|
||||
@rp_worlds = RpWorld.all
|
||||
end
|
||||
|
||||
def show
|
||||
@rp_world = RpWorld.includes(:wow_characters).find(params[:id])
|
||||
end
|
||||
end
|
||||
2
app/helpers/rp_world_helper.rb
Normal file
2
app/helpers/rp_world_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module RpWorldHelper
|
||||
end
|
||||
9
app/models/rp_world.rb
Normal file
9
app/models/rp_world.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class RpWorld < ApplicationRecord
|
||||
belongs_to :user
|
||||
alias_attribute :owner, :user
|
||||
has_many :wow_character_play_rp_worlds, dependent: :destroy
|
||||
has_many :wow_characters, through: :wow_character_play_rp_worlds
|
||||
alias_attribute :members, :wow_characters
|
||||
|
||||
validates :name, presence: true
|
||||
end
|
||||
@@ -17,6 +17,8 @@ class WowCharacter < ApplicationRecord
|
||||
has_one :wow_character_medium, dependent: :destroy
|
||||
has_many :wow_standings, dependent: :destroy
|
||||
has_many :wow_reputations, through: :wow_standings
|
||||
has_many :wow_character_play_rp_worlds, dependent: :destroy
|
||||
has_many :rp_worlds, through: :wow_character_play_rp_worlds
|
||||
|
||||
validates :name, presence: true
|
||||
validates :character_id, presence: true, uniqueness: true
|
||||
|
||||
7
app/models/wow_character_play_rp_world.rb
Normal file
7
app/models/wow_character_play_rp_world.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class WowCharacterPlayRpWorld < ApplicationRecord
|
||||
belongs_to :wow_character
|
||||
belongs_to :rp_world
|
||||
|
||||
validates :status, presence: true, format: { with: /(INVITED|PENDING|PLAYING|BANNED)/ }
|
||||
validates :role, presence: true, format: { with: /(PLAYER|MODERATOR|ADMIN)/ }
|
||||
end
|
||||
10
app/models/wow_creature.rb
Normal file
10
app/models/wow_creature.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class WowCreature < ApplicationRecord
|
||||
extend Mobility
|
||||
translates :name
|
||||
|
||||
belongs_to :wow_creature_family, optional: true
|
||||
belongs_to :wow_creature_type, optional: true
|
||||
|
||||
validates :name, presence: true
|
||||
validates :creature_id, presence: true, uniqueness: true
|
||||
end
|
||||
9
app/models/wow_creature_family.rb
Normal file
9
app/models/wow_creature_family.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class WowCreatureFamily < ApplicationRecord
|
||||
extend Mobility
|
||||
translates :name
|
||||
|
||||
has_many :wow_creatures, dependent: :destroy
|
||||
|
||||
validates :name, presence: true
|
||||
validates :creature_family_id, presence: true, uniqueness: true
|
||||
end
|
||||
9
app/models/wow_creature_type.rb
Normal file
9
app/models/wow_creature_type.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class WowCreatureType < ApplicationRecord
|
||||
extend Mobility
|
||||
translates :name
|
||||
|
||||
has_many :wow_creatures, dependent: :destroy
|
||||
|
||||
validates :name, presence: true
|
||||
validates :creature_type_id, presence: true, uniqueness: true
|
||||
end
|
||||
@@ -16,6 +16,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link <%= 'active' if current_page?(wow_reputations_path) %>" aria-current="page" href="<%= wow_reputations_path %>"><%= t('layouts.navbar.reputations') %></a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link <%= 'active' if current_page?(rp_worlds_path) %>" aria-current="page" href="<%= rp_worlds_path %>"><%= t('layouts.navbar.worlds') %></a>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
|
||||
<%= render 'layouts/locales' %>
|
||||
|
||||
18
app/views/rp_worlds/index.html.erb
Normal file
18
app/views/rp_worlds/index.html.erb
Normal file
@@ -0,0 +1,18 @@
|
||||
<h2>Characters list</h2>
|
||||
|
||||
<table class="table table-hover table-dark table-image">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><%= t('rp_worlds.world_list.name') %></th>
|
||||
<th scope="col"><%= t('rp_worlds.world_list.description') %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @rp_worlds.each do |world| %>
|
||||
<tr>
|
||||
<td><%= link_to world.name, world %></td>
|
||||
<td><%= world.description %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
17
app/views/rp_worlds/show.html.erb
Normal file
17
app/views/rp_worlds/show.html.erb
Normal file
@@ -0,0 +1,17 @@
|
||||
<div class="row">
|
||||
<div class="col-5">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title"><%= @rp_world.name %></h5>
|
||||
<p class="card-text">Description: <%= @rp_world.description %></p>
|
||||
<p>Membres: </p>
|
||||
<% @rp_world.wow_characters.each do |member| %>
|
||||
<p><%= link_to member.name, member %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-7">
|
||||
<h1>Suite...</h1>
|
||||
</div>
|
||||
</div>
|
||||
22
app/workers/wow_creature_families_worker.rb
Normal file
22
app/workers/wow_creature_families_worker.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class WowCreatureFamiliesWorker < 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::CreatureFamily.all
|
||||
|
||||
return unless result.status_code == 200
|
||||
|
||||
result.creature_families.each do |creature_family|
|
||||
wow_creature_family = WowCreatureFamily.find_or_initialize_by(creature_family_id: creature_family.id)
|
||||
|
||||
# Localisation data
|
||||
locales.each do |locale|
|
||||
Mobility.with_locale(locale[0]) { wow_creature_family.name = creature_family.name[locale[1]] }
|
||||
end
|
||||
|
||||
wow_creature_family.save
|
||||
end
|
||||
end
|
||||
end
|
||||
22
app/workers/wow_creature_types_worker.rb
Normal file
22
app/workers/wow_creature_types_worker.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class WowCreatureTypesWorker < 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::CreatureType.all
|
||||
|
||||
return unless result.status_code == 200
|
||||
|
||||
result.creature_types.each do |creature_type|
|
||||
wow_creature_type = WowCreatureType.find_or_initialize_by(creature_type_id: creature_type.id)
|
||||
|
||||
# Localisation data
|
||||
locales.each do |locale|
|
||||
Mobility.with_locale(locale[0]) { wow_creature_type.name = creature_type.name[locale[1]] }
|
||||
end
|
||||
|
||||
wow_creature_type.save
|
||||
end
|
||||
end
|
||||
end
|
||||
42
app/workers/wow_creatures_worker.rb
Normal file
42
app/workers/wow_creatures_worker.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class WowCreaturesWorker < WowSidekiqWorker
|
||||
def perform(creature_id, batch_size, keep_going_on)
|
||||
RBattlenet.authenticate(client_id: ENV['BLIZZARD_API_CLIENT_ID'], client_secret: ENV['BLIZZARD_API_CLIENT_SECRET'])
|
||||
RBattlenet.set_options(locale: 'all')
|
||||
|
||||
params = {
|
||||
_page: 1,
|
||||
_pageSize: batch_size,
|
||||
orderby: 'id',
|
||||
filters: { id: "[#{creature_id},]" }
|
||||
}
|
||||
result = RBattlenet::Wow::Search::Creature.find(params)
|
||||
|
||||
return unless result.status_code == 200
|
||||
|
||||
result.results&.each do |creature|
|
||||
wow_creature = WowCreature.find_or_initialize_by(creature_id: creature.data.id)
|
||||
|
||||
wow_creature.display_id = creature.data.creature_displays&.first&.id
|
||||
wow_creature.is_tameable = creature.data&.is_tameable
|
||||
|
||||
wow_creature.wow_creature_family = WowCreatureFamily.find_by(creature_family_id: creature.data.family.id) if creature.data.family
|
||||
wow_creature.wow_creature_type = WowCreatureType.find_by(creature_type_id: creature.data.type.id) if creature.data.type
|
||||
|
||||
# Localisation data
|
||||
locales.each do |locale|
|
||||
Mobility.with_locale(locale[0]) do
|
||||
wow_creature.name = creature.data.name[locale[1]]
|
||||
end
|
||||
end
|
||||
|
||||
wow_creature.save
|
||||
end
|
||||
|
||||
# Create a new job for the next batch if keep_going_on is true
|
||||
return unless keep_going_on && !result.results.count.zero?
|
||||
|
||||
WowCreaturesWorker.perform_async(result.results.last.data.id + 1, batch_size, keep_going_on)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user