smalruby 0.0.4-x86-mingw32 → 0.0.5-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of smalruby might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45eb0f5709ef72b39314c1982a65e393a6b8e8d2
4
- data.tar.gz: 7646edaa91e6ad975537a71fc1de4a87379c082c
3
+ metadata.gz: c97b7635bf897b9c568b789e0700cbd259e3e48d
4
+ data.tar.gz: a5ed5cfc94e1a22b881bc34ea08445ec6cb195a3
5
5
  SHA512:
6
- metadata.gz: 7b6ef7e1e01e6d1dd70f7955f09eb3f474ebf472aabc99ef211bf1102bf66f1beeb07b8cfd8061f47d2a1c353dfc6db823f0d30cd1b4d14f5d19bb4456f8ac36
7
- data.tar.gz: 471257b5324c12c6953baa9c6ede5720ab86343d7d5bb4590b75bbdf982ade9e0344276fd2d2f88c76c6a0b57ac50e4b72f69ebce16cce2c9697ca25bea3599e
6
+ metadata.gz: dabbb222a06e49e9194707c38afdb921c4ab5dd8af0df7775d57062cbf9e0124daecceae2e1ded295eced8ee1c8486cd78e1854031d5a9956df2bb58b3deee82
7
+ data.tar.gz: dcd4bdb3b0c3eb9713845e212ca135ff398a7b912da78c6d5d0723c71aad0906170f4a6b06215dd66e0c34561baae271c5d1e23db2e24f2ab1f6e436402ae09e
@@ -4,84 +4,118 @@ module Smalruby
4
4
  # お絵かきを表現するクラス
5
5
  class Canvas < Character
6
6
  def initialize(option = {})
7
- opt = {
7
+ defaults = {
8
8
  x: 0,
9
9
  y: 0,
10
10
  width: Window.width,
11
11
  height: Window.height,
12
- }.merge(option)
12
+ }
13
+ opt = process_optional_arguments(option, defaults)
14
+
13
15
  opt[:costume] = Image.new(opt[:width], opt[:height])
14
- super(opt)
16
+ super(opt.reject { |k, v| [:width, :height].include?(k) })
15
17
  image.set_color_key([0, 0, 0])
16
18
  end
17
19
 
18
20
  # @!group ペン
19
21
 
20
22
  def draw_font(option)
21
- opt = {
23
+ defaults = {
22
24
  x: 0,
23
25
  y: 0,
24
26
  string: "",
25
27
  size: 32,
26
- color: "white",
27
- }.merge(option)
28
+ }.merge(DEFAULT_COLOR_OPTION)
29
+ opt = process_optional_arguments(option, defaults)
30
+
28
31
  image.draw_font(opt[:x], opt[:y], opt[:string], new_font(opt[:size]),
29
32
  Color.smalruby_to_dxruby(opt[:color]))
30
33
  end
31
34
 
32
35
  def line(option)
33
- opt = {
34
- color: "white",
35
- }.merge(verify_rect_option(option))
36
+ opt = process_rect_option(option)
37
+
36
38
  image.line(opt[:left], opt[:top], opt[:right], opt[:bottom],
37
39
  Color.smalruby_to_dxruby(opt[:color]))
38
40
  end
39
41
 
40
42
  def box(option)
41
- opt = {
42
- color: "white",
43
- }.merge(verify_rect_option(option))
43
+ opt = process_rect_option(option)
44
+
44
45
  image.box(opt[:left], opt[:top], opt[:right], opt[:bottom],
45
46
  Color.smalruby_to_dxruby(opt[:color]))
46
47
  end
47
48
 
48
49
  def box_fill(option)
49
- opt = {
50
- color: "white",
51
- }.merge(verify_rect_option(option))
50
+ opt = process_rect_option(option)
51
+
52
52
  image.box_fill(opt[:left], opt[:top], opt[:right], opt[:bottom],
53
53
  Color.smalruby_to_dxruby(opt[:color]))
54
54
  end
55
55
 
56
56
  def circle(option)
57
- opt = {
58
- color: "white",
59
- }.merge(option)
57
+ opt = process_circle_option(option)
58
+
60
59
  image.circle(opt[:x], opt[:y], opt[:r],
61
60
  Color.smalruby_to_dxruby(opt[:color]))
62
61
  end
63
62
 
64
63
  def circle_fill(option)
65
- opt = {
66
- color: "white",
67
- }.merge(option)
64
+ opt = process_circle_option(option)
65
+
68
66
  image.circle_fill(opt[:x], opt[:y], opt[:r],
69
67
  Color.smalruby_to_dxruby(opt[:color]))
70
68
  end
71
69
 
70
+ def fill(option)
71
+ opt = process_optional_arguments(option, DEFAULT_COLOR_OPTION)
72
+
73
+ image.box_fill(0, 0, image.width, image.height,
74
+ Color.smalruby_to_dxruby(opt[:color]))
75
+ end
76
+
72
77
  def_delegators :image, :clear
