Module: Gamefic::Messaging

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

Instance Method Summary collapse

Instance Method Details

#flushObject



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

def flush
  p_set_messages '' unless messages.empty?
end

#messagesString

Returns:



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

def messages
  @messages ||= ''
end

#outputObject



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

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:



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

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
16
# 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]*/, ' ')
  #user.send message
  p_set_messages messages + message
end