gamebox 0.5.0 → 0.5.1

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
  SHA1:
3
- metadata.gz: 29d17db2fdbdf1732b5e68f6b8584d12270e8c3d
4
- data.tar.gz: b955424dab5554402acf08f8dd425c1af86649c3
3
+ metadata.gz: 596c34ae3dddc838592f0ad6446aa76e9707566f
4
+ data.tar.gz: 9841d8e860c8eb0d21843cde072b64d9cdd5855a
5
5
  SHA512:
6
- metadata.gz: 17cbdefcebc2f904c9ccfb4a4d44477b5ffc07a0a5eac840933fc7ff2e68da7fe7e343835eb3a69a98c52ec1fdd5d63d84a228dcebe55676690b883571c7c133
7
- data.tar.gz: 1e3ac16757af09d3404decd43298a5509fbb0461fff5bfe1cbbcca7af86562ef6f6d5e6c60a88bdd82d8603bf40ae3b86e070400980445be80f5f9a6ecf1457f
6
+ metadata.gz: 383de6900d2dff39287008d85a5e4633eefbac6207ae290d0340007b6326645bbb276d25d74e5af5a3d8817a9c296fd73e92cfa4491c651956cbb4b5ff691557
7
+ data.tar.gz: 412dbf66737bb8ca48f32de711626eab89c958ff2f7faba758ef1da6cc53fe4e1f682f041f49d3144671041a01677a440ed69a3984093d0588ae2aebbed4c358
@@ -1,4 +1,5 @@
1
1
  GAMEBOX_PATH = File.join(File.dirname(__FILE__),"gamebox/")
2
+ require 'publisher'
2
3
  require 'conject'
3
4
  require 'kvo'
4
5
  require 'tween'
@@ -1,5 +1,5 @@
1
1
  define_behavior :score_keeper do
2
- requires :backstage, :stage
2
+ requires :stage
3
3
 
4
4
  setup do
5
5
  # TODO helper for "attached subactor"
@@ -76,33 +76,16 @@ class Actor
76
76
  end
77
77
 
78
78
  def to_s
79
- attrs = []
80
- attributes.keys.sort.each do |name|
81
- attrs << "#{name}: #{printable_value(attributes[name])}"
82
- end
83
79
  """
84
80
  #{actor_type}:#{self.object_id}
85
81
  Behaviors:
86
82
  #{@behaviors.keys.sort}
87
83
  Attributes:
88
- #{attrs.join("\n")}
89
- """
84
+ #{attributes.map{|name, val| "#{name}: #{val}"}.join("\n")} """
90
85
  end
91
86
  alias pretty_inspect to_s
92
87
 
93
88
  private
94
- def printable_value(value)
95
- case value
96
- when String, Float, Fixnum, TrueClass, FalseClass, Vector2
97
- value
98
- when Array
99
- value.map do |pv|
100
- printable_value(pv)
101
- end
102
- else
103
- value.class
104
- end
105
- end
106
89
 
107
90
  class << self
108
91
 
@@ -1,5 +1,3 @@
1
- require 'publisher'
2
-
3
1
  # InputManager handles the pumping for events and distributing of said events.
4
2
  # You can gain access to these events by registering for all events,
5
3
  # or just the ones you care about.
@@ -31,6 +29,7 @@ class InputManager
31
29
  @hooks = {}
32
30
  @non_id_hooks = {}
33
31
  @down_ids = {}
32
+ @block_self_lookup = {}
34
33
 
35
34
  setup
36
35
  end
@@ -87,6 +86,7 @@ class InputManager
87
86
  event_class = :up if UP_EVENTS.include? event_class
88
87
  return unless block_given?
89
88
  listener = eval("self", block.binding)
89
+ @block_self_lookup[block] = listener
90
90
  _register_hook listener, event_class, *event_ids, &block
91
91
  end
92
92
  alias reg register_hook
