Compare commits
97 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 32f4c27637 | |||
| 2107739640 | |||
| ce9775c838 | |||
| 91fdbfe393 | |||
| df21dd6f37 | |||
| 1474580d37 | |||
| 6c12b1937a | |||
| 8fb6fab0d7 | |||
| c336aef449 | |||
| 54ed380d57 | |||
| 651a7ff5f6 | |||
| d39dca337b | |||
| 3dc606de9e | |||
| 7a290c2945 | |||
| 6c084610ad | |||
| 2c4d8b6fe1 | |||
| 906faaeb1e | |||
| 986ef2fb56 | |||
| 1e0ada0613 | |||
| 584fd31776 | |||
| 5025f51d04 | |||
| 8bd78d7764 | |||
| 159439a67e | |||
| c70290d6d5 | |||
| caf357a84d | |||
| 7911374c1e | |||
| bc14ac80ec | |||
| 404720d259 | |||
| 7d142ada54 | |||
| ea7650a9bb | |||
| c474d8030b | |||
| 0ff7e7a8dd | |||
| 7de4bb6863 | |||
| 95748db677 | |||
| 90f2f6e390 | |||
| 1f785d4695 | |||
| 3ced0c6523 | |||
| 5b7a61c3bb | |||
| 7d7c96df80 | |||
| cbfe7ce2da | |||
| bb7d32d262 | |||
| 31240936ab | |||
| fcbf97fe0a | |||
| 6bf100a830 | |||
| ec0549cd18 | |||
| 098fdbffa8 | |||
| a1967bbd2c | |||
| 99578d33ee | |||
| 0797306569 | |||
| 559f30226d | |||
| ee7085f65e | |||
| 9fea1350b3 | |||
| 6ecc2a706c | |||
| d91fd72431 | |||
| ed76afe44c | |||
| 4ee65aecd3 | |||
| 67146e3ab3 | |||
| 54948e4435 | |||
| a8a0a5944c | |||
| d343adeca3 | |||
| bd15d91cdd | |||
| 5460a1d167 | |||
| b248fb62ea | |||
| 717c08ea8f | |||
| 422651668e | |||
| 8c1fae02d4 | |||
| bb79f68a2c | |||
| cfee8b0b31 | |||
| cf270f0243 | |||
| 65d8024476 | |||
| 67cc1138e6 | |||
| c5f2c9d080 | |||
| 633db43e94 | |||
| 73022778f6 | |||
| 18ca78a272 | |||
| f73593d8e1 | |||
| 79b9b4e225 | |||
| b6e8dd93b1 | |||
| fa2962ae1c | |||
| a3e76d53e7 | |||
| 1925678888 | |||
| b0b446aba3 | |||
| 433bd19f6d | |||
| 2a465aca3b | |||
| c2576973bb | |||
| 70bbd47606 | |||
| 24b15c0740 | |||
| 3f914d3be7 | |||
| 8f9bd0077e | |||
| 3617088418 | |||
| 5351123aa2 | |||
| beb9f5aa0c | |||
| a2fff663d6 | |||
| 7404bcbac9 | |||
| e18b628940 | |||
| 6cf9c8d2ae | |||
| 3313f21a47 |
24 changed files with 514 additions and 7 deletions
5
Gemfile
5
Gemfile
|
|
@ -44,12 +44,16 @@ gem 'pg_search'
|
|||
# Pagination library
|
||||
gem 'will_paginate', '~> 3.3'
|
||||
|
||||
|
||||
gem 'httparty'
|
||||
|
||||
# Migrate and update data alongside your database structure.
|
||||
gem 'data_migrate'
|
||||
|
||||
# A ruby gem to allow the copying of ActiveRecord objects and their associated children, configurable with a DSL on the model
|
||||
gem 'amoeba'
|
||||
|
||||
|
||||
group :doc do
|
||||
gem 'apipie-rails'
|
||||
gem 'sdoc'
|
||||
|
|
@ -60,6 +64,7 @@ group :development, :test do
|
|||
gem 'dotenv-rails'
|
||||
gem 'factory_bot_rails'
|
||||
gem 'faker'
|
||||
gem 'pry'
|
||||
gem 'rspec_junit_formatter'
|
||||
gem 'rspec-rails'
|
||||
end
|
||||
|
|
|
|||
13
Gemfile.lock
13
Gemfile.lock
|
|
@ -87,6 +87,7 @@ GEM
|
|||
msgpack (~> 1.2)
|
||||
builder (3.2.4)
|
||||
byebug (11.1.3)
|
||||
coderay (1.1.3)
|
||||
concurrent-ruby (1.1.10)
|
||||
crass (1.0.6)
|
||||
data_migrate (8.5.0)
|
||||
|
|
@ -126,6 +127,9 @@ GEM
|
|||
gemoji (>= 2.1.0)
|
||||
globalid (1.0.1)
|
||||
activesupport (>= 5.0)
|
||||
httparty (0.20.0)
|
||||
mime-types (~> 3.0)
|
||||
multi_xml (>= 0.5.2)
|
||||
i18n (1.12.0)
|
||||
concurrent-ruby (~> 1.0)
|
||||
jaro_winkler (1.5.4)
|
||||
|
|
@ -147,10 +151,14 @@ GEM
|
|||
net-smtp
|
||||
marcel (1.0.2)
|
||||
method_source (1.0.0)
|
||||
mime-types (3.4.1)
|
||||
mime-types-data (~> 3.2015)
|
||||
mime-types-data (3.2022.0105)
|
||||
mini_mime (1.1.2)
|
||||
mini_portile2 (2.8.1)
|
||||
minitest (5.17.0)
|
||||
msgpack (1.6.0)
|
||||
multi_xml (0.6.0)
|
||||
net-imap (0.3.4)
|
||||
date
|
||||
net-protocol
|
||||
|
|
@ -172,6 +180,9 @@ GEM
|
|||
pg_search (2.3.6)
|
||||
activerecord (>= 5.2)
|
||||
activesupport (>= 5.2)
|
||||
pry (0.14.1)
|
||||
coderay (~> 1.1)
|
||||
method_source (~> 1.0)
|
||||
psych (5.0.2)
|
||||
stringio
|
||||
puma (6.0.2)
|
||||
|
|
@ -332,10 +343,12 @@ DEPENDENCIES
|
|||
faker
|
||||
figaro
|
||||
gemoji-parser
|
||||
httparty
|
||||
listen
|
||||
oj
|
||||
pg
|
||||
pg_search
|
||||
pry
|
||||
puma
|
||||
rack-cors
|
||||
rails
|
||||
|
|
|
|||
|
|
@ -18,10 +18,33 @@ module Api
|
|||
end
|
||||
|
||||
field :awakening do |c|
|
||||
<<<<<<< HEAD
|
||||
c.awakening
|
||||
end
|
||||
|
||||
field :over_mastery, if: lambda { |_fn, obj, _opt|
|
||||
!obj.ring1['modifier'].nil? && !obj.ring2['modifier'].nil?
|
||||
} do |c|
|
||||
rings = []
|
||||
|
||||
rings.push(c.ring1) unless c.ring1['modifier'].nil?
|
||||
rings.push(c.ring2) unless c.ring2['modifier'].nil?
|
||||
rings.push(c.ring3) unless c.ring3['modifier'].nil?
|
||||
rings.push(c.ring4) unless c.ring4['modifier'].nil?
|
||||
|
||||
rings
|
||||
end
|
||||
|
||||
field :aetherial_mastery, if: lambda { |_fn, obj, _opt|
|
||||
!obj.earring['modifier'].nil?
|
||||
} do |c|
|
||||
c.earring
|
||||
=======
|
||||
{
|
||||
type: AwakeningBlueprint.render_as_hash(c.awakening),
|
||||
level: c.awakening_level
|
||||
}
|
||||
>>>>>>> main
|
||||
end
|
||||
|
||||
field :over_mastery, if: lambda { |_fn, obj, _opt|
|
||||
|
|
|
|||
|
|
@ -9,7 +9,11 @@ module Api
|
|||
end
|
||||
|
||||
view :nested do
|
||||
<<<<<<< HEAD
|
||||
fields :main, :friend, :position, :uncap_level, :transcendence_step
|
||||
=======
|
||||
fields :main, :friend, :position, :quick_summon, :uncap_level, :transcendence_step
|
||||
>>>>>>> main
|
||||
association :summon, name: :object, blueprint: SummonBlueprint
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -17,9 +17,13 @@ module Api
|
|||
]
|
||||
end
|
||||
|
||||
<<<<<<< HEAD
|
||||
fields :granblue_id, :row, :ml, :order
|
||||
=======
|
||||
fields :granblue_id, :row, :order,
|
||||
:master_level, :ultimate_mastery,
|
||||
:accessory, :accessory_type
|
||||
>>>>>>> main
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -45,6 +45,10 @@ module Api
|
|||
}
|
||||
end
|
||||
|
||||
field :remix do |p|
|
||||
p.is_remix
|
||||
end
|
||||
|
||||
association :raid,
|
||||
blueprint: RaidBlueprint,
|
||||
view: :full
|
||||
|
|
@ -74,12 +78,18 @@ module Api
|
|||
include_view :characters
|
||||
include_view :job_skills
|
||||
|
||||
<<<<<<< HEAD
|
||||
association :accessory,
|
||||
blueprint: JobAccessoryBlueprint
|
||||
fields :description, :charge_attack, :button_count, :turn_count, :chain_count
|
||||
=======
|
||||
fields :local_id, :description, :charge_attack,
|
||||
:button_count, :turn_count, :chain_count,
|
||||
:master_level, :ultimate_mastery
|
||||
|
||||
association :accessory,
|
||||
blueprint: JobAccessoryBlueprint
|
||||
>>>>>>> main
|
||||
|
||||
association :source_party,
|
||||
blueprint: PartyBlueprint,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,11 @@ module Api
|
|||
|
||||
before_action :find_party, only: :create
|
||||
before_action :set, only: %i[update destroy]
|
||||
<<<<<<< HEAD
|
||||
before_action :check_authorization, only: %i[update destroy]
|
||||
=======
|
||||
before_action :authorize, only: %i[create update destroy]
|
||||
>>>>>>> main
|
||||
before_action :find_incoming_character, only: :create
|
||||
before_action :find_current_characters, only: :create
|
||||
|
||||
|
|
@ -135,22 +139,33 @@ module Api
|
|||
render_unauthorized_response if current_user && (party.user != current_user)
|
||||
end
|
||||
|
||||
<<<<<<< HEAD
|
||||
def check_authorization
|
||||
render_unauthorized_response if @character.party.user != current_user
|
||||
=======
|
||||
def authorize
|
||||
# Create
|
||||
unauthorized_create = @party && (@party.user != current_user || @party.edit_key != edit_key)
|
||||
unauthorized_update = @character && @character.party && (@character.party.user != current_user || @character.party.edit_key != edit_key)
|
||||
|
||||
render_unauthorized_response if unauthorized_create || unauthorized_update
|
||||
>>>>>>> main
|
||||
end
|
||||
|
||||
# Specify whitelisted properties that can be modified.
|
||||
def character_params
|
||||
params.require(:character).permit(:id, :party_id, :character_id, :position,
|
||||
:uncap_level, :transcendence_step, :perpetuity,
|
||||
<<<<<<< HEAD
|
||||
ring1: %i[modifier strength], ring2: %i[modifier strength],
|
||||
ring3: %i[modifier strength], ring4: %i[modifier strength],
|
||||
earring: %i[modifier strength], awakening: %i[type level])
|
||||
=======
|
||||
:awakening_id, :awakening_level,
|
||||
ring1: %i[modifier strength], ring2: %i[modifier strength],
|
||||
ring3: %i[modifier strength], ring4: %i[modifier strength],
|
||||
earring: %i[modifier strength])
|
||||
>>>>>>> main
|
||||
end
|
||||
|
||||
def resolve_params
|
||||
|
|
|
|||
|
|
@ -3,12 +3,21 @@
|
|||
module Api
|
||||
module V1
|
||||
class GridSummonsController < Api::V1::ApiController
|
||||
<<<<<<< HEAD
|
||||
before_action :set, only: %w[update destroy]
|
||||
|
||||
attr_reader :party, :incoming_summon
|
||||
|
||||
before_action :find_party, only: :create
|
||||
before_action :find_incoming_summon, only: :create
|
||||
=======
|
||||
attr_reader :party, :incoming_summon
|
||||
|
||||
before_action :set, only: %w[update update_uncap_level update_quick_summon]
|
||||
before_action :find_party, only: :create
|
||||
before_action :find_incoming_summon, only: :create
|
||||
before_action :authorize, only: %i[create update update_uncap_level update_quick_summon destroy]
|
||||
>>>>>>> main
|
||||
|
||||
def create
|
||||
# Create the GridSummon with the desired parameters
|
||||
|
|
@ -24,6 +33,12 @@ module Api
|
|||
|
||||
def update
|
||||
@summon.attributes = summon_params
|
||||
<<<<<<< HEAD
|
||||
|
||||
return render json: GridSummonBlueprint.render(@summon, view: :nested, root: :grid_summon) if @summon.save
|
||||
|
||||
render_validation_error_response(@character)
|
||||
=======
|
||||
|
||||
return render json: GridSummonBlueprint.render(@summon, view: :nested, root: :grid_summon) if @summon.save
|
||||
|
||||
|
|
@ -83,6 +98,7 @@ module Api
|
|||
summons = [@summon] + quick_summons
|
||||
|
||||
render json: GridSummonBlueprint.render(summons, view: :nested, root: :summons)
|
||||
>>>>>>> main
|
||||
end
|
||||
|
||||
def save_summon(summon)
|
||||
|
|
@ -97,10 +113,12 @@ module Api
|
|||
|
||||
output = render_grid_summon_view(summon)
|
||||
render json: output, status: :created
|
||||
<<<<<<< HEAD
|
||||
end
|
||||
|
||||
def handle_conflict(summon)
|
||||
conflict_summon = summon.conflicts(party)
|
||||
ap conflict_summon
|
||||
return unless conflict_summon.summon.id == incoming_summon.id
|
||||
|
||||
old_position = conflict_summon.position
|
||||
|
|
@ -108,14 +126,41 @@ module Api
|
|||
|
||||
return unless conflict_summon.save
|
||||
|
||||
output = render_grid_summon_view(conflict_summon, old_position)
|
||||
render json: output
|
||||
=======
|
||||
>>>>>>> main
|
||||
end
|
||||
|
||||
def handle_conflict(summon)
|
||||
conflict_summon = summon.conflicts(party)
|
||||
return unless conflict_summon.summon.id == incoming_summon.id
|
||||
|
||||
old_position = conflict_summon.position
|
||||
conflict_summon.position = summon_params[:position]
|
||||
|
||||
<<<<<<< HEAD
|
||||
summon.uncap_level = summon_params[:uncap_level]
|
||||
summon.transcendence_step = 0
|
||||
|
||||
return unless summon.save!
|
||||
=======
|
||||
return unless conflict_summon.save
|
||||
>>>>>>> main
|
||||
|
||||
output = render_grid_summon_view(conflict_summon, old_position)
|
||||
render json: output
|
||||
end
|
||||
|
||||
def destroy
|
||||
<<<<<<< HEAD
|
||||
render_unauthorized_response if @summon.party.user != current_user
|
||||
return render json: GridSummonBlueprint.render(@summon, view: :destroyed) if @summon.destroy
|
||||
=======
|
||||
summon = GridSummon.find_by('id = ?', params[:id])
|
||||
render_unauthorized_response if summon.party.user != current_user
|
||||
return render json: GridSummonBlueprint.render(summon, view: :destroyed) if summon.destroy
|
||||
>>>>>>> main
|
||||
end
|
||||
|
||||
private
|
||||
|
|
@ -132,6 +177,14 @@ module Api
|
|||
|
||||
def render_grid_summon_view(grid_summon, conflict_position = nil)
|
||||
GridSummonBlueprint.render(grid_summon, view: :nested,
|
||||
<<<<<<< HEAD
|
||||
root: :grid_summon,
|
||||
meta: { replaced: conflict_position })
|
||||
end
|
||||
|
||||
def set
|
||||
@summon = GridSummon.where('id = ?', params[:id]).first
|
||||
=======
|
||||
root: :grid_summon,
|
||||
meta: { replaced: conflict_position })
|
||||
end
|
||||
|
|
@ -146,12 +199,18 @@ module Api
|
|||
|
||||
def set
|
||||
@summon = GridSummon.find_by('id = ?', summon_params[:id])
|
||||
>>>>>>> main
|
||||
end
|
||||
|
||||
# Specify whitelisted properties that can be modified.
|
||||
def summon_params
|
||||
<<<<<<< HEAD
|
||||
params.require(:summon).permit(:id, :party_id, :summon_id, :position, :main, :friend, :uncap_level,
|
||||
:transcendence_step)
|
||||
=======
|
||||
params.require(:summon).permit(:id, :party_id, :summon_id, :position, :main, :friend,
|
||||
:quick_summon, :uncap_level, :transcendence_step)
|
||||
>>>>>>> main
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,6 +3,11 @@
|
|||
module Api
|
||||
module V1
|
||||
class GridWeaponsController < Api::V1::ApiController
|
||||
<<<<<<< HEAD
|
||||
before_action :set, except: %w[create update_uncap_level]
|
||||
|
||||
=======
|
||||
>>>>>>> main
|
||||
attr_reader :party, :incoming_weapon
|
||||
|
||||
before_action :set, except: %w[create update_uncap_level]
|
||||
|
|
@ -121,15 +126,15 @@ module Api
|
|||
# Render the conflict view as a string
|
||||
def render_conflict_view(conflict_weapon, incoming_weapon, incoming_position)
|
||||
ConflictBlueprint.render(nil, view: :weapons,
|
||||
conflict_weapon: conflict_weapon,
|
||||
incoming_weapon: incoming_weapon,
|
||||
incoming_position: incoming_position)
|
||||
conflict_weapon: conflict_weapon,
|
||||
incoming_weapon: incoming_weapon,
|
||||
incoming_position: incoming_position)
|
||||
end
|
||||
|
||||
def render_grid_weapon_view(grid_weapon, conflict_position)
|
||||
GridWeaponBlueprint.render(grid_weapon, view: :full,
|
||||
root: :grid_weapon,
|
||||
meta: { replaced: conflict_position })
|
||||
root: :grid_weapon,
|
||||
meta: { replaced: conflict_position })
|
||||
end
|
||||
|
||||
def save_weapon(weapon)
|
||||
|
|
|
|||
259
app/helpers/granblue_wiki.rb
Normal file
259
app/helpers/granblue_wiki.rb
Normal file
|
|
@ -0,0 +1,259 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rubygems'
|
||||
require 'httparty'
|
||||
require 'strscan'
|
||||
require 'pry'
|
||||
|
||||
# GranblueWiki fetches and parses data from gbf.wiki
|
||||
class GranblueWiki
|
||||
URL = 'https://gbf.wiki/api.php'
|
||||
|
||||
PROFICIENCY_MAP = {
|
||||
'Sabre' => 1,
|
||||
'Dagger' => 2,
|
||||
'Axe' => 3,
|
||||
'Spear' => 4,
|
||||
'Bow' => 5,
|
||||
'Staff' => 6,
|
||||
'Melee' => 7,
|
||||
'Harp' => 8,
|
||||
'Gun' => 9,
|
||||
'Katana' => 10
|
||||
}
|
||||
|
||||
ELEMENT_MAP = {
|
||||
'Wind' => 1,
|
||||
'Fire' => 2,
|
||||
'Water' => 3,
|
||||
'Earth' => 4,
|
||||
'Dark' => 5,
|
||||
'Light' => 6
|
||||
}
|
||||
|
||||
RARITY_MAP = {
|
||||
'R' => 1,
|
||||
'SR' => 2,
|
||||
'SSR' => 3
|
||||
}
|
||||
|
||||
RACE_MAP = {
|
||||
'Other' => 0,
|
||||
'Human' => 1,
|
||||
'Erune' => 2,
|
||||
'Draph' => 3,
|
||||
'Harvin' => 4,
|
||||
'Primal' => 5
|
||||
}
|
||||
|
||||
GENDER_MAP = {
|
||||
'o' => 0,
|
||||
'm' => 1,
|
||||
'f' => 2,
|
||||
'mf' => 3
|
||||
}
|
||||
|
||||
BOOLEAN_MAP = {
|
||||
'yes' => true,
|
||||
'no' => false
|
||||
}
|
||||
|
||||
def fetch(page)
|
||||
query_params = params(page).map do |key, value|
|
||||
"#{key}=#{value}"
|
||||
end.join('&')
|
||||
|
||||
destination = "#{URL}?#{query_params}"
|
||||
response = HTTParty.get(destination)
|
||||
|
||||
response['parse']['wikitext']['*']
|
||||
end
|
||||
|
||||
def save_characters(characters)
|
||||
success = 0
|
||||
characters.each do |chara|
|
||||
success += 1 if parse(chara)
|
||||
end
|
||||
puts "Saved #{success} characters to the database"
|
||||
end
|
||||
def parse(page)
|
||||
parsed = parse_string(fetch(page))
|
||||
info = extract_chara_info(parsed)
|
||||
create_character(info)
|
||||
|
||||
# abilities = extract_abilities(parsed)
|
||||
# ougis = extract_ougis(parsed)
|
||||
|
||||
# ap abilities.merge(ougis)
|
||||
end
|
||||
|
||||
def extract_chara_info(hash)
|
||||
info = Hash.new
|
||||
|
||||
info[:name] = {
|
||||
en: hash['name'],
|
||||
ja: hash['jpname']
|
||||
}
|
||||
info[:id] = hash['id']
|
||||
info[:charid] = hash['charid'].scan(/\b\d{4}\b/)
|
||||
|
||||
info[:flb] = BOOLEAN_MAP.fetch(hash['5star'], false)
|
||||
info[:ulb] = true if hash['max_evo'].to_i == 6
|
||||
|
||||
info[:rarity] = RARITY_MAP.fetch(hash['rarity'], 0)
|
||||
info[:element] = ELEMENT_MAP.fetch(hash['element'], 0)
|
||||
info[:gender] = GENDER_MAP.fetch(hash['gender'], 0)
|
||||
|
||||
profs = hash['weapon'].to_s.split(',')
|
||||
proficiencies = profs.map.with_index do |prof, i|
|
||||
{ "proficiency#{i + 1}" => PROFICIENCY_MAP[prof] }
|
||||
end
|
||||
info[:proficiencies] = proficiencies.reduce({}, :merge)
|
||||
|
||||
races = hash['race'].to_s.split(',')
|
||||
mapped_races = races.map.with_index do |race, i|
|
||||
{ "race#{i + 1}" => RACE_MAP[race] }
|
||||
end
|
||||
info[:races] = mapped_races.reduce({}, :merge)
|
||||
|
||||
info[:hp] = {
|
||||
min_hp: hash['min_hp'].to_i,
|
||||
max_hp: hash['max_hp'].to_i,
|
||||
max_hp_flb: hash['flb_hp'].to_i
|
||||
}
|
||||
|
||||
info[:atk] = {
|
||||
min_atk: hash['min_atk'].to_i,
|
||||
max_atk: hash['max_atk'].to_i,
|
||||
max_atk_flb: hash['flb_atk'].to_i
|
||||
}
|
||||
|
||||
{ 'info' => info.compact }
|
||||
end
|
||||
|
||||
def create_character(hash)
|
||||
info = hash['info']
|
||||
|
||||
c = Character.new
|
||||
c.granblue_id = info[:id]
|
||||
c.character_id = info[:charid]
|
||||
c.name_en = info[:name][:en]
|
||||
c.name_jp = info[:name][:ja]
|
||||
c.flb = info[:flb]
|
||||
c.ulb = info[:ulb] if info.key?(:ulb)
|
||||
c.rarity = info[:rarity]
|
||||
c.element = info[:element]
|
||||
c.gender = info[:gender]
|
||||
c.race1 = info[:races]['race1']
|
||||
c.race2 = info[:races]['race2'] if info[:races].key?('race2')
|
||||
c.proficiency1 = info[:proficiencies]['proficiency1']
|
||||
c.proficiency2 = info[:proficiencies]['proficiency2'] if info[:proficiencies].key?('proficiency2')
|
||||
c.min_hp = info[:hp][:min_hp]
|
||||
c.max_hp = info[:hp][:max_hp]
|
||||
c.max_hp_flb = info[:hp][:max_hp_flb]
|
||||
c.min_atk = info[:atk][:min_atk]
|
||||
c.max_atk = info[:atk][:max_atk]
|
||||
c.max_atk_flb = info[:atk][:max_atk_flb]
|
||||
|
||||
if c.save
|
||||
puts "Saved #{c.name_en} (#{c.granblue_id}) to the database"
|
||||
true
|
||||
end
|
||||
|
||||
false
|
||||
end
|
||||
|
||||
def extract_abilities(hash)
|
||||
abilities = []
|
||||
hash.each do |key, value|
|
||||
next unless key =~ /^a(\d+)_/
|
||||
|
||||
ability_number = Regexp.last_match(1).to_i
|
||||
abilities[ability_number] ||= {}
|
||||
|
||||
case key.gsub(/^a\d+_/, '')
|
||||
when 'cd'
|
||||
cooldown = parse_substring(value)
|
||||
abilities[ability_number]['cooldown'] = cooldown
|
||||
when 'dur'
|
||||
duration = parse_substring(value)
|
||||
abilities[ability_number]['duration'] = duration
|
||||
when 'oblevel'
|
||||
obtained = parse_substring(value)
|
||||
abilities[ability_number]['obtained'] = obtained
|
||||
else
|
||||
abilities[ability_number][key.gsub(/^a\d+_/, '')] = value
|
||||
end
|
||||
end
|
||||
|
||||
{ 'abilities' => abilities.compact }
|
||||
end
|
||||
|
||||
def parse_substring(string)
|
||||
hash = {}
|
||||
|
||||
string.scan(/\|([^|=]+?)=([^|]+)/) do |key, value|
|
||||
value.gsub!(/\}\}$/, '') if value.include?('}}')
|
||||
hash[key] = value
|
||||
end
|
||||
|
||||
hash
|
||||
end
|
||||
|
||||
def extract_ougis(hash)
|
||||
ougi = []
|
||||
hash.each do |key, value|
|
||||
next unless key =~ /^ougi(\d*)_(.*)/
|
||||
|
||||
ougi_number = Regexp.last_match(1)
|
||||
ougi_key = Regexp.last_match(2)
|
||||
ougi[ougi_number.to_i] ||= {}
|
||||
ougi[ougi_number.to_i][ougi_key] = value
|
||||
end
|
||||
|
||||
{ 'ougis' => ougi.compact }
|
||||
end
|
||||
|
||||
def parse_string(string)
|
||||
# Split the string into lines
|
||||
lines = string.split("\n")
|
||||
|
||||
# Initialize an empty hash to store the key/value pairs
|
||||
data = {}
|
||||
|
||||
# Iterate over the lines
|
||||
good_lines = lines.map do |line|
|
||||
line if line[0] == '|' && line.size > 2
|
||||
end
|
||||
|
||||
good_lines.compact.each do |line|
|
||||
trimmed_line = line[1..]
|
||||
|
||||
# Split the line into key and value by the '=' character
|
||||
key, value = trimmed_line.split('=', 2)
|
||||
|
||||
next unless value
|
||||
|
||||
# Strip leading and trailing whitespace from the key and value
|
||||
key = key.strip
|
||||
value = value.strip
|
||||
|
||||
# Store the key/value pair in the data hash
|
||||
data[key] = value
|
||||
end
|
||||
|
||||
# Return the data hash
|
||||
data
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def params(page)
|
||||
{
|
||||
action: 'parse',
|
||||
format: 'json',
|
||||
page: page,
|
||||
prop: 'wikitext'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -13,8 +13,8 @@ Rails.application.config.middleware.insert_before 0, Rack::Cors do
|
|||
origins %w[staging.granblue.team 127.0.0.1:1234]
|
||||
end
|
||||
|
||||
resource '*',
|
||||
resource "*",
|
||||
headers: :any,
|
||||
methods: %i[get post put patch delete options head]
|
||||
methods: [:get, :post, :put, :patch, :delete, :options, :head]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
class ChangeAwakeningTypeDefaultValue < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_column :grid_characters, :awakening_type, :integer, null: false, default: 1
|
||||
end
|
||||
end
|
||||
22
db/migrate/20230107121520_change_mastery_columns_to_jsonb.rb
Normal file
22
db/migrate/20230107121520_change_mastery_columns_to_jsonb.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
class ChangeMasteryColumnsToJsonb < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
# Remove old columns
|
||||
remove_column :grid_characters, :ring_modifier1, :integer
|
||||
remove_column :grid_characters, :ring_modifier2, :integer
|
||||
remove_column :grid_characters, :ring_modifier3, :integer
|
||||
remove_column :grid_characters, :ring_modifier4, :integer
|
||||
remove_column :grid_characters, :ring_strength1, :integer
|
||||
remove_column :grid_characters, :ring_strength2, :integer
|
||||
remove_column :grid_characters, :ring_strength3, :integer
|
||||
remove_column :grid_characters, :ring_strength4, :integer
|
||||
remove_column :grid_characters, :earring_modifier, :integer
|
||||
remove_column :grid_characters, :earring_strength, :integer
|
||||
|
||||
# Add new columns
|
||||
add_column :grid_characters, :ring1, :jsonb, default: { modifier: nil, strength: nil }
|
||||
add_column :grid_characters, :ring2, :jsonb, default: { modifier: nil, strength: nil }
|
||||
add_column :grid_characters, :ring3, :jsonb, default: { modifier: nil, strength: nil }
|
||||
add_column :grid_characters, :ring4, :jsonb, default: { modifier: nil, strength: nil }
|
||||
add_column :grid_characters, :earring, :jsonb, default: { modifier: nil, strength: nil }
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
class ChangeAwakeningColumnsToJsonb < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
# Remove old columns
|
||||
remove_column :grid_characters, :awakening_type, :integer
|
||||
remove_column :grid_characters, :awakening_level, :integer
|
||||
|
||||
# Add new column
|
||||
add_column :grid_characters, :awakening, :jsonb, default: { type: 1, level: 1 }
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
class MakeMasteryColumnsNotNullable < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_column :grid_characters, :ring1, :jsonb, null: false
|
||||
change_column :grid_characters, :ring2, :jsonb, null: false
|
||||
change_column :grid_characters, :ring3, :jsonb, null: false
|
||||
change_column :grid_characters, :ring4, :jsonb, null: false
|
||||
change_column :grid_characters, :earring, :jsonb, null: false
|
||||
change_column :grid_characters, :awakening, :jsonb, null: false
|
||||
end
|
||||
end
|
||||
7
db/migrate/20230108150956_add_source_party_to_parties.rb
Normal file
7
db/migrate/20230108150956_add_source_party_to_parties.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class AddSourcePartyToParties < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_table(:parties) do |t|
|
||||
t.references :source_party, type: :uuid, foreign_key: { to_table: 'parties' }
|
||||
end
|
||||
end
|
||||
end
|
||||
6
db/migrate/20230123035602_add_max_hpatkxlb_to_summon.rb
Normal file
6
db/migrate/20230123035602_add_max_hpatkxlb_to_summon.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
class AddMaxHpatkxlbToSummon < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :summons, :max_atk_xlb, :integer
|
||||
add_column :summons, :max_hp_xlb, :integer
|
||||
end
|
||||
end
|
||||
5
db/migrate/20230123055508_add_granblue_id_to_jobs.rb
Normal file
5
db/migrate/20230123055508_add_granblue_id_to_jobs.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class AddGranblueIdToJobs < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :jobs, :granblue_id, :string
|
||||
end
|
||||
end
|
||||
14
db/migrate/20230124000252_create_job_accessories.rb
Normal file
14
db/migrate/20230124000252_create_job_accessories.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
class CreateJobAccessories < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :job_accessories, id: :uuid, default: -> { "gen_random_uuid()" } do |t|
|
||||
t.references :job, type: :uuid
|
||||
|
||||
t.string :name_en, null: false, unique: true
|
||||
t.string :name_jp, null: false, unique: true
|
||||
t.string :granblue_id, null: false, unique: true
|
||||
|
||||
t.integer :rarity
|
||||
t.date :release_date
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
class AddAccessoryTypeToJobAccessories < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :job_accessories, :accessory_type, :integer
|
||||
end
|
||||
end
|
||||
7
db/migrate/20230124100823_add_accessory_id_to_party.rb
Normal file
7
db/migrate/20230124100823_add_accessory_id_to_party.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class AddAccessoryIdToParty < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_table(:parties) do |t|
|
||||
t.references :accessory, type: :uuid, foreign_key: { to_table: 'job_accessories' }
|
||||
end
|
||||
end
|
||||
end
|
||||
8
db/migrate/20230126030358_add_updates_table.rb
Normal file
8
db/migrate/20230126030358_add_updates_table.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
class AddUpdatesTable < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :app_updates, id: false do |t|
|
||||
t.string :update_type, null: false
|
||||
t.datetime :updated_at, null: false, unique: true, primary_key: true
|
||||
end
|
||||
end
|
||||
end
|
||||
5
db/migrate/20230126040207_add_version_to_app_updates.rb
Normal file
5
db/migrate/20230126040207_add_version_to_app_updates.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class AddVersionToAppUpdates < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :app_updates, :version, :string
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
class AddCharacterAndSummonCountsToParty < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :parties, :characters_count, :integer
|
||||
add_column :parties, :summons_count, :integer
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue