Compare commits

...

97 commits

Author SHA1 Message Date
32f4c27637 Merge main into gbf-wiki 2023-07-16 02:07:33 -07:00
2107739640 Add ability to save characters from wiki script 2023-01-30 03:43:39 -08:00
ce9775c838 Merge staging 2023-01-29 23:58:11 -08:00
91fdbfe393
Merge pull request #64 from jedmund/fix-weapon-conflicts
Small change to assist with weapon conflicts
2023-01-29 23:38:14 -08:00
df21dd6f37 Send replace position 2023-01-29 23:37:24 -08:00
1474580d37
Merge pull request #63 from jedmund/fix-users-response
Fix response when requesting nonexistent user
2023-01-28 20:51:08 -08:00
6c12b1937a Fix response when requesting nonexistent user 2023-01-28 20:50:35 -08:00
8fb6fab0d7
Merge pull request #62 from jedmund/fix-blueprint
Remove accessory fields from JobBlueprint
2023-01-28 04:20:10 -08:00
c336aef449 Remove accessory fields from JobBlueprint 2023-01-28 04:19:53 -08:00
54ed380d57
Merge pull request #61 from jedmund/fix-base-skills
Fix bug preventing selection of base skills
2023-01-28 02:38:31 -08:00
651a7ff5f6
Merge pull request #60 from jedmund/fix-yatima
Fix limit when adding summons
2023-01-28 02:38:19 -08:00
d39dca337b
Merge pull request #58 from jedmund/remove-weapon-count
Fix counter caches
2023-01-28 02:38:07 -08:00
3dc606de9e Fix bug preventing selection of base skills 2023-01-28 02:36:48 -08:00
7a290c2945 Fix limit when adding summons 2023-01-28 02:20:52 -08:00
6c084610ad Fix counter caches 2023-01-28 01:19:46 -08:00
2c4d8b6fe1 Add source party to output 2023-01-28 00:23:06 -08:00
906faaeb1e Change view for remixes 2023-01-28 00:01:40 -08:00
986ef2fb56 Add remix state and remixes to output 2023-01-27 23:33:28 -08:00
1e0ada0613
Merge pull request #56 from jedmund/shields-manabelly
Add accessory output
2023-01-27 11:54:09 -08:00
584fd31776 Update job_blueprint.rb 2023-01-27 11:53:30 -08:00
5025f51d04
Merge pull request #55 from jedmund/updates
Adds support for managing app updates
2023-01-25 22:56:20 -08:00
8bd78d7764 Add version field 2023-01-25 20:03:00 -08:00
159439a67e Rename to version 2023-01-25 20:02:56 -08:00
c70290d6d5 Add primary key to migration 2023-01-25 19:30:06 -08:00
caf357a84d Add support for AppUpdates
* Added model
* Added blueprint
* Added method to ApiController
* Added route
2023-01-25 19:27:49 -08:00
7911374c1e Add updates table 2023-01-25 19:12:29 -08:00
bc14ac80ec Update rake task for manaturas 2023-01-25 18:56:52 -08:00
404720d259 Add relation to Party and output in Blueprint 2023-01-24 02:38:09 -08:00
7d142ada54 Add accessory_id to Party and enable saving
Saves without validation right now
2023-01-24 02:11:54 -08:00
ea7650a9bb Add controller, blueprint and route for JobAccessories 2023-01-23 20:52:20 -08:00
c474d8030b Add rake task for downloading job accessory images 2023-01-23 20:52:10 -08:00
0ff7e7a8dd Add JobAccessory model and add type to schema
We need type because we don't want to hardcode job ids in scripts
2023-01-23 20:52:06 -08:00
7de4bb6863 Add job accessories table 2023-01-23 17:03:41 -08:00
95748db677
Merge pull request #53 from jedmund/add-host-to-rails7
Add host to development environment file
2023-01-23 01:20:56 -08:00
90f2f6e390 Add host to development environment file 2023-01-23 01:20:39 -08:00
1f785d4695
Merge pull request #52 from jedmund/rails7
Properly update to Rails 7
2023-01-23 01:02:45 -08:00
3ced0c6523 Upgrade to rails 7 2023-01-23 01:01:08 -08:00
5b7a61c3bb Add sprockets to gemfile 2023-01-23 00:53:57 -08:00
7d7c96df80
Merge pull request #51 from jedmund/fix-staging-2023012302
Attempt to fix staging by updating gems
2023-01-23 00:44:11 -08:00
cbfe7ce2da Attempt to fix staging by updating gems 2023-01-23 00:42:55 -08:00
bb7d32d262
Merge pull request #50 from jedmund/fix-staging-20230123
Attempt to fix staging (2023-01-23)
2023-01-23 00:01:43 -08:00
31240936ab Move bootsnap back 2023-01-23 00:00:56 -08:00
fcbf97fe0a Recreate schema.rb 2023-01-23 00:00:38 -08:00
6bf100a830
Merge pull request #49 from jedmund/fix-staging-20230122
Attempt to fix staging (2023-01-22)
2023-01-22 23:48:18 -08:00
ec0549cd18
Merge branch 'staging' into fix-staging-20230122 2023-01-22 23:48:11 -08:00
098fdbffa8 Attempt moving Gemfile 2023-01-22 23:45:49 -08:00
a1967bbd2c
Merge pull request #46 from jedmund/job-icons
Adds support for Granblue IDs on Jobs
2023-01-22 23:15:39 -08:00
99578d33ee
Merge branch 'staging' into job-icons 2023-01-22 23:15:31 -08:00
0797306569
Merge pull request #47 from jedmund/transcendence
Adds support for transcendence
2023-01-22 23:14:40 -08:00
559f30226d
Merge pull request #45 from jedmund/summon-renewal
Update summon grid features
2023-01-22 23:13:08 -08:00
ee7085f65e
Merge branch 'staging' into summon-renewal 2023-01-22 23:12:57 -08:00
9fea1350b3
Merge pull request #39 from jedmund/remix-teams
Implements remixing teams
2023-01-22 23:10:05 -08:00
6ecc2a706c
Merge branch 'staging' into remix-teams 2023-01-22 23:09:55 -08:00
d91fd72431
Merge pull request #38 from jedmund/character-mods
Implements mods on GridCharacter
2023-01-22 23:08:59 -08:00
ed76afe44c Add granblue_id to Job output 2023-01-22 22:31:25 -08:00
4ee65aecd3 Add Rake task for creating a list of Job icon URLs 2023-01-22 22:25:02 -08:00
67146e3ab3 Add Granblue ID instead of slug 2023-01-22 21:59:43 -08:00
54948e4435 Add slug to Jobs table 2023-01-22 21:56:08 -08:00
a8a0a5944c Merge branch 'summon-renewal' into transcendence 2023-01-22 21:24:28 -08:00
d343adeca3 Merge branch 'character-mods' into summon-renewal 2023-01-22 21:24:14 -08:00
bd15d91cdd Fix grid character creation
Grid characters were only replacing the character when replacing an existing character, so the mods were persisted. This creates a new GridCharacter every time a replacement happens and destroys the old one.
2023-01-22 21:24:00 -08:00
5460a1d167 Reset transcendence step on uncap 2023-01-22 21:02:19 -08:00
b248fb62ea Add transcendence_step to output 2023-01-22 21:02:06 -08:00
717c08ea8f Update summon task to download XLB images 2023-01-22 21:01:58 -08:00
422651668e Permit transcendence_step 2023-01-22 20:41:24 -08:00
8c1fae02d4 Add update method to GridSummonsController 2023-01-22 20:37:52 -08:00
bb79f68a2c Remove extraneous code 2023-01-22 20:37:15 -08:00
cfee8b0b31 Support for frontend transcendence
Set transcendence step when updating uncap level
2023-01-22 19:58:45 -08:00
cf270f0243 Add XLB and stats to JSON output 2023-01-22 19:57:57 -08:00
65d8024476 Add XLB stat fields 2023-01-22 19:57:49 -08:00
67cc1138e6 Implements limits on GridSummons 2023-01-21 18:44:25 -08:00
c5f2c9d080 Implement deleting summons 2023-01-21 15:41:16 -08:00
633db43e94 Implement removing characters and weapons 2023-01-20 21:39:20 -08:00
73022778f6 Add server-side validation for OM and AM rings
Note: Over mastery is not validating properly yet
2023-01-09 01:51:38 -08:00
18ca78a272 Implement localized remix names 2023-01-09 00:29:12 -08:00
f73593d8e1 Blank values using defaults instead of null 2023-01-09 00:29:01 -08:00
79b9b4e225 Exclude certain values from remixing 2023-01-09 00:05:18 -08:00
b6e8dd93b1 Add party validation and inverse to GridObject associations 2023-01-08 21:50:30 -08:00
fa2962ae1c Add remix method to parties controller 2023-01-08 21:50:30 -08:00
a3e76d53e7 Add amoeba configuration to Party 2023-01-08 21:50:30 -08:00
1925678888 Return when no params 2023-01-08 21:50:30 -08:00
b0b446aba3 Fix set_from_slug 2023-01-08 21:50:30 -08:00
433bd19f6d Fix party creation 2023-01-08 21:50:30 -08:00
2a465aca3b Move shortcode setting to before_save on Party model 2023-01-08 21:50:30 -08:00
c2576973bb Add source party column to parties 2023-01-08 21:50:30 -08:00
70bbd47606 Add endpoint and stub method 2023-01-08 21:49:57 -08:00
24b15c0740 Add amoeba gem for cloning ActiveRecord objects 2023-01-08 21:49:57 -08:00
3f914d3be7 Merge branch 'main' into character-mods 2023-01-08 05:54:00 -08:00
8f9bd0077e Add new fields to output of GridCharacter 2023-01-07 07:51:54 -08:00
3617088418 Add update method for GridCharacter and other utils
* Add check_authorization for before update and eventually destroy runs
* Update permitted parameters
2023-01-07 07:51:40 -08:00
5351123aa2 Add basic validation for various mastery bonuses
* Ensure transcendence is possible on that character
* Ensure transcendence_step is in bounds
* Ensure Over Mastery Attack is a valid value
* Ensure Over Mastery HP is a valid value
* Ensure Over Mastery Attack is 2x Over Mastery HP
* Ensure Awakening level is in bounds
2023-01-07 07:51:04 -08:00
beb9f5aa0c Add GridCharacters#update route 2023-01-07 07:49:39 -08:00
a2fff663d6 More database updates for mastery cols
* Awakening should be jsonb
* All mastery columns are not nullable
2023-01-07 07:49:28 -08:00
7404bcbac9 Change mastery columns to use jsonb
5 columns better than 10
2023-01-07 05:33:16 -08:00
e18b628940 Stuff 2023-01-06 01:30:51 -08:00
6cf9c8d2ae Create 20230106023753_change_awakening_type_default_value.rb 2023-01-06 01:29:09 -08:00
3313f21a47 Learning how to parse 2022-12-30 03:42:30 -08:00
24 changed files with 514 additions and 7 deletions

