ehb_game_lib 0.3.0 → 0.4.0

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: bed38ad4e4913133709910358b6cefecc19b31806dbebf56fa0634436854df16
4
- data.tar.gz: 6f5f10d50d575fd6318fb46ef148b779b2cb1dae36f221f9bb1f8c1c49af9ae4
3
+ metadata.gz: 42ec189978ad34c8ab1c64d5ba99e63ae27099553310cfa380e1cb2eec9bb19d
4
+ data.tar.gz: aabf62f8fcb17570c9088b3c94dc9d6c47c5900916cb7630e113f3672a3e8f1e
5
5
  SHA512:
6
- metadata.gz: 56b31e0d389e0623a6eac2cef4b665b97f0bca16b3130c7f191d7d66186c5d35fd8f24e28bd1ce329433441edfffa64a77c839e5cdadefa0514abd6c1052681d
7
- data.tar.gz: 49d76a3c978287e715977ec2c1117a437b698e1ede1a8de4c6e8f3340037198fcf8900d3459931db172e0a7011050b5be0f4c3163886b215c13f6c326db48eba
6
+ metadata.gz: 1964fd37af7244749fc0303dbe7c9504e2df777574ada1fb5cd7db174705e485363f45bbeacefb66c27ef2436b3f8c5c8b3926bcdc9004f37c81e0740f816fe0
7
+ data.tar.gz: e8de637269a0de65b42668c04df1632268689cbb26476803b2681d347e1b7ba49525272e5960697b5aca6cbe83f4f1d9a74aee32b7216b34e3c609c2b7217b98
@@ -1,99 +1,50 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/core_ext'
4
+
3
5
  module EhbGameLib
4
6
  module Math
5
7
  module RectableObject
