tabletop 0.2.1 → 0.3.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.
- data/.gitignore +2 -1
- data/README.markdown +59 -37
- data/Rakefile +6 -2
- data/lib/fixnum.rb +4 -8
- data/lib/tabletop/condition.rb +20 -0
- data/lib/tabletop/pool.rb +61 -30
- data/lib/tabletop/randomizers.rb +37 -22
- data/lib/tabletop/roll.rb +37 -29
- data/lib/tabletop/token.rb +57 -19
- data/lib/tabletop/version.rb +1 -1
- data/lib/tabletop.rb +1 -0
- data/spec/condition_spec.rb +15 -0
- data/spec/fixnum_spec.rb +4 -0
- data/spec/pool_spec.rb +141 -117
- data/spec/randomizers_spec.rb +79 -59
- data/spec/roll_spec.rb +19 -18
- data/spec/spec_helper.rb +1 -5
- data/spec/token_spec.rb +72 -13
- data/tabletop.gemspec +1 -1
- metadata +7 -4
data/spec/randomizers_spec.rb
CHANGED
@@ -2,16 +2,25 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Tabletop
|
4
4
|
describe Die do
|
5
|
-
|
6
5
|
before :each do
|
7
|
-
@d6_2 = Die.new(
|
8
|
-
@d6_3 = Die.new(
|
6
|
+
@d6_2 = Die.new(value: 2)
|
7
|
+
@d6_3 = Die.new(value: 3)
|
9
8
|
end
|
10
|
-
|
9
|
+
|
10
|
+
describe ".new_from_string" do
|
11
|
+
it "expects a string in the format 'n/o', where n and o are integers" do
|
12
|
+
d = Die.new_from_string('4/5')
|
13
|
+
d.value.should == 4
|
14
|
+
d.sides.should == 5
|
15
|
+
expect {Die.new_from_string('10')}.to raise_error(ArgumentError)
|
16
|
+
expect {Die.new_from_string(4/5)}.to raise_error(ArgumentError)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
11
20
|
describe "#sides" do
|
12
21
|
it "can be accessed" do
|
13
22
|
(2..10).each do |i|
|
14
|
-
Die.new(i).sides.should == i
|
23
|
+
Die.new(sides: i).sides.should == i
|
15
24
|
end
|
16
25
|
end
|
17
26
|
|
@@ -20,15 +29,16 @@ module Tabletop
|
|
20
29
|
end
|
21
30
|
|
22
31
|
it "cannot be 1 or less" do
|
23
|
-
expect { Die.new(0) }.to raise_error(ArgumentError)
|
24
|
-
expect { Die.new(1) }.to raise_error(ArgumentError)
|
25
|
-
expect { Die.new(-5) }.to raise_error(ArgumentError)
|
32
|
+
expect { Die.new(sides: 0) }.to raise_error(ArgumentError)
|
33
|
+
expect { Die.new(sides: 1) }.to raise_error(ArgumentError)
|
34
|
+
expect { Die.new(sides: -5) }.to raise_error(ArgumentError)
|
26
35
|
end
|
27
36
|
|
28
|
-
it "
|
29
|
-
expect { Die.new(0.1) }.to raise_error(ArgumentError)
|
30
|
-
|
31
|
-
|
37
|
+
it "is cast as an integer" do
|
38
|
+
expect { Die.new(sides: 0.1) }.to raise_error(ArgumentError)
|
39
|
+
Die.new(sides: 5.7694).sides.should == 5
|
40
|
+
Die.new(sides: "10").sides.should == 10
|
41
|
+
expect { Die.new(sides: "foof") }.to raise_error(ArgumentError)
|
32
42
|
end
|
33
43
|
end
|
34
44
|
|
@@ -36,31 +46,35 @@ module Tabletop
|
|
36
46
|
it "should be random on instantiation by default" do
|
37
47
|
Random.srand(10)
|
38
48
|
Die.new.value.should == 2
|
39
|
-
Die.new(10).value.should == 5
|
40
|
-
Die.new(50).value.should == 16
|
49
|
+
Die.new(sides: 10).value.should == 5
|
50
|
+
Die.new(sides: 50, value: nil).value.should == 16
|
41
51
|
end
|
42
52
|
|
43
53
|
it "can be set to a given value on instantiation" do
|
44
|
-
Die.new(
|
45
|
-
Die.new(10, 2).value.should == 2
|
54
|
+
Die.new(value: 5).value.should == 5
|
55
|
+
Die.new(sides: 10, value: 2).value.should == 2
|
46
56
|
end
|
47
57
|
|
48
|
-
it "
|
49
|
-
expect { Die.new(
|
50
|
-
|
51
|
-
expect { Die.new("foof")
|
58
|
+
it "is cast as an integer" do
|
59
|
+
expect { Die.new(value: []) }.to raise_error(TypeError)
|
60
|
+
Die.new(value: 5.7694).value.should == 5
|
61
|
+
expect { Die.new(value: "foof")}.to raise_error(ArgumentError)
|
52
62
|
end
|
53
63
|
end
|
54
64
|
|
55
65
|
describe "#value=" do
|
56
|
-
it "can only be set to
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
66
|
+
it "can only be set to i, where 0 < i <= sides" do
|
67
|
+
[4, 6, 10].each do |type|
|
68
|
+
d = Die.new(sides: type)
|
69
|
+
-10.upto(15).each do |v|
|
70
|
+
if v < 1 or v > type
|
71
|
+
lambda { d.value = v }.should raise_error(ArgumentError)
|
72
|
+
else
|
73
|
+
d.value = v
|
74
|
+
d.value.should == v
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
64
78
|
end
|
65
79
|
end
|
66
80
|
|
@@ -69,9 +83,9 @@ module Tabletop
|
|
69
83
|
Random.srand(10)
|
70
84
|
end
|
71
85
|
|
72
|
-
context "six sides" do
|
86
|
+
context "a die with six sides" do
|
73
87
|
before(:each) do
|
74
|
-
@d6 = Die.new
|
88
|
+
@d6 = Die.new
|
75
89
|
end
|
76
90
|
|
77
91
|
it "should return a random result between 1 and @sides" do
|
@@ -91,7 +105,7 @@ module Tabletop
|
|
91
105
|
describe "#to_str" do
|
92
106
|
it "should tell you the die's value" do
|
93
107
|
5.times do
|
94
|
-
d = Die.new(rand(10)+3)
|
108
|
+
d = Die.new(sides: rand(10)+3)
|
95
109
|
"#{d}".should == "[#{d.value}]/d#{d.sides}"
|
96
110
|
end
|
97
111
|
end
|
@@ -131,41 +145,38 @@ module Tabletop
|
|
131
145
|
|
132
146
|
describe "#value" do
|
133
147
|
it "can be set on instantiation" do
|
134
|
-
|
135
|
-
|
136
|
-
|
148
|
+
[-1, 0, 1].each do |v|
|
149
|
+
FudgeDie.new(value:v).value.should == v
|
150
|
+
end
|
137
151
|
end
|
138
152
|
|
139
153
|
it "is randomly rolled if not set" do
|
140
154
|
@fudge.value.should == 0
|
141
155
|
end
|
142
|
-
|
143
|
-
it "can only be
|
144
|
-
|
145
|
-
|
146
|
-
end
|
147
|
-
expect {FudgeDie.new(2)}.to raise_error(ArgumentError)
|
148
|
-
expect {FudgeDie.new(0.6)}.to raise_error(ArgumentError)
|
149
|
-
expect {FudgeDie.new("5")}.to raise_error(ArgumentError)
|
156
|
+
|
157
|
+
it "can only be -1, 0 or 1" do
|
158
|
+
expect {FudgeDie.new(value:2)}.to raise_error(ArgumentError)
|
159
|
+
expect {FudgeDie.new(value:"-5")}.to raise_error(ArgumentError)
|
150
160
|
end
|
151
161
|
end
|
152
162
|
|
153
163
|
describe "#value=" do
|
154
|
-
it "
|
155
|
-
expect {@fudge.value = 2}.to raise_error(ArgumentError)
|
156
|
-
expect {@fudge.value = 0.6}.to raise_error(ArgumentError)
|
157
|
-
expect {@fudge.value = "5"}.to raise_error(ArgumentError)
|
164
|
+
it "can be set to -1, 0, or 1" do
|
158
165
|
[-1, 0, 1].each do |v|
|
159
166
|
@fudge.value = v
|
160
167
|
end
|
161
168
|
end
|
169
|
+
it "cannot be set to anything else" do
|
170
|
+
expect {@fudge.value = 2}.to raise_error(ArgumentError)
|
171
|
+
expect {@fudge.value = "-5"}.to raise_error(ArgumentError)
|
172
|
+
end
|
162
173
|
end
|
163
174
|
|
164
175
|
describe "#to_s" do
|
165
176
|
it "should return cute little dice with symbols" do
|
166
|
-
FudgeDie.new(1).to_s.should == "[+]"
|
167
|
-
FudgeDie.new(0).to_s.should == "[ ]"
|
168
|
-
FudgeDie.new(
|
177
|
+
FudgeDie.new(value:1).to_s.should == "[+]"
|
178
|
+
FudgeDie.new(value:0).to_s.should == "[ ]"
|
179
|
+
FudgeDie.new(value:-1).to_s.should == "[-]"
|
169
180
|
end
|
170
181
|
end
|
171
182
|
end
|
@@ -183,27 +194,36 @@ module Tabletop
|
|
183
194
|
end
|
184
195
|
|
185
196
|
it "can't be anything else" do
|
186
|
-
expect {subject.value = "
|
187
|
-
expect {subject.value =
|
197
|
+
expect {subject.value = "2"}.to raise_error(ArgumentError)
|
198
|
+
expect {subject.value = -1.6}.to raise_error(ArgumentError)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "heads?" do
|
203
|
+
it "is true if #value is 1" do
|
204
|
+
Coin.new(value:1).heads?.should be_true
|
205
|
+
Coin.new(value:0).heads?.should be_false
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe "tails?" do
|
210
|
+
it "is true if #value is 0" do
|
211
|
+
Coin.new(value:0).tails?.should be_true
|
212
|
+
Coin.new(value:1).tails?.should be_false
|
188
213
|
end
|
189
214
|
end
|
190
215
|
|
191
216
|
describe "#flip" do
|
192
217
|
it {subject.flip.should be_instance_of(Coin)}
|
193
218
|
it "should alias roll" do
|
194
|
-
|
219
|
+
subject.should_receive(:roll)
|
195
220
|
subject.flip
|
196
|
-
# I have to use implicit expectations, because the below code doesn't
|
197
|
-
# work in rspec2
|
198
|
-
#stub(subject).roll
|
199
|
-
#subject.flip
|
200
|
-
#subject.should have_received.roll
|
201
221
|
end
|
202
222
|
end
|
203
223
|
|
204
224
|
describe "#to_s" do
|
205
|
-
it {Coin.new(1).to_s.should == "(+)"}
|
206
|
-
it {Coin.new(0).to_s.should == "( )"}
|
225
|
+
it {Coin.new(value:1).to_s.should == "(+)"}
|
226
|
+
it {Coin.new(value:0).to_s.should == "( )"}
|
207
227
|
end
|
208
228
|
end
|
209
229
|
end
|
data/spec/roll_spec.rb
CHANGED
@@ -32,11 +32,12 @@ module Tabletop
|
|
32
32
|
under_fire.roll
|
33
33
|
end
|
34
34
|
if under_fire.pool.sum + cool + mod >= 10
|
35
|
-
effect = "You do it"
|
35
|
+
effect = ["You do it"]
|
36
36
|
elsif under_fire.pool.sum + cool + mod >= 7
|
37
|
-
effect = "You flinch, hesitate, or stall"
|
37
|
+
effect = ["You flinch, hesitate, or stall"]
|
38
38
|
end
|
39
|
-
under_fire.
|
39
|
+
under_fire.result.should == under_fire.pool.sum + cool + mod
|
40
|
+
under_fire.effects.should == effect
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
@@ -67,15 +68,16 @@ module Tabletop
|
|
67
68
|
it "can count successes" do
|
68
69
|
@exalted.roll(:pool=>10)
|
69
70
|
10.times do
|
70
|
-
@exalted.
|
71
|
+
@exalted.result.should == count_successes(@exalted.pool)
|
72
|
+
@exalted.effects.should ==nil
|
71
73
|
end
|
72
74
|
end
|
73
75
|
|
74
76
|
it "can determine success" do
|
75
77
|
(1..10).each do |i|
|
76
78
|
@exalted.roll(:pool=>6, :difficulty=>i)
|
77
|
-
effect = (count_successes(@exalted.pool) >= i) ? "Success" : nil
|
78
|
-
@exalted.effects.should ==
|
79
|
+
effect = (count_successes(@exalted.pool) >= i) ? ["Success"] : nil
|
80
|
+
@exalted.effects.should == effect
|
79
81
|
end
|
80
82
|
end
|
81
83
|
end
|
@@ -99,20 +101,19 @@ module Tabletop
|
|
99
101
|
equals 1, "Rock Paper Scissors", rps
|
100
102
|
equals 2, "JanKenPon", jkp
|
101
103
|
}
|
102
|
-
a, b
|
104
|
+
a, b = fist_game.roll.effects
|
103
105
|
|
104
|
-
[1,2].include?(
|
106
|
+
[1,2].include?(fist_game.result).should be_true
|
105
107
|
|
106
|
-
if
|
107
|
-
|
108
|
+
if fist_game.result == 1
|
109
|
+
a.should == "Rock Paper Scissors"
|
108
110
|
else
|
109
|
-
|
111
|
+
a.should == "JanKenPon"
|
110
112
|
end
|
111
113
|
|
112
|
-
|
113
|
-
|
114
|
-
b[
|
115
|
-
|
114
|
+
b.should be_instance_of(Array)
|
115
|
+
b.length.should == 1
|
116
|
+
b[0].should be_instance_of(String)
|
116
117
|
end
|
117
118
|
before :each do
|
118
119
|
ill_fortune = Roll.new(1.d10) do
|
@@ -149,10 +150,10 @@ module Tabletop
|
|
149
150
|
it "can compose multiple nested results" do
|
150
151
|
20.times do
|
151
152
|
@childhood_event.roll
|
152
|
-
if @childhood_event.
|
153
|
-
@childhood_event.effects.length.should == 4
|
154
|
-
else
|
153
|
+
if @childhood_event.result >= 9
|
155
154
|
@childhood_event.effects.length.should == 3
|
155
|
+
else
|
156
|
+
@childhood_event.effects.length.should == 2
|
156
157
|
end
|
157
158
|
end
|
158
159
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -12,8 +12,4 @@ require 'tabletop'
|
|
12
12
|
|
13
13
|
# Requires supporting files with custom matchers and macros, etc,
|
14
14
|
# in ./support/ and its subdirectories.
|
15
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
16
|
-
|
17
|
-
RSpec.configure do |config|
|
18
|
-
config.mock_framework = :rr
|
19
|
-
end
|
15
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
data/spec/token_spec.rb
CHANGED
@@ -42,14 +42,14 @@ module Tabletop
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
it "
|
46
|
-
|
45
|
+
it "casts arguments to integers" do
|
46
|
+
subject.add(3.5)
|
47
|
+
subject.count.should == 4
|
48
|
+
expect { subject.add(Object) }.to raise_error(ArgumentError)
|
47
49
|
end
|
48
50
|
|
49
|
-
it "does not accept arguments <
|
50
|
-
expect { subject.add(0) }.to raise_error(ArgumentError)
|
51
|
+
it "does not accept arguments < 0" do
|
51
52
|
expect { subject.add(-1) }.to raise_error(ArgumentError)
|
52
|
-
subject.add(1)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -69,14 +69,15 @@ module Tabletop
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
it "
|
73
|
-
|
72
|
+
it "casts arguments to integers" do
|
73
|
+
subject.count = 2
|
74
|
+
subject.remove(Math::E)
|
75
|
+
subject.count.should == 0
|
76
|
+
expect { subject.remove(Object) }.to raise_error(ArgumentError)
|
74
77
|
end
|
75
78
|
|
76
|
-
it "does not accept arguments <
|
77
|
-
expect { subject.remove(0) }.to raise_error(ArgumentError)
|
79
|
+
it "does not accept arguments < 0" do
|
78
80
|
expect { subject.remove(-1) }.to raise_error(ArgumentError)
|
79
|
-
subject.remove(1)
|
80
81
|
end
|
81
82
|
|
82
83
|
it "raises an error when trying to remove too many" do
|
@@ -110,12 +111,70 @@ module Tabletop
|
|
110
111
|
end
|
111
112
|
end
|
112
113
|
it "doesn't move any tokens if :to isn't a TokenStack" do
|
113
|
-
expect {@a.move(1, :to => [])}.to raise_error
|
114
|
-
|
115
|
-
|
114
|
+
expect {@a.move(1, :to => [])}.to raise_error ArgumentError
|
115
|
+
@a.count.should == 1
|
116
|
+
end
|
117
|
+
it "doesn't move any tokens if no :to option is passed" do
|
118
|
+
expect {@a.move(1)}.to raise_error ArgumentError
|
119
|
+
@a.count.should == 1
|
120
|
+
end
|
121
|
+
it "doesn't move any tokens if there aren't enough tokens to move" do
|
122
|
+
expect {@a.move(2, :to => @b)}.to raise_error NotEnoughTokensError
|
116
123
|
@a.count.should == 1
|
117
124
|
@b.count.should == 1
|
118
125
|
end
|
119
126
|
end
|
127
|
+
|
128
|
+
context "with a maximum set" do
|
129
|
+
describe "#max" do
|
130
|
+
it "can be set on instantiation" do
|
131
|
+
2.upto(5) do |v|
|
132
|
+
s = TokenStack.new(1, max: v)
|
133
|
+
s.max.should == v
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
describe "#count=" do
|
138
|
+
it "cannot be set higher than the current maximum" do
|
139
|
+
2.upto(5) do |v|
|
140
|
+
s = TokenStack.new(1, max: v)
|
141
|
+
s.count = v
|
142
|
+
expect{s.count = v+1}.should raise_error ExceedMaxTokensError
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
describe "#add" do
|
147
|
+
it "cannot go above the maximum" do
|
148
|
+
s = TokenStack.new(1, max: 1)
|
149
|
+
expect{s.add(1)}.should raise_error ExceedMaxTokensError
|
150
|
+
s.max = 5
|
151
|
+
s.add(1)
|
152
|
+
expect{s.add(5)}.should raise_error ExceedMaxTokensError
|
153
|
+
end
|
154
|
+
it "knows to round down decimals" do
|
155
|
+
subject.max = 2
|
156
|
+
subject.add(1.8)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
describe "#refresh" do
|
160
|
+
it "sets the count to the maximum" do
|
161
|
+
2.upto(5) do |v|
|
162
|
+
s = TokenStack.new(1, max: v)
|
163
|
+
s.refresh
|
164
|
+
s.count.should == v
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
context "with no maximum set" do
|
170
|
+
describe "#max" do
|
171
|
+
it {subject.max.should be_nil}
|
172
|
+
end
|
173
|
+
describe "#refresh" do
|
174
|
+
it "pretends it doesn't exist" do
|
175
|
+
expect{subject.refresh}.should raise_error NoMethodError
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
120
179
|
end
|
121
180
|
end
|
data/tabletop.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.authors = ['Nick Novitski']
|
10
10
|
s.email = 'nicknovitski@gmail.com'
|
11
11
|
s.homepage = 'http://github.com/njay/tabletop'
|
12
|
-
s.summary = '
|
12
|
+
s.summary = 'An RPG and tabletop game library'
|
13
13
|
s.description = 'Tabletop aims to provide a simple way of describing, automating and tracking the tools and tasks involved in "analog" games, determining results from the motions and properties of various dice and chips.'
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
'LICENSE',
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: tabletop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nick Novitski
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- doc/Tabletop.html
|
124
124
|
- Gemfile
|
125
125
|
- lib/fixnum.rb
|
126
|
+
- lib/tabletop/condition.rb
|
126
127
|
- lib/tabletop/pool.rb
|
127
128
|
- lib/tabletop/randomizers.rb
|
128
129
|
- lib/tabletop/roll.rb
|
@@ -132,6 +133,7 @@ files:
|
|
132
133
|
- LICENSE
|
133
134
|
- Rakefile
|
134
135
|
- README.markdown
|
136
|
+
- spec/condition_spec.rb
|
135
137
|
- spec/fixnum_spec.rb
|
136
138
|
- spec/pool_spec.rb
|
137
139
|
- spec/randomizers_spec.rb
|
@@ -153,7 +155,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
155
|
requirements:
|
154
156
|
- - ">="
|
155
157
|
- !ruby/object:Gem::Version
|
156
|
-
hash:
|
158
|
+
hash: 302190484113960974
|
157
159
|
segments:
|
158
160
|
- 0
|
159
161
|
version: "0"
|
@@ -166,11 +168,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
168
|
requirements: []
|
167
169
|
|
168
170
|
rubyforge_project:
|
169
|
-
rubygems_version: 1.8.
|
171
|
+
rubygems_version: 1.8.11
|
170
172
|
signing_key:
|
171
173
|
specification_version: 3
|
172
|
-
summary:
|
174
|
+
summary: An RPG and tabletop game library
|
173
175
|
test_files:
|
176
|
+
- spec/condition_spec.rb
|
174
177
|
- spec/fixnum_spec.rb
|
175
178
|
- spec/pool_spec.rb
|
176
179
|
- spec/randomizers_spec.rb
|