foca / d20 fork watch download tarball
public
Description: A model of the d20 roleplaying rules system
Clone URL: git://github.com/foca/d20.git
Search Repo:
Races a plenty (fixes and such)
foca (author)
Thu Feb 21 19:30:39 -0800 2008
commit  62893212d71cbb52ab2223289c32e89ae692ce6c
tree    c97a10f7daaef769fc99c348cee5d46b2865d337
parent  b4edb6d71867058458c6b1a9b75867e5c04279b5
...
3
4
5
6
 
 
 
 
 
 
 
 
 
7
8
9
...
3
4
5
 
6
7
8
9
10
11
12
13
14
15
16
17
0
@@ -3,7 +3,15 @@ module D20
0
     def race(name, &block)
0
       returning D20::Races.load_or_create(name) do |race|
0
         mappings = { :str => :str=, :dex => :dex=, :con => :con=, :int => :int=, :wis => :wis=, :cha => :cha=,
0
- :size => :size=, :base_speed => :base_speed= }
0
+ :size => :size= }
0
+
0
+ mappings[:base_speed] = lambda do |race, speeds|
0
+ light, medium_heavy = speeds # speeds = [20, { :medium => 15, :heavy => 15 }]
0
+ medium_heavy ||= {}
0
+ race.base_speed[:light] = light
0
+ race.base_speed[:medium] = medium_heavy[:medium] if medium_heavy[:medium]
0
+ race.base_speed[:heavy] = medium_heavy[:heavy] if medium_heavy[:heavy]
0
+ end
0
         
0
         mappings[:darkvision] = lambda {|race| race.vision = :darkvision }
0
         mappings[:low_light_vision] = lambda {|race| race.vision = :low_light_vision}
...
6
7
8
9
10
11
12
13
14
15
16
 
 
17
18
19
20
 
21
22
23
...
6
7
8
 
9
10
11
12
13
14
 
15
16
17
18
19
20
21
22
23
24
0
@@ -6,18 +6,19 @@ module D20
0
 
0
     def self.load_or_create(name)
0
       const_name = name.to_s.underscore.camelize
0
- puts Races.const_defined?(const_name)
0
       Races.const_defined?(const_name) ? Races.const_get(const_name) : Races::Base.new(name)
0
     end
0
     
0
     class Base
0
       attr_reader :name
0
       attr_accessor :str, :dex, :con, :int, :wis, :cha
0
- attr_accessor :size, :base_speed
0
+ attr_accessor :size
0
+ attr_reader :base_speed
0
       
0
       def initialize(name)
0
         @name = name.to_s.titleize
0
         Races.const_set(name.to_s.underscore.camelize, self)
0
+ @base_speed = { :light => nil, :medium => nil, :heavy => nil }
0
       end
0
     end
0
   end
...
36
37
38
39
40
41
 
 
 
 
 
42
43
44
45
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
48
49
...
36
37
38
 
 
 
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
0
@@ -36,14 +36,36 @@ describe "A new race declaration" do
0
     end
0
   end
0
   
0
- it "should accept the base speed" do
0
- @race.should_receive(:base_speed=).with(20)
0
-
0
+ it "should allow setting the speed in light encumberance" do
0
+ speeds = {}
0
+ @race.should_receive(:base_speed).and_return(speeds)
0
+ speeds.should_receive(:[]=).with(:light, 20)
0
+
0
     race :testing do
0
       base_speed 20
0
     end
0
   end
0
   
0
+ it "should accept medium and heavy encumberance speeds as options to the base_speed call" do
0
+ @race.should_receive(:base_speed).exactly(3).times.and_return({})
0
+
0
+ race :testing do
0
+ base_speed 20, :medium => 15, :heavy => 15
0
+ end
0
+ end
0
+
0
+ it "should set the medium and heavy encumberance speed" do
0
+ speeds = {}
0
+ @race.should_receive(:base_speed).exactly(3).times.and_return(speeds)
0
+ speeds.should_receive(:[]=).with(:light, 20)
0
+ speeds.should_receive(:[]=).with(:medium, 15)
0
+ speeds.should_receive(:[]=).with(:heavy, 15)
0
+
0
+ race :testing do
0
+ base_speed 20, :medium => 15, :heavy => 15
0
+ end
0
+ end
0
+
0
   it "should allow setting the 'vision' to darkvision" do
0
     @race.should_receive(:vision=).with(:darkvision)
0
     
...
1
2
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
5
6
...
17
18
19
20
21
22
23
24
25
26
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
...
48
49
50
 
 
 
 
 
 
51
52
53
54
55
56
57
58
0
@@ -1,6 +1,37 @@
0
 require File.dirname(__FILE__) + "/../spec_helper"
0
 require "races"
0
 
0
+describe "Loading a race" do
0
+
0
+ describe "when it's not defined" do
0
+ before do
0
+ D20::Races.stub!(:const_defined?).and_return(false)
0
+ end
0
+
0
+ it "should initialize a new class" do
0
+ D20::Races::Base.should_receive(:new).with("some_race")
0
+ D20::Races.load_or_create("some_race")
0
+ end
0
+
0
+ it "should set the class as a constant in D20::Races" do
0
+ race_type = duck_type('str', 'dex', 'con', 'int', 'wis', 'cha', 'size', 'base_speed')
0
+ D20::Races.should_receive(:const_set).with("SomeRace", race_type)
0
+ D20::Races.load_or_create("some_race")
0
+ end
0
+ end
0
+
0
+ describe "when it's already defined" do
0
+ before do
0
+ D20::Races.stub!(:const_defined?).and_return(true)
0
+ end
0
+
0
+ it "should get the constant from the D20::Races module" do
0
+ D20::Races.should_receive(:const_get).with("SomeRace")
0
+ D20::Races.load_or_create("some_race")
0
+ end
0
+ end
0
+end
0
+
0
 describe "A new race" do
0
 
0
   before do
0
@@ -17,9 +48,10 @@ describe "A new race" do
0
     @race.name.should == "The Name"
0
   end
0
   
0
- it "should be available as a constant in D20::Races" do
0
- D20::Races.should be_const_defined(:TheName)
0
- D20::Races::TheName.should == @race
0
- end
0
-
0
-end
0
\ No newline at end of file
0
+ it { @race.should declare_accessors_for(:str, :dex, :con, :int, :wis, :cha) }
0
+
0
+ it { @race.should declare_accessors_for(:size) }
0
+
0
+ it { @race.should respond_to(:base_speed) }
0
+
0
+end

Comments

    No one has commented yet.