@@ -138,7 +138,8 @@ class InputManager
138
138
  for event_klass, id_listeners in @hooks
139
139
  for key in id_listeners.keys.dup
140
140
  id_listeners[key].delete_if do |block|
141
- eval('self',block.binding).equal?(listener)
141
+ block_self = @block_self_lookup.delete block
142
+ block_self.equal?(listener)
142
143
  end
143
144
  end
144
145
  end
@@ -0,0 +1,23 @@
1
+ module Conject
2
+ class ObjectContext
3
+ def has_config?(name)
4
+ @object_configs.has_key?(name.to_sym)
5
+ end
6
+ def directly_has?(name)
7
+ @cache.has_key?(name.to_sym) or has_config?(name.to_sym)
8
+ end
9
+ def get(name)
10
+ name = name.to_sym
11
+ return @cache[name] if @cache.has_key?(name)
12
+
13
+ if !has_config?(name) and parent_context and parent_context.has?(name)
14
+ return parent_context.get(name)
15
+ else
16
+ object = object_factory.construct_new(name,self)
17
+ object.instance_variable_set(:@_conject_contextual_name, name.to_s)
18
+ @cache[name] = object unless no_cache?(name)
19
+ return object
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ class Hash
2
+ def symbolize_keys
3
+ inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
4
+ end
5
+
6
+ def slice(*keys)
7
+ keys = keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
8
+ hash = self.class.new
9
+ keys.each { |k| hash[k] = self[k] if has_key?(k) }
10
+ hash
11
+ end
12
+ end
13
+
@@ -1,10 +1,12 @@
1
1
  module Publisher
2
2
  module InstanceMethods
3
+ def ensure_valid(*args)
4
+ true
5
+ end
3
6
  def can_fire?(event)
4
- events = self.class.class_eval { @published_events }
5
- events = self.class.published_events
6
- return true if events == :any_event_is_ok
7
- return false unless events and events.include?(event)
7
+ # events = self.class.published_events
8
+ # return true if events == :any_event_is_ok
9
+ # return false unless events and events.include?(event)
8
10
  return true
9
11
  end
10
12
  def unsubscribe_all(listener)
@@ -25,9 +25,12 @@
25
25
  #
26
26
  class Vector2
27
27
  include Enumerable
28
+ include MinMaxHelpers
28
29
 
29
30
  RAD_TO_DEG = 180.0 / Math::PI
30
31
  DEG_TO_RAD = Math::PI / 180.0
32
+ MAX_DOT_PRODUCT = 1.0
33
+ MIN_DOT_PRODUCT = -1.0
31
34
 
32
35
  class << self
33
36
 
@@ -284,7 +287,14 @@ class Vector2
284
287
 
285
288
  # Returns the dot product between this vector and the other vector.
286
289
  def dot( vector )
287
- (@x * vector.at(0)) + (@y * vector.at(1))
290
+ unclamped_dot = (@x * vector.at(0)) + (@y * vector.at(1))
291
+ max(min(unclamped_dot, MAX_DOT_PRODUCT), MIN_DOT_PRODUCT)
292
+ end
293
+
294
+
295
+ # Returns the cross product between this vector and the other vector.
296
+ def cross( vector )
297
+ (@x * vector.y) - (@y * vector.x)
288
298
  end
289
299
 
290
300
 
@@ -477,11 +477,21 @@ module GameboxAcceptanceSpecHelpers
477
477
  end
478
478
  end
479
479
 
480
+
480
481
  RSpec::Matchers.define :have_attrs do |expected_attributes|
481
482
  match do |actor|
482
- expected_attributes.each do |key, val|
483
- actor.send(key).should == val
484
- end
483
+ relevant_attrs = actual.attributes.slice(*expected[0].keys)
484
+ relevant_attrs.should == expected_attributes
485
+ end
486
+
487
+ failure_message_for_should do |actual|
488
+ relevant_attrs = actual.attributes.slice(*expected[0].keys)
489
+ "#{relevant_attrs} did not match #{expected[0]}"
490
+ end
491
+
492
+ failure_message_for_should_not do |actual|
493
+ relevant_attrs = actual.attributes.slice(*expected[0].keys)
494
+ "#{relevant_attrs} matched #{expected[0]}"
485
495
  end
