sugarcube 2.10.0 → 2.11.0

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
  SHA1:
3
- metadata.gz: edbf069e18731e7ae27cf805c765176069145cea
4
- data.tar.gz: 9f7d20f7ec6eaf89bebcdb3636ed9e5b8d65dc79
3
+ metadata.gz: 22b77dfa2e3bdac875e9a2b30e67e87a36f73196
4
+ data.tar.gz: b8cf4de06268d4ef2ab5c307b2e8af2733ccb61b
5
5
  SHA512:
6
- metadata.gz: 9de9e1809c679e49a68561eeecdc488bf9384d2e2798e663bbe24314d779cc5b91301a82eeffda4704b5677eaf3a4261fe05d81762acd4600c7b05a11d2089b3
7
- data.tar.gz: d9aca20f973bfcd4d13d58cfeac4b65b5fa0c7fbc1503e2ef1246e198b73c67c32432090031f911e7b7fd8675a22abf649e19350bf2eae16b2a8dab7bbca6271
6
+ metadata.gz: 279d52c846b648abc706cc88ff915ea1f592379180808e840ad2ddc9638016b3977332004c3ce67279cc5b8daca7529679e0791aef73be122b534479b3ba0384
7
+ data.tar.gz: 5db35daa081d9aaa51b69969a616b80de8b7b31e1f082c1a9c6c76d71661eba6e162fef2841b1a3a0da4563413b529b38907e64a3620b5d58eabb9c3d7d92f4c
data/README.md CHANGED
@@ -1321,6 +1321,37 @@ data.write_to('some_image.png'.document_path)
1321
1321
  image_data = NSData.read_from('some_image.png'.document_path)
