forked from OpenNeo/impress
sort effects to the end of the gender/emotion list
This commit is contained in:
parent
74482dbf75
commit
99a23fc2cb
2 changed files with 17 additions and 15 deletions
|
@ -1,20 +1,21 @@
|
||||||
class PetState < ActiveRecord::Base
|
class PetState < ActiveRecord::Base
|
||||||
SwfAssetType = 'biology'
|
SwfAssetType = 'biology'
|
||||||
|
|
||||||
has_many :contributions, :as => :contributed # in case of duplicates being merged
|
has_many :contributions, :as => :contributed # in case of duplicates being merged
|
||||||
has_many :outfits
|
has_many :outfits
|
||||||
has_many :parent_swf_asset_relationships, :foreign_key => 'parent_id',
|
has_many :parent_swf_asset_relationships, :foreign_key => 'parent_id',
|
||||||
:conditions => {:swf_asset_type => SwfAssetType}
|
:conditions => {:swf_asset_type => SwfAssetType}
|
||||||
has_many :swf_assets, :through => :parent_swf_asset_relationships, :source => :biology_asset,
|
has_many :swf_assets, :through => :parent_swf_asset_relationships, :source => :biology_asset,
|
||||||
:conditions => {:type => SwfAssetType}
|
:conditions => {:type => SwfAssetType}
|
||||||
|
|
||||||
belongs_to :pet_type
|
belongs_to :pet_type
|
||||||
|
|
||||||
alias_method :swf_asset_ids_from_association, :swf_asset_ids
|
alias_method :swf_asset_ids_from_association, :swf_asset_ids
|
||||||
|
|
||||||
scope :emotion_order, joins(:parent_swf_asset_relationships).
|
bio_effect_zone_id = 4
|
||||||
group("pet_states.id").order("COUNT(parents_swf_assets.swf_asset_id) DESC, SUM(parents_swf_assets.swf_asset_id) ASC")
|
scope :emotion_order, joins(:parent_swf_asset_relationships => :biology_asset).
|
||||||
|
group("pet_states.id").order("COUNT(swf_assets.zone_id = #{bio_effect_zone_id}) ASC, COUNT(parents_swf_assets.swf_asset_id) DESC, SUM(parents_swf_assets.swf_asset_id) ASC")
|
||||||
|
|
||||||
def reassign_children_to!(main_pet_state)
|
def reassign_children_to!(main_pet_state)
|
||||||
self.contributions.each do |contribution|
|
self.contributions.each do |contribution|
|
||||||
contribution.contributed = main_pet_state
|
contribution.contributed = main_pet_state
|
||||||
|
@ -26,7 +27,7 @@ class PetState < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
ParentSwfAssetRelationship.where(ParentSwfAssetRelationship.arel_table[:parent_id].eq(self.id)).delete_all
|
ParentSwfAssetRelationship.where(ParentSwfAssetRelationship.arel_table[:parent_id].eq(self.id)).delete_all
|
||||||
end
|
end
|
||||||
|
|
||||||
def reassign_duplicates!
|
def reassign_duplicates!
|
||||||
raise "This may only be applied to pet states that represent many duplicate entries" unless duplicate_ids
|
raise "This may only be applied to pet states that represent many duplicate entries" unless duplicate_ids
|
||||||
pet_states = duplicate_ids.split(',').map do |id|
|
pet_states = duplicate_ids.split(',').map do |id|
|
||||||
|
@ -38,19 +39,19 @@ class PetState < ActiveRecord::Base
|
||||||
pet_state.destroy
|
pet_state.destroy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def sort_swf_asset_ids!
|
def sort_swf_asset_ids!
|
||||||
self.swf_asset_ids = swf_asset_ids.split(',').map(&:to_i).sort.join(',')
|
self.swf_asset_ids = swf_asset_ids.split(',').map(&:to_i).sort.join(',')
|
||||||
end
|
end
|
||||||
|
|
||||||
def swf_asset_ids
|
def swf_asset_ids
|
||||||
self['swf_asset_ids']
|
self['swf_asset_ids']
|
||||||
end
|
end
|
||||||
|
|
||||||
def swf_asset_ids=(ids)
|
def swf_asset_ids=(ids)
|
||||||
self['swf_asset_ids'] = ids
|
self['swf_asset_ids'] = ids
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.from_pet_type_and_biology_info(pet_type, info)
|
def self.from_pet_type_and_biology_info(pet_type, info)
|
||||||
swf_asset_ids = []
|
swf_asset_ids = []
|
||||||
info.each do |zone_id, asset_info|
|
info.each do |zone_id, asset_info|
|
||||||
|
@ -104,14 +105,14 @@ class PetState < ActiveRecord::Base
|
||||||
pet_state.parent_swf_asset_relationships = relationships
|
pet_state.parent_swf_asset_relationships = relationships
|
||||||
pet_state
|
pet_state
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.repair_all!
|
def self.repair_all!
|
||||||
self.transaction do
|
self.transaction do
|
||||||
self.all.each do |pet_state|
|
self.all.each do |pet_state|
|
||||||
pet_state.sort_swf_asset_ids!
|
pet_state.sort_swf_asset_ids!
|
||||||
pet_state.save
|
pet_state.save
|
||||||
end
|
end
|
||||||
|
|
||||||
self.
|
self.
|
||||||
select('pet_states.pet_type_id, pet_states.swf_asset_ids, GROUP_CONCAT(DISTINCT pet_states.id) AS duplicate_ids').
|
select('pet_states.pet_type_id, pet_states.swf_asset_ids, GROUP_CONCAT(DISTINCT pet_states.id) AS duplicate_ids').
|
||||||
joins('INNER JOIN pet_states ps2 ON pet_states.pet_type_id = ps2.pet_type_id AND pet_states.swf_asset_ids = ps2.swf_asset_ids').
|
joins('INNER JOIN pet_states ps2 ON pet_states.pet_type_id = ps2.pet_type_id AND pet_states.swf_asset_ids = ps2.swf_asset_ids').
|
||||||
|
@ -124,3 +125,4 @@ class PetState < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ class PetType < ActiveRecord::Base
|
||||||
|
|
||||||
def as_json(options={})
|
def as_json(options={})
|
||||||
if options[:for] == 'wardrobe'
|
if options[:for] == 'wardrobe'
|
||||||
{:id => id, :body_id => body_id, :pet_state_ids => pet_states.select([:id]).emotion_order.map(&:id)}
|
{:id => id, :body_id => body_id, :pet_state_ids => pet_states.select('pet_states.id').emotion_order.map(&:id)}
|
||||||
else
|
else
|
||||||
{:image_hash => image_hash}
|
{:image_hash => image_hash}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue