aniruby 0.2.0 → 0.2.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 361fe4d0f4dddeca7090d35a7bb225440fd51c94c69d5b7ea0a0be8826437340
4
- data.tar.gz: afb5d871c301e09df8559cd66e2609c408e810f9f3d48e68adaf851569f19a4b
3
+ metadata.gz: 91784f282491084327d6f2317ad87316de4eae20a1bd06a4c63cebb56eb8a159
4
+ data.tar.gz: 5425f60a700e2ab366a15583c5bf3860f3bd7ff5cf540d45a21cfd7e4176b44b
5
5
  SHA512:
6
- metadata.gz: 9a1d8d7b7c1fabdde8b84c68199463af199ed6bfdf7e5f7e7b684f5fc5a9abba315095655bb22904be5eb29c61877c4ae6f5f348a29971b2103e739506a6950f
7
- data.tar.gz: d79b9b2f63047cad421027880c40723472a22fcf4f13e0444a4da89cb99aab772fc8eff1d1cacabb6c38ce568dd6276651f6d9b1d5b9fbf10cb738d19320b454
6
+ metadata.gz: 40b40a12aad67d97800e999db54887428c89314b35a2aa2a6102fbcdbc544b8cfa5079bc21b2e9b2be3397862e729d676bdb1ba456b9ffdaae6e1ec1d3b05325
7
+ data.tar.gz: f37a4474aecf9e50c87e8340a218ba4845ba2900b0a3b4b5874b8b79db73d18897a315567e9402173e47aa1931380ef9208831f52d603525f689f40e1b5629f1
data/CHANGELOG.md CHANGED
@@ -7,7 +7,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## Unreleased
9
9
 
10
- ## 0.2.0 - 2023-09-02
10
+ ## [0.2.2] - 2023-12-27
11
+
12
+ ### Added
13
+
14
+ - Aliased `Animation#reset` to `Animation#reset!`.
15
+
16
+ ### Changed
17
+
18
+ - Arguments `retro` and `loop` from `Animation#new` are now keyword arguments.
19
+ - Renamed "position" attribute from `Animation` to "cursor".
20
+ - Passing a negative value as duration to `Animation#new` will default to 0.1.
21
+
22
+ ## [0.2.1] - 2023-09-07
23
+
24
+ ### Fixed
25
+
26
+ - **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
27
+ the need to change every use of `@current_frame` to `@position`, however
28
+ since I wasn't thorough enough I forgot to do that in the `Animation#draw` and `Animation#draw_rot`
29
+ methods, effectively rendering them useless.
30
+ - **Important**: There was a error in `Animation#done?` too, where it'll return `false` always
31
+ independently of if the animation was finished, this was because I forgot to add a `return` in
32
+ the condition check for the `true`.
33
+ - Internally, `Animation#update` now resets the animation, instead of `Animation#draw`
34
+ or `Animation#draw_rot` (I know, that sounds counterintuitive). This (I think) fixes a precision problem when drawing the last frame
35
+ of an animation, in the which it was drawn for less time than required.
36
+
37
+ ## [0.2.0] - 2023-09-02
11
38
 
12
39
  This release brings mostly improvements and fixes, however there's not that much
13
40
  new features yet.
@@ -23,7 +50,7 @@ for `Frame`.
23
50
 
24
51
  ### Fixed
25
52
 