1322
1322
  ```
1323
1323
 
1324
+ SpriteKit
1325
+ -----
1326
+
1327
+ ```ruby
1328
+ node_a = SKNode.node
1329
+ node_a.name = 'parent'
1330
+
1331
+ node_b = SKNode.node
1332
+ node_b.name = 'child'
1333
+ node_c = SKNode.node
1334
+ node_c.name = 'child'
1335
+
1336
+ # add child nodes
1337
+ node_a << node_b
1338
+ node_a << node_c
1339
+
1340
+ # set user data
1341
+ node_a[:life] = 100
1342
+
1343
+ # enumerate child nodes
1344
+ node_a.each_named('child') do |node, stop_ptr|
1345
+ if node == node_b
1346
+ stop_ptr.value = true
1347
+ end
1348
+ end
1349
+
1350
+ node_a.run_action(SKAction.fadeOut) do
1351
+ # done fading out
1352
+ end
1353
+ ```
1354
+
1324
1355
  Localized
1325
1356
  -----
1326
1357
 
@@ -9,11 +9,22 @@ class SKNode
9
9
  end
10
10
 
11
11
  def [](key)
12
- userData[key]
12
+ self.userData ||= {}
13
+ userData[key.to_s]
13
14
  end
14
15
 
15
16
  def []=(key, value)
16
- userData[key] = value
17
+ self.userData ||= {}
18
+ userData[key.to_s] = value
19
+ end
20
+
21
+ def each_named(name, &block)
22
+ if block.arity == 1
23
+ using_block = -> (node, stop_ptr) { block.call(node) }
24
+ else
25
+ using_block = block
26
+ end
27
+ enumerateChildNodesWithName(name, usingBlock: using_block)
17
28
  end
18
29
 
19
30
  def to_s
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '2.10.0'
2
+ Version = '2.11.0'
3
3
  end
@@ -0,0 +1,116 @@
1
+ class SpriteKitGameController < UIViewController
2
+ attr :scene
3
+
4
+ def loadView
5
+ self.view = SKView.alloc.initWithFrame(UIScreen.mainScreen.bounds)
6
+
7
+ # Create and configure the scene.
8
+ @scene = SKScene.sceneWithSize(self.view.bounds.size)
9
+ @scene.scaleMode = SKSceneScaleModeAspectFill
10
+
11
+ # Present the scene.
12
+ self.view.presentScene(@scene)
13
+ end
14
+
15
+ end
16
+
17
+
18
+ describe 'SpriteKit' do
19
+ tests SpriteKitGameController
20
+
21
+ before do
22
+ path = CGPathCreateWithRect([[0, 0], [10, 10]], nil)
23
+
24
+ @node_a = SKShapeNode.shapeNodeWithPath(path, centered: true)
25
+ @node_a.position = [100, 100]
26
+ @node_a.name = 'parent'
27
+ controller.scene.addChild(@node_a)
28
+
29
+ @node_b = SKShapeNode.shapeNodeWithPath(path, centered: true)
30
+ @node_b.position = [0, 20]
31
+ @node_b.name = 'child'
32
+ @node_c = SKShapeNode.shapeNodeWithPath(path, centered: true)
33
+ @node_c.position = [20, 20]
34
+ @node_c.name = 'child'
35
+ @node_d = SKShapeNode.shapeNodeWithPath(path, centered: true)
36
+ @node_d.position = [20, 0]
37
+ @node_d.name = 'not a child!'
38
+ end
39
+
40
+ describe '<< method' do
41
+ it 'should add child nodes' do
42
+ @node_a << @node_b
43
+ @node_a << @node_c
44
+ @node_b.parent.should == @node_a
45
+ @node_c.parent.should == @node_a
46
+ @node_a.children.should == [@node_b, @node_c]
47
+ end
48
+ end
49
+
50
+ describe 'run_action method' do
51
+ it 'should run an action and then call the completion block' do
52
+ @completed = false
53
+
54
+ @node_a.run_action(SKAction.moveTo([1, 1], duration: 1)) do
55
+ @completed = true
56
+ end
57
+
58
+ wait 2 do
59
+ @completed.should == true
60
+ @node_a.position.x.should == 1
61
+ @node_a.position.y.should == 1
62
+ end
63
+ end
64
+ end
65
+
66
+ describe '[] and []= methods' do
67
+ it 'should assign user data with []=' do
68
+ @node_a['life'] = 100
69
+ @node_a.userData['life'].should == 100
70
+ end
71
+ it 'should assign user data and convert symbols to strings' do
72
+ @node_a[:life] = 100
73
+ @node_a.userData['life'].should == 100
74
+ end
75
+ it 'should get user data with []' do
76
+ @node_a['life'] = 100
77
+ @node_a['life'].should == 100
78
+ end
79
+ it 'should get user data and convert symbols to strings' do
80
+ @node_a[:life] = 100
81
+ @node_a[:life].should == 100
82
+ end
83
+ end
84
+
85
+ describe 'each_named method' do
86
+ before do
87
+ @node_a << @node_b
88
+ @node_a << @node_c
89
+ @node_a << @node_d
90
+ end
91
+
92
+ it 'should iterate over child nodes (arity: 1)' do
93
+ @found_b = false
94
+ @found_c = false
95
+ @found_d = false
96
+ @node_a.each_named('child') do |node|
97
+ @found_b = true if node == @node_b
98
+ @found_c = true if node == @node_c
99
+ @found_d = true if node == @node_d
100
+ end
101
+ @found_b.should == true
102
+ @found_c.should == true
103
+ @found_d.should == false
104
+ end
105
+
106
+ it 'should iterate over child nodes and stop with stop-pointer (arity: 2)' do
107
+ @found = 0
108
+ @node_a.each_named('child') do |node, stop_ptr|
109
+ @found += 1
110
+ stop_ptr.assign(true)
111
+ end
112
+ @found.should == 1
113
+ end
114
+ end
115
+
116
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugarcube
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.0
4
+ version: 2.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin T.A. Gray
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-11-01 00:00:00.000000000 Z
14
+ date: 2014-11-05 00:00:00.000000000 Z
15
15
  dependencies: []
16
16
  description: |
17
17
  == Description
@@ -216,6 +216,7 @@ files:
216
216
  - spec/cocoa/nsdata_files_spec.rb
217
217
  - spec/cocoa/nsdictionary_files_spec.rb
218
218
  - spec/cocoa/numeric_time_spec.rb
219
+ - spec/cocoa/spritekit_spec.rb
219
220
  - spec/cocoa/timer_spec.rb
220
221
  - spec/ios/568_spec.rb
221
222
  - spec/ios/animation_chain_spec.rb
@@ -309,6 +310,7 @@ test_files:
309
310
  - spec/cocoa/nsdata_files_spec.rb
310
311
  - spec/cocoa/nsdictionary_files_spec.rb
311
312
  - spec/cocoa/numeric_time_spec.rb
313
+ - spec/cocoa/spritekit_spec.rb
312
314
  - spec/cocoa/timer_spec.rb
313
315
  - spec/ios/568_spec.rb
314
316
  - spec/ios/animation_chain_spec.rb