Class: Gamefic::Character
Instance Attribute Summary collapse
- #last_object ⇒ Entity? readonly
- #last_order ⇒ Gamefic::Director::Order readonly
-
#next_scene ⇒ Object
readonly
Returns the value of attribute next_scene.
-
#object_of_pronoun ⇒ Object
Returns the value of attribute object_of_pronoun.
-
#playbook ⇒ Object
Returns the value of attribute playbook.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#scene ⇒ Object
readonly
Returns the value of attribute scene.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Attributes inherited from Entity
Attributes included from Grammar::Plural
Attributes included from Grammar::Person
Attributes included from Grammar::Gender
Attributes included from Describable
#definite_article, #indefinite_article, #name, #synonyms
Instance Method Summary collapse
- #conclude(scene) ⇒ Object
- #concluded? ⇒ Boolean
-
#connect(user) ⇒ Object
Connect a User.
- #cue(scene) ⇒ Object
-
#disconnect ⇒ Object
Disconnect the current User.
-
#initialize(args = {}) ⇒ Character
constructor
A new instance of Character.
-
#perform(*command) ⇒ Object
Perform a command.
- #performed(order) ⇒ Object
- #prepare(scene) ⇒ Object
-
#proceed ⇒ Object
Proceed to the next Action in the current stack.
- #prompt ⇒ Object
-
#quietly(*command) ⇒ String
Quietly perform a command.
-
#stream(message) ⇒ Object
Send a message to the Character as raw text.
-
#tell(message) ⇒ Object
Send a message to the Character.
Methods inherited from Entity
#[], #[]=, #parent=, #post_initialize, #pre_initialize, #uid, #update
Methods included from Serialized::ClassMethods
Methods included from Grammar::WordAdapter
Methods included from Grammar::Plural
Methods included from Serialized
included, #serialized_attributes
Methods included from Describable
default_description, default_description=, #definitely, #description, #description=, #has_description?, #indefinitely, #keywords, #proper_named=, #proper_named?, #to_s
Methods included from Node
#children, #flatten, #parent, #parent=
Constructor Details
#initialize(args = {}) ⇒ Character
Returns a new instance of Character.
18 19 20 21 22 23 |
# File 'lib/gamefic/character.rb', line 18 def initialize(args = {}) @queue = Array.new super @buffer_stack = 0 @buffer = "" end |
Instance Attribute Details
#last_object ⇒ Entity? (readonly)
12 13 14 |
# File 'lib/gamefic/character.rb', line 12 def last_object @last_object end |
#last_order ⇒ Gamefic::Director::Order
10 11 12 |
# File 'lib/gamefic/character.rb', line 10 def last_order @last_order end |
#next_scene ⇒ Object (readonly)
Returns the value of attribute next_scene.
15 16 17 |
# File 'lib/gamefic/character.rb', line 15 def next_scene @next_scene end |
#object_of_pronoun ⇒ Object
Returns the value of attribute object_of_pronoun.
13 14 15 |
# File 'lib/gamefic/character.rb', line 13 def object_of_pronoun @object_of_pronoun end |
#playbook ⇒ Object
Returns the value of attribute playbook.
16 17 18 |
# File 'lib/gamefic/character.rb', line 16 def playbook @playbook end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
8 9 10 |
# File 'lib/gamefic/character.rb', line 8 def queue @queue end |
#scene ⇒ Object (readonly)
Returns the value of attribute scene.
14 15 16 |
# File 'lib/gamefic/character.rb', line 14 def scene @scene end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
8 9 10 |
# File 'lib/gamefic/character.rb', line 8 def user @user end |
Instance Method Details
#conclude(scene) ⇒ Object
133 134 135 136 |
# File 'lib/gamefic/character.rb', line 133 def conclude scene raise NotConclusionError if !scene.kind_of?(Scene::Conclusion) cue scene end |
#concluded? ⇒ Boolean
138 139 140 |
# File 'lib/gamefic/character.rb', line 138 def concluded? !scene.nil? and scene.kind_of?(Scene::Conclusion) end |
#connect(user) ⇒ Object
Connect a User.
28 29 30 |
# File 'lib/gamefic/character.rb', line 28 def connect(user) @user = user end |
#cue(scene) ⇒ Object
123 124 125 126 127 |
# File 'lib/gamefic/character.rb', line 123 def cue scene @next_scene = nil @scene = scene @scene.start self unless @scene.nil? end |
#disconnect ⇒ Object
Disconnect the current User.
34 35 36 |
# File 'lib/gamefic/character.rb', line 34 def disconnect @user = nil end |
#perform(*command) ⇒ Object
Perform a command. The command can be specified as a String or a set of tokens. Either form should yield the same result, but using tokens can yield better performance since it bypasses the parser.
The command will be executed immediately regardless of game state.
51 52 53 |
# File 'lib/gamefic/character.rb', line 51 def perform(*command) Director.dispatch(self, *command) end |
#performed(order) ⇒ Object
142 143 144 |
# File 'lib/gamefic/character.rb', line 142 def performed order @last_order = order end |
#prepare(scene) ⇒ Object
129 130 131 |
# File 'lib/gamefic/character.rb', line 129 def prepare scene @next_scene = scene end |
#proceed ⇒ Object
Proceed to the next Action in the current stack. This method is typically used in Action blocks to cascade through multiple implementations of the same verb.
119 120 121 |
# File 'lib/gamefic/character.rb', line 119 def proceed Director::Delegate.proceed_for self end |
#prompt ⇒ Object
146 147 148 |
# File 'lib/gamefic/character.rb', line 146 def prompt scene.nil? ? '>' : scene.prompt_for(self) end |
#quietly(*command) ⇒ String
Quietly perform a command. This method executes the command exactly as #perform does, except it buffers the resulting output instead of sending it to the user.
60 61 62 63 64 65 66 67 68 |
# File 'lib/gamefic/character.rb', line 60 def quietly(*command) if @buffer_stack == 0 @buffer = "" end @buffer_stack += 1 self.perform *command @buffer_stack -= 1 @buffer end |
#stream(message) ⇒ Object
Send a message to the Character as raw text. Unlike #tell, this method will not wrap the message in HTML paragraphs.
94 95 96 |
# File 'lib/gamefic/character.rb', line 94 def stream() user.send .strip unless user.nil? end |
#tell(message) ⇒ Object
Send a message to the Character. This method will automatically wrap the message in HTML paragraphs. To send a message without paragraph formatting, use #stream instead.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/gamefic/character.rb', line 75 def tell() if user != nil and .to_s != '' if @buffer_stack > 0 @buffer += else = "<p>#{message.strip}</p>" # This method uses String#gsub instead of String#gsub! for # compatibility with Opal. = .gsub(/[ \t\r]*\n[ \t\r]*\n[ \t\r]*/, '</p><p>') = .gsub(/[ \t]*\n[ \t]*/, ' ') user.send end end end |