woyo-world 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -82,148 +82,192 @@ describe 'DSL' do
82
82
  away.description.should eq 'Okay'
83
83
  end
84
84
 
85
- context 'new way' do
86
-
87
- it 'to new location' do
88
- world = Woyo::World.new do
89
- location :home do
90
- way :door do
91
- name 'Large Wooden Door'
92
- to :away
85
+ context 'ways' do
86
+
87
+ context 'new way' do
88
+
89
+ it 'to new location' do
90
+ world = Woyo::World.new do
91
+ location :home do
92
+ way :door do
93
+ name 'Large Wooden Door'
94
+ to :away
95
+ end
93
96
  end
94
97
  end
98
+ home = world.locations[:home]
99
+ home.ways.count.should eq 1
100
+ door = home.ways[:door]
101
+ door.should be_instance_of Woyo::Way
102
+ door.name.should eq 'Large Wooden Door'
103
+ door.to.should be_instance_of Woyo::Location
104
+ door.to.id.should eq :away
105
+ away = world.locations[:away]
106
+ away.ways.count.should eq 0
107
+ door.to.should eq away
95
108
  end
96
- home = world.locations[:home]
97
- home.ways.count.should eq 1
98
- door = home.ways[:door]
99
- door.should be_instance_of Woyo::Way
100
- door.name.should eq 'Large Wooden Door'
101
- door.to.should be_instance_of Woyo::Location
102
- door.to.id.should eq :away
103
- away = world.locations[:away]
104
- away.ways.count.should eq 0
105
- door.to.should eq away
106
- end
107
109
 
108
- it 'to existing location' do
109
- world = Woyo::World.new do
110
- location :away do
111
- end
112
- location :home do
113
- way :door do
114
- name 'Large Wooden Door'
115
- to :away
110
+ it 'to existing location' do
111
+ world = Woyo::World.new do
112
+ location :away do
113
+ end
114
+ location :home do
115
+ way :door do
116
+ name 'Large Wooden Door'
117
+ to :away
118
+ end
116
119
  end
117
120
  end
121
+ home = world.locations[:home]
122
+ home.ways.count.should eq 1
123
+ door = home.ways[:door]
124
+ door.should be_instance_of Woyo::Way
125
+ door.name.should eq 'Large Wooden Door'
126
+ door.to.should be_instance_of Woyo::Location
127
+ door.to.id.should eq :away
128
+ away = world.locations[:away]
129
+ away.ways.count.should eq 0
130
+ door.to.should eq away
118
131
  end
119
- home = world.locations[:home]
120
- home.ways.count.should eq 1
121
- door = home.ways[:door]
122
- door.should be_instance_of Woyo::Way
123
- door.name.should eq 'Large Wooden Door'
124
- door.to.should be_instance_of Woyo::Location
125
- door.to.id.should eq :away
126
- away = world.locations[:away]
127
- away.ways.count.should eq 0
128
- door.to.should eq away
129
- end
130
132
 
131
- it 'to same location' do
132
- world = Woyo::World.new do
133
- location :home do
134
- way :door do
135
- name 'Large Wooden Door'
136
- to :home
133
+ it 'to same location' do
134
+ world = Woyo::World.new do
135
+ location :home do
136
+ way :door do
137
+ name 'Large Wooden Door'
138
+ to :home
139
+ end
137
140
  end
138
141
  end
142
+ home = world.locations[:home]
143
+ home.ways.count.should eq 1
144
+ door = home.ways[:door]
145
+ door.should be_instance_of Woyo::Way
146
+ door.name.should eq 'Large Wooden Door'
147
+ door.to.should be_instance_of Woyo::Location
148
+ door.to.id.should eq :home
149
+ door.to.should eq home
139
150
  end
140
- home = world.locations[:home]
141
- home.ways.count.should eq 1
142
- door = home.ways[:door]
143
- door.should be_instance_of Woyo::Way
144
- door.name.should eq 'Large Wooden Door'
145
- door.to.should be_instance_of Woyo::Location
146
- door.to.id.should eq :home
147
- door.to.should eq home
151
+
148
152
  end
149
153
 
