Class: FactorySpritesheet
- Inherits:
-
Object
- Object
- FactorySpritesheet
- Defined in:
- lib/ordlite/factory.rb
Overview
check - rename to catalog or atlas NOT spritesheet - why? why not?
Class Method Summary collapse
Instance Method Summary collapse
- #add(img) ⇒ Object (also: #<<)
- #add_inscribe(inscribe) ⇒ Object
- #count ⇒ Object (also: #size, #tile_count)
-
#initialize(*images, width:, height:) ⇒ FactorySpritesheet
constructor
A new instance of FactorySpritesheet.
- #tile(index) ⇒ Object (also: #[])
-
#tile_height ⇒ Object
use height - why? why not?.
-
#tile_width ⇒ Object
use width - why? why not?.
Constructor Details
#initialize(*images, width:, height:) ⇒ FactorySpritesheet
Returns a new instance of FactorySpritesheet.
14 15 16 17 18 19 20 |
# File 'lib/ordlite/factory.rb', line 14 def initialize( *images, width:, height: ) @tile_width = width @tile_height = height @tiles = [] images.each {|img| add(img) } end |
Class Method Details
.read_inscribes(*inscribes, width:, height:) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/ordlite/factory.rb', line 4 def self.read_inscribes( *inscribes, width:, height: ) ## map inscribes to images images = inscribes.map {|inscribe| Pixelart::Image.blob( inscribe.content ) } ## puts " #{images.size} image(s)" new( *images, width: width, height: height) end |
Instance Method Details
#add(img) ⇒ Object Also known as: <<
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ordlite/factory.rb', line 32 def add( img ) ## 1:1 tile; use as is if img.width == @tile_width && img.height == @tile_height @tiles << img else ## assume spritesheet?? ## wrap into composite image composite = Pixelart::ImageComposite.new( img.image, width: @tile_width, height: @tile_height ) cols = img.width / composite.tile_width rows = img.height / composite.tile_height puts " #{composite.count} tile(s) in #{cols}x#{rows} grid" composite.each {|tile| @tiles << tile } end end |
#add_inscribe(inscribe) ⇒ Object
31 |
# File 'lib/ordlite/factory.rb', line 31 def add_inscribe( inscribe ) _add( Pixelart::Image.blob( inscribe.content )); end |
#count ⇒ Object Also known as: size, tile_count
22 |
# File 'lib/ordlite/factory.rb', line 22 def count() @tiles.size; end |
#tile(index) ⇒ Object Also known as: []
28 |
# File 'lib/ordlite/factory.rb', line 28 def tile( index ) @tiles[ index ]; end |
#tile_height ⇒ Object
use height - why? why not?
26 |
# File 'lib/ordlite/factory.rb', line 26 def tile_height() @tile_height; end |
#tile_width ⇒ Object
use width - why? why not?
25 |
# File 'lib/ordlite/factory.rb', line 25 def tile_width() @tile_width; end |