486
496
  end
487
497
 
@@ -491,6 +501,17 @@ module GameboxAcceptanceSpecHelpers
491
501
  actor.has_attribute?(name).should be_false
492
502
  end
493
503
  end
504
+
505
+ failure_message_for_should do |actual|
506
+ relevant_attrs = actual.attributes.slice(*expected[0].keys)
507
+ "#{relevant_attrs} matched #{expected[0]}"
508
+ end
509
+
510
+ failure_message_for_should_not do |actual|
511
+ relevant_attrs = actual.attributes.slice(*expected[0].keys)
512
+ "#{relevant_attrs} matched but should not have #{expected[0]}"
513
+ end
514
+
494
515
  end
495
516
  end
496
517
  end
@@ -2,7 +2,7 @@ module Gamebox
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 5
5
- TINY = 0
5
+ TINY = 1
6
6
  RC = 0
7
7
 
8
8
  if RC > 0
@@ -155,6 +155,23 @@ describe Actor do
155
155
  subject.remove
156
156
  end
157
157
  end
158
+
159
+ describe "#to_s" do
160
+ it 'prints meta data about the actor' do
161
+ subject.to_s.should include(subject.object_id.to_s)
162
+ end
163
+
164
+ it 'prints the attributes' do
165
+ subject.has_attribute :foo, :bar
166
+ subject.to_s.should include('foo')
167
+ subject.to_s.should include('bar')
168
+ end
169
+
170
+ it 'prints the behaviors' do
171
+ subject.add_behavior :foo, :bar
172
+ subject.to_s.should include('foo')
173
+ end
174
+ end
158
175
  end
159
176
 
160
177
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamebox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shawn Anderson
@@ -10,286 +10,286 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-02-21 00:00:00.000000000 Z
13
+ date: 2014-04-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: gosu
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ">="
19
+ - - '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ">="
26
+ - - '>='
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: publisher
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - ">="
33
+ - - '>='
34
34
  - !ruby/object:Gem::Version
35
35
  version: '0'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - ">="
40
+ - - '>='
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: conject
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ">="
47
+ - - '>='
48
48
  - !ruby/object:Gem::Version
49
49
  version: 0.0.8
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ">="
54
+ - - '>='
55
55
  - !ruby/object:Gem::Version
56
56
  version: 0.0.8
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: tween
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ">="
61
+ - - '>='
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ">="
68
+ - - '>='
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: i18n
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - ">="
75
+ - - '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  type: :runtime
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - ">="
82
+ - - '>='
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: thor
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - ">="
89
+ - - '>='
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  type: :runtime
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - ">="
96
+ - - '>='
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  - !ruby/object:Gem::Dependency
100
100
  name: require_all
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - ">="
103
+ - - '>='
104
104
  - !ruby/object:Gem::Version
105
105
  version: '0'
106
106
  type: :runtime
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - ">="
110
+ - - '>='
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: kvo
115
115
  requirement: !ruby/object:Gem::Requirement
116
116
  requirements:
117
- - - ">="
117
+ - - '>='
118
118
  - !ruby/object:Gem::Version
119
119
  version: 0.1.0
120
120
  type: :runtime
121
121
  prerelease: false
122
122
  version_requirements: !ruby/object:Gem::Requirement
123
123
  requirements:
124
- - - ">="
124
+ - - '>='
125
125
  - !ruby/object:Gem::Version
126
126
  version: 0.1.0
127
127
  - !ruby/object:Gem::Dependency
128
128
  name: listen
129
129
  requirement: !ruby/object:Gem::Requirement
