Changeset 235
- Timestamp:
- 06/18/05 08:45:51 (3 years ago)
- Location:
- trunk
- Files:
-
- 13 modified
-
lib/fm/animatedobject.rb (modified) (3 diffs)
-
lib/fm/area.rb (modified) (1 diff)
-
lib/fm/composedobject.rb (modified) (2 diffs)
-
lib/fm/developmentalobject.rb (modified) (1 diff)
-
lib/fm/locus.rb (modified) (1 diff)
-
lib/fm/logger.rb (modified) (1 diff)
-
lib/fm/mixins.rb (modified) (3 diffs)
-
lib/fm/properties/fuzzy.rb (modified) (1 diff)
-
lib/fm/spirit.rb (modified) (8 diffs)
-
lib/fm/statistic.rb (modified) (2 diffs)
-
tests/animatedobject.tests.rb (modified) (6 diffs)
-
tests/composedobject.tests.rb (modified) (1 diff)
-
tests/spirit.tests.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/fm/animatedobject.rb
r212 r235 35 35 # SVN Id 36 36 SVNId = %q$Id$ 37 38 # SVN URL39 SVNURL = %q$URL$40 37 41 38 … … 80 77 attr_accessor :description 81 78 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. 85 81 attr_accessor :name 86 82 … … 90 86 91 87 88 89 92 90 end # class FaerieMUD::AnimatedObject 93 91 -
trunk/lib/fm/area.rb
r198 r235 38 38 SVNId = %q$Id$ 39 39 40 # SVN URL41 SVNURL = %q$URL$42 40 43 41 -
trunk/lib/fm/composedobject.rb
r232 r235 338 338 } 339 339 define_method( develAspectEq ) {|arg| 340 self.send(name).statistic. send( develAspectEq, arg )340 self.send(name).statistic.developmental = arg 341 341 } 342 342 define_method( linearAspect ) { … … 344 344 } 345 345 define_method( linearAspectEq ) {|arg| 346 self.send(name).statistic. send( linearAspectEq, arg )346 self.send(name).statistic.linear = arg 347 347 } 348 348 } -
trunk/lib/fm/developmentalobject.rb
r212 r235 36 36 # SVN Id 37 37 SVNId = %q$Id$ 38 39 # SVN URL40 SVNURL = %q$URL$41 38 42 39 -
trunk/lib/fm/locus.rb
r216 r235 193 193 # list with the current contents; then remove 'em. 194 194 removedObjects = @contents & expanded 195 removedObjects.each {|obj| obj.removeContainer(self) } 195 196 @mutex.synchronize( Sync::EX ) { @contents -= removedObjects } 196 removedObjects.each {|obj| obj.removeContainer(self) }197 197 } 198 198 -
trunk/lib/fm/logger.rb
r172 r235 59 59 SVNId = %q$Id$ 60 60 61 # SVN URL62 SVNURL = %q$URL$63 61 64 62 # Construct a log levels Hash on the fly -
trunk/lib/fm/mixins.rb
r227 r235 61 61 ### Mixin that adds some type-checking functions to the current scope 62 62 module ArgCheckFunctions 63 64 ### The Ouroboros Trick 65 def self::included( klass ) 66 super 67 klass.extend( self ) 68 end 69 63 70 64 71 ############### … … 232 239 require 'fm/logger' 233 240 241 ### The Ouroboros Trick 242 def self::included( klass ) 243 super 244 klass.extend( self ) 245 end 246 247 234 248 ######### 235 249 protected … … 237 251 238 252 ### 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 242 261 end 243 262 -
trunk/lib/fm/properties/fuzzy.rb
r229 r235 53 53 ### in subclasses. 54 54 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] 56 56 subclass.module_eval { 57 57 @descriptionPair = PairStruct::new() -
trunk/lib/fm/spirit.rb
r219 r235 32 32 ### FaerieMUD::Character objects or other instances of FaerieMUD::AnimatedObject 33 33 ### in the world. 34 class FaerieMUD::Spirit < FaerieMUD::ComposedObject 35 include FaerieMUD::AccessorFunctions 34 class FaerieMUD::Spirit < FaerieMUD::Entity 35 include FaerieMUD::AccessorFunctions, 36 FaerieMUD::ArgCheckFunctions 36 37 contributors :ged 37 38 … … 42 43 SVNId = %q$Id$ 43 44 44 # SVN URL45 SVNURL = %q$URL$46 45 47 46 … … 77 76 78 77 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 79 115 80 116 ################################################################# … … 92 128 } 93 129 130 @aspects = { 131 :physical => PhysicalAspect::new, 132 :mental => MentalAspect::new, 133 :creative => CreativeAspect::new, 134 } 135 94 136 super 95 137 end … … 106 148 attr_locked_reader :animatedObjects 107 149 108 # The Spirit's immortal statistics hash, keyed by the name of the109 # corresponding sphere (ie., <tt>:physical</tt>, <tt>:mental</tt>, and110 # <tt>:creative</tt>).111 attr_typelocked_accessor :statistics, Hash112 113 150 # IO Callbacks 114 151 attr_reader :ioHandlers 115 152 153 # Pseudo-ComposedObject accessors 154 def_aspect_methods :physical, :mental, :creative 116 155 117 156 … … 127 166 @ioHandlers[:input] = handler 128 167 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 E133 #################################################################134 135 # Set up the classes for the three constituents of a trinary136 # ComposedObject137 def_constituents :physicalAspect => PhysicalAspect,138 :mentalAspect => MentalAspect,139 :creativeAspect => CreativeAspect140 141 168 142 169 … … 155 182 ### Remove the specified +object+ (FaerieMUD::AnimatedObject) from the 156 183 ### list being controlled by the Spirit. 157 def unanimate( object )184 def deanimate( object ) 158 185 self.writelocked do 159 186 object.controller = nil … … 161 188 end 162 189 end 190 alias_method :unanimate, :deanimate 163 191 164 192 -
trunk/lib/fm/statistic.rb
r212 r235 59 59 SVNId = %q$Id$ 60 60 61 # SVN URL62 SVNURL = %q$URL$63 64 61 65 62 # The maximum value a statistic can have (derived from … … 101 98 102 99 # The developmental part of the statistic (FaerieMUD::DevelopmentalObject) 103 attr_ locked_reader :developmental100 attr_typelocked_accessor :developmental, FaerieMUD::DevelopmentalObject 104 101 105 102 # The name of the linear part of the statistic -
trunk/tests/animatedobject.tests.rb
r212 r235 4 4 # $Id$ 5 5 # 6 # Copyright (c) 2003 , 2004The FaerieMUD Consortium.6 # Copyright (c) 2003-2005 The FaerieMUD Consortium. 7 7 # 8 8 … … 65 65 ################################################################# 66 66 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 ) 70 71 assert_instance_of Class, FaerieMUD::AnimatedObject 71 72 end 72 73 73 74 74 ### Derivative test 75 def test_01_Derivative 75 ### Subclassing test 76 def test_10_SubclassingShouldWork 77 printTestHeader "AnimatedObject: Subclassing should work" 76 78 rval, derivClass, derivObject = nil, nil, nil 77 79 … … 108 110 109 111 # Set up a testing instance for further tests. 110 self.class.addSetupBlock {112 addSetupBlock { 111 113 constituentClasses = @constituentClasses 112 114 @derivClass = Class::new( FaerieMUD::AnimatedObject ){ … … 121 123 :controller => TestController ) 122 124 } 123 self.class.addTeardownBlock {125 addTeardownBlock { 124 126 @derivObject = nil 125 127 @derivClass = nil … … 128 130 129 131 ### Test duplication 130 def test_05_Duplication 132 def test_20_Clone 133 printTestHeader "AnimatedObject: Cloning should clone the object's attributes" 131 134 rval = nil 132 135 … … 143 146 end 144 147 145 146 148 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 148 214 end 149 215 -
trunk/tests/composedobject.tests.rb
r232 r235 494 494 "trait modifiers hashes disparate?" 495 495 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 497 543 498 544 end -
trunk/tests/spirit.tests.rb
r212 r235 79 79 # Aspect accessors (ComposedObject::Constituents) 80 80 %w{physical mental creative}.each do |atype| 81 meth = "#{atype}Aspect"81 meth = atype 82 82 assert_respond_to @testSpirit, meth 83 83 assert_nothing_raised { rval = @testSpirit.send(meth) }