150
- end
154
+ context 'existing way' do
151
155
 
152
- context 'existing way' do
156
+ it 'to new location' do
157
+ world = Woyo::World.new do
158
+ location :home do
159
+ way :door do
160
+ name 'Large Wooden Door'
161
+ description "Big, real big!"
162
+ end
163
+ way :door do
164
+ description 'Nicer'
165
+ to :away
166
+ end
167
+ end
168
+ end
169
+ home = world.locations[:home]
170
+ home.ways.count.should eq 1
171
+ door = home.ways[:door]
172
+ door.name.should eq 'Large Wooden Door'
173
+ door.description.should eq "Nicer"
174
+ door.to.should be_instance_of Woyo::Location
175
+ door.to.id.should eq :away
176
+ away = world.locations[:away]
177
+ away.ways.count.should eq 0
178
+ door.to.should eq away
179
+ end
153
180
 
154
- it 'to new location' do
155
- world = Woyo::World.new do
156
- location :home do
157
- way :door do
158
- name 'Large Wooden Door'
159
- description "Big, real big!"
181
+ it 'to existing location' do
182
+ world = Woyo::World.new do
183
+ location :away do
160
184
  end
161
- way :door do
162
- description 'Nicer'
163
- to :away
185
+ location :home do
186
+ way :door do
187
+ name 'Large Wooden Door'
188
+ description "Big, real big!"
189
+ end
190
+ way :door do
191
+ description 'Nicer'
192
+ to :away
193
+ end
164
194
  end
165
195
  end
196
+ home = world.locations[:home]
197
+ home.ways.count.should eq 1
198
+ door = home.ways[:door]
199
+ door.name.should eq 'Large Wooden Door'
200
+ door.description.should eq "Nicer"
201
+ door.to.should be_instance_of Woyo::Location
202
+ door.to.id.should eq :away
203
+ away = world.locations[:away]
204
+ away.ways.count.should eq 0
205
+ door.to.should eq away
166
206
  end
167
- home = world.locations[:home]
168
- home.ways.count.should eq 1
169
- door = home.ways[:door]
170
- door.name.should eq 'Large Wooden Door'
171
- door.description.should eq "Nicer"
172
- door.to.should be_instance_of Woyo::Location
173
- door.to.id.should eq :away
174
- away = world.locations[:away]
175
- away.ways.count.should eq 0
176
- door.to.should eq away
177
- end
178
207
 
179
- it 'to existing location' do
180
- world = Woyo::World.new do
181
- location :away do
182
- end
183
- location :home do
184
- way :door do
185
- name 'Large Wooden Door'
186
- description "Big, real big!"
187
- end
188
- way :door do
189
- description 'Nicer'
190
- to :away
208
+ it 'to same location' do
209
+ world = Woyo::World.new do
210
+ location :home do
211
+ way :door do
212
+ name 'Large Wooden Door'
213
+ description "Big, real big!"
214
+ end
215
+ way :door do
216
+ description 'Nicer'
217
+ to :home
218
+ end
191
219
  end
192
220
  end
221
+ home = world.locations[:home]
222
+ home.ways.count.should eq 1
223
+ door = home.ways[:door]
224
+ door.name.should eq 'Large Wooden Door'
225
+ door.description.should eq "Nicer"
226
+ door.to.should be_instance_of Woyo::Location
227
+ door.to.id.should eq :home
228
+ door.to.should eq home
193
229
  end
194
- home = world.locations[:home]
195
- home.ways.count.should eq 1
196
- door = home.ways[:door]
197
- door.name.should eq 'Large Wooden Door'
198
- door.description.should eq "Nicer"
199
- door.to.should be_instance_of Woyo::Location
200
- door.to.id.should eq :away
201
- away = world.locations[:away]
202
- away.ways.count.should eq 0
203
- door.to.should eq away
230
+
204
231
  end
205
232
 