130
130
  requirements:
131
- - - ">="
131
+ - - '>='
132
132
  - !ruby/object:Gem::Version
133
133
  version: 2.4.0
134
134
  type: :runtime
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
137
137
  requirements:
138
- - - ">="
138
+ - - '>='
139
139
  - !ruby/object:Gem::Version
140
140
  version: 2.4.0
141
141
  - !ruby/object:Gem::Dependency
142
142
  name: pry
143
143
  requirement: !ruby/object:Gem::Requirement
144
144
  requirements:
145
- - - "~>"
145
+ - - ~>
146
146
  - !ruby/object:Gem::Version
147
147
  version: 0.9.7
148
148
  type: :development
149
149
  prerelease: false
150
150
  version_requirements: !ruby/object:Gem::Requirement
151
151
  requirements:
152
- - - "~>"
152
+ - - ~>
153
153
  - !ruby/object:Gem::Version
154
154
  version: 0.9.7
155
155
  - !ruby/object:Gem::Dependency
156
156
  name: pry-remote
157
157
  requirement: !ruby/object:Gem::Requirement
158
158
  requirements:
159
- - - ">="
159
+ - - '>='
160
160
  - !ruby/object:Gem::Version
161
161
  version: '0'
162
162
  type: :development
163
163
  prerelease: false
164
164
  version_requirements: !ruby/object:Gem::Requirement
165
165
  requirements:
166
- - - ">="
166
+ - - '>='
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0'
169
169
  - !ruby/object:Gem::Dependency
170
170
  name: rspec-core
171
171
  requirement: !ruby/object:Gem::Requirement
172
172
  requirements:
173
- - - ">="
173
+ - - '>='
174
174
  - !ruby/object:Gem::Version
175
175
  version: '0'
176
176
  type: :development
177
177
  prerelease: false
178
178
  version_requirements: !ruby/object:Gem::Requirement
179
179
  requirements:
180
- - - ">="
180
+ - - '>='
181
181
  - !ruby/object:Gem::Version
182
182
  version: '0'
183
183
  - !ruby/object:Gem::Dependency
184
184
  name: rspec-mocks
185
185
  requirement: !ruby/object:Gem::Requirement
186
186
  requirements:
187
- - - ">="
187
+ - - '>='
188
188
  - !ruby/object:Gem::Version
189
189
  version: '0'
190
190
  type: :development
191
191
  prerelease: false
192
192
  version_requirements: !ruby/object:Gem::Requirement
193
193
  requirements:
194
- - - ">="
194
+ - - '>='
195
195
  - !ruby/object:Gem::Version
196
196
  version: '0'
197
197
  - !ruby/object:Gem::Dependency
198
198
  name: rspec-expectations
199
199
  requirement: !ruby/object:Gem::Requirement
200
200
  requirements:
201
- - - ">="
201
+ - - '>='
202
202
  - !ruby/object:Gem::Version
203
203
  version: '0'
204
204
  type: :development
205
205
  prerelease: false
206
206
  version_requirements: !ruby/object:Gem::Requirement
207
207
  requirements:
208
- - - ">="
208
+ - - '>='
209
209
  - !ruby/object:Gem::Version
210
210
  version: '0'
211
211
  - !ruby/object:Gem::Dependency
212
212
  name: mocha
213
213
  requirement: !ruby/object:Gem::Requirement
214
214
  requirements:
215
- - - ">="
215
+ - - '>='
216
216
  - !ruby/object:Gem::Version
217
217
  version: '0'
218
218
  type: :development
219
219
  prerelease: false
220
220
  version_requirements: !ruby/object:Gem::Requirement
221
221
  requirements:
222
- - - ">="
222
+ - - '>='
223
223
  - !ruby/object:Gem::Version
224
224
  version: '0'
225
225
  - !ruby/object:Gem::Dependency
226
226
  name: rspec
227
227
  requirement: !ruby/object:Gem::Requirement
