Class: RubySpriter::MetadataManager

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_spriter/metadata_manager.rb

Overview

Manages PNG metadata for spritesheets

Constant Summary collapse

METADATA_PREFIX =
'SPRITESHEET'
METADATA_VERSION =
RubySpriter::VERSION

Class Method Summary collapse

Class Method Details

.embed(input_file, output_file, columns:, rows:, frames:, debug: false) ⇒ Object

Embed metadata into PNG file

Parameters:

  • input_file (String)

    Source PNG file

  • output_file (String)

    Destination PNG file with metadata

  • columns (Integer)

    Number of columns in grid

  • rows (Integer)

    Number of rows in grid

  • frames (Integer)

    Total number of frames

  • debug (Boolean) (defaults to: false)

    Enable debug output



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ruby_spriter/metadata_manager.rb', line 18

def self.embed(input_file, output_file, columns:, rows:, frames:, debug: false)
  Utils::FileHelper.validate_readable!(input_file)

   = (columns, rows, frames)
  
  cmd = build_embed_command(input_file, output_file, )
  
  if debug
    Utils::OutputFormatter.indent("DEBUG: Metadata command: #{cmd}")
  end

  stdout, stderr, status = Open3.capture3(cmd)

  unless status.success?
    raise ProcessingError, "Failed to embed metadata: #{stderr}"
  end

  Utils::FileHelper.validate_exists!(output_file)
end

.read(file) ⇒ Hash?

Read metadata from PNG file

Parameters:

  • file (String)

    PNG file path

Returns:

  • (Hash, nil)

    Metadata hash or nil if not found



41
42
43
44
45
46
47
48
49
50
# File 'lib/ruby_spriter/metadata_manager.rb', line 41

def self.read(file)
  Utils::FileHelper.validate_readable!(file)

  cmd = build_read_command(file)
  stdout, stderr, status = Open3.capture3(cmd)

  return nil unless status.success?

  (stdout)
end

.verify(file) ⇒ Object

Verify and print metadata from file

Parameters:

  • file (String)

    PNG file path



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ruby_spriter/metadata_manager.rb', line 54

def self.verify(file)
  Utils::OutputFormatter.header("Spritesheet Metadata Verification")
  
  puts "File: #{file}"
  puts "Size: #{Utils::FileHelper.format_size(File.size(file))}\n\n"

   = read(file)

  if 
    Utils::OutputFormatter.success("Metadata Found")
    puts "\n  Grid Layout:"
    Utils::OutputFormatter.indent("Columns: #{[:columns]}")
    Utils::OutputFormatter.indent("Rows: #{[:rows]}")
    Utils::OutputFormatter.indent("Total Frames: #{[:frames]}")
    Utils::OutputFormatter.indent("Metadata Version: #{[:version]}")
  else
    Utils::OutputFormatter.warning("No spritesheet metadata found in this file")
    puts "\nThis file may not have been created by Ruby Spriter,"
    puts "or the metadata was stripped during processing."
  end

  puts "\n" + "=" * 60 + "\n"
end