206
- it 'to same location' do
207
- world = Woyo::World.new do
208
- location :home do
209
- way :door do
210
- name 'Large Wooden Door'
211
- description "Big, real big!"
233
+ context 'going' do
234
+
235
+ before :all do
236
+ @world = Woyo::World.new do
237
+ location :room do
238
+ way :stairs do
239
+ to :cellar
240
+ description open: 'Rickety stairs lead down into darkness.',
241
+ closed: 'Broken stairs end in darkness.'
242
+ going open: 'Creaky steps lead uncertainly downwards...',
243
+ closed: 'The dangerous stairs are impassable.'
244
+ end
212
245
  end
213
- way :door do
214
- description 'Nicer'
215
- to :home
246
+ location :cellar do
247
+ description 'Dark and damp, as expected.'
216
248
  end
217
249
  end
218
250
  end
219
- home = world.locations[:home]
220
- home.ways.count.should eq 1
221
- door = home.ways[:door]
222
- door.name.should eq 'Large Wooden Door'
223
- door.description.should eq "Nicer"
224
- door.to.should be_instance_of Woyo::Location
225
- door.to.id.should eq :home
226
- door.to.should eq home
251
+
252
+ it 'an open way' do
253
+ room = @world.locations[:room]
254
+ stairs = room.ways[:stairs]
255
+ stairs.to.id.should eq :cellar
256
+ stairs.should be_open
257
+ stairs.description.should eq 'Rickety stairs lead down into darkness.'
258
+ stairs.go.should eq ( { go: true, going: 'Creaky steps lead uncertainly downwards...' } )
259
+ end
260
+
261
+ it 'a closed way' do
262
+ room = @world.locations[:room]
263
+ stairs = room.ways[:stairs]
264
+ stairs.to.id.should eq :cellar
265
+ stairs.close!
266
+ stairs.should be_closed
267
+ stairs.description.should eq 'Broken stairs end in darkness.'
268
+ stairs.go.should eq ( { go: false, going: 'The dangerous stairs are impassable.' } )
269
+ end
270
+
227
271
  end
228
272
 
229
273
  end
@@ -5,7 +5,7 @@ require 'woyo/world/way'
5
5
  describe Woyo::Way do
6
6
 
7
7
  it 'has attributes' do
8
- expected_attrs = [:name,:description]
8
+ expected_attrs = [:name,:description,:open,:closed,:going]
9
9
  Woyo::Way.attributes.sort.should eq expected_attrs.sort
10
10
  end
11
11
 
@@ -41,5 +41,124 @@ describe Woyo::Way do
41
41
  end
42
42
  door.to.should be_a Woyo::Location
43
43
  end
