Class: Gamefic::Character
Instance Attribute Summary collapse
- #last_object ⇒ Entity? readonly
- #last_order ⇒ Gamefic::Director::Order readonly
-
#object_of_pronoun ⇒ Object
Returns the value of attribute object_of_pronoun.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#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_name) ⇒ Object
-
#connect(user) ⇒ Object
Connect a User.
- #cue(scene_name) ⇒ Object
-
#disconnect ⇒ Object
Disconnect the current User.
-
#initialize(plot, args = {}) ⇒ Character
constructor
A new instance of Character.
- #next_scene ⇒ Object
-
#perform(*command, from_user: false) ⇒ Object
Perform a command.
- #prepare(scene_name) ⇒ Object
-
#proceed ⇒ Object
Proceed to the next Action in the current stack.
-
#quietly(*command) ⇒ String
Quietly perform a command.
-
#scene ⇒ Symbol
Get the name of the character’s current scene.
-
#scene=(key) ⇒ Object
Alias for Character#cue key.
-
#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
#[], #[]=, #destroy, #on_update, #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
Instance Attribute Details
#last_object ⇒ Entity? (readonly)
9 10 11 |
# File 'lib/gamefic/character.rb', line 9 def last_object @last_object end |
#last_order ⇒ Gamefic::Director::Order
7 8 9 |
# File 'lib/gamefic/character.rb', line 7 def last_order @last_order end |
#object_of_pronoun ⇒ Object
Returns the value of attribute object_of_pronoun.
10 11 12 |
# File 'lib/gamefic/character.rb', line 10 def object_of_pronoun @object_of_pronoun end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
5 6 7 |
# File 'lib/gamefic/character.rb', line 5 def queue @queue end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
5 6 7 |
# File 'lib/gamefic/character.rb', line 5 def user @user end |
Instance Method Details
#conclude(scene_name) ⇒ Object
144 145 146 147 148 |
# File 'lib/gamefic/character.rb', line 144 def conclude scene_name scene = plot.scenes[scene_name] raise "#{scene_name} is not a conclusion" unless scene.kind_of?(Scene::Conclusion) cue scene_name end |
#connect(user) ⇒ Object
Connect a User.
24 25 26 |
# File 'lib/gamefic/character.rb', line 24 def connect(user) @user = user end |
#cue(scene_name) ⇒ Object
134 135 136 137 138 |
# File 'lib/gamefic/character.rb', line 134 def cue scene_name @scene = scene_name @next_scene = nil plot.scenes[scene_name].start self end |
#disconnect ⇒ Object
Disconnect the current User.
30 31 32 |
# File 'lib/gamefic/character.rb', line 30 def disconnect @user = nil end |
#next_scene ⇒ Object
162 163 164 |
# File 'lib/gamefic/character.rb', line 162 def next_scene @next_scene end |
#perform(*command, from_user: false) ⇒ 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.
If the from_user argument is true, the command is assumed to have come directly from user input. The character’s last_order and last_object will be updated with the result.
51 52 53 54 55 |
# File 'lib/gamefic/character.rb', line 51 def perform(*command, from_user: false) o = Director.dispatch(self, *command) last_order = o if from_user o end |
#prepare(scene_name) ⇒ Object
140 141 142 |
# File 'lib/gamefic/character.rb', line 140 def prepare scene_name @next_scene = scene_name 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.
129 130 131 132 |
# File 'lib/gamefic/character.rb', line 129 def proceed return if delegate_stack.last.nil? delegate_stack.last.proceed 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.
62 63 64 65 66 67 68 69 70 |
# File 'lib/gamefic/character.rb', line 62 def quietly(*command) if @buffer_stack == 0 @buffer = "" end @buffer_stack += 1 self.perform *command @buffer_stack -= 1 @buffer end |
#scene ⇒ Symbol
Get the name of the character’s current scene
153 154 155 |
# File 'lib/gamefic/character.rb', line 153 def scene @scene end |
#scene=(key) ⇒ Object
Alias for Character#cue key
158 159 160 |
# File 'lib/gamefic/character.rb', line 158 def scene= key cue key.to_sym 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.
96 97 98 |
# File 'lib/gamefic/character.rb', line 96 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.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/gamefic/character.rb', line 77 def tell() if user != nil and .to_s != '' if @buffer_stack > 0 @buffer += else = "<p>#{.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 |