Class: FactoryGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ordlite/factory.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spritesheet) ⇒ FactoryGenerator

Returns a new instance of FactoryGenerator.



60
61
62
# File 'lib/ordlite/factory.rb', line 60

def initialize( spritesheet )
  @spritesheet = spritesheet
end

Class Method Details

.read_inscribes(*inscribes, width:, height:) ⇒ Object

convenience setup helper(s)



53
54
55
56
57
58
# File 'lib/ordlite/factory.rb', line 53

def self.read_inscribes( *inscribes, width:, 
                                     height: )                                         
      new( FactorySpritesheet.read_inscribes( *inscribes,
                                                 width: width,
                                                 height: height ))
end

Instance Method Details

#_parse(spec) ⇒ Object



64
65
66
67
68
69
# File 'lib/ordlite/factory.rb', line 64

def _parse( spec )
  ## for delimiter allow for now:  - why? why not?
  ##     (multiple) space ( )
  ##      command or semicolon
  spec.strip.split( %r{[ ,;/_-]+} ).map {|v| v.to_i(10) }
end

#countObject



89
# File 'lib/ordlite/factory.rb', line 89

def count()   @spritesheet.count; end

#generate(*attributes) ⇒ Object Also known as: g



78
79
80
81
82
83
84
# File 'lib/ordlite/factory.rb', line 78

def generate( *attributes )
  img = Pixelart::Image.new( width, height )
  attributes.each do |num|
      img.compose!( @spritesheet[ num ] )
  end
  img
end

#heightObject



88
# File 'lib/ordlite/factory.rb', line 88

def height()  @spritesheet.tile_height; end

#parse(spec) ⇒ Object



71
72
73
74
75
76
# File 'lib/ordlite/factory.rb', line 71

def parse( spec )
  ## convenience helper
  ##   parses g spec in various (delimited) formats
  g = _parse( spec )
  generate( *g )
end

#widthObject



87
# File 'lib/ordlite/factory.rb', line 87

def width()   @spritesheet.tile_width; end