motion-sprites 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in motion-sprites.gemspec
4
+ gemspec
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ motion-sprites (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ motion-sprites!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Joel Bryan Juliano <joelbryan.juliano@gmail.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ motion-sprites
2
+ ==============
3
+
4
+ Easily load spritesheet images for RubyMotion.
5
+
6
+ To use, require 'motion-sprites' in your Rakefile.
7
+
8
+ Example usage.
9
+
10
+ class MyApplicationController < UIViewController
11
+ LOLCATS = [[200,70], [50, 50]] # Add constants of your sprite coordinates to easily refer them
12
+
13
+ def loadView
14
+ self.view = UIImageView.alloc.init
15
+ @sprite = MotionSprites.new('spritesheet.png') # 'spritesheet.png' should be copied in the
16
+ # 'resources/spritesheet.png' directory
17
+ end
18
+
19
+ def viewDidLoad
20
+ view.image = @sprite.coordinates(LOLCATS)
21
+ end
22
+ end
23
+
24
+ You can also use Hash and Strings for your coordinates
25
+
26
+ MotionSprites.new('spritesheet.png').coordinates(x: 200, y: 70, width: 50, height: 50)
27
+
28
+ # or
29
+
30
+ MotionSprites.new('spritesheet.png').coordinates("200, 70, 50, 50")
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,12 @@
1
+ require "motion_sprites/version"
2
+ require "motion_sprites/motion_sprites"
3
+
4
+ unless defined?(Motion::Project::Config)
5
+ raise "This file must be required within a RubyMotion project Rakefile."
6
+ end
7
+
8
+ Motion::Project::App.setup do |app|
9
+ Dir.glob(File.join(File.dirname(__FILE__), 'motion_sprites/**/*.rb')).each do |file|
10
+ app.files.unshift(file)
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ class CheckCoordinatesContext
2
+ def self.call(coords)
3
+ CheckCoordinatesContext.new(coords).call
4
+ end
5
+
6
+ def initialize(coords)
7
+ @coords = coords
8
+ @klass = Object.new
9
+ @klass.extend CoordinateRoles
10
+ end
11
+
12
+ def call
13
+ @klass.check_coordinates @coords
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ class CreateRectangleBoundsContext
2
+ def self.call(rect_coords)
3
+ CreateRectangleBoundsContext.new(rect_coords).call
4
+ end
5
+
6
+ def initialize(rect_coords)
7
+ @rect_coords = rect_coords
8
+ @klass = Object.new
9
+ @klass.extend RectangleRoles
10
+ end
11
+
12
+ def call
13
+ @klass.make_rectangle @rect_coords
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ class CreateWithImageInRectangleBoundsContext
2
+ def self.call(sprite, rectangle)
3
+ CreateWithImageInRectangleBoundsContext.new(sprite, rectangle).call
4
+ end
5
+
6
+ def initialize(sprite, rectangle)
7
+ @sprite = sprite
8
+ @rectangle = rectangle
9
+ @klass = Object.new
10
+ @klass.extend ImageRoles
11
+ end
12
+
13
+ def call
14
+ @klass.create_image_sprite_with_rectangle_bounds @sprite, @rectangle
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ class GetCoordinatesFromParametersContext
2
+ def self.call(coords)
3
+ GetCoordinatesFromParameters.new(coords).call
4
+ end
5
+
6
+ def initialize(coords)
7
+ @coords = coords
8
+ @klass = Object.new
9
+ @klass.extend CoordinateRoles
10
+ end
11
+
12
+ def call
13
+ @klass.get_coordinates_from_parameters @coords
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ class LoadSpriteImageContext
2
+ def self.call(image_in_rect)
3
+ LoadSpriteImageContext.new(image_in_rect).call
4
+ end
5
+
6
+ def initialize(image_in_rect)
7
+ @image_in_rect = image_in_rect
8
+ @klass = Object.new
9
+ @klass.extend ImageRoles
10
+ end
11
+
12
+ def call
13
+ @klass.create_image_from_sprite @image_in_rect
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ module CoordinateRoles
2
+ def get_coordinates_from_parameters(coords)
3
+ case coords
4
+ when String
5
+ coords = coords.gsub(/[^[:digit:]]/, ' ').split
6
+ unless coords.size < 4
7
+ [coords[0], coords[1], coords[2], coords[3]]
8
+ end
9
+ end
10
+ end
11
+
12
+ def check_coordinates(coords)
13
+ case coords
14
+ when Hash
15
+ if (coords.has_key?(:width) && coords.has_key?(:height) && coords.has_key?(:x) && coords.has_key?(:y))
16
+ [coords[:x], coords[:y], coords[:width], coords[:height]]
17
+ end
18
+ when Array
19
+ flat_array = coords.flatten
20
+ unless flat_array.size < 4
21
+ [flat_array[0], flat_array[1], flat_array[2], flat_array[3]]
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ module ImageRoles
2
+ def create_image_sprite_with_rectangle_bounds(sprite, rectangle)
3
+ CGImageCreateWithImageInRect(sprite.CGImage, rectangle)
4
+ end
5
+
6
+ def create_image_from_sprite(image_in_rect)
7
+ UIImage.imageWithCGImage(image_in_rect)
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module RectangleRoles
2
+ def make_rectangle(rect_coords)
3
+ CGRectMake(rect_coords[0], rect_coords[1], rect_coords[2], rect_coords[3])
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ class MotionSprites
2
+ def initialize(sprite)
3
+ @sprite = UIImage.imageNamed("#{sprite}")
4
+ end
5
+
6
+ def coordinates(coords)
7
+ rect_coords = CheckCoordinatesContext.new(coords).call
8
+ unless rect_coords
9
+ rect_coords = GetCoordinatesFromParametersContext.new(coords).call
10
+ end
11
+ rect = CreateRectangleBoundsContext.new(rect_coords).call
12
+ image_in_rect = CreateWithImageInRectangleBoundsContext.new(@sprite, rect).call
13
+ LoadSpriteImageContext.new(image_in_rect).call
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module Motion
2
+ module Sprites
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/motion_sprites/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Joel Bryan Juliano"]
6
+ gem.email = ["joelbryan.juliano@gmail.com"]
7
+ gem.description = "Easily load sprite sheet images for RubyMotion"
8
+ gem.summary = "Easily load sprite sheet images for RubyMotion"
9
+ gem.homepage = "http://jjuliano.github.com/motion-sprites"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "motion-sprites"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Motion::Sprites::VERSION
17
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-sprites
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Joel Bryan Juliano
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-20 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Easily load sprite sheet images for RubyMotion
15
+ email:
16
+ - joelbryan.juliano@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - lib/motion-sprites.rb
28
+ - lib/motion_sprites/interactions/contexts/check_coordinates_context.rb
29
+ - lib/motion_sprites/interactions/contexts/create_rectangle_bounds_context.rb
30
+ - lib/motion_sprites/interactions/contexts/create_with_image_in_rectangle_bounds_context.rb
31
+ - lib/motion_sprites/interactions/contexts/get_coordinates_from_parameters_context.rb
32
+ - lib/motion_sprites/interactions/contexts/load_sprite_image_context.rb
33
+ - lib/motion_sprites/interactions/roles/coordinate_roles.rb
34
+ - lib/motion_sprites/interactions/roles/image_roles.rb
35
+ - lib/motion_sprites/interactions/roles/rectangle_roles.rb
36
+ - lib/motion_sprites/motion_sprites.rb
37
+ - lib/motion_sprites/version.rb
38
+ - motion-sprites.gemspec
39
+ homepage: http://jjuliano.github.com/motion-sprites
40
+ licenses: []
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 1.8.24
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Easily load sprite sheet images for RubyMotion
63
+ test_files: []