Changeset 251
- Timestamp:
- 01/04/06 05:06:22 (3 years ago)
- Location:
- trunk
- Files:
-
- 13 modified
-
acceptance/epic5.rb (modified) (3 diffs)
-
bin/faeriemud.rb (modified) (4 diffs)
-
lib/fm/character.rb (modified) (3 diffs)
-
lib/fm/entity.rb (modified) (1 diff)
-
lib/fm/event.rb (modified) (1 diff)
-
lib/fm/events/astronomical.rb (modified) (1 diff)
-
lib/fm/events/meteorological.rb (modified) (1 diff)
-
lib/fm/events/science.rb (modified) (1 diff)
-
lib/fm/linguistics.rb (modified) (1 diff)
-
lib/fm/perception.rb (modified) (1 diff)
-
tests/entity.tests.rb (modified) (9 diffs)
-
tests/verb.tests.rb (modified) (5 diffs)
-
utils.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/acceptance/epic5.rb
r218 r251 1 1 #!/usr/bin/env ruby 2 2 # 3 # FaerieMUD - The Hidden Path - Epic 5: Volition 3 # FaerieMUD - The Hidden Path - Epic 5: Observation 4 # 5 # As a player, I want to be able to observe the world around me, so that I can 6 # distinguish between myself and other things. 4 7 # 5 8 # == Authors … … 9 12 # == Legal 10 13 # 11 # Copyright (c) 2000-200 5The FaerieMUD Consortium. Some rights reserved.14 # Copyright (c) 2000-2006 The FaerieMUD Consortium. Some rights reserved. 12 15 # 13 16 # This is free software. You may use, modify, and/or redistribute this software … … 31 34 require "fm" 32 35 36 -
trunk/bin/faeriemud.rb
r218 r251 11 11 end 12 12 13 require 'optparse' 14 require 'fm' 13 verboseOff { 14 require 'optparse' 15 require 'fm' 16 } 15 17 16 18 … … 34 36 } 35 37 38 class SimpleVerb < FaerieMUD::Verb 39 @event_class = nil 40 class << self 41 attr_reader :event_class 42 end 43 44 def self::set_event_class( klass ) 45 # $deferr.puts "Setting %s's event class to %p" % [ self, klass ] 46 @event_class = klass 47 end 48 49 def self::inherited( mod ) 50 super 51 # $deferr.puts "Setting %s's event class to %p" % [ mod, @event_class ] 52 mod.instance_variable_set( :@event_class, @event_class ) 53 end 54 55 def invoke( instigator, origin, target=nil ) 56 eclass = self.class.event_class or 57 return super 58 59 return eclass.new( 60 :instigator => instigator, 61 :origin => origin, 62 :target => target, 63 :verb => self ) 64 end 65 end 66 67 # I know, I know -- at least I didn't call it a Heartbeat 68 class TickEvent < FaerieMUD::Event 69 end 70 class TickVerb < SimpleVerb 71 set_event_class TickEvent 72 end 73 74 # Little world class 75 class World < FaerieMUD::Area 76 def start 77 @thread = Thread::new do 78 Thread.current[:running] = true 79 Thread.current.abort_on_exception = true 80 81 while Thread.current[:running] 82 tick = TickVerb.instance.invoke( self, self ) 83 immerseEvents( tick ) 84 sleep 0.5 85 end 86 end 87 88 trap( 'INT' ) { stop } 89 trap( 'HUP' ) { stop } 90 trap( 'TERM' ) { stop } 91 92 @thread.join 93 end 94 95 def stop 96 return unless @thread 97 @thread[:running] = false 98 end 99 100 end 101 102 # Stuff for a Spark to do 103 class TwinkleVerb < SimpleVerb 104 set_event_class FaerieMUD::VisualEvent 105 end 106 107 # An active object to occasionally generate observable events 108 class Spark < FaerieMUD::Locus 109 def noun 110 'spark' 111 end 112 113 def handleTickEvent( event ) 114 if ( rand(100) < 5 ) 115 return TwinkleVerb.instance.invoke( self, self ) 116 else 117 return [] 118 end 119 end 120 end 121 36 122 37 123 # Create the world 38 124 header "FaerieMUD Explorer" 39 message "Setting up the world...\n"40 world = FaerieMUD::Area::new41 125 42 126 # Create the character … … 50 134 spirit = FaerieMUD::Spirit::new 51 135 52 # Hook up the CommandParser's IO callbacks136 # Hook up the Spirit's IO callbacks 53 137 message "Setting the Spirit's IO callbacks...\n" 54 138 spirit.onInputReady do |promptText| … … 65 149 66 150 # Stick the character's body into the world Area 67 message "Placing the Character's body in the World...\n" 151 message "Setting up the world...\n" 152 world = World::new 153 spark = Spark::new 154 world << spark 155 156 message "Placing the Character's body in the world...\n" 68 157 world << character.body 69 158 159 $defout.sync = true 160 $deferr.sync = true 161 162 world.start 163 164 -
trunk/lib/fm/character.rb
r247 r251 74 74 ############################################################# 75 75 76 ### Create a new FaerieMUD::Character object. 77 def initialize( args={} ) 78 @verbs = [] 79 80 super 81 end 82 76 83 77 84 ###### … … 79 86 ###### 80 87 88 ### The Array of FaerieMUD::Verb objects which define this character's 89 ### abilities. 90 attr_reader :verbs 81 91 82 92 … … 129 139 130 140 131 #########132 protected133 #########134 135 136 141 end # class FaerieMUD::Character 137 142 -
trunk/lib/fm/entity.rb
r250 r251 111 111 debugMsg( 1, "Handling a #{event.class.name} event." ) 112 112 handler = self.getHandlerForEvent( event ) 113 return handler.call( event ) 113 result = handler.call( event ) 114 115 return Array( result ) 114 116 end 115 117 -
trunk/lib/fm/event.rb
r250 r251 133 133 134 134 return sentence.join( " " ) 135 136 135 end 137 136 -
trunk/lib/fm/events/astronomical.rb
r198 r251 34 34 # SVN Id 35 35 SVNId = %q$Id$ 36 37 # SVN URL38 SVNURL = %q$URL$39 36 40 37 end # class AstronomicalEvent -
trunk/lib/fm/events/meteorological.rb
r247 r251 37 37 38 38 39 ### Object which represents a timeslice of precipitation of some kind. They will 40 ### most probably be generated by a precipitation activity of a weather system, 41 ### which propagates these events to simulate the ongoing rainfall, snowfall, 42 ### etc. 43 class FaerieMUD::PrecipitationEvent < FaerieMUD::MeteorologicalEvent 44 contributors :ged 45 46 # SVN Revision 47 SVNRev = %q$Rev$ 48 49 # SVN Id 50 SVNId = %q$Id$ 51 52 # The default amount of water in a slice of rainfall, in cubic meters. 53 DefaultAmount = 0.01 54 55 # The default temperature of a slice of rainfall 56 DefaultTemperature = 25 57 58 59 ### Create a RainEvent which represents the falling of a collection of 60 ### drops. The amount, temperature, and intensity can be specified with 61 ### optional hash +args+. 62 def initialize( args={} ) 63 @amount = args[:amount] || DefaultAmount 64 @temperature = args[:temperature] || DefaultTemperature 65 end 66 67 68 ###### 69 public 70 ###### 71 72 # The amount of water in this slice of rainfall. Value may be between 73 # 0.01 (mist) to 1.0 (deluge). 74 attr_accessor :amount 75 76 # The temperature of the water in this slice of rainfall. Value may be between 77 attr_accessor :temperature 78 79 end -
trunk/lib/fm/events/science.rb
r172 r251 34 34 SVNId = %q$Id$ 35 35 36 # SVN URL37 SVNURL = %q$URL$38 36 39 37 end # class FaerieMUD::ScienceEvent -
trunk/lib/fm/linguistics.rb
r250 r251 91 91 92 92 93 ### Linguistic sentence class -- instances of this class are used to 94 ### encapsulate single-sentence chunks of linguistic content in the 95 ### natural-language system. 93 96 class Sentence 94 97 include FaerieMUD::Linguistics -
trunk/lib/fm/perception.rb
r250 r251 48 48 ################################################################# 49 49 50 # GWRN: 4497551 ### Create a new Perception for the given +perceiver+, which50 ### Create a new Perception for the given +perceiver+, which will be the 51 ### deleated describer of any PerceptualEvents which are handled. 52 52 def initialize( perceiver, args={} ) 53 53 @perceiver = perceiver -
trunk/tests/entity.tests.rb
r250 r251 4 4 # $Id$ 5 5 # 6 # Copyright (c) 2003 , 2004, 2005The FaerieMUD Consortium.6 # Copyright (c) 2003-2006 The FaerieMUD Consortium. 7 7 # 8 8 … … 38 38 class DerivTestingEvent < TestingEvent; end 39 39 class DerivDerivTestingEvent < DerivTestingEvent; end 40 class ResultEvent < FaerieMUD::Event 41 def initialize; end 42 end 43 40 44 41 45 … … 43 47 def setup 44 48 @entity = TestingEntity::new 49 @testingEvent = TestingEvent::new 50 @derivTestingEvent = DerivTestingEvent::new 51 @derivDerivTestingEvent = DerivDerivTestingEvent::new 45 52 end 46 53 … … 58 65 def test_unhandled_events_should_raise_an_exception 59 66 rval = nil 60 te = TestingEvent::new61 dte = DerivTestingEvent::new62 67 63 68 # Passing an event without a specific handler should cause an exception 64 69 # to be raised. 65 70 assert_raises( FaerieMUD::UnhandledEventError ) { 66 @entity.handleEvents( te)71 @entity.handleEvents( @testingEvent ) 67 72 } 68 73 assert_raises( FaerieMUD::UnhandledEventError ) { 69 @entity.handleEvents( dte)74 @entity.handleEvents( @derivTestingEvent ) 70 75 } 71 76 end … … 75 80 def test_entities_which_define_fallback_handler_should_handle_any_event 76 81 rval = nil 77 te = TestingEvent::new78 dte = DerivTestingEvent::new79 82 80 83 # Add a fallback handler … … 86 89 # Now try again -- both kinds of event should be handled by the fallback 87 90 # handler now. 88 assert_nothing_raised { @entity.handleEvents( te) }89 assert_same te, @entity.lastSeenEvent, "last seen event"91 assert_nothing_raised { @entity.handleEvents(@testingEvent) } 92 assert_same @testingEvent, @entity.lastSeenEvent, "last seen event" 90 93 assert_equal :handleAnyEvent, @entity.lastHandler 91 assert_nothing_raised { @entity.handleEvents( dte) }92 assert_same dte, @entity.lastSeenEvent, "last seen event"94 assert_nothing_raised { @entity.handleEvents(@derivTestingEvent) } 95 assert_same @derivTestingEvent, @entity.lastSeenEvent, "last seen event" 93 96 assert_equal :handleAnyEvent, @entity.lastHandler 94 97 … … 99 102 def test_entities_should_handle_derivative_events_with_more_general_handlers 100 103 rval = nil 101 te = TestingEvent::new102 dte = DerivTestingEvent::new103 ddte = DerivDerivTestingEvent::new104 104 105 105 def @entity.handleTestingEvent( ev ) … … 108 108 end 109 109 110 assert_nothing_raised { @entity.handleEvents( te) }111 assert_same te, @entity.lastSeenEvent,110 assert_nothing_raised { @entity.handleEvents(@testingEvent) } 111 assert_same @testingEvent, @entity.lastSeenEvent, 112 112 "last seen event for TestingEvent" 113 113 assert_equal :handleTestingEvent, @entity.lastHandler, 114 114 "last handler for TestingEvent" 115 115 116 assert_nothing_raised { @entity.handleEvents( dte) }117 assert_same dte, @entity.lastSeenEvent,116 assert_nothing_raised { @entity.handleEvents(@derivTestingEvent) } 117 assert_same @derivTestingEvent, @entity.lastSeenEvent, 118 118 "last seen event for DerivTestingEvent" 119 119 assert_equal :handleTestingEvent, @entity.lastHandler, 120 120 "last handler for DerivTestingEvent" 121 121 122 assert_nothing_raised { @entity.handleEvents( ddte) }123 assert_same ddte, @entity.lastSeenEvent,122 assert_nothing_raised { @entity.handleEvents(@derivDerivTestingEvent) } 123 assert_same @derivDerivTestingEvent, @entity.lastSeenEvent, 124 124 "last seen event for DerivDerivTestingEvent" 125 125 assert_equal :handleTestingEvent, @entity.lastHandler, … … 128 128 129 129 130 def test_event_handler_should_be_able_to_handle_single_event_result 131 rval = nil 132 133 def @entity.handleTestingEvent( ev ) 134 return ResultEvent::new 135 end 136 137 assert_nothing_raised { rval = @entity.handleEvents(@testingEvent) } 138 assert_instance_of Array, rval 139 assert_equal 1, rval.length 140 assert_instance_of ResultEvent, rval[0] 141 142 assert_nothing_raised { rval = @entity.handleEvent(@testingEvent) } 143 assert_instance_of Array, rval 144 assert_equal 1, rval.length 145 assert_instance_of ResultEvent, rval[0] 146 end 147 130 148 end 131 149 -
trunk/tests/verb.tests.rb
r217 r251 4 4 # $Id$ 5 5 # 6 # Copyright (c) 2004 , 2005The FaerieMUD Consortium.6 # Copyright (c) 2004-2006 The FaerieMUD Consortium. 7 7 # 8 8 … … 43 43 44 44 ### Instance test 45 def test_00_Instance 46 printTestHeader "FaerieMUD::Verb: Class/instantiation" 45 def test_verb_class_should_be_defined_and_a_singleton 47 46 rval = nil 48 47 … … 60 59 61 60 62 # ## Event-generation interface63 def test_50_invoke64 printTestHeader "FaerieMUD::Verb: Event-generation interface: invoke"61 # Event interface: Things which employ verbs expect to be able to fire the 62 # verb and get back one or more appropriate events. 63 def test_verbs_should_be_able_to_be_invoked 65 64 rval = nil 66 65 … … 80 79 81 80 82 # ## CommandParser interface83 def test_60_words84 printTestHeader "FaerieMUD::Verb: CommandParser interface: words"81 # CommandParser interface: Verbs should be able to provide a list of 82 # commands they expect to be invoked for. 83 def test_verbs_should_be_able_to_provide_a_list_of_autogenerated_command_words 85 84 rval = nil 86 85 verb = TestVerb::instance … … 95 94 end 96 95 96 # Subclasses of Verbs should be singletons, too. 97 def test_subclasses_should_be_singletons 98 rval = nil 99 100 assert_raises( NoMethodError ) { TestVerb.new } 101 assert_nothing_raised { rval = TestVerb.instance } 102 103 assert_instance_of TestVerb, rval 104 end 97 105 98 106 end -
trunk/utils.rb
r250 r251 3 3 # $Id: utils.rb,v 1.20 2003/11/23 04:37:57 stillflame Exp $ 4 4 # 5 # Copyright (c) 2001-200 5, The FaerieMUD Consortium.5 # Copyright (c) 2001-2006, The FaerieMUD Consortium. 6 6 # 7 7 # This is free software. You may use, modify, and/or redistribute this … … 26 26 end 27 27 28 begin29 require 'yaml'30 $yaml = true31 rescue LoadError => e32 $stderr.puts "No YAML; try() will use PrettyPrint instead."33 $yaml = false34 end35 28 } 36 29 … … 642 635 end 643 636 644 if $yaml 645 result = rval.to_yaml 646 else 647 PP.pp( rval, result ) 648 end 637 PP.pp( rval, result ) 649 638 650 639 rescue Exception => err