26
- - Previously methods like `Animation#done?` or `Animation#resume` didn't return `self`, so it wasn't possible to chaint them like this
53
+ - Previously methods like `Animation#pause?` or `Animation#resume` didn't return `self`, so it wasn't possible to chain them like this
27
54
  ```ruby
28
55
  # Example
29
56
  my_animation.pause.resume.duration(200)
@@ -42,13 +69,13 @@ for `Frame`.
42
69
  - The way milliseconds are used as duration, before you'll have to use whole numbers
43
70
  (1000 is a second, 500 half a second and so on), now we can just use floats for that (1.0 as a second, 0.5 half a second and so on).
44
71
 
45
- ## 0.1.2 - 2023-08-20
72
+ ## [0.1.2] - 2023-08-20
46
73
 
47
74
  ### Changed
48
75
 
49
76
  - Downcased the gem name in the gemspec.
50
77
 
51
- ## 0.1.1 - 2023-08-20
78
+ ## [0.1.1] - 2023-08-20
52
79
 
53
80
  ### Added
54
81
 
@@ -58,6 +85,15 @@ for `Frame`.
58
85
 
59
86
  - Required ruby not being used correctly in gemspec.
60
87
 
61
- ## 0.1.0 - 2023-08-20
88
+ ## [0.1.0] - 2023-08-20
62
89
 
63
90
  Initial release.
91
+
92
+ [unreleased]: https://github.com/Chadowo/aniruby/compare/v0.2.2...HEAD
93
+ [0.2.2]: https://github.com/Chadowo/aniruby/compare/v0.2.1...v0.2.2
94
+ [0.2.1]: https://github.com/Chadowo/aniruby/compare/v0.2.0...v0.2.1
95
+ [0.2.0]: https://github.com/Chadowo/aniruby/compare/v0.1.3...v0.2.0
96
+ [0.1.3]: https://github.com/Chadowo/aniruby/compare/v0.1.2...v0.1.3
97
+ [0.1.2]: https://github.com/Chadowo/aniruby/compare/v0.1.1...v0.1.2
98
+ [0.1.1]: https://github.com/Chadowo/aniruby/compare/v0.1.0...v0.1.1
99
+ [0.1.0]: https://github.com/Chadowo/aniruby/releases/v0.1.0
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # AniRuby
2
2
 
3
- ![Gem (including prereleases)](https://img.shields.io/gem/v/aniruby?style=flat-square&color=blue)
3
+ ![Gem (including prereleases)](https://img.shields.io/gem/v/aniruby?style=flat-square&logo=rubygems&logoColor=white&color=blue) ![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/chadowo/aniruby/minitest.yml?style=flat-square&logo=github&label=minitest&link=https%3A%2F%2Fgithub.com%2FChadowo%2Faniruby%2Factions%2Fworkflows%2Fminitest.yml) ![GitHub](https://img.shields.io/github/license/chadowo/aniruby?style=flat-square)
4
4
 
5
- Make sprite animations on Gosu simple and easy.
5
+ Make sprite animations on Gosu, simply and easily.
6
6
 
7
7
  ## Summary
8
8
 
@@ -10,13 +10,15 @@ This library will provide you with a nice n easy interface to do sprite animatio
10
10
  on [Gosu](https://www.libgosu.org/), while being as nifty and simple as possible.
11
11
 
12
12
  The library is made in pure Ruby with no dependencies at all (except Gosu, of course) so
13
- its quite lightweight.
13
+ it's quite lightweight.
14
14
 
15
15
  ## Install
16
16
 
17
17
  You can install the gem with the following command:
18
18
 
19
- `gem install aniruby`
19
+ ```console
20
+ gem install aniruby
21
+ ```
20
22
 
21
23
  or use it with a bundle:
22
24
 
@@ -40,8 +42,7 @@ class MyWindow < Gosu::Window
40
42
  super(800, 600, false)
41
43
 
42
44
  @animation = AniRuby::Animation.new('my_spritesheet.png', 32, 32,
43
- false, true,
44
- 0.15)
45
+ 0.15, retro: false, loop: true)
45
46
  end
46
47
 
47
48
  def update
@@ -92,17 +93,29 @@ have to learn anything new.
92
93
 
93
94
  Each `Animation` has extra helpful methods, like `pause` & `unpause`, `reset`,
94
95
  `done?`, etc. I recommend you to look on the source, its pretty small and easy to
95
- understand, or build the YARD documentation with
96
+ understand, or build the YARD documentation with:
96
97
 
97
- `rake doc`
98
+ ```console
99
+ rake doc
100
+ ```
98
101
 
99
102
  ## Development
100
103
 
104
+ ### Setup
105
+
101
106
  First clone this repo locally:
102
107
 
103
- `git clone https://github.com/Chadowo/aniruby`
108
+ ```console
109
+ git clone https://github.com/Chadowo/aniruby
110
+ ```
111
+
112
+ Next you'll need to install the development dependencies of this gem with
113
+ `bundle install`, Then you can use `rake` to build or test the gem.
114
+
115
+ ### Testing
104
116
 