6
- H_AXIS = { name: :ax, coord: :x, size: :width, floor: :left, mean: :center,
7
- ceil: :right }.freeze
8
- V_AXIS = { name: :ay, coord: :y, size: :height, floor: :top, mean: :middle,
9
- ceil: :bottom }.freeze
10
-
11
- [H_AXIS, V_AXIS].each do |a|
12
- class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
13
- def #{a[:name]}
14
- @#{a[:name]} ||= Axis.new(
15
- -> { #{a[:coord]} },
16
- -> (v) { self.#{a[:coord]} = v },
17
- -> { #{a[:size]} }
8
+ require_sub __FILE__
9
+
10
+ [%i[ax x width x_anchor left center right], # rubocop:disable Metrics/BlockLength
11
+ %i[ay y height y_anchor top middle bottom]].each do |aa|
12
+ a = ::OpenStruct.new(
13
+ %i[name coord size anchor floor mean ceil]
14
+ .each_with_index.map { |k, i| [k, aa[i]] }.to_h
15
+ )
16
+
17
+ define_method a.name do
18
+ @data ||= {}
19
+ @data[a.name] ||=
20
+ Axis.new(
21
+ -> { send(a.coord) },
22
+ ->(v) { send("#{a.coord}=", v) },
23
+ -> { send(a.size) }
18
24
  )
19
- end
20
- RUBY_EVAL
21
-
22
- %i[floor mean ceil].each do |m|
23
- class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
24
- def #{a[m]}
25
- #{a[:name]}.#{m}
26
- end
27
-
28
- def #{a[m]}=(v)
29
- #{a[:name]}.#{m} = v
30
- end
31
- RUBY_EVAL
32
- end
33
- end
34
-
35
- def rect
36
- ::Chingu::Rect.new(left, top, width, height)
37
- end
38
-
39
- class Axis
40
- attr_accessor :anchor
41
-
42
- def initialize(coord_get, coord_set, size_get)
43
- @coord_get = coord_get
44
- @coord_set = coord_set
45
- @size_get = size_get
46
25
  end
47
26
 
48
- def coord
49
- @coord_get.call
50
- end
27
+ %i[anchor floor mean ceil].each do |m|
28
+ define_method a[m] do |*args|
29
+ if args.count.zero?
30
+ send(a.name).send(m)
31
+ elsif args.count == 1
32
+ send(a.name).send("#{m}=", args[0])
51
33
 
52
- def coord=(v)
53
- @coord_set.call(v)
54
- end
55
-
56
- def size
57
- @size_get.call
58
- end
59
-
60
- %w[floor mean ceil].each do |m|
61
- class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
62
- def #{m}
63
- coord + #{m}_delta
34
+ self
35
+ else
36
+ raise ::ArgumentError, "Invalid number of arguments (#{args.count} for 0..1)"
64
37
  end
65
-
66
- def #{m}=(v)
67
- self.coord = v - #{m}_delta
68
- end
69
- RUBY_EVAL
70
- end
71
-
72
- private
73
-
74
- def floor_delta
75
- case anchor
76
- when :mean then - size / 2
77
- when :ceil then - size
78
- else 0
79
38
  end
80
- end
81
39
 
82
- def mean_delta
83
- case anchor
84
- when :mean then 0
85
- when :ceil then - size / 2
86
- else size / 2
40
+ define_method "#{a[m]}=" do |v|
41
+ send(a.name).send("#{m}=", v)
87
42
  end
88
43
  end
44
+ end
89
45
 
90
- def ceil_delta
91
- case anchor
92
- when :mean then size / 2
93
- when :ceil then 0
94
- else size
95
- end
96
- end
46
+ def rect
47
+ ::Chingu::Rect.new(left, top, width, height)
97
48
  end
98
49
  end
99
50
  end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbGameLib
6
+ module Math
7
+ module RectableObject
8
+ class Axis
9
+ attr_accessor :anchor
10
+
11
+ common_constructor :coord_get, :coord_set, :size_get
12
+
13
+ def coord
14
+ coord_get.call
15
+ end
16
+
17
+ def coord=(v)
18
+ coord_set.call(v)
19
+ end
20
+
21
+ def size
22
+ size_get.call
23
+ end
24
+
25
+ %w[floor mean ceil].each do |m|
26
+ define_method m do
27
+ coord + send("#{m}_delta")
28
+ end
29
+
30
+ define_method "#{m}=" do |v|
31
+ self.coord = v - send("#{m}_delta")
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def floor_delta
38
+ case anchor
39
+ when :mean then - size / 2
40
+ when :ceil then - size
41
+ else 0
42
+ end
43
+ end
44
+
45
+ def mean_delta
46
+ case anchor
47
+ when :mean then 0
48
+ when :ceil then - size / 2
49
+ else size / 2
50
+ end
51
+ end
52
+
53
+ def ceil_delta
54
+ case anchor
55
+ when :mean then size / 2
56
+ when :ceil then 0
57
+ else size
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -19,8 +19,10 @@ module EhbGameLib
19
19
  quantum
20
20
  end
21
21
 
22
- def quantum_to_magick_range(quantum)
23
- ((quantum / QUANTUM_MAX.to_f) * ::Magick::QuantumRange).floor
22
+ def quantum_to_magick_range(quantum, invert = false)
23
+ r = ((quantum / QUANTUM_MAX.to_f) * ::Magick::QuantumRange).floor
24
+ r = ::Magick::QuantumRange - r if invert
25
+ r
24
26
  end
25
27
 
26
28
  # @return [Array<EhbGameLib::Palettes::Color>]
@@ -54,7 +56,8 @@ module EhbGameLib
54
56
  # @return [Magick::Pixel]
55
57
  def magick_pixel
56
58
  @magick_pixel ||= ::Magick::Pixel.new(
57
- *[red, green, blue, alpha].map { |n| self.class.quantum_to_magick_range(n) }
59
+ *[red, green, blue].map { |n| self.class.quantum_to_magick_range(n) },
60
+ self.class.quantum_to_magick_range(alpha, true)
58
61
  )
59
62
  end
60
63
 
@@ -16,7 +16,9 @@ module EhbGameLib
16
16
  end
17
17
  end
18
18
 
19
- common_constructor :magick_image
19
+ common_constructor :magick_image do
20
+ magick_image.alpha(::Magick::ActivateAlphaChannel)
21
+ end
20
22
 
21
23
  # @return Gosu::Image
22
24
  def gosu_image
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbGameLib
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ehb_game_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-05 00:00:00.000000000 Z
11
+ date: 2021-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chingu
@@ -154,6 +154,7 @@ files:
154
154
  - lib/ehb_game_lib/math/line_segment.rb
155
155
  - lib/ehb_game_lib/math/quadratic_equation.rb
156
156
  - lib/ehb_game_lib/math/rectable_object.rb
157
+ - lib/ehb_game_lib/math/rectable_object/axis.rb
157
158
  - lib/ehb_game_lib/math/vector.rb
158
159
  - lib/ehb_game_lib/media_path.rb
159
160
  - lib/ehb_game_lib/nes.rb