woyo-world 0.0.1 → 0.0.2

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: 92e60772a29ca3925bf5353033bc0c0ac96ad465
4
- data.tar.gz: ed75edcf3e85dfe1da2a579dfc9280464a68c3f2
3
+ metadata.gz: 0d6862d01d89d1601671ede0a31d858b78669e5e
4
+ data.tar.gz: edfeb22a481103e623e82e101a215dc469478e50
5
5
  SHA512:
6
- metadata.gz: ab053485fdf8aca924a7c8947bf77603d93c578b4f852ae746e20fc893cf28500ebbb16aa4b013389b6466c0fbcf65645f60954e43ab018bafe9edd7c68f5b79
7
- data.tar.gz: 36e5fa7bc6217185d7d1240f8da948b4f209cd057464a635c65784885afebf1026ea707ceb7288e2df59469a056cb050c9fa74d73f6a882d8f5e201198572a5d
6
+ metadata.gz: 3fbe0786d5b34845f0652d046088d3e16e68619c36486ddbd615e8102f69c5e55f5e329a789d5e7d2e0c42a7c74d66626c58eb3f21c86b9f9fa9e39c3e99ee93
7
+ data.tar.gz: a5c70a37d42d62630d72431867a5189908e7cc1cb68d1f3d97724af284247195e1315c0b5c3ae3c7acb1103187a376d01d4faee1788a54af0be56728bd70fd54
@@ -5,23 +5,43 @@ module Attributes
5
5
 
6
6
  module ClassMethods
7
7
 
