Class: FactoryGenerator
- Inherits:
-
Object
- Object
- FactoryGenerator
- Defined in:
- lib/ordlite/factory.rb
Class Method Summary collapse
-
.read_inscribes(*inscribes, width:, height:) ⇒ Object
convenience setup helper(s).
Instance Method Summary collapse
- #_parse(spec) ⇒ Object
- #count ⇒ Object
- #generate(*attributes) ⇒ Object (also: #g)
- #height ⇒ Object
-
#initialize(spritesheet) ⇒ FactoryGenerator
constructor
A new instance of FactoryGenerator.
- #parse(spec) ⇒ Object
- #width ⇒ Object
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 |
#count ⇒ Object
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 |
#height ⇒ Object
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 |
#width ⇒ Object
87 |
# File 'lib/ordlite/factory.rb', line 87 def width() @spritesheet.tile_width; end |