View file

@ -44,12 +44,16 @@ gem 'pg_search'
# Pagination library # Pagination library
gem 'will_paginate', '~> 3.3' gem 'will_paginate', '~> 3.3'
gem 'httparty'
# Migrate and update data alongside your database structure. # Migrate and update data alongside your database structure.
gem 'data_migrate' gem 'data_migrate'
# A ruby gem to allow the copying of ActiveRecord objects and their associated children, configurable with a DSL on the model # A ruby gem to allow the copying of ActiveRecord objects and their associated children, configurable with a DSL on the model
gem 'amoeba' gem 'amoeba'
group :doc do group :doc do
gem 'apipie-rails' gem 'apipie-rails'
gem 'sdoc' gem 'sdoc'
@ -60,6 +64,7 @@ group :development, :test do
gem 'dotenv-rails' gem 'dotenv-rails'
gem 'factory_bot_rails' gem 'factory_bot_rails'
gem 'faker' gem 'faker'
gem 'pry'
gem 'rspec_junit_formatter' gem 'rspec_junit_formatter'
gem 'rspec-rails' gem 'rspec-rails'
end end

View file

@ -87,6 +87,7 @@ GEM
msgpack (~> 1.2) msgpack (~> 1.2)
builder (3.2.4) builder (3.2.4)
byebug (11.1.3) byebug (11.1.3)
coderay (1.1.3)
concurrent-ruby (1.1.10) concurrent-ruby (1.1.10)
crass (1.0.6) crass (1.0.6)
data_migrate (8.5.0) data_migrate (8.5.0)
@ -126,6 +127,9 @@ GEM
gemoji (>= 2.1.0) gemoji (>= 2.1.0)
globalid (1.0.1) globalid (1.0.1)
activesupport (>= 5.0) activesupport (>= 5.0)
httparty (0.20.0)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
i18n (1.12.0) i18n (1.12.0)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
jaro_winkler (1.5.4) jaro_winkler (1.5.4)
@ -147,10 +151,14 @@ GEM
net-smtp net-smtp
marcel (1.0.2) marcel (1.0.2)
method_source (1.0.0) 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_mime (1.1.2)
mini_portile2 (2.8.1) mini_portile2 (2.8.1)
minitest (5.17.0) minitest (5.17.0)
msgpack (1.6.0) msgpack (1.6.0)
multi_xml (0.6.0)
net-imap (0.3.4) net-imap (0.3.4)
date date
net-protocol net-protocol
@ -172,6 +180,9 @@ GEM
pg_search (2.3.6) pg_search (2.3.6)
activerecord (>= 5.2) activerecord (>= 5.2)
activesupport (>= 5.2) activesupport (>= 5.2)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
psych (5.0.2) psych (5.0.2)
stringio stringio
puma (6.0.2) puma (6.0.2)
@ -332,10 +343,12 @@ DEPENDENCIES
faker faker
figaro figaro
gemoji-parser gemoji-parser
httparty
listen listen
oj oj
pg pg
pg_search pg_search
pry
puma puma
rack-cors rack-cors
rails rails

