smalruby 0.0.4 → 0.0.5
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 +4 -4
- data/lib/smalruby/canvas.rb +57 -23
- data/lib/smalruby/character.rb +38 -6
- data/lib/smalruby/version.rb +1 -1
- data/lib/smalruby.rb +1 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6ffd138d50392da1d959baaaf5434e0dbb8d498
|
4
|
+
data.tar.gz: e656644b4616ec34134827b4e8611e25200433ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81c3ab25a45088f9d0b3d0d693e1c43d295ada2d76089646fd43ef9598fd0319a59164012a1cc4768dc11e54861202d6613c72f305d2fd2b0e7027bafd7aeee9
|
7
|
+
data.tar.gz: da6a8060951a5699c1ad67c3ddb58df91e7983dd62055c366155f3b1d1da49968a0c5ea2b34f7dc388cdc5db3c64b15130997b6226cb8bcb0beebe32355b7563
|
data/lib/smalruby/canvas.rb
CHANGED
@@ -4,84 +4,118 @@ module Smalruby
|
|
4
4
|
# お絵かきを表現するクラス
|
5
5
|
class Canvas < Character
|
6
6
|
def initialize(option = {})
|
7
|
-
|
7
|
+
defaults = {
|
8
8
|
x: 0,
|
9
9
|
y: 0,
|
10
10
|
width: Window.width,
|
11
11
|
height: Window.height,
|
12
|
-
}
|
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
|
-
|
23
|
+
defaults = {
|
22
24
|
x: 0,
|
23
25
|
y: 0,
|
24
26
|
string: "",
|
25
27
|
size: 32,
|
26
|
-
|
27
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
79
|
-
|
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
|
data/lib/smalruby/character.rb
CHANGED
@@ -16,12 +16,13 @@ module Smalruby
|
|
16
16
|
attr_accessor :checking_hit_targets
|
17
17
|
|
18
18
|
def initialize(option = {})
|
19
|
-
|
19
|
+
defaults = {
|
20
20
|
x: 0,
|
21
21
|
y: 0,
|
22
22
|
costume: nil,
|
23
23
|
visible: true
|
24
|
-
}
|
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[
|
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
|
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
|
-
|
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
|
data/lib/smalruby/version.rb
CHANGED
data/lib/smalruby.rb
CHANGED
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
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouji Takao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|