Changeset 217

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

- Added interface for CommandParser to get wordset for its collection of Verbs.
- Renamed #happen to #invoke

Location:
branches/simplest-thing
Files:
2 modified

Legend:

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

    r198 r217  
    3939    SVNId = %q$Id$ 
    4040 
    41     # SVN URL 
    42     SVNURL = %q$URL$ 
     41 
     42    ### Generate a default set of words for a verb which doesn't explicitly 
     43    ### provide them. 
     44    def self::generateWords 
     45        word = self.name. 
     46            sub( /^.*::/, ''). 
     47            sub( /(\w+)Verb/, "\\1" ). 
     48            downcase 
     49        return [word] 
     50    end 
    4351 
    4452 
     
    4755    ################################################################# 
    4856 
     57    ### Set up the verb's internal structure 
     58    def initialize # :notnew: 
     59        super 
     60        @words = self.class.generateWords() 
     61    end 
     62 
     63 
     64    ###### 
     65    public 
     66    ###### 
     67 
     68    ### CommandParser interface: query the verb for the word/s which cause it to 
     69    ### be invoked. By default this returns the name of the verb class with the 
     70    ### 'verb' part removed. 
     71    attr_reader :words 
     72 
     73 
    4974    ### Event interface: "run" the verb, generating the event/s necessary to 
    5075    ### express the action in the game world. The given +instigator+, +origin+, 
    5176    ### and +target+ will be used when building event/s. See 
    5277    ### FaerieMUD::Event::new for definitions 
    53     def happen( instigator, origin, target=nil ) 
     78    def invoke( instigator, origin, target=nil ) 
    5479        raise NotImplementedError, 
    55             "Required method #happen not implemented in %s" % 
     80            "Required method #invoke not implemented in %s" % 
    5681            [self.class.name] 
    5782    end 
  • branches/simplest-thing/tests/verb.tests.rb

    r191 r217  
    44# $Id$ 
    55# 
    6 # Copyright (c) 2004 The FaerieMUD Consortium. 
     6# Copyright (c) 2004, 2005 The FaerieMUD Consortium. 
    77#  
    88 
     
    2626    class TestInstigator < FaerieMUD::GameObject; end 
    2727    class TestOrigin < FaerieMUD::Locus; end 
     28 
     29    class TestVerb < FaerieMUD::Verb 
     30         
     31    end 
     32 
    2833 
    2934    def setup 
     
    5661 
    5762    ### Event-generation interface 
    58     def test_50_happen 
    59         printTestHeader "FaerieMUD::Verb: Event-generation interface" 
     63    def test_50_invoke 
     64        printTestHeader "FaerieMUD::Verb: Event-generation interface: invoke" 
    6065        rval = nil 
    6166 
     
    6570 
    6671        # Should require an instigator and an origin 
    67         assert_raises( ArgumentError ) { derivObj.happen } 
    68         assert_raises( ArgumentError ) { derivObj.happen(@instigator) } 
     72        assert_raises( ArgumentError ) { derivObj.invoke } 
     73        assert_raises( ArgumentError ) { derivObj.invoke(@instigator) } 
    6974 
    70         # Derivative classes should override #happen 
     75        # Derivative classes should override #invoke 
    7176        assert_raises( NotImplementedError ) { 
    72             derivObj.happen( @instigator, @origin ) 
     77            derivObj.invoke( @instigator, @origin ) 
    7378        } 
    7479    end 
     80 
     81 
     82    ### CommandParser interface 
     83    def test_60_words 
     84        printTestHeader "FaerieMUD::Verb: CommandParser interface: words" 
     85        rval = nil 
     86        verb = TestVerb::instance 
     87 
     88        assert_nothing_raised do 
     89            rval = verb.words 
     90        end 
     91 
     92        assert_instance_of Array, rval 
     93        assert_equal 1, rval.length 
     94        assert_equal 'test', rval.first 
     95    end 
     96 
     97 
    7598end 
    7699