View file

@ -18,10 +18,33 @@ module Api
end end
field :awakening do |c| 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), type: AwakeningBlueprint.render_as_hash(c.awakening),
level: c.awakening_level level: c.awakening_level
} }
>>>>>>> main
end end
field :over_mastery, if: lambda { |_fn, obj, _opt| field :over_mastery, if: lambda { |_fn, obj, _opt|

View file

@ -9,7 +9,11 @@ module Api
end end
view :nested do view :nested do
<<<<<<< HEAD
fields :main, :friend, :position, :uncap_level, :transcendence_step
=======
fields :main, :friend, :position, :quick_summon, :uncap_level, :transcendence_step fields :main, :friend, :position, :quick_summon, :uncap_level, :transcendence_step
>>>>>>> main
association :summon, name: :object, blueprint: SummonBlueprint association :summon, name: :object, blueprint: SummonBlueprint
end end

View file

@ -17,9 +17,13 @@ module Api
] ]
end end
<<<<<<< HEAD
fields :granblue_id, :row, :ml, :order
=======
fields :granblue_id, :row, :order, fields :granblue_id, :row, :order,
:master_level, :ultimate_mastery, :master_level, :ultimate_mastery,
:accessory, :accessory_type :accessory, :accessory_type
>>>>>>> main
end end
end end
end end

