1
0
Fork 0

Merge branch 'atomaka/feature/costs' into 'master'

Add Cost Stat

Database migration will update all cards to add new stat with all zero values.

See merge request !25
This commit is contained in:
Andrew Tomaka 2015-11-09 12:17:08 -05:00
commit c6a42c7c8f
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_hp_stat
@card.build_atk_stat @card.build_atk_stat
@card.build_def_stat @card.build_def_stat
@card.build_cost_stat
authorize @card authorize @card
end end

View file

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

View file

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

View file

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

View file

@ -26,6 +26,19 @@
.row .row
.col-md-6 .col-md-6
= f.association :dokkan_card, collection: Card.includes(:character).all, label_method: :full_name = 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 .row
.col-md-12 .col-md-12
= f.label 'Health Points' = 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. # 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| create_table "awaken_types", force: :cascade do |t|
t.string "name" t.string "name"
@ -37,6 +37,7 @@ ActiveRecord::Schema.define(version: 20151103193404) do
t.integer "atk_stat_id" t.integer "atk_stat_id"
t.integer "def_stat_id" t.integer "def_stat_id"
t.integer "links_count", default: 0, null: false t.integer "links_count", default: 0, null: false
t.integer "cost_stat_id"
end end
add_index "cards", ["awaken_type_id"], name: "index_cards_on_awaken_type_id" add_index "cards", ["awaken_type_id"], name: "index_cards_on_awaken_type_id"

View file

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