gosu_extensions 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.14
1
+ 0.1.15
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/lib/core/trait.rb ADDED
@@ -0,0 +1 @@
1
+ module Trait; end
@@ -0,0 +1,9 @@
1
+ module Traits
2
+
3
+ # A List all Traits.
4
+ #
5
+ def self.list
6
+ ObjectSpace.each_object.select { |object| object.kind_of?(Trait) }.sort!{ |moda, modb| moda.to_s <=> modb.to_s }
7
+ end
8
+
9
+ end
File without changes
@@ -15,19 +15,30 @@ rescue LoadError => e
15
15
  end
16
16
 
17
17
  require 'resources'
18
- require 'vector_utilities'
19
18
 
20
19
  $:.unshift File.join(File.dirname(__FILE__), '/extensions')
21
20
  require 'module'
22
21
  require 'numeric'
23
22
 
24
- $:.unshift File.join(File.dirname(__FILE__), '/traits')
23
+ $:.unshift File.join(File.dirname(__FILE__), '/core')
24
+ require 'vector_utilities'
25
+ require 'initializer_hooks'
26
+
27
+ require 'trait'
28
+ require 'traits'
25
29
  require 'it_is_a'
30
+
31
+ require 'scheduling'
32
+ require 'game_window'
33
+ require 'controls'
34
+ require 'waves'
35
+ require 'layer'
36
+
37
+ $:.unshift File.join(File.dirname(__FILE__), '/traits')
26
38
  require 'pod'
27
39
  require 'attachable'
28
40
  require 'damaging'
29
41
  require 'generator'
30
- require 'initializer_hooks'
31
42
  require 'lives'
32
43
  require 'targeting'
33
44
  require 'targeting/closest'
@@ -43,12 +54,7 @@ require 'short_lived'
43
54
  $:.unshift File.join(File.dirname(__FILE__), '/units')
44
55
  require 'thing'
45
56
 
46
- require 'controls'
47
57
  require 'menu'
48
- require 'game_window'
49
- require 'scheduling'
50
- require 'waves'
51
- require 'layer'
52
58
 
53
59
  DEFAULT_SCREEN_WIDTH = 1200 unless defined?(DEFAULT_SCREEN_WIDTH)
54
60
  DEFAULT_SCREEN_HEIGHT = 700 unless defined?(DEFAULT_SCREEN_HEIGHT)
@@ -1,6 +1,6 @@
1
1
  # An Attachable can be attached to a Pod.
2
2
  #
3
- module Attachable
3
+ module Attachable extend Trait
4
4
 
5
5
  attr_accessor :relative_position
6
6
 
@@ -1,6 +1,6 @@
1
1
  #
2
2
  #
3
- module Controllable
3
+ module Controllable extend Trait
4
4
 
5
5
  def self.included controllable
6
6
  controllable.extend ClassMethods
@@ -24,7 +24,7 @@
24
24
  # end
25
25
  # end
26
26
  #
27
- module Damaging
27
+ module Damaging extend Trait
28
28
 
29
29
  class DamageMissingError < RuntimeError
30
30
  def initialize
@@ -1,4 +1,4 @@
1
- module Generator
1
+ module Generator extend Trait
2
2
 
3
3
  def self.included base
4
4
  base.extend ClassMethods
@@ -1,4 +1,4 @@
1
- module Imageable
1
+ module Imageable extend Trait
2
2
 
3
3
  class ImageMissingError < RuntimeError
4
4
  def initialize
data/lib/traits/lives.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # A thing is destroyed if a number of lives has been passed.
2
2
  #
3
- module Lives
3
+ module Lives extend Trait
4
4
 
5
5
  # TODO def revive!
6
6
  #
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # TODO moveable should only have active components, like accelerate etc. Positioning etc. should go to Thing.
4
4
  #
5
- module Moveable
5
+ module Moveable extend Trait
6
6
 
7
7
  Accelerate = :accelerate
8
8
  Left = :move_left
data/lib/traits/pod.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  #
4
4
  #