View file

@ -45,6 +45,10 @@ module Api
} }
end end
field :remix do |p|
p.is_remix
end
association :raid, association :raid,
blueprint: RaidBlueprint, blueprint: RaidBlueprint,
view: :full view: :full
@ -74,12 +78,18 @@ module Api
include_view :characters include_view :characters
include_view :job_skills 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, fields :local_id, :description, :charge_attack,
:button_count, :turn_count, :chain_count, :button_count, :turn_count, :chain_count,
:master_level, :ultimate_mastery :master_level, :ultimate_mastery
association :accessory, association :accessory,
blueprint: JobAccessoryBlueprint blueprint: JobAccessoryBlueprint
>>>>>>> main
association :source_party, association :source_party,
blueprint: PartyBlueprint, blueprint: PartyBlueprint,

View file

@ -7,7 +7,11 @@ module Api
before_action :find_party, only: :create before_action :find_party, only: :create
before_action :set, only: %i[update destroy] before_action :set, only: %i[update destroy]
<<<<<<< HEAD
before_action :check_authorization, only: %i[update destroy]
=======
before_action :authorize, only: %i[create update destroy] before_action :authorize, only: %i[create update destroy]
>>>>>>> main
before_action :find_incoming_character, only: :create before_action :find_incoming_character, only: :create
before_action :find_current_characters, 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) render_unauthorized_response if current_user && (party.user != current_user)
end end
<<<<<<< HEAD
def check_authorization
render_unauthorized_response if @character.party.user != current_user
=======
def authorize def authorize
# Create # Create
unauthorized_create = @party && (@party.user != current_user || @party.edit_key != edit_key) 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) unauthorized_update = @character && @character.party && (@character.party.user != current_user || @character.party.edit_key != edit_key)
render_unauthorized_response if unauthorized_create || unauthorized_update render_unauthorized_response if unauthorized_create || unauthorized_update
>>>>>>> main
end end
# Specify whitelisted properties that can be modified. # Specify whitelisted properties that can be modified.
def character_params def character_params
params.require(:character).permit(:id, :party_id, :character_id, :position, params.require(:character).permit(:id, :party_id, :character_id, :position,
:uncap_level, :transcendence_step, :perpetuity, :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, :awakening_id, :awakening_level,
ring1: %i[modifier strength], ring2: %i[modifier strength], ring1: %i[modifier strength], ring2: %i[modifier strength],
ring3: %i[modifier strength], ring4: %i[modifier strength], ring3: %i[modifier strength], ring4: %i[modifier strength],
earring: %i[modifier strength]) earring: %i[modifier strength])
>>>>>>> main
end end
def resolve_params def resolve_params

