Class: MtgCardMaker::BaseCard

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

Overview

Base class for all Magic: The Gathering card types that provides common functionality with simplified configuration. This class handles the creation of complete MTG cards with all necessary layers (frames, text, art, etc.) using predefined dimensions and layouts.

Examples:

card = MtgCardMaker::BaseCard.new(
  name: "Lightning Bolt",
  mana_cost: "R",
  type_line: "Instant",
  rules_text: "Lightning Bolt deals 3 damage to any target.",
  color_scheme: :red
)
card.save("lightning_bolt.svg")

Since:

  • 0.1.0

Constant Summary collapse

DEFAULTS =

Fixed defaults for card layout and dimensions

Returns:

  • (Hash)

    the default configuration for card layers and dimensions

Since:

  • 0.1.0

{
  layers: {
    border: {
      x: 0,
      y: 0,
      width: 630,
      height: 880
    },
    frame: {
      x: 10,
      y: 10,
      width: 610,
      height: 860
    },
    name_area: {
      x: 30,
      y: 40,
      width: 570,
      height: 50
    },
    art_layer: {
      x: 40,
      y: 95,
      width: 550,
      height: 400,
      corner_radius: { x: 5, y: 5 }
    },
    type_area: {
      x: 30,
      y: 500,
      width: 570,
      height: 40
    },
    text_box: {
      x: 40,
      y: 545,
      width: 550,
      height: 265
    },
    power_area: {
      x: 455,
      y: 790,
      width: 140,
      height: 40
    }
  },
  mask_id: 'artWindowMask',
  frame_stroke_width: 2
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ BaseCard

Initialize a new card with the given configuration

Parameters:

  • config (Hash)

    the card configuration

Options Hash (config):

  • :name (String)

    the card name

  • :mana_cost (String)

    the mana cost in MTG notation

  • :type_line (String)

    the card type

  • :rules_text (String)

    the card rules text

  • :flavor_text (String)

    the flavor text

  • :power (String)

    the power value for creatures

  • :toughness (String)

    the toughness value for creatures

  • :border_color (String)

    the border color

  • :color (Symbol, String)

    the color scheme

  • :art (String)

    the URL or path for card artwork

  • :embed_font (Boolean)

    whether to embed the font as base64 (default: true)

Since:

  • 0.1.0



125
126
127
128
129
130
# File 'lib/mtg_card_maker/base_card.rb', line 125

def initialize(config)
  assign_attributes(config)
  validate_required_fields
  @template = Template.new(embed_font: config.fetch(:embed_font, true))
  add_layers
end

Instance Attribute Details

#artString? (readonly)

Returns the URL or path for the card artwork.

Returns:

  • (String, nil)

    the URL or path for the card artwork

Since:

  • 0.1.0



109
110
111
# File 'lib/mtg_card_maker/base_card.rb', line 109

def art
  @art
end

#border_colorString? (readonly)

Returns the border color.

Returns:

  • (String, nil)

    the border color

Since:

  • 0.1.0



103
104
105
# File 'lib/mtg_card_maker/base_card.rb', line 103

def border_color
  @border_color
end

#color_schemeColorScheme (readonly)

Returns the color scheme for the card.

Returns:

  • (ColorScheme)

    the color scheme for the card

Since:

  • 0.1.0



106
107
108
# File 'lib/mtg_card_maker/base_card.rb', line 106

def color_scheme
  @color_scheme
end

#flavor_textString? (readonly)

Returns the flavor text (italic text at bottom).

Returns:

  • (String, nil)

    the flavor text (italic text at bottom)

Since:

  • 0.1.0



94
95
96
# File 'lib/mtg_card_maker/base_card.rb', line 94

def flavor_text
  @flavor_text
end

#mana_costString? (readonly)

Returns the mana cost in MTG notation (e.g., "R", "1U").

Returns:

  • (String, nil)

    the mana cost in MTG notation (e.g., "R", "1U")

Since:

  • 0.1.0



85
86
87
# File 'lib/mtg_card_maker/base_card.rb', line 85

def mana_cost
  @mana_cost
end

#nameString? (readonly)

Returns the card name.

Returns:

  • (String, nil)

    the card name

Since:

  • 0.1.0



82
83
84
# File 'lib/mtg_card_maker/base_card.rb', line 82

def name
  @name
end

#powerString? (readonly)

Returns the power value for creatures.

Returns:

  • (String, nil)

    the power value for creatures

Since:

  • 0.1.0



97
98
99
# File 'lib/mtg_card_maker/base_card.rb', line 97

def power
  @power
end

#rules_textString? (readonly)

Returns the card description/rules text.

Returns:

  • (String, nil)

    the card description/rules text

Since:

  • 0.1.0



91
92
93
# File 'lib/mtg_card_maker/base_card.rb', line 91

def rules_text
  @rules_text
end

#toughnessString? (readonly)

Returns the toughness value for creatures.

Returns:

  • (String, nil)

    the toughness value for creatures

Since:

  • 0.1.0



100
101
102
# File 'lib/mtg_card_maker/base_card.rb', line 100

def toughness
  @toughness
end

#type_lineString? (readonly)

Returns the card type (e.g., "Instant", "Creature").

Returns:

  • (String, nil)

    the card type (e.g., "Instant", "Creature")

Since:

  • 0.1.0



88
89
90
# File 'lib/mtg_card_maker/base_card.rb', line 88

def type_line
  @type_line
end

Instance Method Details

#art_window_configObject

Since:

  • 0.1.0



166
167
168
# File 'lib/mtg_card_maker/base_card.rb', line 166

def art_window_config
  DEFAULTS[:layers][:art_layer]
end

#card_heightObject

Since:

  • 0.1.0



156
157
158
# File 'lib/mtg_card_maker/base_card.rb', line 156

def card_height
  CARD_HEIGHT
end

#card_widthObject

Delegate dimension methods to DEFAULTS for LayerFactory compatibility

Since:

  • 0.1.0



151
152
153
# File 'lib/mtg_card_maker/base_card.rb', line 151

def card_width
  CARD_WIDTH
end

#dimensions_for_layer(layer_name) ⇒ Object

Since:

  • 0.1.0



161
162
163
# File 'lib/mtg_card_maker/base_card.rb', line 161

def dimensions_for_layer(layer_name)
  DEFAULTS[:layers][layer_name.to_sym] || {}
end

#frame_stroke_widthObject

Since:

  • 0.1.0



171
172
173
# File 'lib/mtg_card_maker/base_card.rb', line 171

def frame_stroke_width
  DEFAULTS[:frame_stroke_width]
end

#save(filename) ⇒ void

This method returns an undefined value.

Save the card to an SVG file

Parameters:

  • filename (String)

    the filename to save to

Since:

  • 0.1.0



136
137
138
# File 'lib/mtg_card_maker/base_card.rb', line 136

def save(filename)
  @template.save(filename)
end

#use_color_scheme(color) ⇒ Object

Since:

  • 0.1.0



141
142
143
144
145
146
147
# File 'lib/mtg_card_maker/base_card.rb', line 141

def use_color_scheme(color)
  if color
    ColorScheme.new(color)
  else
    DEFAULT_COLOR_SCHEME
  end
end