aniruby 0.1.3 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f06e5010221982c6ac29ff4f0670f1315236397182aa8df23bbc199b411f959
4
- data.tar.gz: 06752b16a07eae712c689130ac7bfaf41b433a6fc18a2bc26339a6fbba0c14eb
3
+ metadata.gz: 07c57ae1df17b975510ec7c10d3e92f5d3de577a3e59d90fa1237e3b25b9cb8a
4
+ data.tar.gz: f6e1cef73f7016f0c1438720b94250ca0be9f57ffc837241af09d7445a7dbc22
5
5
  SHA512:
6
- metadata.gz: 07dfe64289a335ffc010d07eb7596e8cdea2cdb55084e81a2d789045bb7b3be59471dcc8a8735aee5e5f11ece070566c8ebf05d1e9bf2aadd3af31603c691b7b
7
- data.tar.gz: a47f0888419c88b9ea73d742f283894a0fbb07c8d1bebd9c8bd5fc1a9db367bf16d9da62ab434a6e1afc3f44fd4ad97c8527b05eeb787bc0f298a01d43d4e6a1
6
+ metadata.gz: 7de44afd2d12a498a42ff63bd48ccfecce6a69ede7b22c0a8e4cf0df4b58898de45de19aec652c28dc84fadcfe9d525bc6677d1466b4cfd4c5cea60ab17f74f8
7
+ data.tar.gz: d6cc64703ade970bda443b91a15c400f510d102d8d6371dad2c559806f6e019b2150829d9fa004663e52c5141377f1d2436b4e81a94bcc778cda608869f3b781
data/CHANGELOG.md CHANGED
@@ -7,6 +7,45 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## Unreleased
9
9
 
10
+ ## 0.2.1 - 2023-09-07
11
+
12
+ ### Fixed
13
+
14
+ - **Important**: in v0.2.0 one of the notable changes is that the instance variable `current_frame` was changed to `position`, following that there was
15
+ the need to change every use of `@current_frame` to `@position`, however
16
+ since I wasn't thorough enough I forgot to do that in the `Animation#draw` and `Animation#draw_rot`
17
+ methods, effectively rendering them useless.
18
+ - **Important**: There was a error in `Animation#done?` too, where it'll return `false` always
19
+ independently of if the animation was finished, this was because I forgot to add a `return` in
20
+ the condition check for the `true`.
21
+ - `Animation#update` now resets the animation, instead of `Animation#draw`
22
+ or `Animation#draw_rot` (I know, that sounds unintuitive). This (I think) fixes a precision problem when drawing the last frame
23
+ of an animation, in the which it was drawn for less time than required.
24
+
25
+
26
+ ## 0.2.0 - 2023-09-02
27
+
28
+ This release brings mostly improvements and fixes, however there's not that much
29
+ new features yet.
30
+
31
+ ### Added
32
+
33
+ - aliased `Animation#width` and `Animation#height` to `w` and `h` respectively, the same was done
34
+ for `Frame`.
35
+
36
+ ### Changed
37
+
38
+ - `Animation#get_current_frame` is now `Animation#current_frame` as to not be redundant. Following that now `Animation#current_frame`(The accessor for the instance variable) is renamed to `Animation#position`.
39
+
40
+ ### Fixed
41
+
42
+ - Previously methods like `Animation#done?` or `Animation#resume` didn't return `self`, so it wasn't possible to chaint them like this
43
+ ```ruby
44
+ # Example
45
+ my_animation.pause.resume.duration(200)
46
+ ```
47
+ now they do so you can do that.
48
+
10
49
  ## 0.1.3 - 2023-08-22
11
50
 
12
51
  ### Fixed
@@ -23,18 +62,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
23
62
 
24
63
  ### Changed
25
64
 
26
- - Downcased the gem name in the gemspec
65
+ - Downcased the gem name in the gemspec.
27
66
 
28
67
  ## 0.1.1 - 2023-08-20
29
68
 
30
69
  ### Added
31
70
 
32
- - Add .yardopts to included files
71
+ - Add .yardopts to included files.
33
72
 
34
73
  ### Fixed
35
74
 
36
- - Required ruby not being used correctly in gemspec
75
+ - Required ruby not being used correctly in gemspec.
37
76
 
38
77
  ## 0.1.0 - 2023-08-20
39
78
 