View file

@ -3,12 +3,21 @@
module Api module Api
module V1 module V1
class GridSummonsController < Api::V1::ApiController 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 attr_reader :party, :incoming_summon
before_action :set, only: %w[update update_uncap_level update_quick_summon] before_action :set, only: %w[update update_uncap_level update_quick_summon]
before_action :find_party, only: :create before_action :find_party, only: :create
before_action :find_incoming_summon, only: :create before_action :find_incoming_summon, only: :create
before_action :authorize, only: %i[create update update_uncap_level update_quick_summon destroy] before_action :authorize, only: %i[create update update_uncap_level update_quick_summon destroy]
>>>>>>> main
def create def create
# Create the GridSummon with the desired parameters # Create the GridSummon with the desired parameters
@ -24,6 +33,12 @@ module Api
def update def update
@summon.attributes = summon_params @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 return render json: GridSummonBlueprint.render(@summon, view: :nested, root: :grid_summon) if @summon.save
@ -83,6 +98,7 @@ module Api
summons = [@summon] + quick_summons summons = [@summon] + quick_summons
render json: GridSummonBlueprint.render(summons, view: :nested, root: :summons) render json: GridSummonBlueprint.render(summons, view: :nested, root: :summons)
>>>>>>> main
end end
def save_summon(summon) def save_summon(summon)
@ -97,10 +113,12 @@ module Api
output = render_grid_summon_view(summon) output = render_grid_summon_view(summon)
render json: output, status: :created render json: output, status: :created
<<<<<<< HEAD
end end
def handle_conflict(summon) def handle_conflict(summon)
conflict_summon = summon.conflicts(party) conflict_summon = summon.conflicts(party)
ap conflict_summon
return unless conflict_summon.summon.id == incoming_summon.id return unless conflict_summon.summon.id == incoming_summon.id
old_position = conflict_summon.position old_position = conflict_summon.position
@ -108,14 +126,41 @@ module Api
return unless conflict_summon.save 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) output = render_grid_summon_view(conflict_summon, old_position)
render json: output render json: output
end end
def destroy 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]) summon = GridSummon.find_by('id = ?', params[:id])
render_unauthorized_response if summon.party.user != current_user render_unauthorized_response if summon.party.user != current_user
return render json: GridSummonBlueprint.render(summon, view: :destroyed) if summon.destroy return render json: GridSummonBlueprint.render(summon, view: :destroyed) if summon.destroy
>>>>>>> main
end end
private private
@ -132,6 +177,14 @@ module Api
def render_grid_summon_view(grid_summon, conflict_position = nil) def render_grid_summon_view(grid_summon, conflict_position = nil)
GridSummonBlueprint.render(grid_summon, view: :nested, 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, root: :grid_summon,
meta: { replaced: conflict_position }) meta: { replaced: conflict_position })
end end
@ -146,12 +199,18 @@ module Api
def set def set
@summon = GridSummon.find_by('id = ?', summon_params[:id]) @summon = GridSummon.find_by('id = ?', summon_params[:id])
>>>>>>> main
end end
# Specify whitelisted properties that can be modified. # Specify whitelisted properties that can be modified.
def summon_params 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, params.require(:summon).permit(:id, :party_id, :summon_id, :position, :main, :friend,
:quick_summon, :uncap_level, :transcendence_step) :quick_summon, :uncap_level, :transcendence_step)
>>>>>>> main
end end
end end
end end