105
- Then you can use rake to build or test gem.
117
+ [Minitest](https://github.com/minitest/minitest) is used to unit test this gem.
118
+ To run the tests just call `rake`.
106
119
 
107
120
  ## Roadmap
108
121
 
data/Rakefile CHANGED
@@ -1,5 +1,4 @@
1
-
2
- require 'fileutils'
1
+ require 'bundler/gem_tasks'
3
2
  require 'minitest/test_task'
4
3
 
5
4
  require_relative 'lib/aniruby/version'
@@ -8,25 +7,6 @@ Minitest::TestTask.create
8
7
 
9
8
  task :default => :test
10
9
 
11
- desc 'Build the gem'
12
- task :build do
13
- Dir.mkdir('pkg') unless Dir.exist?('pkg')
14
-
15
- sh 'gem build aniruby.gemspec'
16
-
17
- FileUtils.mv("aniruby-#{AniRuby::VERSION}.gem", 'pkg')
18
- end
19
-
20
- desc 'Clean the build enviroment'
21
- task :clean do
22
- FileUtils.rm_rf('pkg')
23
- end
24
-
25
- desc 'Push the gem to RubyGems'
26
- task :push do
27
- sh "gem push pkg/aniruby-#{AniRuby::VERSION}.gem"
28
- end
29
-
30
10
  desc 'Use YARD to generate documentation'
31
11
  task :doc do
32
12
  sh 'yardoc'
@@ -1,4 +1,3 @@
1
-
2
1
  module AniRuby
3
2
  # Has a AniRuby::Frames colletion, with a simple counter to keep track of
4
3
  # current frame plus looping and pausing functionality
@@ -6,7 +5,7 @@ module AniRuby
6
5
  # @return [AniRuby::Frames] The collection of frames this animation uses
7
6
  attr_accessor :frames
8
7
  # @return [Integer] The current frame index of the animation
9
- attr_accessor :position
8
+ attr_accessor :cursor
10
9
  # @return [Boolean] The loop parameter
11
10
  attr_accessor :loop
12
11
 
@@ -15,32 +14,37 @@ module AniRuby
15
14
  # @param spritesheet [String] Path to the spritesheet file
16
15
  # @param frame_w [Integer] The width of each individual frame
17
16
  # @param frame_h [Integer] The height of each individual frame
18
- # @param retro [Boolean] If true, the animation will not be interpolated when scaled
19
- # @param loop [Boolean] If true, the animation will loop indefinitely
20
17
  # @param durations [Float] The duration of the frames in MS (0.5 is half a second,
21
18
  # 1.0 a second, etc). If there's more than one duration
22
19
  # provided they will be mapped to each frame of the
23
20
  # animation. The default for each frame is 0.1.
21
+ # If the value is negative it'll default to 0.1.
22
+ # @param retro [Boolean] If true, the animation will not be interpolated when scaled
23
+ # @param loop [Boolean] If true, the animation will loop indefinitely
24
24
  #
25
25
  # @return [Animation] A new animation ready to play
26
26
  def initialize(spritesheet,
27
27
  frame_w, frame_h,
28
- retro = false,
29
- loop = true,
30
- *durations)
28
+ *durations,
29
+ retro: false,
30
+ loop: true)
31
31
  @frame_w = frame_w
32
32
  @frame_h = frame_h
33
33
 
34
34
  @loop = loop
35
-
36
- @position = 0
37
35
  @pause = false
38
36
 
37
+ @cursor = 0
38
+ @step = 1
39
+
39
40
  @frames = AniRuby::Frames.new(Gosu::Image.load_tiles(spritesheet,
40
41
  @frame_w,
41
42
  @frame_h,
42
43
  retro: retro))