5
5
  #
6
- module Pod
6
+ module Pod extend Trait
7
7
 
8
8
  manual <<-MANUAL
9
9
  Defines:
@@ -1,4 +1,4 @@
1
- module Shooter
1
+ module Shooter extend Trait
2
2
 
3
3
  Shoot = :shoot
4
4
 
@@ -1,4 +1,4 @@
1
- module ShortLived
1
+ module ShortLived extend Trait
2
2
 
3
3
  class LifetimeMissingError < RuntimeError
4
4
  def initialize
data/lib/traits/shot.rb CHANGED
@@ -1,4 +1,4 @@
1
- module Shot
1
+ module Shot extend Trait
2
2
 
3
3
  #
4
4
  #
@@ -1,6 +1,6 @@
1
1
  # Any object that is targetable.
2
2
  #
3
- module Targetable
3
+ module Targetable extend Trait
4
4
 
5
5
  # Distance from the potential shooter.
6
6
  #
@@ -2,7 +2,7 @@
2
2
  #
3
3
  module Targeting
4
4
 
5
- module Closest
5
+ module Closest extend Trait
6
6
 
7
7
  # Returns the closest target of all targets in the fire arc.
8
8
  #
@@ -1,6 +1,6 @@
1
1
  #
2
2
  #
3
- module Turnable
3
+ module Turnable extend Trait
4
4
 
5
5
  Left = :turn_left
6
6
  Right = :turn_right
@@ -9,7 +9,10 @@ module Turnable
9
9
  base.extend ClassMethods
10
10
  end
11
11
 
12
- # TODO meta
12
+ # Defines a turn_speed method on the class.
13
+ #
14
+ # Calling it will define a turn_speed method on the instance
15
+ # that lets the thing rotate with the given frequency.
13
16
  #
14
17
  module ClassMethods
15
18
  def turn_speed amount
File without changes
@@ -0,0 +1,70 @@
1
+ require File.join(File.dirname(__FILE__), '/../../spec_helper')
2
+
3
+ describe ItIsA do
4
+
5
+ before(:all) do
6
+ Trait1 = Trait
7
+ Trait2 = Trait
8
+ end
9
+
10
+ before(:each) do
11
+ @class = Class.new do
12
+ include ItIsA
13
+ def self.to_s
14
+ "TestClass"
15
+ end
16
+ end
17
+ end
18
+
19
+ it "should define a it_is_a method that calls include" do
20
+ @class.should_receive(:include).once.with Trait
21
+
22
+ @class.it_is_a Trait
23
+ end
24
+ it "should take multiple traits" do
25
+ @class.should_receive(:include).once.with Trait1
26
+ @class.should_receive(:include).once.with Trait2
27
+
28
+ @class.it_is_a Trait1, Trait2
29
+ end
30
+ it "should call a given block on the instance" do
31
+ @class.it_is_a Trait1, Trait2 do
32
+ self.to_s.should == "TestClass"
33
+ end
34
+ end
35
+
36
+ it "should define a it_is method that calls include" do
37
+ @class.should_receive(:include).once.with Trait
38
+
39
+ @class.it_is Trait
40
+ end
41
+ it "should take multiple traits" do
42
+ @class.should_receive(:include).once.with Trait1
43
+ @class.should_receive(:include).once.with Trait2
44
+
45
+ @class.it_is Trait1, Trait2
46
+ end
47
+ it "should call a given block on the instance" do
48
+ @class.it_is Trait1, Trait2 do
49
+ self.to_s.should == "TestClass"
50
+ end
51
+ end
52
+
53
+ it "should define a it_has method that calls include" do
54
+ @class.should_receive(:include).once.with Trait
55
+
56
+ @class.it_has Trait
57
+ end
58
+ it "should take multiple traits" do
59
+ @class.should_receive(:include).once.with Trait
60
+ @class.should_receive(:include).once.with Trait2
61
+
62
+ @class.it_has Trait1, Trait2
63
+ end
64
+ it "should call a given block on the instance" do
65
+ @class.it_has Trait1, Trait2 do
66
+ self.to_s.should == "TestClass"
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,9 @@
1
+ require File.join(File.dirname(__FILE__), '/../../spec_helper')
2
+
3
+ describe "Trait" do
4
+
5
+ it "should define a constant" do
6
+ lambda { Trait }.should_not raise_error
7
+ end
8
+
9
+ end
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), '/../../spec_helper')
2
+
3
+ describe Traits do
4
+
5
+ describe "list" do
6
+ it "should return a list of all traits that can be included using it_is_a, it_is, or it_has" do
7
+ ActiveSupport::Deprecation.stub! :warn => :shut_up
8
+
9
+ Traits.list.should == [Attachable, Controllable, Damaging, Generator, Imageable, Lives, Moveable, Pod, Shooter, ShortLived, Shot, Targetable, Targeting::Closest, Turnable]
10
+ end
11
+ end
12
+
13
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 14
9
- version: 0.1.14
8
+ - 15
9
+ version: 0.1.15
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Hanke
@@ -53,22 +53,26 @@ files:
53
53
  - Rakefile
