smalruby 0.1.9 → 0.1.10

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: a9f0fcdd82c5f32169894f3c3979754c77e03366
4
- data.tar.gz: b0bbd80816a9b8017334ae62a03ec9996499be10
3
+ metadata.gz: c653bf8bf1d484ba6a8eccc48d7a18808f620a48
4
+ data.tar.gz: 94dd489b31df228615620be1d3165d2c6868bafc
5
5
  SHA512:
6
- metadata.gz: 81ac5d86f76812303ab7863e72afa328349a60c4b3bf4dc7087857db37e4589c8bde546303642a1abd4f29bbcdec8ed7c81a70900dd1969fd21cc03b8869619e
7
- data.tar.gz: 114d5d1161bfd7a0cac06fa798a410597c1c325ea1bc1a3db6f0073e7dad79465e77ed0887681bf7d6f7e8be0ae308d4a36c2ed8afc71430595adea280b7389c
6
+ metadata.gz: 63f96b60b5be18287e21abc88b6ad9e2bfa22e471b7a69a4f0f7f81c25e1ccf9db5724fbe6a12006e239fa7370d3309f7c84ca38051a654664293c66441f4a56
7
+ data.tar.gz: a9ed2d45d22d54b61295cc36d361a8854996f249ed4515c05c82255cc7df777c447edc6e566c15bf9d20b87a25a9537169d105a154ea943627a1d2ff08ad3a97
@@ -1,147 +1,109 @@
1
1
  AllCops:
2
- Excludes:
2
+ Exclude:
3
3
  - tmp/**/*
4
4
  - vendor/**/*
5
5
  - work/**/*
6
6
  - samples/**/*
7
7
 
8
- # Offense count: 1
9
8
  # Configuration parameters: AllowSafeAssignment.
10
9
  Lint/AssignmentInCondition:
11
10
  Enabled: false
12
11
 
13
- # Offense count: 2
14
12
  Lint/HandleExceptions:
15
13
  Enabled: false
16
14
 
17
- # Offense count: 1
18
15
  Lint/RescueException:
19
16
  Enabled: false
20
17
 
21
- # Offense count: 2
22
18
  # Cop supports --auto-correct.
23
19
  Lint/UnusedMethodArgument:
24
20
  Enabled: false
25
21
 
26
- # Offense count: 17
27
22
  Metrics/AbcSize:
28
23
  Max: 58
29
24
 
30
- # Offense count: 3
31
25
  # Configuration parameters: CountComments.
32
26
  Metrics/ClassLength:
33
- Max: 433
27
+ Max: 1000
34
28
 
35
- # Offense count: 3
36
29
  Metrics/CyclomaticComplexity:
37
30
  Max: 8
38
31
 
39
- # Offense count: 4
40
32
  # Configuration parameters: AllowURI, URISchemes.
41
33
  Metrics/LineLength:
42
34
  Max: 162
43
35
 
44
- # Offense count: 22
45
36
  # Configuration parameters: CountComments.
46
37
  Metrics/MethodLength:
47
- Max: 37
38
+ Max: 100
48
39
 
49
- # Offense count: 2
50
40
  # Configuration parameters: CountComments.
51
41
  Metrics/ModuleLength:
52
42
  Max: 170
53
43
 
54
- # Offense count: 1
55
44
  Metrics/PerceivedComplexity:
56
45
  Max: 8
57
46
 
58
- # Offense count: 1
59
- # Cop supports --auto-correct.
60
47
  Performance/ParallelAssignment:
61
48
  Enabled: false
62
49
 
63
- # Offense count: 1
64
50
  Style/AccessorMethodName:
65
51
  Enabled: false
66
52
 
67
- # Offense count: 160
68
53
  Style/AsciiComments:
69
54
  Enabled: false
70
55
 
71
- # Offense count: 4
72
- # Cop supports --auto-correct.
73
56
  # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
74
57
  Style/BlockDelimiters:
75
58
  Enabled: false
76
59
 
77
- # Offense count: 4
78
60
  Style/Documentation:
79
61
  Enabled: false
80
62
 