44
+
45
+ it 'defaults to closed if "to" not defined' do
46
+ door = Woyo::Way.new(:door)
47
+ door.open.should be_false
48
+ door.closed.should be_true
49
+ end
50
+
51
+ it 'defaults to open if "to" defined' do
52
+ door = Woyo::Way.new(:door)
53
+ door.to = :someplace
54
+ door.open.should be_true
55
+ door.closed.should be_false
56
+ end
57
+
58
+ it 'may be made closed' do
59
+ door = Woyo::Way.new(:door)
60
+ door.to = :someplace
61
+ door.open.should be_true
62
+ door.closed.should be_false
63
+ door.closed = true
64
+ door.open.should be_false
65
+ door.closed.should be_true
66
+ end
67
+
68
+ it 'may be made open' do
69
+ door = Woyo::Way.new(:door)
70
+ door.open.should be_false
71
+ door.closed.should be_true
72
+ door.open = true
73
+ door.open.should be_true
74
+ door.closed.should be_false
75
+ end
76
+
77
+ it 'may be closed!' do
78
+ door = Woyo::Way.new(:door)
79
+ door.to = :someplace
80
+ door.open.should be_true
81
+ door.closed.should be_false
82
+ door.close!
83
+ door.open.should be_false
84
+ door.closed.should be_true
85
+ end
86
+
87
+ it 'can close!' do
88
+ door = Woyo::Way.new(:door)
89
+ door.to = :someplace
90
+ door.open.should be_true
91
+ door.closed.should be_false
92
+ door.close!
93
+ door.open.should be_false
94
+ door.closed.should be_true
95
+ end
96
+
97
+ it 'can open!' do
98
+ door = Woyo::Way.new(:door)
99
+ door.open.should be_false
100
+ door.closed.should be_true
101
+ door.open!
102
+ door.open.should be_true
103
+ door.closed.should be_false
104
+ end
105
+
106
+ it 'query open?' do
107
+ door = Woyo::Way.new(:door)
108
+ door.to = :someplace
109
+ door.should be_open
110
+ door.close!
111
+ door.should_not be_open
112
+ end
113
+
114
+ it 'query closed?' do
115
+ door = Woyo::Way.new(:door)
116
+ door.should be_closed
117
+ door.open!
118
+ door.should_not be_closed
119
+ end
120
+
121
+ context 'description' do
122
+
123
+ before :all do
124
+ @door = Woyo::Way.new(:door)
125
+ @door.to = :someplace
126
+ end
127
+
128
+ it 'can be described' do
129
+ @door.description = 'Just a door'
130
+ @door.description.should eq 'Just a door'
131
+ end
132
+
133
+ it 'can be described open' do
134
+ @door.description open: 'An open door', closed: 'A closed door'
135
+ @door.description.should eq 'An open door'
136
+ end
137
+
138
+ it 'can be described closed' do
139
+ @door.close!
140
+ @door.description.should eq 'A closed door'
141
+ end
142
+
143
+ end
144
+
145
+ context 'going' do
146
+
147
+ before :all do
148
+ @door = Woyo::Way.new(:door)
149
+ @door.to :someplace
150
+ @door.going :open => 'Swings open', :closed => 'Slams shut'
151
+ end
152
+
153
+ it 'when open' do
154
+ @door.go.should eq ( { go: true, going: 'Swings open' } )
155
+ end
156
+
157
+ it 'when closed' do
158
+ @door.close!
159
+ @door.go.should eq ( { go: false, going: 'Slams shut' } )
160
+ end
161
+
162
+ end
44
163
 
45
164
  end
data/todo.txt CHANGED
@@ -1,62 +1,85 @@
1
1
 
2
-
3
2
  world object features...
4
3
 
5
4
  # world
6
5
 
7
- location to start in...
6
+ # attributes
8
7
 
9
- start :location
10
8
 
11
- # attributes
9
+ default procs will be called upon access, not at initialization
10
+ this will fix the problem of WorldObject#id being nil when Attributes is prepended and Attributes#initialize is run first
12
11
 
13
- single...
12
+ boolean attributes
14
13
 
15
- attribute :color
14
+ ok detected by class level definition boolean default value
16
15
 
17
- multiple...
16
+ attribute open: true
17
+ attribute dark: false
18
18
 
19
- attributes :size, :shape, :color
19
+ ok after defintion, set boolean attribute values...
20
20
 
21
- boolean opposites / mutually exclusive...
22
- first one will be true
23
-
24
- attributes_exclusive :open, :closed
25
- attributes_exclusive :light, :dark
26
- attributes_exclusive :dark, :dim, :light, :bright
27
- attributes_exclusive :cold, :cool, :warm, :hot
21
+ open = true
22
+ open true
23
+ open! # ... open true
24
+
25
+ ok query boolean attribute values... ?
28
26
 
29
- set attribute values via method style...
27
+ dark
28
+ dark? # ... dark ? true : false
29
+ is? :dark # ... def is? attr ; attributes[attr] ? true : false ; end
30
30
 
31
- color 'Blue'
32
- size 10
33
- open true
31
+ additional class level define (and detect?) boolean attribute values...
34
32
 
35
- set attribute values via assignment style...
33
+ is :open
34
+ is :dark
35
+ is :warm, :bright
36
36
 
37
- color = 'Blue'
38
- size = 10
39
- open = true
37
+ group...
40
38
 
41
- defaults via hash instead of just symbol
42
- # name
43
- # if not specified default to id.to_s.capitalize ?
39
+ group weapons: [ :sword, :knife, :rock, :fists ] # hash - key will be group name, value an array of symbols for members
40
+ group :weapons, [ :sword, :knife, :rock, :fists ] # symbol will be group name, array of symbols for members
41
+ ok group :weapons, :sword, :knife, :rock, :fists # symbols, first will be group name, rest will be members
44
42
 
