Class: MtgCardMaker::LayerConfig
- Inherits:
-
Object
- Object
- MtgCardMaker::LayerConfig
- 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.
Constant Summary collapse
- DEFAULT_CONFIG =
Default configuration for all layers
{ # 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
-
#config ⇒ Hash
readonly
The merged configuration hash.
Class Method Summary collapse
-
.default ⇒ Object
Class method for easy access to default config.
Instance Method Summary collapse
- #char_width_multiplier ⇒ Object
-
#copyright_config ⇒ Object
Copyright getters.
- #corner_radius(layer_type) ⇒ Object
- #css_class(layer_type) ⇒ Object
- #default_font_size ⇒ Object
- #default_line_height_multiplier ⇒ Object
- #default_text_color ⇒ Object
-
#drop_shadow_config ⇒ Object
Drop shadow getters.
-
#font_size(layer_type) ⇒ Object
Font size getters.
- #frame_bottom_margin ⇒ Object
-
#frame_config ⇒ Object
Frame getters.
-
#horizontal_padding ⇒ Object
Padding getters.
-
#icon_opacity_config ⇒ Object
Icon opacity getters.
-
#initialize(custom_config = {}) ⇒ LayerConfig
constructor
Initialize a new layer configuration.
-
#mana_cost_config ⇒ Object
Mana cost getters.
- #mana_cost_font_size ⇒ Object
- #mana_cost_icon_opacity ⇒ Object
- #mana_cost_text_y_offset ⇒ Object
-
#positioning(layer_type) ⇒ Object
Positioning getters.
-
#stroke_width ⇒ Object
Frame styling getters.
-
#text_positioning_config ⇒ Object
Text positioning getters.
-
#text_rendering_config ⇒ Object
Text rendering getters.
-
#text_width(base_width, layer_type = nil) ⇒ Object
Convenience methods for common calculations.
- #text_x_position(base_x) ⇒ Object
- #text_y_position(base_y, layer_type, height = nil) ⇒ Object
-
#type_icon_config ⇒ Object
Type icon getters.
- #vertical_padding ⇒ Object
Constructor Details
#initialize(custom_config = {}) ⇒ LayerConfig
Initialize a new layer configuration
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
#config ⇒ Hash (readonly)
Returns the merged configuration hash.
147 148 149 |
# File 'lib/mtg_card_maker/layer_config.rb', line 147 def config @config end |
Class Method Details
.default ⇒ Object
Class method for easy access to default config
285 286 287 |
# File 'lib/mtg_card_maker/layer_config.rb', line 285 def self.default new end |
Instance Method Details
#char_width_multiplier ⇒ Object
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_config ⇒ Object
Copyright getters
192 193 194 |
# File 'lib/mtg_card_maker/layer_config.rb', line 192 def copyright_config config[:copyright] end |
#corner_radius(layer_type) ⇒ Object
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
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_size ⇒ Object
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_multiplier ⇒ Object
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_color ⇒ Object
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_config ⇒ Object
Drop shadow getters
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
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_margin ⇒ Object
231 232 233 |
# File 'lib/mtg_card_maker/layer_config.rb', line 231 def frame_bottom_margin frame_config[:bottom_margin] end |
#frame_config ⇒ Object
Frame getters
227 228 229 |
# File 'lib/mtg_card_maker/layer_config.rb', line 227 def frame_config config[:frame] end |
#horizontal_padding ⇒ Object
Padding getters
164 165 166 |
# File 'lib/mtg_card_maker/layer_config.rb', line 164 def horizontal_padding config[:padding][:horizontal] end |
#icon_opacity_config ⇒ Object
Icon opacity getters
254 255 256 |
# File 'lib/mtg_card_maker/layer_config.rb', line 254 def icon_opacity_config config[:icon_opacity] end |
#mana_cost_config ⇒ Object
Mana cost getters
187 188 189 |
# File 'lib/mtg_card_maker/layer_config.rb', line 187 def mana_cost_config config[:mana_cost] end |
#mana_cost_font_size ⇒ Object
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_opacity ⇒ Object
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_offset ⇒ Object
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
173 174 175 |
# File 'lib/mtg_card_maker/layer_config.rb', line 173 def positioning(layer_type) config[:positioning][layer_type] || {} end |
#stroke_width ⇒ Object
Frame styling getters
178 179 180 |
# File 'lib/mtg_card_maker/layer_config.rb', line 178 def stroke_width config[:frames][:stroke_width] end |
#text_positioning_config ⇒ Object
Text positioning getters
241 242 243 |
# File 'lib/mtg_card_maker/layer_config.rb', line 241 def text_positioning_config config[:text_positioning] end |
#text_rendering_config ⇒ Object
Text rendering getters
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
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
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
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_config ⇒ Object
Type icon getters
197 198 199 |
# File 'lib/mtg_card_maker/layer_config.rb', line 197 def type_icon_config config[:type_icon] end |
#vertical_padding ⇒ Object
168 169 170 |
# File 'lib/mtg_card_maker/layer_config.rb', line 168 def vertical_padding config[:padding][:vertical] end |