Class: MtgCardMaker::LayerConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/mtg_card_maker/layer_config.rb

Overview

Configuration class for layer-specific styling and positioning that centralizes all hardcoded values used across different layers. This class provides a centralized configuration system for font sizes, positioning, frame styling, and other layer-specific settings.

Examples:

config = MtgCardMaker::LayerConfig.new
config.font_size(:name) # => 32
config.corner_radius(:outer) # => { x: 25, y: 25 }

Custom configuration

custom_config = {
  font_sizes: { name: 36, type: 24 },
  padding: { horizontal: 20 }
}
config = MtgCardMaker::LayerConfig.new(custom_config)

Since:

  • 0.1.0

Constant Summary collapse

DEFAULT_CONFIG =

Default configuration for all layers

Returns:

  • (Hash)

    the default configuration hash

Since:

  • 0.1.0

{
  # Text rendering settings
  font_sizes: {
    name: 32,
    type: 22,
    description: 24,
    flavor_text: 18,
    power_area: 28,
    copyright: 14
  },

  # Text rendering configuration
  text_rendering: {
    default_font_size: 16,
    default_color: '#111',
    default_line_height_multiplier: 1.2,
    char_width_multiplier: 0.42,
    css_classes: {
      card_name: 'card-name',
      card_type: 'card-type',
      card_description: 'card-description',
      flavor_text: 'card-flavor-text',
      power_area: 'card-power-toughness',
      copyright: 'card-copyright'
    }
  },

  # Positioning and spacing
  padding: {
    horizontal: 15,
    vertical: 30
  },

  # Layer-specific positioning offsets
  positioning: {
    name_area: {
      y_offset: 10,
      width_ratio: 0.75
    },
    type_area: {
      y_offset: 8,
      width_ratio: 0.75
    },
    description: {
      y_offset: 30,
      width_ratio: 1.0
    },
    flavor_text: {
      y_offset: 45,
      width_ratio: 1.0,
      separator_offset: 70
    },
    power_area: {
      y_offset: 9
    }
  },

  # Frame styling
  frames: {
    stroke_width: 2,
    corner_radius: {
      name: { x: 10, y: 25 },
      type: { x: 10, y: 25 },
      power: { x: 10, y: 25 },
      art: { x: 8, y: 8 },
      inner: { x: 10, y: 10 },
      outer: { x: 25, y: 25 }
    }
  },

  # Mana cost settings
  mana_cost: {
    circle_radius: 15,
    circle_spacing: 35,
    icon_size: 24,
    max_circles: 10,
    margin: 10
  },

  # Copyright text settings
  copyright: {
    base_y: 830,
    line_spacing: 18,
    x_position: 90
  },

  # Type line icon settings
  type_icon: {
    x_offset: 13,
    y_offset: 4,
    scale: 0.23,
    aspect_ratio: { x: 0.93839063, y: 1.0656543 }
  },

  # Frame settings
  frame: {
    bottom_margin: 120
  },

  # Drop shadow settings
  drop_shadow: {
    dx: -2,
    dy: 2,
    std_deviation: 1,
    flood_opacity: 1.0
  },

  # Text positioning adjustments
  text_positioning: {
    mana_cost_text_y_offset: 7,
    mana_cost_font_size: 24
  },

  # Icon opacity settings
  icon_opacity: {
    mana_cost: 0.7
  }
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(custom_config = {}) ⇒ LayerConfig

Initialize a new layer configuration

Parameters:

  • custom_config (Hash) (defaults to: {})

    custom configuration to merge with defaults

Since:

  • 0.1.0



152
153
154
155
156
# File 'lib/mtg_card_maker/layer_config.rb', line 152

def initialize(custom_config = {})
  # Extend the DEFAULT_CONFIG hash with deep merge functionality
  default_config_with_merge = DEFAULT_CONFIG.dup.extend(DeepMerge)
  @config = default_config_with_merge.deep_merge(custom_config)
end

Instance Attribute Details

#configHash (readonly)

Returns the merged configuration hash.

Returns:

  • (Hash)

    the merged configuration hash

Since:

  • 0.1.0



147
148
149
# File 'lib/mtg_card_maker/layer_config.rb', line 147

def config
  @config
end

Class Method Details

.defaultObject

Class method for easy access to default config

Since:

  • 0.1.0



285
286
287
# File 'lib/mtg_card_maker/layer_config.rb', line 285

def self.default
  new
end

Instance Method Details

#char_width_multiplierObject

Since:

  • 0.1.0



218
219
220
# File 'lib/mtg_card_maker/layer_config.rb', line 218

def char_width_multiplier
  text_rendering_config[:char_width_multiplier]
end

Copyright getters

Since:

  • 0.1.0



192
193
194
# File 'lib/mtg_card_maker/layer_config.rb', line 192

def copyright_config
  config[:copyright]
end

#corner_radius(layer_type) ⇒ Object

Since:

  • 0.1.0



182
183
184
# File 'lib/mtg_card_maker/layer_config.rb', line 182

def corner_radius(layer_type)
  config[:frames][:corner_radius][layer_type] || { x: 5, y: 5 }
end

#css_class(layer_type) ⇒ Object

Since:

  • 0.1.0



222
223
224
# File 'lib/mtg_card_maker/layer_config.rb', line 222

def css_class(layer_type)
  text_rendering_config[:css_classes][layer_type]
end

#default_font_sizeObject

Since:

  • 0.1.0



206
207
208
# File 'lib/mtg_card_maker/layer_config.rb', line 206

def default_font_size
  text_rendering_config[:default_font_size]
end

#default_line_height_multiplierObject

Since:

  • 0.1.0



214
215
216
# File 'lib/mtg_card_maker/layer_config.rb', line 214

def default_line_height_multiplier
  text_rendering_config[:default_line_height_multiplier]
end

#default_text_colorObject

Since:

  • 0.1.0



210
211
212
# File 'lib/mtg_card_maker/layer_config.rb', line 210

def default_text_color
  text_rendering_config[:default_color]
end

#drop_shadow_configObject

Drop shadow getters

Since:

  • 0.1.0



236
237
238
# File 'lib/mtg_card_maker/layer_config.rb', line 236

def drop_shadow_config
  config[:drop_shadow]
end

#font_size(layer_type) ⇒ Object

Font size getters

Since:

  • 0.1.0



159
160
161
# File 'lib/mtg_card_maker/layer_config.rb', line 159

def font_size(layer_type)
  config[:font_sizes][layer_type]
end

#frame_bottom_marginObject

Since:

  • 0.1.0



231
232
233
# File 'lib/mtg_card_maker/layer_config.rb', line 231

def frame_bottom_margin
  frame_config[:bottom_margin]
end

#frame_configObject

Frame getters

Since:

  • 0.1.0



227
228
229
# File 'lib/mtg_card_maker/layer_config.rb', line 227

def frame_config
  config[:frame]
end

#horizontal_paddingObject

Padding getters

Since:

  • 0.1.0



164
165
166
# File 'lib/mtg_card_maker/layer_config.rb', line 164

def horizontal_padding
  config[:padding][:horizontal]
end

#icon_opacity_configObject

Icon opacity getters

Since:

  • 0.1.0



254
255
256
# File 'lib/mtg_card_maker/layer_config.rb', line 254

def icon_opacity_config
  config[:icon_opacity]
end

#mana_cost_configObject

Mana cost getters

Since:

  • 0.1.0



187
188
189
# File 'lib/mtg_card_maker/layer_config.rb', line 187

def mana_cost_config
  config[:mana_cost]
end

#mana_cost_font_sizeObject

Since:

  • 0.1.0



249
250
251
# File 'lib/mtg_card_maker/layer_config.rb', line 249

def mana_cost_font_size
  text_positioning_config[:mana_cost_font_size]
end

#mana_cost_icon_opacityObject

Since:

  • 0.1.0



258
259
260
# File 'lib/mtg_card_maker/layer_config.rb', line 258

def mana_cost_icon_opacity
  icon_opacity_config[:mana_cost]
end

#mana_cost_text_y_offsetObject

Since:

  • 0.1.0



245
246
247
# File 'lib/mtg_card_maker/layer_config.rb', line 245

def mana_cost_text_y_offset
  text_positioning_config[:mana_cost_text_y_offset]
end

#positioning(layer_type) ⇒ Object

Positioning getters

Since:

  • 0.1.0



173
174
175
# File 'lib/mtg_card_maker/layer_config.rb', line 173

def positioning(layer_type)
  config[:positioning][layer_type] || {}
end

#stroke_widthObject

Frame styling getters

Since:

  • 0.1.0



178
179
180
# File 'lib/mtg_card_maker/layer_config.rb', line 178

def stroke_width
  config[:frames][:stroke_width]
end

#text_positioning_configObject

Text positioning getters

Since:

  • 0.1.0



241
242
243
# File 'lib/mtg_card_maker/layer_config.rb', line 241

def text_positioning_config
  config[:text_positioning]
end

#text_rendering_configObject

Text rendering getters

Since:

  • 0.1.0



202
203
204
# File 'lib/mtg_card_maker/layer_config.rb', line 202

def text_rendering_config
  config[:text_rendering]
end

#text_width(base_width, layer_type = nil) ⇒ Object

Convenience methods for common calculations

Since:

  • 0.1.0



263
264
265
266
267
268
269
# File 'lib/mtg_card_maker/layer_config.rb', line 263

def text_width(base_width, layer_type = nil)
  if layer_type && positioning(layer_type)[:width_ratio]
    (base_width * positioning(layer_type)[:width_ratio]) - (horizontal_padding * 2)
  else
    base_width - (horizontal_padding * 2)
  end
end

#text_x_position(base_x) ⇒ Object

Since:

  • 0.1.0



271
272
273
# File 'lib/mtg_card_maker/layer_config.rb', line 271

def text_x_position(base_x)
  base_x + horizontal_padding
end

#text_y_position(base_y, layer_type, height = nil) ⇒ Object

Since:

  • 0.1.0



275
276
277
278
279
280
281
282
# File 'lib/mtg_card_maker/layer_config.rb', line 275

def text_y_position(base_y, layer_type, height = nil)
  offset = positioning(layer_type)[:y_offset] || 0
  if height
    base_y + (height / 2) + offset
  else
    base_y + offset
  end
end

#type_icon_configObject

Type icon getters

Since:

  • 0.1.0



197
198
199
# File 'lib/mtg_card_maker/layer_config.rb', line 197

def type_icon_config
  config[:type_icon]
end

#vertical_paddingObject

Since:

  • 0.1.0



168
169
170
# File 'lib/mtg_card_maker/layer_config.rb', line 168

def vertical_padding
  config[:padding][:vertical]
end