Changeset 219

Show
Ignore:
Timestamp:
06/08/05 06:26:58 (3 years ago)
Author:
ged
Message:

- Futher work on the input/output code. Committing for merge with trunk, so no

tests yet.

Location:
branches/simplest-thing/lib/fm
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/simplest-thing/lib/fm/commandparser.rb

    r212 r219  
    5353 
    5454    # The hash of verbs used by the parser 
    55     attr_locked_reader :verbset 
     55    attr_reader :verbset 
    5656 
    5757 
     
    5959    def updateVerbSet( *verbs ) 
    6060 
     61        @verbset.clear 
     62 
    6163        # Extract the words from each verb and add them to the table after 
    6264        # checking for collisions. 
    6365        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| 
    7267 
    7368                # Collision-check 
     
    8580 
    8681 
    87  
    8882end # class FaerieMUD::CommandParser 
    8983 
  • branches/simplest-thing/lib/fm/spirit.rb

    r212 r219  
    8787        @parser = FaerieMUD::CommandParser::new 
    8888 
     89        @ioHandlers = { 
     90            :input      => nil, 
     91            :output     => nil, 
     92        } 
     93 
    8994        super 
    9095    end 
     
    106111    attr_typelocked_accessor :statistics, Hash 
    107112 
     113    # IO Callbacks 
     114    attr_reader :ioHandlers 
     115 
     116 
    108117     
     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 
    109131    ################################################################# 
    110132    ### C O M P O S E D O B J E C T   I N T E R F A C E 
     
    125147            object.controller = self 
    126148            @animatedObjects += [ object ] 
    127             @parser.updateVerbSet( @animatedObjects ) 
    128149        end 
     150 
     151        self.updateParser 
    129152    end 
    130153 
     
    136159            object.controller = nil 
    137160            @animatedObjects -= [ object ] 
    138             @parser.updateVerbSet( @animatedObjects ) 
    139161        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 ) 
    140170    end 
    141171