81
- # Offense count: 8
82
63
  # Configuration parameters: MinBodyLength.
83
64
  Style/GuardClause:
84
65
  Enabled: false
85
66
 
86
- # Offense count: 1
87
- # Cop supports --auto-correct.
88
67
  # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
89
68
  Style/HashSyntax:
90
69
  Enabled: false
91
70
 
92
- # Offense count: 11
93
- # Cop supports --auto-correct.
94
71
  # Configuration parameters: MaxLineLength.
95
72
  Style/IfUnlessModifier:
96
73
  Enabled: false
97
74
 
98
- # Offense count: 1
99
- # Cop supports --auto-correct.
100
75
  # Configuration parameters: EnforcedStyle, SupportedStyles.
101
76
  Style/MultilineOperationIndentation:
102
77
  Enabled: false
103
78
 
104
- # Offense count: 2
105
- # Cop supports --auto-correct.
106
79
  # Configuration parameters: PreferredDelimiters.
107
80
  Style/PercentLiteralDelimiters:
108
81
  Enabled: false
109
82
 
110
- # Offense count: 1
111
- # Cop supports --auto-correct.
112
83
  Style/PerlBackrefs:
113
84
  Enabled: false
114
85
 
115
- # Offense count: 4
116
- # Cop supports --auto-correct.
117
86
  # Configuration parameters: AllowMultipleReturnValues.
118
87
  Style/RedundantReturn:
119
88
  Enabled: false
120
89
 
121
- # Offense count: 2
122
- # Cop supports --auto-correct.
123
90
  Style/SpecialGlobalVars:
124
91
  Enabled: false
125
92
 
126
- # Offense count: 12
127
- # Cop supports --auto-correct.
128
93
  # Configuration parameters: EnforcedStyle, SupportedStyles.
129
94
  Style/StringLiterals:
130
95
  Enabled: false
131
96
 
132
- # Offense count: 3
133
- # Cop supports --auto-correct.
134
97
  # Configuration parameters: IgnoredMethods.
135
98
  Style/SymbolProc:
136
99
  Enabled: false
137
100
 
138
- # Offense count: 6
139
- # Cop supports --auto-correct.
140
101
  # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
141
102
  Style/TrailingComma:
142
103
  Enabled: false
143
104
 
144
- # Offense count: 2
145
- # Cop supports --auto-correct.
146
105
  Style/UnneededPercentQ:
147
106
  Enabled: false
107
+
108
+ Style/NegatedIf:
109
+ Enabled: false
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 1.9.3
4
+ - 2.1.5
5
5
 
6
6
  env:
7
7
  AUDIODEV=null
@@ -33,16 +33,26 @@ module Smalruby
33
33
  x: 0,
34
34
  y: 0,
35
35
  costume: nil,
36
+ costume_index: 0,
36
37
  angle: 0,
37
38
  visible: true,
38
39
  rotation_style: :free
39
40
  }
40
41
  opt = process_optional_arguments(option, defaults)
41
42
 