228
228
  requirements:
229
- - - ">="
229
+ - - '>='
230
230
  - !ruby/object:Gem::Version
231
231
  version: '0'
232
232
  type: :development
233
233
  prerelease: false
234
234
  version_requirements: !ruby/object:Gem::Requirement
235
235
  requirements:
236
- - - ">="
236
+ - - '>='
237
237
  - !ruby/object:Gem::Version
238
238
  version: '0'
239
239
  - !ruby/object:Gem::Dependency
240
240
  name: rake
241
241
  requirement: !ruby/object:Gem::Requirement
242
242
  requirements:
243
- - - ">="
243
+ - - '>='
244
244
  - !ruby/object:Gem::Version
245
245
  version: '0'
246
246
  type: :development
247
247
  prerelease: false
248
248
  version_requirements: !ruby/object:Gem::Requirement
249
249
  requirements:
250
- - - ">="
250
+ - - '>='
251
251
  - !ruby/object:Gem::Version
252
252
  version: '0'
253
253
  - !ruby/object:Gem::Dependency
254
254
  name: polaris
255
255
  requirement: !ruby/object:Gem::Requirement
256
256
  requirements:
257
- - - ">="
257
+ - - '>='
258
258
  - !ruby/object:Gem::Version
259
259
  version: '0'
260
260
  type: :development
261
261
  prerelease: false
262
262
  version_requirements: !ruby/object:Gem::Requirement
263
263
  requirements:
264
- - - ">="
264
+ - - '>='
265
265
  - !ruby/object:Gem::Version
266
266
  version: '0'
267
267
  - !ruby/object:Gem::Dependency
268
268
  name: simplecov
269
269
  requirement: !ruby/object:Gem::Requirement
270
270
  requirements:
271
- - - ">="
271
+ - - '>='
272
272
  - !ruby/object:Gem::Version
273
273
  version: '0'
274
274
  type: :development
275
275
  prerelease: false
276
276
  version_requirements: !ruby/object:Gem::Requirement
277
277
  requirements:
278
- - - ">="
278
+ - - '>='
279
279
  - !ruby/object:Gem::Version
280
280
  version: '0'
281
281
  - !ruby/object:Gem::Dependency
282
282
  name: chipmunk
283
283
  requirement: !ruby/object:Gem::Requirement
284
284
  requirements:
285
- - - ">="
285
+ - - '>='
286
286
  - !ruby/object:Gem::Version
287
287
  version: '0'
288
288
  type: :development
289
289
  prerelease: false
290
290
  version_requirements: !ruby/object:Gem::Requirement
291
291
  requirements:
292
- - - ">="
292
+ - - '>='
293
293
  - !ruby/object:Gem::Version
294
294
  version: '0'
295
295
  description: Framework for building and distributing games using Gosu
@@ -389,6 +389,8 @@ files:
389
389
  - lib/gamebox/lib/aliasing.rb
390
390
  - lib/gamebox/lib/array_ext.rb
391
391
  - lib/gamebox/lib/code_statistics.rb
392
+ - lib/gamebox/lib/conject_ext.rb
393
+ - lib/gamebox/lib/hash_ext.rb
392
394
  - lib/gamebox/lib/inflections.rb
393
395
  - lib/gamebox/lib/inflector.rb
394
396
  - lib/gamebox/lib/linked_list.rb
@@ -494,12 +496,12 @@ require_paths:
494
496
  - lib
495
497
  required_ruby_version: !ruby/object:Gem::Requirement
496
498
  requirements:
497
- - - ">="
499
+ - - '>='
498
500
  - !ruby/object:Gem::Version
499
501
  version: '0'
500
502
  required_rubygems_version: !ruby/object:Gem::Requirement
501
503
  requirements:
502
- - - ">="
504
+ - - '>='
503
505
  - !ruby/object:Gem::Version
504
506
  version: '0'
505
507
  requirements: []