Changeset 235

Show
Ignore:
Timestamp:
06/18/05 08:45:51 (3 years ago)
Author:
ged
Message:
  • Closes #7, #13, #14, #15, and #16.
  • Fixed docs for AnimatedObject#name?
  • Fixed bug in ComposedObject::createConstituentMethods: setters for statistic aspects were being defined incorrectly.
  • Moved call to #removeContainer to occur before they are actually removed.
  • Made ArgCheckFunctions? and Loggable mixins apply to the class as well as instances.
  • Undid the Spirit-suclassing-from-ComposedObject? thing, as it was logically flawed despite being somewhat programmatically desirable. Added code-generation for the pseudo-statistics.
  • Extended the test suite a bit.
  • Removed some more SVNUrl constants.
Location:
trunk
Files:
13 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/fm/animatedobject.rb

    r212 r235  
    3535    # SVN Id 
    3636    SVNId = %q$Id$ 
    37  
    38     # SVN URL 
    39     SVNURL = %q$URL$ 
    4037 
    4138 
     
    8077    attr_accessor :description 
    8178 
    82     # A one-word unique name for the object; used as the name associated 
    83     # with the FaerieMUD::Role which encapsulates this object when offering 
    84     # roles to connecting users. 
     79    # A one-word unique name for the object, used when identifying it for 
     80    # animation. 
    8581    attr_accessor :name 
    8682 
     
    9086 
    9187 
     88     
     89 
    9290end # class FaerieMUD::AnimatedObject 
    9391 
  • trunk/lib/fm/area.rb

    r198 r235  
    3838    SVNId = %q$Id$ 
    3939 
    40     # SVN URL 
    41     SVNURL = %q$URL$ 
    4240 
    4341 
  • trunk/lib/fm/composedobject.rb

    r232 r235  
    338338            } 
    339339            define_method( develAspectEq ) {|arg| 
    340                 self.send(name).statistic.send( develAspectEq, arg ) 
     340                self.send(name).statistic.developmental = arg 
    341341            } 
    342342            define_method( linearAspect ) { 
     
    344344            } 
    345345            define_method( linearAspectEq ) {|arg| 
    346                 self.send(name).statistic.send( linearAspectEq, arg ) 
     346                self.send(name).statistic.linear = arg 
    347347            } 
    348348        } 
  • trunk/lib/fm/developmentalobject.rb

    r212 r235  
    3636    # SVN Id 
    3737    SVNId = %q$Id$ 
    38  
    39     # SVN URL 
    40     SVNURL = %q$URL$ 
    4138 
    4239 
  • trunk/lib/fm/locus.rb

    r216 r235  
    193193            # list with the current contents; then remove 'em. 
    194194            removedObjects = @contents & expanded 
     195            removedObjects.each {|obj| obj.removeContainer(self) } 
    195196            @mutex.synchronize( Sync::EX ) { @contents -= removedObjects } 
    196             removedObjects.each {|obj| obj.removeContainer(self) } 
    197197        } 
    198198 
  • trunk/lib/fm/logger.rb

    r172 r235  
    5959    SVNId = %q$Id$ 
    6060 
    61     # SVN URL 
    62     SVNURL = %q$URL$ 
    6361 
    6462    # Construct a log levels Hash on the fly 
  • trunk/lib/fm/mixins.rb

    r227 r235  
    6161    ### Mixin that adds some type-checking functions to the current scope 
    6262    module ArgCheckFunctions 
     63 
     64        ### The Ouroboros Trick 
     65        def self::included( klass ) 
     66            super 
     67            klass.extend( self ) 
     68        end 
     69 
    6370 
    6471        ############### 
     
    232239        require 'fm/logger' 
    233240 
     241        ### The Ouroboros Trick 
     242        def self::included( klass ) 
     243            super 
     244            klass.extend( self ) 
     245        end 
     246 
     247 
    234248        ######### 
    235249        protected 
     
    237251 
    238252        ### Return the Arrow::Logger object for the receiving class. 
    239         def log  
    240             FaerieMUD::Logger[ self.class.name ] || 
    241                 FaerieMUD::Logger::new( self.class.name ) 
     253        def log 
     254            if self.is_a?( Class ) 
     255                FaerieMUD::Logger[ self ] || 
     256                    FaerieMUD::Logger::new( self ) 
     257            else 
     258                FaerieMUD::Logger[ self.class.name ] || 
     259                    FaerieMUD::Logger::new( self.class.name ) 
     260            end 
    242261        end 
    243262 
  • trunk/lib/fm/properties/fuzzy.rb

    r229 r235  
    5353    ### in subclasses. 
    5454    def self::inherited( subclass ) 
    55         FaerieMUD::Logger[self].debug "Adding descriptionPair ivar to %p" % [subclass] 
     55        self.log.debug "Adding descriptionPair ivar to %p" % [subclass] 
    5656        subclass.module_eval { 
    5757            @descriptionPair = PairStruct::new() 
  • trunk/lib/fm/spirit.rb

    r219 r235  
    3232### FaerieMUD::Character objects or other instances of FaerieMUD::AnimatedObject 
    3333### in the world. 
    34 class FaerieMUD::Spirit < FaerieMUD::ComposedObject 
    35     include FaerieMUD::AccessorFunctions 
     34class FaerieMUD::Spirit < FaerieMUD::Entity 
     35    include FaerieMUD::AccessorFunctions, 
     36        FaerieMUD::ArgCheckFunctions 
    3637    contributors :ged 
    3738 
     
    4243    SVNId = %q$Id$ 
    4344 
    44     # SVN URL 
    45     SVNURL = %q$URL$ 
    4645 
    4746 
     
    7776 
    7877 
     78    ### Define accessor methods for the given aspect. 
     79    def self::def_aspect_methods( *aspects ) 
     80        aspects.each do |aspect| 
     81            aspectClass = const_get( "#{aspect.to_s.capitalize}Aspect" ) or 
     82                raise FaerieMUD::ConstituentError, 
     83                "Cannot define aspect methods for non-existent aspect '#{aspect}'" 
     84 
     85            # The aspect itself 
     86            define_method( aspect ) { @aspects[aspect] } 
     87            define_method( "#{aspect}=" ) {|arg| 
     88                checkType( arg, aspectClass ) 
     89                @aspects[aspect] = arg 
     90            } 
     91 
     92            # Statistic accessors 
     93            develAspect, linearAspect = aspectClass.statisticNames 
     94            develAspectEq = "#{develAspect}=".intern 
     95            linearAspectEq = "#{linearAspect}=".intern 
     96 
     97            self.log.debug "Defining statistic accessors: %s/%s" % 
     98                [ develAspect, linearAspect ] 
     99 
     100            define_method( develAspect ) { 
     101                self.send(aspect).statistic.developmental 
     102            } 
     103            define_method( develAspectEq ) {|arg| 
     104                self.send(aspect).statistic.developmental = arg 
     105            } 
     106            define_method( linearAspect ) { 
     107                self.send(aspect).statistic.linear 
     108            } 
     109            define_method( linearAspectEq ) {|arg| 
     110                self.send(aspect).statistic.linear = arg 
     111            } 
     112        end 
     113    end 
     114     
    79115 
    80116    ################################################################# 
     
    92128        } 
    93129 
     130        @aspects = { 
     131            :physical => PhysicalAspect::new, 
     132            :mental => MentalAspect::new, 
     133            :creative => CreativeAspect::new, 
     134        } 
     135 
    94136        super 
    95137    end 
     
    106148    attr_locked_reader :animatedObjects 
    107149 
    108     # The Spirit's immortal statistics hash, keyed by the name of the 
    109     # corresponding sphere (ie., <tt>:physical</tt>, <tt>:mental</tt>, and 
    110     # <tt>:creative</tt>). 
    111     attr_typelocked_accessor :statistics, Hash 
    112  
    113150    # IO Callbacks 
    114151    attr_reader :ioHandlers 
    115152 
     153    # Pseudo-ComposedObject accessors 
     154    def_aspect_methods :physical, :mental, :creative 
    116155 
    117156     
     
    127166        @ioHandlers[:input] = handler 
    128167    end 
    129  
    130  
    131     ################################################################# 
    132     ### C O M P O S E D O B J E C T   I N T E R F A C E 
    133     ################################################################# 
    134  
    135     # Set up the classes for the three constituents of a trinary 
    136     # ComposedObject 
    137     def_constituents :physicalAspect => PhysicalAspect, 
    138         :mentalAspect => MentalAspect, 
    139         :creativeAspect => CreativeAspect 
    140  
    141168 
    142169 
     
    155182    ### Remove the specified +object+ (FaerieMUD::AnimatedObject) from the 
    156183    ### list being controlled by the Spirit. 
    157     def unanimate( object ) 
     184    def deanimate( object ) 
    158185        self.writelocked do 
    159186            object.controller = nil 
     
    161188        end 
    162189    end 
     190    alias_method :unanimate, :deanimate 
    163191 
    164192     
  • trunk/lib/fm/statistic.rb

    r212 r235  
    5959    SVNId = %q$Id$ 
    6060 
    61     # SVN URL 
    62     SVNURL = %q$URL$ 
    63  
    6461 
    6562    # The maximum value a statistic can have (derived from 
     
    10198 
    10299    # The developmental part of the statistic (FaerieMUD::DevelopmentalObject) 
    103     attr_locked_reader :developmental 
     100    attr_typelocked_accessor :developmental, FaerieMUD::DevelopmentalObject 
    104101 
    105102    # The name of the linear part of the statistic 
  • trunk/tests/animatedobject.tests.rb

    r212 r235  
    44# $Id$ 
    55# 
    6 # Copyright (c) 2003, 2004 The FaerieMUD Consortium. 
     6# Copyright (c) 2003-2005 The FaerieMUD Consortium. 
    77#  
    88 
     
    6565    ################################################################# 
    6666 
    67     ### Instance test 
    68     def test_00_Instance 
    69         # Make sure the class is defined. 
     67    ### Class should exist 
     68    def test_00_ClassShouldExist 
     69        printTestHeader "AnimatedObject: Class" 
     70        assert defined?( FaerieMUD::AnimatedObject ) 
    7071        assert_instance_of Class, FaerieMUD::AnimatedObject 
    7172    end 
    7273 
    7374 
    74     ### Derivative test 
    75     def test_01_Derivative 
     75    ### Subclassing test 
     76    def test_10_SubclassingShouldWork 
     77        printTestHeader "AnimatedObject: Subclassing should work" 
    7678        rval, derivClass, derivObject = nil, nil, nil 
    7779 
     
    108110 
    109111        # Set up a testing instance for further tests. 
    110         self.class.addSetupBlock { 
     112        addSetupBlock { 
    111113            constituentClasses = @constituentClasses 
    112114            @derivClass = Class::new( FaerieMUD::AnimatedObject ){ 
     
    121123                :controller => TestController ) 
    122124        } 
    123         self.class.addTeardownBlock { 
     125        addTeardownBlock { 
    124126            @derivObject = nil 
    125127            @derivClass = nil 
     
    128130 
    129131    ### Test duplication 
    130     def test_05_Duplication 
     132    def test_20_Clone 
     133        printTestHeader "AnimatedObject: Cloning should clone the object's attributes" 
    131134        rval = nil 
    132135 
     
    143146    end 
    144147 
    145  
    146148     
    147      
     149    ### Instances should have an affinities hash 
     150    def test_30_InstancesShouldHaveAffinities 
     151        printTestHeader "AnimatedObject: Instances should have an affinities Hash" 
     152        rval = nil 
     153 
     154        # Getter 
     155        assert_nothing_raised do 
     156            rval = @derivObject.affinities 
     157        end 
     158        assert_instance_of Hash, rval 
     159        assert_equal 0, rval.length 
     160 
     161        # Setter 
     162        newHash = { Object::new => 12 } 
     163        assert_nothing_raised do 
     164            @derivObject.affinities = newHash 
     165        end 
     166        assert_same newHash, @derivObject.affinities 
     167    end 
     168 
     169 
     170    ### Instances should have a description 
     171    def test_40_InstancesShouldHaveADescription 
     172        printTestHeader "AnimatedObject: Instances should have a description" 
     173        rval = nil 
     174         
     175        # Getter 
     176        assert_nothing_raised do 
     177            rval = @derivObject.description 
     178        end 
     179        # (Description from derivClass above) 
     180        assert_instance_of String, rval 
     181        assert_equal "a testing object", rval 
     182         
     183        # Setter 
     184        newDesc = "The Black Legion" 
     185        assert_nothing_raised do 
     186            @derivObject.description = newDesc 
     187        end 
     188        assert_same newDesc, @derivObject.description 
     189    end 
     190 
     191 
     192    ### Instances should have a name 
     193    def test_40_InstancesShouldHaveAName 
     194        printTestHeader "AnimatedObject: Instances should have a name" 
     195        rval = nil 
     196         
     197        # Getter 
     198        assert_nothing_raised do 
     199            rval = @derivObject.name 
     200        end 
     201        # (Name from derivClass above) 
     202        assert_instance_of String, rval 
     203        assert_equal "testobj", rval 
     204         
     205        # Setter 
     206        newName = "Black Legion" 
     207        assert_nothing_raised do 
     208            @derivObject.name = newName 
     209        end 
     210        assert_same newName, @derivObject.name 
     211    end 
     212 
     213 
    148214end 
    149215 
  • trunk/tests/composedobject.tests.rb

    r232 r235  
    494494            "trait modifiers hashes disparate?" 
    495495    end 
    496      
     496 
     497 
     498    ### Test statistic readers 
     499    def test_70_StatisticAccessors 
     500        printTestHeader "ComposedObject: Statistic readers" 
     501        rval = nil 
     502 
     503        # Test the developmental and linear parts of all three aspects 
     504        3.times do |i| 
     505 
     506            # Get developmental 
     507            assert_nothing_raised do 
     508                rval = @derivObject.send( "devel_aspect#{i}" ) 
     509            end 
     510            assert_instance_of FaerieMUD::DevelopmentalObject, rval 
     511            assert_equal 1, rval.to_i 
     512 
     513            # Set developmental 
     514            assert_nothing_raised do 
     515                newVal = rval + 5 
     516                @derivObject.send( "devel_aspect#{i}=", newVal ) 
     517            end 
     518            rval = @derivObject.send( "devel_aspect#{i}" ) 
     519            assert_instance_of FaerieMUD::DevelopmentalObject, rval 
     520            assert_equal 6, rval.to_i 
     521 
     522            # Get linear (should be the same as the new developmental value) 
     523            assert_nothing_raised do 
     524                rval = @derivObject.send( "linear_aspect#{i}" ) 
     525            end 
     526            assert_instance_of Fixnum, rval 
     527            assert_equal 6, rval 
     528 
     529            # Set linear 
     530 
     531            # Setting to something higher than the developmental value should 
     532            # not raise it. 
     533            assert_nothing_raised do 
     534                @derivObject.send( "linear_aspect#{i}=", 12 ) 
     535            end 
     536            rval = @derivObject.send( "linear_aspect#{i}" ) 
     537            assert_instance_of Fixnum, rval 
     538            assert_equal 6, rval.to_i 
     539        end 
     540 
     541 
     542    end 
    497543 
    498544end 
  • trunk/tests/spirit.tests.rb

    r212 r235  
    7979        # Aspect accessors (ComposedObject::Constituents) 
    8080        %w{physical mental creative}.each do |atype| 
    81             meth = "#{atype}Aspect" 
     81            meth = atype 
    8282            assert_respond_to @testSpirit, meth 
    8383            assert_nothing_raised { rval = @testSpirit.send(meth) }