1
0
Fork 0

Add Cost Stat

This commit is contained in:
Andrew Tomaka 2015-11-09 12:11:53 -05:00
parent 3a80191239
commit 697c893b17
8 changed files with 41 additions and 3 deletions

View File

@ -17,6 +17,7 @@ class Admin::CardsController < Admin::BaseController
@card.build_hp_stat
@card.build_atk_stat
@card.build_def_stat
@card.build_cost_stat
authorize @card
end

View File

@ -4,7 +4,7 @@ class Api::V1::CardsController < Api::V1::BaseController
@cards = Card.includes(:character, :rarity, :type, :leader_skill,
:passive_skill, :super_attack, :awaken_type,
:dokkan_card, :hp_stat, :atk_stat, :def_stat,
:links).all.order(:gameid)
:cost_stat, :links).all.order(:gameid)
render json: @cards, root: false
end

View File

@ -19,10 +19,12 @@ class Card < ActiveRecord::Base
belongs_to :hp_stat, class_name: 'Stat'
belongs_to :atk_stat, class_name: 'Stat'
belongs_to :def_stat, class_name: 'Stat'
belongs_to :cost_stat, class_name: 'Stat'
accepts_nested_attributes_for :hp_stat
accepts_nested_attributes_for :atk_stat
accepts_nested_attributes_for :def_stat
accepts_nested_attributes_for :cost_stat
delegate :name, to: :character, prefix: false
@ -59,6 +61,7 @@ class Card < ActiveRecord::Base
self.hp_stat.stat_type_id = 1
self.atk_stat.stat_type_id = 2
self.def_stat.stat_type_id = 3
self.cost_stat.stat_type_id = 4
self.save
end

View File

@ -1,7 +1,7 @@
class Api::V1::CardSerializer < Api::V1::BaseSerializer
attributes :character, :rarity, :type, :leader_skill, :passive_skill,
:super_attack, :awaken_type, :dokkan_card, :links, :title,
:gameid, :hp_stat, :atk_stat, :def_stat
:gameid, :hp_stat, :atk_stat, :def_stat, :cost_stat
private
@ -63,6 +63,10 @@ class Api::V1::CardSerializer < Api::V1::BaseSerializer
stat_formatter(object.def_stat)
end
def cost_stat
stat_formatter(object.cost_stat)
end
private
def stat_formatter(stat)

View File

@ -26,6 +26,19 @@
.row
.col-md-6
= f.association :dokkan_card, collection: Card.includes(:character).all, label_method: :full_name
.row
.col-md-12
= f.label 'Cost'
.row
= f.simple_fields_for :cost_stat do |c|
.col-md-3
= c.input :min
.col-md-3
= c.input :max
.col-md-3
= c.input :awaken_min
.col-md-3
= c.input :awaken_max
.row
.col-md-12
= f.label 'Health Points'

View File

@ -0,0 +1,15 @@
class AddCostStatToCard < ActiveRecord::Migration
def self.up
add_column :cards, :cost_stat_id, :integer
PaperTrail.whodunnit = 1
Card.all.each do |c|
c.cost_stat = Stat.new(stat_type_id: 4)
c.save
end
end
def self.down
remove_column :cards, :cost_stat_id
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151103193404) do
ActiveRecord::Schema.define(version: 20151109165630) do
create_table "awaken_types", force: :cascade do |t|
t.string "name"
@ -37,6 +37,7 @@ ActiveRecord::Schema.define(version: 20151103193404) do
t.integer "atk_stat_id"
t.integer "def_stat_id"
t.integer "links_count", default: 0, null: false
t.integer "cost_stat_id"
end
add_index "cards", ["awaken_type_id"], name: "index_cards_on_awaken_type_id"

View File

@ -23,6 +23,7 @@ stat_types = [
['HP', 'Health Points'],
['ATK', 'Attack'],
['DEF', 'Defense'],
['Cost', 'Cost'],
]
roles = [