Module: Gamefic::Messaging

Included in:
Entity
Defined in:
lib/gamefic/messaging.rb

Instance Method Summary collapse

Instance Method Details

#flushObject



34
35
36
# File 'lib/gamefic/messaging.rb', line 34

def flush
  p_set_messages '' unless messages.empty?
end

#messagesString

Returns:



26
27
28
# File 'lib/gamefic/messaging.rb', line 26

def messages
  @messages ||= ''
end

#outputObject



30
31
32
# File 'lib/gamefic/messaging.rb', line 30

def output
  messages
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.

Parameters:



21
22
23
# File 'lib/gamefic/messaging.rb', line 21

def stream(message)
  p_set_messages messages + message.strip
end

#tell(message) ⇒ Object

Send a message to the entity. This method will automatically wrap the message in HTML paragraphs. To send a message without paragraph formatting, use #stream instead.

Parameters:



8
9
10
11
12
13
14
15
# File 'lib/gamefic/messaging.rb', line 8

def tell(message)
  message = "<p>#{message.strip}</p>"
  # This method uses String#gsub instead of String#gsub! for
  # compatibility with Opal.
  message = message.gsub(/[ \t\r]*\n[ \t\r]*\n[ \t\r]*/, '</p><p>')
  message = message.gsub(/[ \t]*\n[ \t]*/, ' ')
  p_set_messages messages + message
end