Class: Ord::Generator
- Inherits:
-
Object
- Object
- Ord::Generator
- Defined in:
- lib/ordgen/generator.rb
Class Method Summary collapse
-
.read(path, width: 24, height: 24) ⇒ Object
convenience setup helper(s).
Instance Method Summary collapse
- #_parse(spec) ⇒ Object
- #count ⇒ Object
- #generate(*attributes) ⇒ Object (also: #g)
- #height ⇒ Object
-
#initialize(spritesheet) ⇒ Generator
constructor
A new instance of Generator.
- #parse(spec) ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(spritesheet) ⇒ Generator
Returns a new instance of Generator.
14 15 16 17 |
# File 'lib/ordgen/generator.rb', line 14 def initialize( spritesheet ) ### todo: check for composite image type? - why? why not? @spritesheet = spritesheet end |
Class Method Details
.read(path, width: 24, height: 24) ⇒ Object
convenience setup helper(s)
7 8 9 10 11 |
# File 'lib/ordgen/generator.rb', line 7 def self.read( path, width: 24, height: 24 ) new( Pixelart::ImageComposite.read( path, width: width, height: height )) end |
Instance Method Details
#_parse(spec) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/ordgen/generator.rb', line 19 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
44 |
# File 'lib/ordgen/generator.rb', line 44 def count() @spritesheet.count; end |
#generate(*attributes) ⇒ Object Also known as: g
33 34 35 36 37 38 39 |
# File 'lib/ordgen/generator.rb', line 33 def generate( *attributes ) img = Pixelart::Image.new( width, height ) attributes.each do |num| img.compose!( @spritesheet[ num ] ) end img end |
#height ⇒ Object
43 |
# File 'lib/ordgen/generator.rb', line 43 def height() @spritesheet.tile_height; end |
#parse(spec) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/ordgen/generator.rb', line 26 def parse( spec ) ## convenience helper ## parses g spec in various (delimited) formats g = _parse( spec ) generate( *g ) end |
#width ⇒ Object
42 |
# File 'lib/ordgen/generator.rb', line 42 def width() @spritesheet.tile_width; end |