View file

@ -3,6 +3,11 @@
module Api module Api
module V1 module V1
class GridWeaponsController < Api::V1::ApiController class GridWeaponsController < Api::V1::ApiController
<<<<<<< HEAD
before_action :set, except: %w[create update_uncap_level]
=======
>>>>>>> main
attr_reader :party, :incoming_weapon attr_reader :party, :incoming_weapon
before_action :set, except: %w[create update_uncap_level] before_action :set, except: %w[create update_uncap_level]
@ -121,15 +126,15 @@ module Api
# Render the conflict view as a string # Render the conflict view as a string
def render_conflict_view(conflict_weapon, incoming_weapon, incoming_position) def render_conflict_view(conflict_weapon, incoming_weapon, incoming_position)
ConflictBlueprint.render(nil, view: :weapons, ConflictBlueprint.render(nil, view: :weapons,
conflict_weapon: conflict_weapon, conflict_weapon: conflict_weapon,
incoming_weapon: incoming_weapon, incoming_weapon: incoming_weapon,
incoming_position: incoming_position) incoming_position: incoming_position)
end end
def render_grid_weapon_view(grid_weapon, conflict_position) def render_grid_weapon_view(grid_weapon, conflict_position)
GridWeaponBlueprint.render(grid_weapon, view: :full, GridWeaponBlueprint.render(grid_weapon, view: :full,
root: :grid_weapon, root: :grid_weapon,
meta: { replaced: conflict_position }) meta: { replaced: conflict_position })
end end
def save_weapon(weapon) def save_weapon(weapon)

View 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

View file

@ -13,8 +13,8 @@ Rails.application.config.middleware.insert_before 0, Rack::Cors do
origins %w[staging.granblue.team 127.0.0.1:1234] origins %w[staging.granblue.team 127.0.0.1:1234]
end end
resource '*', resource "*",
headers: :any, headers: :any,
methods: %i[get post put patch delete options head] methods: [:get, :post, :put, :patch, :delete, :options, :head]
end end
end end

View file

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

View 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

View file

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

View file

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

View 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

View 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

View file

@ -0,0 +1,5 @@
class AddGranblueIdToJobs < ActiveRecord::Migration[7.0]
def change
add_column :jobs, :granblue_id, :string
end
end

View 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

View file

@ -0,0 +1,5 @@
class AddAccessoryTypeToJobAccessories < ActiveRecord::Migration[7.0]
def change
add_column :job_accessories, :accessory_type, :integer
end
end

View 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

View 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

View file

@ -0,0 +1,5 @@
class AddVersionToAppUpdates < ActiveRecord::Migration[7.0]
def change
add_column :app_updates, :version, :string
end
end

View file

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