Sha256: 3b35489274a555119cfe02a2386dd12f866075506522da80167eeb26311e3716

Contents?: true

Size: 1.67 KB

Versions: 7

Compression:

Stored size: 1.67 KB

Contents

def is_template?
  cardname.trait_name? :structure, :default
end

def is_structure?
  cardname.trait_name? :structure
end

def template
  # currently applicable templating card.
  # note that a *default template is never returned for an existing card.
  @template ||= begin
    @virtual = false

    if new_card?
      new_card_template
    else
      structure_rule_card
    end
  end
end

def new_card_template
  default = rule_card :default, skip_modules: true

  dup_card = dup
  dup_card.type_id = default ? default.type_id : Card.default_type_id

  if (structure = dup_card.structure_rule_card)
    @virtual = true if junction?
    self.type_id = structure.type_id if assign_type_to?(structure)
    structure
  else
    default
  end
end

def assign_type_to? structure
  return if type_id == structure.type_id
  structure.assigns_type?
end

def assigns_type?
  # needed because not all *structure templates govern the type of set members
  # for example, X+*type+*structure governs all cards of type X,
  # but the content rule does not (in fact cannot) have the type X.
  return unless (set_pattern = Card.fetch cardname.trunk_name.tag_name,
                                          skip_modules: true)
  return unless (pattern_code = set_pattern.codename)
  return unless (set_class = Card::SetPattern.find pattern_code)
  set_class.assigns_type
end

def structure
  return unless template && template.is_structure?
  template
end

def virtual?
  return false unless new_card?
  cardname.simple? ? (@virtual = false) : template if @virtual.nil?
  @virtual
end

def structure_rule_card
  card = rule_card :structure, skip_modules: true
  card && card.db_content.strip == '_self' ? nil : card
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
card-1.18.6 mod/01_core/set/all/templating.rb
card-1.18.5 mod/01_core/set/all/templating.rb
card-1.18.4 mod/01_core/set/all/templating.rb
card-1.18.3 mod/01_core/set/all/templating.rb
card-1.18.2 mod/01_core/set/all/templating.rb
card-1.18.1 mod/01_core/set/all/templating.rb
card-1.18.0 mod/01_core/set/all/templating.rb