45
- attribute color: :blue
46
- attribute size: 10
47
- attribute name: proc { id.to_s.capitalize }
43
+ group stats: [ speed: 10, charisma: 20, strength: 30 ] # defaults like attributes (these are attributes)
44
+ ok group :stats, speed: 10, charisma: 20, strength: 30 # ditto
45
+
46
+ ok group is hash-like
47
+ alias :names, :keys
48
+
49
+ world_object.weapons.names #=> weapons.keys
50
+ world_object.weapons.values #=> weapons.values
51
+
52
+ ok group is not an enum, it has no value itself
53
+ ok attribute methods for members in parent
54
+
55
+ world_object.sword
56
+ world_object.knife
57
+
58
+ is group a namespace ? - optional ... attribute methods in group
48
59
 
49
- set boolean attribute values... ?
60
+ world_object.weapons.sword
61
+ world_object.weapons.knife
50
62
 
51
- is :open
52
- is :dark
53
- is :warm, :bright
63
+ ok access attributes via group hash
54
64
 
55
- test boolean attribute values... ?
65
+ world_object.weapons[:sword] #=> rusty_sword
66
+ world_object.weapons[:sword] = sharp_sword
56
67
 
57
- if is? :cold
58
- if is_cold?
59
- if cold
68
+ ok exclusive group (booleans)...
69
+
70
+ ok exclusive_group passable: , :open, :close
71
+ exclusive_group light: [ :dark, :dim, :bright ]
72
+ exclusive_group temperature: [ :cold, :cool, :warm, :hot ]
73
+
74
+ ok same as regular group +...
75
+
76
+ ok first member will be true, the rest false
77
+ ok additional convenience methods for members...
78
+
79
+ world_object.open?
80
+ world_object.close?
81
+ world_object.open!
82
+ world_object.close!
60
83
 
61
84
  # descriptions
62
85
 
@@ -141,6 +164,25 @@ world object features...
141
164
  to :garden
142
165
  end
143
166
 
167
+ way can describe being open closed
168
+
169
+ way :out do
170
+ name 'Door'
171
+ to :garden
172
+ description 'Wooden door'
173
+ description :open => 'An open wooden door leading to sunlit garden',
174
+ :closed => 'A closed solid wooden door'
175
+ end
176
+
177
+ way can describe going (open) or not (closed)
178
+
179
+ way :out do
180
+ name 'Door'
181
+ to :garden
182
+ go :open => 'Stepping into the warm sunlight',
183
+ :closed => 'The solid wooden door remains stubbornly closed'
184
+ end
185
+
144
186
  way :door, to: :other_location, description: 'Big'
145
187
 
146
188
  is openable, default open
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: woyo-world
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerard Fowley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-10 00:00:00.000000000 Z
11
+ date: 2014-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,6 +70,7 @@ files:
70
70
  - lib/woyo/world/attributes.rb
71
71
  - lib/woyo/world/character.rb
72
72
  - lib/woyo/world/dsl.rb
73
+ - lib/woyo/world/group.rb
73
74
  - lib/woyo/world/location.rb
74
75
  - lib/woyo/world/version.rb
75
76
  - lib/woyo/world/way.rb
@@ -78,6 +79,7 @@ files:
78
79
  - spec/woyo/world/attributes_spec.rb
79
80
  - spec/woyo/world/character_spec.rb
80
81
  - spec/woyo/world/dsl_spec.rb
82
+ - spec/woyo/world/group_spec.rb
81
83
  - spec/woyo/world/language_spec.rb
82
84
  - spec/woyo/world/location_spec.rb
83
85
  - spec/woyo/world/way_spec.rb
@@ -114,6 +116,7 @@ test_files:
114
116
  - spec/woyo/world/attributes_spec.rb
115
117
  - spec/woyo/world/character_spec.rb
116
118
  - spec/woyo/world/dsl_spec.rb
119
+ - spec/woyo/world/group_spec.rb
117
120
  - spec/woyo/world/language_spec.rb
118
121
  - spec/woyo/world/location_spec.rb
119
122
  - spec/woyo/world/way_spec.rb