Class: MtgCardMaker::SpriteSheetService

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

Overview

Service for creating sprite sheets by generating individual cards and stitching them together using SpriteSheetBuilder and SpriteSheetAssets. This service handles the complete workflow from card configurations to final sprite sheet output, including temporary file management.

Examples:

service = MtgCardMaker::SpriteSheetService.new(cards_per_row: 4, spacing: 30)
success = service.create_sprite_sheet(card_configs, 'output.svg')
width, height = service.sprite_dimensions(card_configs.length)

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cards_per_row: 5, spacing: 30) ⇒ SpriteSheetService

Initialize a new sprite sheet service

Parameters:

  • cards_per_row (Integer) (defaults to: 5)

    the number of cards per row (default: 5)

  • spacing (Integer) (defaults to: 30)

    the spacing between cards in pixels (default: 30)

Since:

  • 0.1.0



28
29
30
31
32
33
# File 'lib/mtg_card_maker/sprite_sheet_service.rb', line 28

def initialize(cards_per_row: 5, spacing: 30)
  @cards_per_row = cards_per_row
  @spacing = spacing
  @builder = SpriteSheetBuilder.new(cards_per_row: cards_per_row, spacing: spacing)
  @assets = SpriteSheetAssets.new
end

Instance Attribute Details

#cards_per_rowInteger (readonly)

Returns the number of cards per row in the sprite sheet.

Returns:

  • (Integer)

    the number of cards per row in the sprite sheet

Since:

  • 0.1.0



19
20
21
# File 'lib/mtg_card_maker/sprite_sheet_service.rb', line 19

def cards_per_row
  @cards_per_row
end

#spacingInteger (readonly)

Returns the spacing between cards in pixels.

Returns:

  • (Integer)

    the spacing between cards in pixels

Since:

  • 0.1.0



22
23
24
# File 'lib/mtg_card_maker/sprite_sheet_service.rb', line 22

def spacing
  @spacing
end

Instance Method Details

#create_sprite_sheet(card_configs, output_file) ⇒ Boolean

Create a sprite sheet from an array of card configurations

Parameters:

  • card_configs (Hash)

    the card configurations

  • output_file (String)

    the output file path

Returns:

  • (Boolean)

    true if successful, false if no cards provided

Raises:

  • (StandardError)

    if card generation or sprite creation fails

Since:

  • 0.1.0



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mtg_card_maker/sprite_sheet_service.rb', line 41

def create_sprite_sheet(card_configs, output_file)
  return false if card_configs.empty?

  begin
    # Generate individual cards first
    card_files = generate_individual_cards(card_configs)

    # Stitch them together into a sprite sheet
    stitch_cards_into_sprite(card_files, output_file)
  ensure
    # Clean up temporary files
    cleanup_temp_files(card_files)
  end
end

#sprite_dimensions(card_count) ⇒ Array<Integer>

Calculate sprite sheet dimensions for a given number of cards

Parameters:

  • card_count (Integer)

    the number of cards in the sprite sheet

Returns:

  • (Array<Integer>)

    the width and height of the sprite sheet

Since:

  • 0.1.0



60
61
62
# File 'lib/mtg_card_maker/sprite_sheet_service.rb', line 60

def sprite_dimensions(card_count)
  @builder.sprite_dimensions(card_count)
end