8
- def attributes *attrs
9
- @attributes ||= [] # class instance variable in ClassMethods scope
10
- return @attributes if attrs.empty?
11
- @attributes = attrs # todo: allow additions to existing attributes
12
- @attributes.each do |attr|
13
- class_eval("
14
- def #{attr}= arg
15
- attributes[:#{attr}] = @#{attr} = arg
16
- end
17
- def #{attr}(arg=nil)
18
- if arg.nil?
19
- @#{attr}
8
+ def create_attribute_methods_with_define_method attr, default = nil
9
+ define_method "#{attr}=" do |arg|
10
+ attributes[attr] = arg
11
+ end
12
+ define_method attr do |arg = nil|
13
+ if arg.nil?
14
+ unless attributes.has_key? attr
15
+ if default.respond_to? :call
16
+ if default.arity == 0
17
+ attributes[attr] = default.call # todo: is this the same as ? ... instance_eval &default
18
+ else
19
+ attributes[attr] = default.call(self)
20
+ end
20
21
  else
21
- self.#{attr} = arg
22
+ attributes[attr] = default
22
23
  end
23
24
  end
24
- ")
25
+ attributes[attr]
26
+ else
27
+ attributes[attr] = arg
28
+ end
29
+ end
30
+ end
31
+
32
+ def attributes *attrs
33
+ @attributes ||= []
34
+ return @attributes if attrs.empty?
35
+ attrs.each do |attr|
36
+ if attr.kind_of? Hash
37
+ attr.each do |attr_sym,default_value|
38
+ @attributes << attr_sym
39
+ create_attribute_methods_with_define_method attr_sym, default_value
40
+ end
41
+ else
42
+ @attributes << attr
43
+ create_attribute_methods_with_define_method attr
44
+ end
25
45
  end
26
46
  end
27
47
 
@@ -10,33 +10,33 @@ module DSL
10
10
 
11
11
  module ClassMethods
12
12
 
13
- def contains *conts
14
- @contains ||= [] # class instance variable in ClassMethods scope
15
- return @contains if conts.empty?
16
- conts.each { |cont| @contains << cont unless @contains.include? cont }
17
- @contains.each do |cont|
13
+ def children *childs
14
+ @children ||= []
15
+ return @children if childs.empty?
16
+ childs.each { |child| @children << child unless @children.include? child }
17
+ @children.each do |child|
18
18
  class_eval("
19
19
 
20
- def #{cont}s
21
- ( @contains ||= {} )[:#{cont}] ||= ( @#{cont}s ||= {} )
20
+ def #{child}s
21
+ ( @children ||= {} )[:#{child}] ||= ( @#{child}s ||= {} )
22
22
  end
23
23
 
24
- def #{cont} cont_or_id, &block
25
- #{cont} = cont_or_id.kind_of?( #{cont.capitalize} ) ? cont_or_id : nil
26
- id = #{cont} ? #{cont}.id : cont_or_id
27
- known = self.#{cont}s[id] ? true : false
24
+ def #{child} child_or_id, &block
25
+ #{child} = child_or_id.kind_of?( #{child.capitalize} ) ? child_or_id : nil
26
+ id = #{child} ? #{child}.id : child_or_id
27
+ known = self.#{child}s[id] ? true : false
28
28
  case
29
- when #{cont} && known && block_given? then #{cont}.evaluate &block
30
- when #{cont} && known && !block_given? then #{cont}
31
- when #{cont} && !known && block_given? then self.#{cont}s[id] = #{cont}.evaluate &block
32
- when #{cont} && !known && !block_given? then self.#{cont}s[id] = #{cont}
33
- when !#{cont} && known && block_given? then #{cont} = self.#{cont}s[id].evaluate &block
34
- when !#{cont} && known && !block_given? then #{cont} = self.#{cont}s[id]
35
- when !#{cont} && !known && block_given? then #{cont} = self.#{cont}s[id] = #{cont.capitalize}.new id, context: self, &block
36
- when !#{cont} && !known && !block_given? then #{cont} = self.#{cont}s[id] = #{cont.capitalize}.new id, context: self
29
+ when #{child} && known && block_given? then #{child}.evaluate &block
30
+ when #{child} && known && !block_given? then #{child}
31
+ when #{child} && !known && block_given? then self.#{child}s[id] = #{child}.evaluate &block
32
+ when #{child} && !known && !block_given? then self.#{child}s[id] = #{child}
33
+ when !#{child} && known && block_given? then #{child} = self.#{child}s[id].evaluate &block
34
+ when !#{child} && known && !block_given? then #{child} = self.#{child}s[id]
35
+ when !#{child} && !known && block_given? then #{child} = self.#{child}s[id] = #{child.capitalize}.new id, context: self, &block
36
+ when !#{child} && !known && !block_given? then #{child} = self.#{child}s[id] = #{child.capitalize}.new id, context: self
37
37
  end
38
- # maybe: god-like lists of everything at world level... would need unique ids... self.world.#{cont}s[id] = #{cont} if !known && self.world
39
- #{cont}
38
+ # maybe: god-like lists of everything at world level... would need unique ids... self.world.#{child}s[id] = #{child} if !known && self.world
39
+ #{child}
40
40
  end
41
41
 
42
42
  ")
@@ -49,8 +49,8 @@ module DSL
49
49
  base.extend(ClassMethods)
50
50
  end
51
51
 
52
- def contains
53
- @contains ||= {}
52
+ def children
53
+ @children ||= {}
54
54
  end
55
55
 
56
56
  end
@@ -4,9 +4,9 @@ module Woyo
4
4
 
5
5
  class Location < WorldObject
6
6
 
7
- attributes :name, :description
7
+ attributes :description, name: lambda { |this| this.id.to_s.capitalize }
8
8
 
9
- contains :way, :character
9
+ children :way, :character
10
10
 
11
11
  def world
12
12
  self.context
@@ -1,3 +1,3 @@
1
1
  module Woyo
2
- WORLD_VERSION = "0.0.1"
2
+ WORLD_VERSION = "0.0.2"
3
3
  end
@@ -7,7 +7,9 @@ module Woyo
7
7
 
8
8
  class World < WorldObject
9
9
 
10
- contains :location, :character
10
+ attributes :name, :description, :start
11
+
12
+ children :location, :character
11
13
 
12
14
  def initialize &block
13
15
  super nil, context: nil, &block
@@ -16,15 +16,15 @@ describe Woyo::Attributes do
16
16
  attrs.all? { |a| a.is_a? Symbol }.should be_true
17
17
  end
18
18
 
19
- it 'names and values can be retrieved for instance' do
19
+ it 'hash of names and values can be retrieved for instance' do
20
20
  attrs = AttrTest.new.attributes
21
21
  attrs.should be_instance_of Hash
22
22
  end
23
23
 
24
- it 'can be written with =' do
24
+ it 'can be written via method with =' do
25
25
  attr_test = AttrTest.new
26
26
  AttrTest.attributes.each do |attr|
27
- eval "attr_test.#{attr} = '#{attr}'.upcase"
27
+ attr_test.send(attr, attr.to_s.upcase)
28
28
  end
29
29
  attr_test.attributes.count.should eq AttrTest.attributes.count
30
30
  attr_test.attributes.each do |name,value|
@@ -32,10 +32,10 @@ describe Woyo::Attributes do
32
32
  end
33
33
  end
34
34
 
35
- it 'can be written without =' do
35
+ it 'can be written via method without =' do
36
36
  attr_test = AttrTest.new
37
37
  AttrTest.attributes.each do |attr|
38
- eval "attr_test.#{attr} '#{attr}'.upcase"
38
+ attr_test.send(attr, attr.to_s.upcase)
39
39
  end
40
40
  attr_test.attributes.count.should eq AttrTest.attributes.count
41
41
  attr_test.attributes.each do |name,value|
@@ -43,10 +43,10 @@ describe Woyo::Attributes do
43
43
  end
44
44
  end
45
45
 
46
- it 'can be read' do
46
+ it 'can be read via method' do
47
47
  attr_test = AttrTest.new
48
48
  AttrTest.attributes.each do |attr|
49
- eval "attr_test.#{attr} '#{attr}'.upcase"
49
+ attr_test.send(attr, attr.to_s.upcase)
50
50
  end
51
51
  attr_test.attributes.count.should eq AttrTest.attributes.count
52
52
  attr_test.attributes.each do |name,value|
@@ -54,9 +54,94 @@ describe Woyo::Attributes do
54
54
  end
55
55
  end
56
56
 
57
- it 'accepts string or symbol key for retrieval'
57
+ it 'list can be added to' do
58
+ expect {
59
+ class AttrTest
60
+ attributes :attr4, :attr5, :attr6
61
+ end
62
+ }.to_not raise_error
63
+ AttrTest.attributes.count.should eq 6
64
+ attr_test = AttrTest.new
65
+ # populate attributes
66
+ AttrTest.attributes.each do |attr|
67
+ attr_test.send(attr, attr.to_s.upcase)
68
+ end
69
+ attr_test.attributes.count.should eq 6
70
+ end
71
+
72
+ it 'can have a default value' do
73
+ expect {
74
+ class AttrTest
75
+ attributes attr_with_array___default: [ 1, 2, 3 ]
76
+ attributes attr_with_hash____default: { a: 1, b: 2, c: 3 }
77
+ attributes attr_with_number__default: 12345
78
+ attributes attr_with_string__default: "abcde"
79
+ attributes attr_with_boolean_default: true
80
+ end
81
+ }.to_not raise_error
82
+ attr_test = AttrTest.new
83
+ attr_test.attr_with_array___default.should eq [ 1, 2, 3 ]
84
+ attr_test.attr_with_array___default = :array
85
+ attr_test.attr_with_array___default.should eq :array
86
+ attr_test.attr_with_hash____default.should eq ( { a: 1, b: 2, c: 3 } )
87
+ attr_test.attr_with_hash____default = :hash
88
+ attr_test.attr_with_hash____default.should eq :hash
89
+ attr_test.attr_with_number__default.should eq 12345
90
+ attr_test.attr_with_number__default = :number
91
+ attr_test.attr_with_number__default.should eq :number
92
+ attr_test.attr_with_string__default.should eq "abcde"
93
+ attr_test.attr_with_string__default = :string
94
+ attr_test.attr_with_string__default.should eq :string
95
+ attr_test.attr_with_boolean_default.should eq true
96
+ attr_test.attr_with_boolean_default = :boolean
97
+ attr_test.attr_with_boolean_default.should eq :boolean
98
+ end
99
+
100
+ it 'can have a default proc' do
101
+ expect {
102
+ class AttrTest
103
+ attributes attr_with_proc_default: proc { Time.now }
104
+ end
105
+ }.to_not raise_error
106
+ attr_test = AttrTest.new
107
+ attr_test.attr_with_proc_default.should be < Time.now
108
+ end
58
109
 
59
- it 'accepts string of symbol key for assignment'
110
+ it 'default proc runs in instance scope' do
111
+ expect {
112
+ class AttrTest
113
+ attributes attr_with_proc_default: proc { |this| this.my_method }
114
+ def my_method
115
+ "okay"
116
+ end
117
+ end
118
+ }.to_not raise_error
119
+ attr_test = AttrTest.new
120
+ attr_test.attr_with_proc_default.should eq "okay"
121
+ end
122
+
123
+ it 'can have a default lambda' do
124
+ expect {
125
+ class AttrTest
126
+ attributes attr_with_lambda_default: lambda { Time.now }
127
+ end
128
+ }.to_not raise_error
129
+ attr_test = AttrTest.new
130
+ attr_test.attr_with_lambda_default.should be < Time.now
131
+ end
132
+
133
+ it 'default lambda runs in instance scope' do
134
+ expect {
135
+ class AttrTest
136
+ attributes attr_with_lambda_default: lambda { |this| this.my_method }
137
+ def my_method
138
+ "okay"
139
+ end
140
+ end
141
+ }.to_not raise_error
142
+ attr_test = AttrTest.new
143
+ attr_test.attr_with_lambda_default.should eq "okay"
144
+ end
60
145
 
61
146
  end
62
147
 
@@ -3,6 +3,11 @@ require 'woyo/world/world'
3
3
  require 'woyo/world/location'
4
4
 
5
5
  describe Woyo::Character do
6
+
7
+ it 'has attributes' do
8
+ expected_attrs = [:name,:description]
9
+ Woyo::Character.attributes.sort.should eq expected_attrs.sort
10
+ end
6
11
 
7
12
  it 'accepts world for parameter context:' do
8
13
  wo = nil
@@ -5,7 +5,7 @@ describe Woyo::DSL do
5
5
  before :all do
6
6
  class DSLTest
7
7
  include Woyo::DSL
8
- contains :dog, :cat
8
+ children :dog, :cat
9
9
  end
10
10
  class Dog ; def initialize id, context: nil ; end ; end
11
11
  class Cat ; def initialize id, context: nil ; end ; end
@@ -28,21 +28,20 @@ describe Woyo::DSL do
28
28
  end
29
29
 
30
30
  it 'can list classes to contain' do
31
- DSLTest.contains.should eq [ :dog, :cat ]
31
+ DSLTest.children.should eq [ :dog, :cat ]
32
32
  end
33
33
 
34
34
  it 'can add classes to contain' do
35
- pending 'fix containment'
36
- class DSLTestMore < DSLTest
37
- contains :cow
38
- contains :duck
35
+ class DSLTest
36
+ children :cow
37
+ children :duck
39
38
  end
40
39
  # class Cow ; def initialize id, context: nil ; end ; end
41
40
  # class Duck ; def initialize id, context: nil ; end ; end
42
- DSLTestMore.contains.should eq [ :dog, :cat, :cow, :duck ]
41
+ DSLTest.children.should eq [ :dog, :cat, :cow, :duck ]
43
42
  end
44
43
 
45
- it 'can create contained objects' do
44
+ it 'can create child objects' do
46
45
  dsl = DSLTest.new
47
46
  dog = dsl.dog :brown
48
47
  dog.should be_instance_of Dog
@@ -50,7 +49,7 @@ describe Woyo::DSL do
50
49
  dsl.dogs[:brown].should be dog
51
50
  end
52
51
 
53
- it 'can list each contained object by class' do
52
+ it 'has hashes of each class of child objects' do
54
53
  dsl = DSLTest.new
55
54
  dog_brown = dsl.dog :brown
56
55
  dog_black = dsl.dog :black
@@ -60,20 +59,16 @@ describe Woyo::DSL do
60
59
  dsl.cats.should eq Hash[ white: cat_white, black: cat_black ]
61
60
  end
62
61
 
63
- it 'can list all contained objects' do
62
+ it 'hash a hash of all classes of child objects' do
64
63
  dsl = DSLTest.new
65
64
  dog_brown = dsl.dog :brown
66
65
  dog_black = dsl.dog :black
67
66
  cat_white = dsl.cat :white
68
67
  cat_black = dsl.cat :black
69
- dsl.contains.keys.should eq [ :dog, :cat ]
68
+ dsl.children.keys.should eq [ :dog, :cat ]
70
69
  cats = Hash[ white: cat_white, black: cat_black ]
71
70
  dogs = Hash[ brown: dog_brown, black: dog_black ]
72
- dsl.contains.should eq Hash[ dog: dogs, cat: cats ]
71
+ dsl.children.should eq Hash[ dog: dogs, cat: cats ]
73
72
  end
74
73
 
75
- it 'accepts string or symbol key for contained object retrieval'
76
-
77
- it 'accepts string of symbol key for contained object assignment'
78
-
79
74
  end
@@ -4,6 +4,16 @@ require 'woyo/world/way'
4
4
 
5
5
  describe Woyo::Location do
6
6
 
7
+ it 'has attributes' do
8
+ expected_attrs = [:name,:description]
9
+ Woyo::Location.attributes.sort.should eq expected_attrs.sort
10
+ end
11
+
12
+ it 'name attribute defaults to id' do
13
+ wo = Woyo::Location.new(:home)
14
+ wo.name.should eq 'Home'
15
+ end
16
+
7
17
  it 'accepts world for parameter context:' do
8
18
  wo = nil
9
19
  expect { wo = Woyo::Location.new(:my_id, context: Woyo::World.new) }.to_not raise_error
@@ -47,7 +47,5 @@ describe Woyo::WorldObject do
47
47
  wo.context.should eq :just_a_test
48
48
  end
49
49
 
50
- it 'name attribute defaults to id'
51
-
52
50
  end
53
51
 
@@ -2,6 +2,11 @@ require 'woyo/world/world'
2
2
 
3
3
  describe Woyo::World do
4
4
 
5
+ it 'has attributes :name, :description, :start' do
6
+ expected_attrs = [:name,:description,:start]
7
+ Woyo::World.attributes.sort.should eq expected_attrs.sort
8
+ end
9
+
5
10
  it 'initializes with no locations' do
6
11
  Woyo::World.new.locations.should be_empty
7
12
  end
@@ -10,120 +15,4 @@ describe Woyo::World do
10
15
  Woyo::World.new.characters.should be_empty
11
16
  end
12
17
 
13
- context '#location' do
14
-
15
- it 'creates new location' do
16
- world = Woyo::World.new
17
- home = world.location :home
18
- away = world.location :away
19
- world.locations.size.should eq 2
20
- world.locations[:home].should be home
21
- world.locations[:away].should be away
22
- end
23
-
24
- it 'adds existing location' do
25
- world = Woyo::World.new
26
- home = world.location Woyo::Location.new :home
27
- away = world.location Woyo::Location.new :away
28
- world.locations.size.should eq 2
29
- world.locations[:home].should be home
30
- world.locations[:away].should be away
31
- end
32
-
33
- it 'accepts a block with arity 0 for new location' do
34
- world = Woyo::World.new
35
- result = ''
36
- home = world.location( :home ) { result = 'ok' }
37
- home.should be_instance_of Woyo::Location
38
- result.should eq 'ok'
39
- end
40
-
41
- it 'accepts a block with arity 1 for new location' do
42
- world = Woyo::World.new
43
- result = ''
44
- home = world.location( :home ) { |loc| result = 'ok' }
45
- home.should be_instance_of Woyo::Location
46
- result.should eq 'ok'
47
- end
48
-
49
- it 'accepts a block with arity 0 for existing location' do
50
- world = Woyo::World.new
51
- home = world.location( :home ) { |loc| loc._test = 'ok' }
52
- home.should be_instance_of Woyo::Location
53
- result = ''
54
- other = world.location( :home ) { result = @_test }
55
- other.should be home
56
- result.should eq 'ok'
57
- end
58
-
59
- it 'accepts a block with arity 1 for existing location' do
60
- world = Woyo::World.new
61
- home = world.location( :home ) { @_test = 'ok' }
62
- home.should be_instance_of Woyo::Location
63
- result = ''
64
- other = world.location( :home ) { |loc| result = loc._test }
65
- other.should be home
66
- result.should eq 'ok'
67
- end
68
-
69
- end
70
-
71
- context '#character' do
72
-
73
- it 'creates new character' do
74
- world = Woyo::World.new
75
- home = world.character :batman
76
- away = world.character :robin
77
- world.characters.size.should eq 2
78
- world.characters[:batman].should be home
79
- world.characters[:robin].should be away
80
- end
81
-
82
- it 'adds existing character' do
83
- world = Woyo::World.new
84
- home = world.character Woyo::Character.new :batman
85
- away = world.character Woyo::Character.new :robin
86
- world.characters.size.should eq 2
87
- world.characters[:batman].should be home
88
- world.characters[:robin].should be away
89
- end
90
-
91
- it 'accepts a block with arity 0 for new character' do
92
- world = Woyo::World.new
93
- result = ''
94
- home = world.character( :batman ) { result = 'ok' }
95
- home.should be_instance_of Woyo::Character
96
- result.should eq 'ok'
97
- end
98
-
99
- it 'accepts a block with arity 1 for new character' do
100
- world = Woyo::World.new
101
- result = ''
102
- home = world.character( :batman ) { |char| result = 'ok' }
103
- home.should be_instance_of Woyo::Character
104
- result.should eq 'ok'
105
- end
106
-
107
- it 'accepts a block with arity 0 for existing character' do
108
- world = Woyo::World.new
109
- home = world.character( :batman ) { |char| char._test = 'ok' }
110
- home.should be_instance_of Woyo::Character
111
- result = ''
112
- other = world.character( :batman ) { result = @_test }
113
- other.should be home
114
- result.should eq 'ok'
115
- end
116
-
117
- it 'accepts a block with arity 1 for existing character' do
118
- world = Woyo::World.new
119
- home = world.character( :batman ) { @_test = 'ok' }
120
- home.should be_instance_of Woyo::Character
121
- result = ''
122
- other = world.character( :batman ) { |char| result = char._test }
123
- other.should be home
124
- result.should eq 'ok'
125
- end
126
-
127
- end
128
-
129
18
  end
data/todo.txt CHANGED
@@ -1,119 +1,234 @@
1
1
 
2
2
 
3
- Woyo::World is a singleton
3
+ world object features...
4
4
 
5
- DSL:
5
+ # world
6
6
 
7
- world do
7
+ location to start in...
8
+
9
+ start :location
10
+
11
+ # attributes
12
+
13
+ single...
14
+
15
+ attribute :color
16
+
17
+ multiple...
18
+
19
+ attributes :size, :shape, :color
20
+
21
+ boolean opposites / mutually exclusive...
22
+ first one will be true
8
23
 
9
- # some states may be mutually exclusive
10
- # setting one will undo others
11
- states do
12
- exclusive :dark, :dim, :light, :bright
13
- exclusive :cold, :cool, :warm, :hot
14
- end
24
+ attributes_exclusive :open, :closed
25
+ attributes_exclusive :light, :dark
26
+ attributes_exclusive :dark, :dim, :light, :bright
27
+ attributes_exclusive :cold, :cool, :warm, :hot
15
28
 
16
- # locations are places a player can be
29
+ set attribute values via method style...
17
30
 
18
- location :name do
19
- # name is a symbol
31
+ color 'Blue'
32
+ size 10
33
+ open true
20
34
 
21
- # default title is name.to_s.capitalize
22
- title "...."
35
+ set attribute values via assignment style...
23
36
 
24
- # default description
25
- description "........."
37
+ color = 'Blue'
38
+ size = 10
39
+ open = true
26
40
 
27
- description do
28
- # may depend on verbose game setting
29
- long "........."
30
- short "...."
31
- # may depend on location state ?
32
- is :bright, "........."
33
- is :cold, "........."
34
- end
41
+ defaults via hash instead of just symbol
42
+ # name
43
+ # if not specified default to id.to_s.capitalize ?
44
+
45
+ attribute color: :blue
46
+ attribute size: 10
47
+ attribute name: proc { id.to_s.capitalize }
35
48
 
36
- # concise hash / named parameters ?
37
- description long: "...................", short: "...."
49
+ set boolean attribute values... ?
38
50
 
39
- # locations do NOT contain locations
40
- # locations are a graph, linked by ways
41
- # ways lead to/from other locations
42
- # standard ways map to directions and movements
43
- # north,south,east,west,up,down,forward,back,left,right
51
+ is :open
52
+ is :dark
53
+ is :warm, :bright
44
54
 
45
- way north:, "location name"
46
- ways do
47
- east :far_east
48
- west :wild_west
49
- up :sky
50
- down :pit
51
- end
55
+ test boolean attribute values... ?
52
56
 
53
- # 'is' a set of multiple states
54
- # default: nil
57
+ if is? :cold
58
+ if is_cold?
59
+ if cold
55
60
 
56
- # symbols or strings
57
- is :cold, :dark
58
- is "bright", "hot"
61
+ # descriptions
62
+
63
+ displayed everytime a location is visited...
59
64
 
60
- # in code: is? :cold / is_cold? like rspec ?
61
- # here == self ?
65
+ description 'string'
62
66
 
63
- end
67
+ full description (short + long) displayed first visit
68
+ short description displayed on subsequent visit + ellipses to expand long description on demand
64
69
 
65
- # items are things that may be in a location
70
+ description short: "...", long: "..."
66
71
 
67
- item "name" do
68
-
69
- # short description used when seen
70
- description "....."
72
+ may depend on location state ?
73
+
74
+ description bright: '...', cold: '...'
75
+ # is :bright, "........."
76
+ # is :cold, "........."
71
77
 
72
- # longer description when examined
73
- detail "....."
78
+ # openable
74
79
 
75
- # have aspects
76
- aspect :small, :light
80
+ open
77
81
 
78
- # may be at a location
79
- location "location name"
82
+ default is open
83
+ way: player can go
84
+ container: player can see inside
80
85
 
81
- # this == self ?
86
+ closed (!open)
82
87
 
83
- end
88
+ specify with 'closed' or 'open false / open no'
89
+ way: player cannot go
90
+ way: is closed without 'to' (wrong-way)
91
+ container: player cannot see inside
92
+
93
+ condition
94
+
95
+ must be true to open
96
+ a proc/lambda
97
+ 'locked' is just closed that has a key condition for opening
98
+ action tests condition to try to open
99
+ response for condition state/progress
84
100
 
85
- # concise hash
101
+ # visiblty
86
102
 
87
- item "name", description: "...", detail: "...", aspect: [ :small, :light ]
103
+ visible
88
104
 
89
- # items can relate to other items ?....
90
- # contains / contained
91
- # before / behind
92
- # on / under
93
- # above / below
94
- # near / far
95
- # module for this 'Relation' feature ?
105
+ default is visible
106
+ description will be displayed
96
107
 
108
+ invisible (!visible)
109
+
110
+ specify with 'invisible' or 'visible false / visible no'
111
+ description will not be displayed
112
+ items will not be counted, etc..
113
+
114
+ # location
115
+
116
+ locations do NOT contain locations
117
+ locations are a graph, linked by ways
118
+
119
+ location :here do
120
+ name 'Home'
121
+ description 'Cosy'
97
122
  end
98
123
 
99
- # code can be instance(?) eval'd when defining world, location, items
100
- # code for ... triggers, events, handlers, conditions, etc...
124
+ location :here, name: 'Home', description: 'cosy'
101
125
 
102
- # can locations, items be subclassed ?
103
- # then defined in DSL ?
126
+ mass assignment...
104
127
 
105
- item :vase do
106
- description "a vase"
107
- aspect :small, :light
128
+ locations do
129
+ home name: 'Home', description: 'Cosy'
130
+ yard name: 'Garden', description: 'Green'
131
+ cellar name: 'Basement', description: 'Damp'
108
132
  end
109
-
110
- vase :blue_vase do
111
- aspect :blue
133
+
134
+ # way
135
+
136
+ a way leads one-way to a location
137
+
138
+ way :out do
139
+ name 'Door'
140
+ description 'Big strong'
141
+ to :garden
112
142
  end
113
143
 
114
- vase :red_vase do
115
- aspect :red
144
+ way :door, to: :other_location, description: 'Big'
145
+
146
+ is openable, default open
147
+
148
+ mass assignment...
149
+
150
+ ways do
151
+ east to: :china, name: 'slow boat'
152
+ west to: :wild_west, name: 'fast horse'
153
+ up to: :sky, name: 'balloon'
154
+ down to: :pit, name: 'hole'
116
155
  end
117
156
 
118
- # is this more like prototyping than subclassing ?
157
+ standard ways map to directions and movements ?
158
+ - north,south,east,west,up,down,forward,back,left,right
159
+
160
+ # items
161
+
162
+ items may be in a location
163
+
164
+ item :id do
165
+ name 'Thing'
166
+ description 'Useful object'
167
+ end
168
+
169
+ item :id, name: 'Thing', description: "...", detail: "..."
170
+
171
+ mass assignment...
172
+
173
+ items do
174
+ thing name: 'Thing', description: "..."
175
+ gadget name: 'Device', description: "..."
176
+ key name: 'Gold key'
177
+ end
178
+
179
+ may be examined ?
180
+
181
+ longer description when examined
182
+ detail "....."
183
+
184
+ have attributes
185
+
186
+ attributes :small, :light
187
+
188
+ may know their location ?
189
+
190
+ if item.location == :home
191
+
192
+ may know their relation to other items ?
193
+
194
+ if item.contains? :water
195
+ if item.near? :monster
196
+ if item.on? :desk
197
+ if item.in? :box
198
+
199
+ # items can relate to other items ?....
200
+ # contains / contained
201
+ # before / behind
202
+ # on / under
203
+ # above / below
204
+ # near / far
205
+ # module for this 'Relation' feature ?
206
+
207
+ end
208
+
209
+ # code for ... triggers, events, handlers, conditions, etc...
210
+
211
+ # can locations, items be subclassed in DSL ?
212
+
213
+ class Vase < Item
214
+ attributes :small
215
+ end
216
+
217
+ vase :default do
218
+ name 'Vase'
219
+ attributes
220
+ item :vase do
221
+ description "a vase"
222
+ aspect :small, :light
223
+ end
224
+
225
+ vase :blue_vase do
226
+ aspect :blue
227
+ end
228
+
229
+ vase :red_vase do
230
+ aspect :red
231
+ end
232
+
233
+ # is this more like prototyping than subclassing ?
119
234
 
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.1
4
+ version: 0.0.2
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-01 00:00:00.000000000 Z
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,7 +85,7 @@ files:
85
85
  - spec/woyo/world/world_spec.rb
86
86
  - tmux
87
87
  - todo.txt
88
- - woyo-dsl.gemspec
88
+ - woyo-world.gemspec
89
89
  homepage: ''
90
90
  licenses:
91
91
  - GPLv3
File without changes