54
54
  - VERSION
55
55
  - generator/gogogosu.rb
56
- - lib/controls.rb
56
+ - lib/core/controls.rb
57
+ - lib/core/game_window.rb
58
+ - lib/core/initializer_hooks.rb
59
+ - lib/core/it_is_a.rb
60
+ - lib/core/layer.rb
61
+ - lib/core/resources.rb
62
+ - lib/core/scheduling.rb
63
+ - lib/core/trait.rb
64
+ - lib/core/traits.rb
65
+ - lib/core/vector_utilities.rb
66
+ - lib/core/waves.rb
57
67
  - lib/extensions/module.rb
58
68
  - lib/extensions/numeric.rb
59
- - lib/game_window.rb
60
69
  - lib/gosu_extensions.rb
61
- - lib/layer.rb
62
70
  - lib/menu.rb
63
- - lib/resources.rb
64
- - lib/scheduling.rb
65
71
  - lib/traits/attachable.rb
66
72
  - lib/traits/controllable.rb
67
73
  - lib/traits/damaging.rb
68
74
  - lib/traits/generator.rb
69
75
  - lib/traits/imageable.rb
70
- - lib/traits/initializer_hooks.rb
71
- - lib/traits/it_is_a.rb
72
76
  - lib/traits/lives.rb
73
77
  - lib/traits/moveable.rb
74
78
  - lib/traits/pod.rb
@@ -80,8 +84,6 @@ files:
80
84
  - lib/traits/targeting/closest.rb
81
85
  - lib/traits/turnable.rb
82
86
  - lib/units/thing.rb
83
- - lib/vector_utilities.rb
84
- - lib/waves.rb
85
87
  has_rdoc: true
86
88
  homepage: http://www.github.com/floere/gosu_extensions
87
89
  licenses: []
@@ -114,12 +116,15 @@ signing_key:
114
116
  specification_version: 3
115
117
  summary: Default extensions built onto the popular Gosu Framework. Uses Chipmunk for game physics. That's it for now. I'm working on them. Anyway, GAME ON!
116
118
  test_files:
119
+ - spec/lib/core/initializer_hooks_spec.rb
120
+ - spec/lib/core/it_is_a_spec.rb
121
+ - spec/lib/core/trait_spec.rb
122
+ - spec/lib/core/traits_spec.rb
117
123
  - spec/lib/extensions/module_spec.rb
118
124
  - spec/lib/extensions/numeric_spec.rb
119
125
  - spec/lib/traits/attachable_spec.rb
120
126
  - spec/lib/traits/damaging_spec.rb
121
127
  - spec/lib/traits/imageable_spec.rb
122
- - spec/lib/traits/initializer_hooks_spec.rb
123
128
  - spec/lib/traits/shooter_spec.rb
124
129
  - spec/lib/traits/short_lived_spec.rb
125
130
  - spec/lib/traits/shot_spec.rb