Changeset 219
- Timestamp:
- 06/08/05 06:26:58 (3 years ago)
- Location:
- branches/simplest-thing/lib/fm
- Files:
-
- 2 modified
-
commandparser.rb (modified) (3 diffs)
-
spirit.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simplest-thing/lib/fm/commandparser.rb
r212 r219 53 53 54 54 # The hash of verbs used by the parser 55 attr_ locked_reader :verbset55 attr_reader :verbset 56 56 57 57 … … 59 59 def updateVerbSet( *verbs ) 60 60 61 @verbset.clear 62 61 63 # Extract the words from each verb and add them to the table after 62 64 # checking for collisions. 63 65 verbs.each do |verb| 64 verb.words.each do |word| 65 66 # If the word's already registered for this verb, skip to the 67 # next 68 if @verbset[ word ].eql?( verb ) 69 self.log.debug " %p already registered" % [word] 70 next 71 end 66 verb.words.uniq.each do |word| 72 67 73 68 # Collision-check … … 85 80 86 81 87 88 82 end # class FaerieMUD::CommandParser 89 83 -
branches/simplest-thing/lib/fm/spirit.rb
r212 r219 87 87 @parser = FaerieMUD::CommandParser::new 88 88 89 @ioHandlers = { 90 :input => nil, 91 :output => nil, 92 } 93 89 94 super 90 95 end … … 106 111 attr_typelocked_accessor :statistics, Hash 107 112 113 # IO Callbacks 114 attr_reader :ioHandlers 115 116 108 117 118 ### Provide a +handler+ for output events. 119 def onOutput( &handler ) 120 @ioHandlers[:output] = handler 121 end 122 123 124 ### Provide a +callback+ which will be called when the spirit is ready for 125 ### input. 126 def onInputReady( &handler ) 127 @ioHandlers[:input] = handler 128 end 129 130 109 131 ################################################################# 110 132 ### C O M P O S E D O B J E C T I N T E R F A C E … … 125 147 object.controller = self 126 148 @animatedObjects += [ object ] 127 @parser.updateVerbSet( @animatedObjects )128 149 end 150 151 self.updateParser 129 152 end 130 153 … … 136 159 object.controller = nil 137 160 @animatedObjects -= [ object ] 138 @parser.updateVerbSet( @animatedObjects )139 161 end 162 end 163 164 165 ### Synchronize the parser's verbset with the set of verbs from the 166 ### currently-animated objects. 167 def updateParser 168 verbs = @animatedObjects.collect {|aobj| aobj.verbs}.flatten 169 @parser.updateVerbSet( *verbs ) 140 170 end 141 171
