Class: TilesetTooling::Commands::InsertBleed
- Defined in:
- lib/tileset_tooling/commands/insert_bleed.rb
Overview
Command used to insert bleed around tiles
Instance Method Summary collapse
-
#run ⇒ Object
Runs this command.
-
#unpack! ⇒ Object
Validates arguments/options and unpacks them.
Methods inherited from Command
Constructor Details
This class inherits a constructor from TilesetTooling::Commands::Command
Instance Method Details
#run ⇒ Object
Runs this command
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tileset_tooling/commands/insert_bleed.rb', line 20 def run @logger.info("Adding bleed to tiles in image file '#{@image_path}'") tileset = gather_image_information raise(::StandardError, 'Current implementation needs an existing margin') unless tileset.margin.positive? ::MiniMagick::Tool::Convert.new do |convert| convert.background('none') convert << tileset.original_image_path tileset.for_each_tile do |tile| copy_rect(convert, tile.left, tile.top, 1, tile.width, tile.left, tile.top - 1) unless tile.top <= 0 copy_rect(convert, tile.left, tile.bottom - 1, 1, tile.width, tile.left, tile.bottom) unless tile.bottom >= tileset.height copy_rect(convert, tile.left, tile.top, tile.height, 1, tile.left - 1, tile.top) unless tile.left <= 0 copy_rect(convert, tile.right - 1, tile.top, tile.height, 1, tile.right, tile.top) unless tile.right >= tileset.width end convert.flatten convert << result_path end @logger.info("Result stored in '#{result_path}'") end |
#unpack! ⇒ Object
Validates arguments/options and unpacks them
11 12 13 14 15 16 17 |
# File 'lib/tileset_tooling/commands/insert_bleed.rb', line 11 def unpack! raise(::StandardError, 'Missing argument') unless @args.count == 1 @image_path = @args.shift raise(::StandardError, "Could not find image '#{@image_path}'") unless ::File.exist?(@image_path) end |