42
- @costumes = [opt[:costume]].flatten.compact.map { |costume|
43
- costume.is_a?(String) ? Image.load(asset_path(costume)) : costume
43
+ @costume_name__index = {}
44
+ @costumes = Array.wrap(opt[:costume]).compact.map.with_index { |costume, i|
45
+ if costume.is_a?(String)
46
+ md = /^(?:([^:]+):)?(.*)$/.match(costume)
47
+ name = md[1]
48
+ path = md[2]
49
+ costume = Image.load(asset_path(path))
50
+ end
51
+ name ||= "costume#{i + 1}"
52
+ @costume_name__index[name] = i
53
+ costume
44
54
  }
45
- @costume_index = 0
55
+ @costume_index = opt[:costume_index]
46
56
  super(opt[:x], opt[:y], @costumes[@costume_index])
47
57
 
48
58
  @event_handlers = {}
@@ -297,8 +307,21 @@ module Smalruby
297
307
 
298
308
  # 次のコスチュームにする
299
309
  def next_costume
300
- @costume_index += 1
301
- @costume_index = @costume_index % @costumes.length
310
+ self.costume_index = @costume_index + 1
311
+ end
312
+
313
+ # コスチュームを( )にする
314
+ def switch_costume(name)
315
+ if @costume_name__index.key?(name)
316
+ index = @costume_name__index[name]
317
+ else
318
+ index = 0
319
+ end
320
+ self.costume_index = index
321
+ end
322
+
323
+ def costume_index=(val)
324
+ @costume_index = val % @costumes.length
302
325
  self.image = @costumes[@costume_index]
303
326
  end
304
327
 
@@ -544,6 +567,7 @@ module Smalruby
544
567
  def asset_path(name)
545
568
  program_path = Pathname($PROGRAM_NAME).expand_path(Dir.pwd)
546
569
  paths = [Pathname("../#{name}").expand_path(program_path),
570
+ Pathname("../__assets__/#{name}").expand_path(program_path),
547
571
  Pathname("../../../assets/#{name}").expand_path(__FILE__)]
548
572
  paths.find { |path| path.file? }.to_s
549
573
  end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Smalruby
4
- VERSION = '0.1.9'
4
+ VERSION = '0.1.10'
5
5
  end
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'smalruby'
3
+
4
+ car1 = Character.new(x: 0, y: 0, costume: 'extra_car2.png')
5
+
6
+ car1.on(:start) do
7
+ loop do
8
+ move(5)
9
+ if reach_wall?
10
+ turn
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Smalruby::Character do
5
+ describe '#switch_costume' do
6
+ let(:character) {
7
+ described_class.new(costume: %w(car1.png char2:car2.png car3.png))
8
+ }
9
+
10
+ subject { character.costume_index }
11
+
12
+ name_to_index = {
13
+ "costume1" => 0,
14
+ "char2" => 1,
15
+ "costume3" => 2,
16
+ }
17
+
18
+ name_to_index.each do |name, index|
19
+ context "name is #{name}" do
20
+ _name, _index = name, index
21
+
22
+ let(:name) { name }
23
+ let(:index) { index }
24
+
25
+ before do
26
+ character.switch_costume(name)
27
+ end
28
+
29
+ it { expect(subject).to eq(index) }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -5,6 +5,7 @@ Coveralls.wear!
5
5
 
6
6
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
7
7
  require 'smalruby'
8
+ Smalruby.instance_variable_set("@started", true)
8
9
 
9
10
  Dir.glob(File.expand_path('../support/**/*.rb', __FILE__)).each do |path|
10
11
  require path
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.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouji Takao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-22 00:00:00.000000000 Z
11
+ date: 2015-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -274,6 +274,7 @@ files:
274
274
  - lib/smalruby/version.rb
275
275
  - lib/smalruby/world.rb
276
276
  - samples/.rubocop.yml
277
+ - samples/__assets__/extra_car2.png
277
278
  - samples/canvas.rb
278
279
  - samples/canvas_color.rb
279
280
  - samples/car.rb
@@ -284,6 +285,7 @@ files:
284
285
  - samples/check_hardware_smalrubot_v3.rb
285
286
  - samples/console.rb
286
287
  - samples/costume.rb
288
+ - samples/costume2.rb
287
289
  - samples/costumes.rb
288
290
  - samples/extra_car.png
289
291
  - samples/finding_cars.rb
@@ -304,6 +306,7 @@ files:
304
306
  - samples/piano.rb
305
307
  - samples/tree.rb
306
308
  - smalruby.gemspec
309
+ - spec/lib/smalruby/character_spec.rb
307
310
  - spec/lib/smalruby/color_spec.rb
308
311
  - spec/lib/smalruby/world_spec.rb
309
312
  - spec/spec_helper.rb
@@ -332,6 +335,7 @@ signing_key:
332
335
  specification_version: 4
333
336
  summary: 2D game development library for kids.
334
337
  test_files:
338
+ - spec/lib/smalruby/character_spec.rb
335
339
  - spec/lib/smalruby/color_spec.rb
336
340
  - spec/lib/smalruby/world_spec.rb
337
341
  - spec/spec_helper.rb