Class: MtgCardMaker::PowerLayer

Inherits:
BaseLayer show all
Includes:
LayerInitializer
Defined in:
lib/mtg_card_maker/layers/power_layer.rb

Overview

PowerLayer is a specialized layer This is the area that surrounds the power and toughness of the card

Since:

  • 0.1.0

Instance Attribute Summary collapse

Attributes inherited from BaseLayer

#color, #height, #template, #width, #x, #y

Instance Method Summary collapse

Methods inherited from BaseLayer

#svg

Constructor Details

#initialize(dimensions:, power:, toughness:, color: nil, color_scheme: DEFAULT_COLOR_SCHEME) ⇒ PowerLayer

Returns a new instance of PowerLayer.

Since:

  • 0.1.0



10
11
12
13
14
15
16
# File 'lib/mtg_card_maker/layers/power_layer.rb', line 10

def initialize(dimensions:, power:, toughness:, color: nil, color_scheme: DEFAULT_COLOR_SCHEME)
  frame_color = initialize_layer_color(color, color_scheme, :background_color)
  super(dimensions: dimensions, color: frame_color)
  @power = power
  @toughness = toughness
  @color_scheme = color_scheme
end

Instance Attribute Details

#color_schemeObject (readonly)

Since:

  • 0.1.0



8
9
10
# File 'lib/mtg_card_maker/layers/power_layer.rb', line 8

def color_scheme
  @color_scheme
end

#powerObject (readonly)

Since:

  • 0.1.0



8
9
10
# File 'lib/mtg_card_maker/layers/power_layer.rb', line 8

def power
  @power
end

#toughnessObject (readonly)

Since:

  • 0.1.0



8
9
10
# File 'lib/mtg_card_maker/layers/power_layer.rb', line 8

def toughness
  @toughness
end

Instance Method Details

#renderObject

Since:

  • 0.1.0



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/mtg_card_maker/layers/power_layer.rb', line 18

def render
  # Don't render if power or toughness are nil, empty, or invalid
  return if power.nil? || toughness.nil? || power.to_s.strip.empty? || toughness.to_s.strip.empty?

  # Ensure gradients are defined for this color scheme
  SvgGradientService.define_all_gradients(svg, color_scheme)

  layer_config = LayerConfig.default
  stroke_width = layer_config.stroke_width
  corners = layer_config.corner_radius(:power)

  svg.g do
    # P/T box with ornate frame
    svg.rect x: x_position, y: y, width: dynamic_width, height: height,
             fill: "url(##{SvgGradientService.name_gradient_id(color_scheme)})",
             stroke: ColorPalette::FRAME_STROKE_COLOR,
             stroke_width: stroke_width, rx: corners[:x], ry: corners[:y]

    # P/T text with bold styling
    cost_attrs = {
      x:           x_position + (dynamic_width / 2),
      y:           y + (height / 2) + layer_config.positioning(:power_area)[:y_offset],
      fill:        DEFAULT_TEXT_COLOR,
      font_size:   layer_config.font_size(:power_area),
      text_anchor: 'middle',
      class:       'card-power-toughness'
    }
    svg.text "#{power}/#{toughness}", cost_attrs
  end
end