43
44
 
45
+ # Default to 0.1 if the duration is negative
46
+ durations.map! { |dur| dur.negative? ? 0.1 : dur }
47
+
44
48
  # TODO: Maybe I could shorten this, adding an extra argument to
45
49
  # AniRuby::Frames
46
50
  if durations.one?
@@ -58,26 +62,32 @@ module AniRuby
58
62
  #
59
63
  # @return [Integer]
60
64
  def width
61
- @frames[@position].width
65
+ @frames[@cursor].width
62
66
  end
63
67
 
64
- alias :w :width
68
+ alias w width
65
69
 
66
70
  # Get the height of the current frame's image
67
71
  #
68
72
  # @return [Integer]
69
73
  def height
70
- @frames[@position].height
74
+ @frames[@cursor].height
71
75
  end
72
76
 
73
- alias :h :height
77
+ alias h height
78
+
79
+ # @!group Drawing
74
80
 
75
81
  # Update the animation, advancing the frame counter. Note that this won't do
76
82
  # do anything if the animation is paused or has finished
77
83
  def update
78
- return if done? || paused?
84
+ return unless frame_expired? && !paused?
79
85
 
80
- @position += 1 if frame_expired?
86
+ if !done?
87
+ @cursor += @step
88
+ elsif done? && @loop
89
+ @cursor = 0
90
+ end
81
91
  end
82
92
 
83
93
  # Draw the animation
@@ -90,17 +100,15 @@ module AniRuby
90
100
  # @param color [Gosu::Color] The color to usw when drawing
91
101
  # @param mode [:default, :additive] The blending mode
92
102
  #
93
- # (see {draw_rot})
103
+ # (see also {draw_rot})
94
104
  def draw(x, y, z = 0,
95
105
  scale_x = 1,
96
106
  scale_y = 1,
97
107
  color = Gosu::Color::WHITE,
98
108
  mode = :default)
99
- frame = @frames[@current_frame]
109
+ frame = @frames[@cursor]
100
110
 
101
111
  frame.sprite.draw(x, y, z, scale_x, scale_y, color, mode)
102
-
103
- @position = 0 if @loop && done?
104
112
  end
105
113
 
106
114
  # Draw the animation rotated, with its rotational center at (x, y).
@@ -116,7 +124,7 @@ module AniRuby
116
124
  # @param color [Gosu::Color] The color to usw when drawing
117
125
  # @param mode [:default, :additive] The blending mode
118
126
  #
119
- # (see {draw})
127
+ # (see also {draw})
120
128
  def draw_rot(x, y, z = 0,
121
129
  angle = 0,
122
130
  center_x = 0.5,
@@ -125,17 +133,18 @@ module AniRuby
125
133
  scale_y = 1,
126
134
  color = Gosu::Color::WHITE,
127
135
  mode = :default)
128
- frame = @frames[@current_frame]
136
+ frame = @frames[@cursor]
129
137
 
130
138
  frame.sprite.draw_rot(x, y, z, angle, center_x, center_y, scale_x, scale_y, color, mode)
131
-
132
- # Loop the animation
133
- @position = 0 if @loop && done?
134
139
  end
135
140
 
141
+ # @!endgroup
142
+
143
+ # @!group Utility
144
+
136
145
  # Pause the animation
137
146
  #
138
- # (see {resume})
147
+ # (see also {resume})
139
148
  def pause
140
149
  @pause = true
141
150
 
@@ -144,7 +153,7 @@ module AniRuby
144
153
 
145
154
  # Resume the animation
146
155
  #
147
- # (see {pause})
156
+ # (see also {pause})
148
157
  def resume
149
158
  @pause = false
150
159
 
@@ -153,11 +162,13 @@ module AniRuby
153
162
 
154
163
  # Set the animation to the beginning frame
155
164
  def reset
156
- @position = 0
165
+ @cursor = 0
157
166
 
158
167
  self
159
168
  end