40
- Initial release
79
+ Initial release.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # AniRuby
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/aniruby.svg)](https://badge.fury.io/rb/aniruby)
3
+ ![Gem (including prereleases)](https://img.shields.io/gem/v/aniruby?style=flat-square&logo=rubygems&logoColor=white&color=blue)
4
4
 
5
5
  Make sprite animations on Gosu simple and easy.
6
6
 
@@ -71,9 +71,9 @@ spritesheet will be divided like this:
71
71
 
72
72
  ![example spritesheet quads](assets/example_spritesheet_quads.png)
73
73
 
74
- That is the bare minimum, to get an animation, of course you can use Gosu's retro
75
- option so pixel animations when scaled will still look crisp, looping or the duration
76
- of the animation (or for every individual frame even!).
74
+ That's the bare minimum to get an animation, of course you can enable Gosu's retro
75
+ option so pixel animations will still look crisp when scaled, enable looping or specify
76
+ the duration of the animation (or for every frame even!).
77
77
 
78
78
  In the example above we initialize the animation with retro off, looping on and
79
79
  with a duration of 0.15 (150ms) for every frame. So we'll get something like this:
@@ -84,7 +84,7 @@ Ain't that nice?
84
84
 
85
85
  ### Drawing
86
86
 
87
- You can draw an animation like any other `Gosu::Image`! Sn animation has both
87
+ You can draw an animation like any other `Gosu::Image`! An animation has both
88
88
  `Animation#draw` and `Animation#draw_rot`, these methods mimic the ones on Gosu, so you don't
89
89
  have to learn anything new.
90
90
 
@@ -114,4 +114,4 @@ Then you can use rake to build or test gem.
114
114
 
115
115
  ## License
116
116
 
117
- [MIT](LICENSE)
117
+ This library is licensed under the [MIT](LICENSE) license.
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  require 'fileutils'
3
- require "minitest/test_task"
3
+ require 'minitest/test_task'
4
4
 
5
5
  require_relative 'lib/aniruby/version'
6
6
 
@@ -6,8 +6,8 @@ module AniRuby
6
6
  # @return [AniRuby::Frames] The collection of frames this animation uses
7
7
  attr_accessor :frames
8
8
  # @return [Integer] The current frame index of the animation
9
- attr_accessor :current_frame
10
- # @return [Boolean] The loop status of the animation
9
+ attr_accessor :position
10
+ # @return [Boolean] The loop parameter
11
11
  attr_accessor :loop
12
12
 
13
13
  # Create a new animation
@@ -22,15 +22,18 @@ module AniRuby
22
22
  # provided they will be mapped to each frame of the
23
23
  # animation. The default for each frame is 0.1.
24
24
  #
25
- #
26
25
  # @return [Animation] A new animation ready to play
27
- def initialize(spritesheet, frame_w, frame_h, retro = false, loop = true, *durations)
26
+ def initialize(spritesheet,
27
+ frame_w, frame_h,
28
+ retro = false,
29
+ loop = true,
30
+ *durations)
28
31
  @frame_w = frame_w
29
32
  @frame_h = frame_h
30
33
 
31
34
  @loop = loop
32
35
 
33
- @current_frame = 0
36
+ @position = 0
34
37
  @pause = false
35
38
 
36
39
  @frames = AniRuby::Frames.new(Gosu::Image.load_tiles(spritesheet,
@@ -55,22 +58,30 @@ module AniRuby
55
58
  #
56
59
  # @return [Integer]
57
60
  def width
58
- @frames[@current_frame].sprite.width
61
+ @frames[@position].width
59
62
  end
60
63
 
64
+ alias :w :width
65
+
61
66
  # Get the height of the current frame's image
62
67
  #
63
68
  # @return [Integer]
64
69
  def height
65
- @frames[@current_frame].sprite.height
70
+ @frames[@position].height
66
71
  end
67
72
 
73
+ alias :h :height
74
+
68
75
  # Update the animation, advancing the frame counter. Note that this won't do
69
76
  # do anything if the animation is paused or has finished
70
77
  def update
71
- return if done? || paused?
78
+ return unless frame_expired? && !paused?
72
79
 
73
- @current_frame += 1 if frame_expired?
80
+ if !done?
81
+ @position += 1
82
+ elsif done? && @loop
83
+ @position = 0
84
+ end
74
85
  end
75
86
 
76
87
  # Draw the animation
@@ -89,11 +100,9 @@ module AniRuby
89
100
  scale_y = 1,
90
101
  color = Gosu::Color::WHITE,
91
102
  mode = :default)
92
- frame = @frames[@current_frame]
103
+ frame = @frames[@position]
93
104
 
94
105
  frame.sprite.draw(x, y, z, scale_x, scale_y, color, mode)
95
-
96
- @current_frame = 0 if @loop && done?
97
106
  end
98
107
 
99
108
  # Draw the animation rotated, with its rotational center at (x, y).
@@ -118,12 +127,9 @@ module AniRuby
118
127
  scale_y = 1,
119
128
  color = Gosu::Color::WHITE,
120
129
  mode = :default)
121
- frame = @frames[@current_frame]
130
+ frame = @frames[@position]
122
131
 
123
132
  frame.sprite.draw_rot(x, y, z, angle, center_x, center_y, scale_x, scale_y, color, mode)
124
-
125
- # Loop the animation
126
- @current_frame = 0 if @loop && done?
127
133
  end
128
134
 
129
135
  # Pause the animation
@@ -131,6 +137,8 @@ module AniRuby
131
137
  # (see {resume})
132
138
  def pause
133
139
  @pause = true
140
+
141
+ self
134
142
  end
135
143
 
136
144
  # Resume the animation
@@ -138,18 +146,24 @@ module AniRuby
138
146
  # (see {pause})
139
147
  def resume
140
148
  @pause = false
149
+
150
+ self
141
151
  end
142
152
 
143
153
  # Set the animation to the beginning frame
144
154
  def reset
145
- @current_frame = 0
155
+ @position = 0
156
+
157
+ self
146
158
  end
147
159
 
148
160
  # Set the duration for all frames in the animation
149
161
  #
150
162
  # @param ms [Float] The new duration in milliseconds
151
163
  def duration(ms)
152
- @frames.each { |frame| frame.duration = ms}
164
+ @frames.each { |frame| frame.duration = ms }
165
+
166
+ self
153
167
  end
154
168
 
155
169
  # Is the animation finished?
@@ -157,7 +171,9 @@ module AniRuby
157
171
  # @return [Boolean]
158
172
  # @note This method will return true in intervals if the animation loops
159
173
  def done?
160
- true if @current_frame == @frames.count - 1
174
+ return true if @position == @frames.count - 1
175
+
176
+ false
161
177
  end
162
178
 
163
179
  # Is the animation paused?
@@ -172,8 +188,8 @@ module AniRuby
172
188
  # Get the current frame
173
189
  #
174
190
  # @return [AniRuby::Frame]
175
- def get_current_frame
176
- @frames[@current_frame % @frames.count]
191
+ def current_frame
192
+ @frames[@position % @frames.count]
177
193
  end
178
194
 
179
195
  # Has the current frame's duration expired?
@@ -181,7 +197,7 @@ module AniRuby
181
197
  now = Gosu.milliseconds / 1000.0
182
198
  @last_frame ||= now
183
199
 
184
- if (now - @last_frame) > @frames[@current_frame].duration
200
+ if (now - @last_frame) > @frames[@position].duration
185
201
  @last_frame = now
186
202
  end
187
203
  end
data/lib/aniruby/frame.rb CHANGED
@@ -3,8 +3,17 @@ module AniRuby
3
3
  # A frame has a sprite that's Gosu::Image and a duration specified in
4
4
  # milliseconds
5
5
  class Frame
6
- attr_accessor :duration, :sprite
7
- attr_reader :w, :h
6
+ # @return [Float]
7
+ attr_accessor :duration
8
+
9
+ # @return [Gosu::Image]
10
+ attr_accessor :sprite
11
+
12
+ # @return [Integer]
13
+ attr_reader :width, :height
14
+
15
+ alias :w :width
16
+ alias :h :height
8
17
 
9
18
  # Create a new frame
10
19
  #
@@ -16,8 +25,8 @@ module AniRuby
16
25
  @sprite = sprite
17
26
  @duration = duration
18
27
 
19
- @w = @sprite.width
20
- @h = @sprite.height
28
+ @width = @sprite.width
29
+ @height = @sprite.height
21
30
  end
22
31
  end
23
32
  end
@@ -1,8 +1,8 @@
1
1
 
2
2
  module AniRuby
3
3
  MAJOR = 0
4
- MINOR = 1
5
- PATCH = 3
4
+ MINOR = 2
5
+ PATCH = 1
6
6
 
7
7
  # See https://semver.org/
8
8
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}".freeze
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aniruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chadow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-22 00:00:00.000000000 Z
11
+ date: 2023-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 5.17.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-reporters
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.6.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 13.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 13.0.0
41
69
  description: |
42
70
  Library for painless sprite animations on Gosu, with a easy
43
71
  and nifty API, made in pure Ruby with no dependencies at all!
@@ -74,7 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
102
  - - ">="
75
103
  - !ruby/object:Gem::Version
76
104
  version: '0'
77
- requirements: []
105
+ requirements:
106
+ - Gosu installed and working
78
107
  rubygems_version: 3.4.19
79
108
  signing_key:
80
109
  specification_version: 4