add creature and base rp_world

This commit is contained in:
2021-06-02 22:24:04 +02:00
parent 5b3da08707
commit 62464846a3
56 changed files with 432 additions and 13 deletions

View 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/

View 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

View File

@@ -0,0 +1,2 @@
module RpWorldHelper
end

9
app/models/rp_world.rb Normal file
View 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

View File

@@ -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

View 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

View 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

View 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

View 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

View File

@@ -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' %>

View 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>

View 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>

View 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

View 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

View 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