160
169
 
170
+ alias reset! reset
171
+
161
172
  # Set the duration for all frames in the animation
162
173
  #
163
174
  # @param ms [Float] The new duration in milliseconds
@@ -172,7 +183,7 @@ module AniRuby
172
183
  # @return [Boolean]
173
184
  # @note This method will return true in intervals if the animation loops
174
185
  def done?
175
- true if @position == @frames.count - 1
186
+ return true if @cursor == @frames.count - 1
176
187
 
177
188
  false
178
189
  end
@@ -190,15 +201,17 @@ module AniRuby
190
201
  #
191
202
  # @return [AniRuby::Frame]
192
203
  def current_frame
193
- @frames[@position % @frames.count]
204
+ @frames[@cursor % @frames.count]
194
205
  end
195
206
 
207
+ # @!endgroup
208
+
196
209
  # Has the current frame's duration expired?
197
210
  def frame_expired?
198
211
  now = Gosu.milliseconds / 1000.0
199
212
  @last_frame ||= now
200
213
 
201
- if (now - @last_frame) > @frames[@position].duration
214
+ if (now - @last_frame) > @frames[@cursor].duration
202
215
  @last_frame = now
203
216
  end
204
217
  end
data/lib/aniruby/frame.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  module AniRuby
3
2
  # A frame has a sprite that's Gosu::Image and a duration specified in
4
3
  # milliseconds
@@ -12,8 +11,8 @@ module AniRuby
12
11
  # @return [Integer]
13
12
  attr_reader :width, :height
14
13
 
15
- alias :w :width
16
- alias :h :height
14
+ alias w width
15
+ alias h height
17
16
 
18
17
  # Create a new frame
19
18
  #
@@ -1,4 +1,3 @@
1
-
2
1
  module AniRuby
3
2
  # Collection of frames
4
3
  class Frames
@@ -1,8 +1,7 @@
1
-
2
1
  module AniRuby
3
2
  MAJOR = 0
4
3
  MINOR = 2
5
- PATCH = 0
4
+ PATCH = 2
6
5
 
7
6
  # See https://semver.org/
8
7
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}".freeze
data/lib/aniruby.rb CHANGED
@@ -1,6 +1,4 @@
1
-
2
- require_relative 'aniruby/version'
3
-
4
- require_relative 'aniruby/frame'
5
- require_relative 'aniruby/frames'
6
- require_relative 'aniruby/animation'
1
+ require 'aniruby/frame'
2
+ require 'aniruby/frames'
3
+ require 'aniruby/animation'
4
+ require 'aniruby/version'
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.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chadow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-02 00:00:00.000000000 Z
11
+ date: 2023-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: 13.0.0
69
69
  description: |
70
- Library for painless sprite animations on Gosu, with a easy
70
+ Library for painless sprite animations on Gosu, with an easy
71
71
  and nifty API, made in pure Ruby with no dependencies at all!
72
72
  email:
73
73
  executables: []
@@ -87,7 +87,11 @@ files:
87
87
  homepage: https://github.com/Chadowo/aniruby
88
88
  licenses:
89
89
  - MIT
90
- metadata: {}
90
+ metadata:
91
+ bug_tracker_uri: https://github.com/Chadowo/aniruby/issues
92
+ changelog_uri: https://github.com/Chadowo/aniruby/blob/main/CHANGELOG.md
93
+ homepage_uri: https://github.com/Chadowo/aniruby
94
+ source_code_uri: https://github.com/Chadowo/aniruby
91
95
  post_install_message:
92
96
  rdoc_options: []
93
97
  require_paths:
@@ -104,8 +108,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
108
  version: '0'
105
109
  requirements:
106
110
  - Gosu installed and working
107
- rubygems_version: 3.4.19
111
+ rubygems_version: 3.5.3
108
112
  signing_key:
109
113
  specification_version: 4
110
- summary: Make sprite animations on Gosu simple and easy
114
+ summary: Make sprite animations on Gosu, simply and easily
111
115
  test_files: []