73
78
 
74
79
  # @!endgroup
75
80
 
76
81
  private
77
82
 
78
- def verify_rect_option(option)
79
- return {
83
+ DEFAULT_COLOR_OPTION = {
84
+ color: 'white',
85
+ }
86
+ private_constant :DEFAULT_COLOR_OPTION
87
+
88
+ DEFAULT_RECT_OPTION = {
89
+ left: nil,
90
+ top: nil,
91
+ right: nil,
92
+ bottom: nil,
93
+
94
+ x1: nil,
95
+ y1: nil,
96
+ x2: nil,
97
+ y2: nil,
98
+ }
99
+ private_constant :DEFAULT_RECT_OPTION
100
+
101
+ def process_rect_option(option)
102
+ defaults = DEFAULT_COLOR_OPTION.merge(DEFAULT_RECT_OPTION)
103
+ opt = {
80
104
  left: option[:x1],
81
105
  top: option[:y1],
82
106
  right: option[:x2],
83
107
  bottom: option[:y2],
84
108
  }.merge(option)
109
+ process_optional_arguments(opt, defaults)
110
+ end
111
+
112
+ def process_circle_option(option)
113
+ defaults = {
114
+ x: 5,
115
+ y: 5,
116
+ r: 5,
117
+ }.merge(DEFAULT_COLOR_OPTION)
118
+ process_optional_arguments(option, defaults)
85
119
  end
86
120
  end
87
121
  end
@@ -16,12 +16,13 @@ module Smalruby
16
16
  attr_accessor :checking_hit_targets
17
17
 
18
18
  def initialize(option = {})
19
- opt = {
19
+ defaults = {
20
20
  x: 0,
21
21
  y: 0,
22
22
  costume: nil,
23
23
  visible: true
24
- }.merge(option)
24
+ }
25
+ opt = process_optional_arguments(option, defaults)
25
26
 
26
27
  # TODO: コスチュームの配列に対応する
27
28
  if opt[:costume].is_a?(String)
@@ -130,8 +131,13 @@ module Smalruby
130
131
  # @!group 音
131
132
 
132
133
  def play(option = {})
134
+ defaults = {
135
+ name: 'piano_do.wav',
136
+ }
137
+ opt = process_optional_arguments(option, defaults)
138
+
133
139
  @sound_cache ||= {}
134
- (@sound_cache[option[:name]] ||= Sound.new(asset_path(option[:name])))
140
+ (@sound_cache[opt[:name]] ||= Sound.new(asset_path(opt[:name])))
135
141
  .play
136
142
  end
137
143
 
@@ -208,15 +214,27 @@ module Smalruby
208
214
  objects = check(@checking_hit_targets)
209
215
  return if objects.empty?
210
216
  @event_handlers[:hit].try(:each) do |h|
211
- if h.options.length == 0 && !h.options.any? { |o| objects.include?(o) }
217
+ if h.options.length > 0 && !h.options.any? { |o| objects.include?(o) }
212
218
  next
213
219
  end
214
- @threads << h.call(objects)
220
+ @threads << h.call(h.options & objects)
215
221
  end
216
222
  end
217
223
 
218
224
  def alive?
219
- return @threads.any?(&:alive?)
225
+ @threads.delete_if { |t|
226
+ if t.alive?
227
+ false
228
+ else
229
+ begin
230
+ t.join
231
+ rescue => e
232
+ print_exception(e)
233
+ end
234
+ true
235
+ end
236
+ }
237
+ @threads.length > 0
220
238
  end
221
239
 
222
240
  def join
@@ -263,5 +281,19 @@ module Smalruby
263
281
  @balloon.draw
264
282
  end
265
283
  end
284
+
285
+ def process_optional_arguments(options, defaults)
286
+ unknown_keys = options.keys - defaults.keys
287
+ if unknown_keys.length > 0
288
+ s = unknown_keys.map { |k| "#{k}: #{options[k].inspect}" }.join(', ')
289
+ fail ArgumentError, "Unknown options: #{s}"
290
+ end
291
+ defaults.merge(options)
292
+ end
293
+
294
+ def print_exception(exception)
295
+ $stderr.puts("#{exception.class}: #{exception.message}")
296
+ $stderr.puts(" #{exception.backtrace.join("\n ")}")
297
+ end
266
298
  end
267
299
  end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Smalruby
4
- VERSION = '0.0.4'
4
+ VERSION = '0.0.5'
5
5
  end
data/lib/smalruby.rb CHANGED
@@ -168,7 +168,5 @@ end
168
168
  include Smalruby
169
169
 
170
170
  at_exit do
171
- if !Smalruby.started?
172
- Smalruby.start
173
- end
171
+ Smalruby.start if !$ERROR_INFO && !Smalruby.started?
174
172
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smalruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: x86-mingw32
6
6
  authors:
7
7
  - Kouji Takao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-11 00:00:00.000000000 Z
11
+ date: 2014-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler