Sha256: 8a1404c4e67d68121e80310c80c06eabef472f5eddfb906d4999951eb787757c

Contents?: true

Size: 1.48 KB

Versions: 5

Compression:

Stored size: 1.48 KB

Contents

module ClassMethods
  def default_type_id
    @@default_type_id ||= Card[:all].fetch( trait: :default ).type_id
  end
end

def type_card
  return if type_id.nil?
  Card.fetch type_id.to_i, skip_modules: true
end

def type_code
  Card::Codename[ type_id.to_i ]
end

def type_name
  type_card.try :name
end

def type_cardname
  type_card.try :cardname
end

def type= type_name
  self.type_id = Card.fetch_id type_name
end

def get_type_id_from_structure
  if name && (t = template)
    reset_patterns # still necessary even with new template handling?
    t.type_id
  end
end

event :validate_type_change, before: :approve, on: :update, changed: :type_id do
  if c = dup and c.action == :create and !c.valid?
    errors.add :type, "of #{ name } can't be changed; errors creating new #{ type_id }: #{ c.errors.full_messages * ', ' }"
  end
end

event :validate_type, before: :approve, changed: :type_id do
  if !type_name
    errors.add :type, "No such type"
  end

  if rt = structure and rt.assigns_type? and type_id!=rt.type_id
    errors.add :type, "can't be changed because #{name} is hard templated to #{rt.type_name}"
  end
end

event :reset_type_specific_fields, after: :store do
  Auth.as_bot do
    Card.search left: { left_id: type_id }, right: {codename: 'type_plus_right'} do |set_card|
      set_card.reset_set_patterns
    end
  end
end

#    Card.search left_plus: [ type_name, right_plus: {codename: 'type_plus_right'}] do |right_anchor|
#      Card["#{lef}"]
#      set_card.reset_set_patterns
#    end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
card-1.16.13 mod/01_core/set/all/type.rb
card-1.16.12 mod/01_core/set/all/type.rb
card-1.16.11 mod/01_core/set/all/type.rb
card-1.16.10 mod/01_core/set/all/type.rb
card-1.16.9 mod/01_core/set/all/type.rb