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

Since:

  • 0.1.0

Returns:

  • the default configuration for card layers and dimensions

{
  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

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

Since:

  • 0.1.0

Parameters:

  • the card configuration



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

def initialize(config)
  assign_attributes(config)
  @template = Template.new
  add_layers
end

Instance Attribute Details

#artString? (readonly)

Returns the URL or path for the card artwork.

Since:

  • 0.1.0

Returns:

  • the URL or path for the card artwork



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

def art
  @art
end

#border_colorString? (readonly)

Returns the border color.

Since:

  • 0.1.0

Returns:

  • the border color



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.

Since:

  • 0.1.0

Returns:

  • the color scheme for the card



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).

Since:

  • 0.1.0

Returns:

  • the flavor text (italic text at bottom)



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").

Since:

  • 0.1.0

Returns:

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



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.

Since:

  • 0.1.0

Returns:

  • the card name



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.

Since:

  • 0.1.0

Returns:

  • the power value for creatures



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.

Since:

  • 0.1.0

Returns:

  • the card description/rules text



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.

Since:

  • 0.1.0

Returns:

  • the toughness value for creatures



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").

Since:

  • 0.1.0

Returns:

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



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



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

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

#card_heightObject

Since:

  • 0.1.0



154
155
156
# File 'lib/mtg_card_maker/base_card.rb', line 154

def card_height
  CARD_HEIGHT
end

#card_widthObject

Delegate dimension methods to DEFAULTS for LayerFactory compatibility

Since:

  • 0.1.0



149
150
151
# File 'lib/mtg_card_maker/base_card.rb', line 149

def card_width
  CARD_WIDTH
end

#dimensions_for_layer(layer_name) ⇒ Object

Since:

  • 0.1.0



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

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

#frame_stroke_widthObject

Since:

  • 0.1.0



169
170
171
# File 'lib/mtg_card_maker/base_card.rb', line 169

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

Since:

  • 0.1.0

Parameters:

  • the filename to save to



134
135
136
# File 'lib/mtg_card_maker/base_card.rb', line 134

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

#use_color_scheme(color) ⇒ Object

Since:

  • 0.1.0



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

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