Class: Lich::Gemstone::Messaging
- Inherits:
-
Object
- Object
- Lich::Gemstone::Messaging
- Defined in:
- documented/gemstone/creature.rb
Overview
Creature messaging and flavor text
Stores creature-specific messages with placeholder support. Messages can contain placeholders like Pronoun, direction, weapon that are replaced at runtime.
Constant Summary collapse
- PLACEHOLDER_MAP =
{ Pronoun: %w[He Her His It She], pronoun: %w[he her his it she], direction: %w[north south east west up down northeast northwest southeast southwest], weapon: %w[RAW:.+?] }
Instance Attribute Summary collapse
-
#arrival ⇒ Object
Returns the value of attribute arrival.
-
#attack ⇒ Object
Returns the value of attribute attack.
-
#bite ⇒ Object
Returns the value of attribute bite.
-
#claw ⇒ Object
Returns the value of attribute claw.
-
#death ⇒ Object
Returns the value of attribute death.
-
#description ⇒ Object
Returns the value of attribute description.
-
#enrage ⇒ Object
Returns the value of attribute enrage.
-
#flee ⇒ Object
Returns the value of attribute flee.
-
#frenzy ⇒ Object
Returns the value of attribute frenzy.
-
#mstrike ⇒ Object
Returns the value of attribute mstrike.
-
#spell_prep ⇒ Object
Returns the value of attribute spell_prep.
-
#sympathy ⇒ Object
Returns the value of attribute sympathy.
Instance Method Summary collapse
- #display(field, subs = {}) ⇒ Object
-
#initialize(data) ⇒ Messaging
constructor
A new instance of Messaging.
- #match(field, str) ⇒ Object
- #normalize(value) ⇒ Object
Constructor Details
#initialize(data) ⇒ Messaging
Returns a new instance of Messaging.
764 765 766 767 768 |
# File 'documented/gemstone/creature.rb', line 764 def initialize(data) data.each do |key, value| instance_variable_set("@#{key}", normalize(value)) end end |
Instance Attribute Details
#arrival ⇒ Object
Returns the value of attribute arrival.
753 754 755 |
# File 'documented/gemstone/creature.rb', line 753 def arrival @arrival end |
#attack ⇒ Object
Returns the value of attribute attack.
753 754 755 |
# File 'documented/gemstone/creature.rb', line 753 def attack @attack end |
#bite ⇒ Object
Returns the value of attribute bite.
753 754 755 |
# File 'documented/gemstone/creature.rb', line 753 def bite @bite end |
#claw ⇒ Object
Returns the value of attribute claw.
753 754 755 |
# File 'documented/gemstone/creature.rb', line 753 def claw @claw end |
#death ⇒ Object
Returns the value of attribute death.
753 754 755 |
# File 'documented/gemstone/creature.rb', line 753 def death @death end |
#description ⇒ Object
Returns the value of attribute description.
753 754 755 |
# File 'documented/gemstone/creature.rb', line 753 def description @description end |
#enrage ⇒ Object
Returns the value of attribute enrage.
753 754 755 |
# File 'documented/gemstone/creature.rb', line 753 def enrage @enrage end |
#flee ⇒ Object
Returns the value of attribute flee.
753 754 755 |
# File 'documented/gemstone/creature.rb', line 753 def flee @flee end |
#frenzy ⇒ Object
Returns the value of attribute frenzy.
753 754 755 |
# File 'documented/gemstone/creature.rb', line 753 def frenzy @frenzy end |
#mstrike ⇒ Object
Returns the value of attribute mstrike.
753 754 755 |
# File 'documented/gemstone/creature.rb', line 753 def mstrike @mstrike end |
#spell_prep ⇒ Object
Returns the value of attribute spell_prep.
753 754 755 |
# File 'documented/gemstone/creature.rb', line 753 def spell_prep @spell_prep end |
#sympathy ⇒ Object
Returns the value of attribute sympathy.
753 754 755 |
# File 'documented/gemstone/creature.rb', line 753 def sympathy @sympathy end |
Instance Method Details
#display(field, subs = {}) ⇒ Object
782 783 784 785 786 787 788 789 790 791 |
# File 'documented/gemstone/creature.rb', line 782 def display(field, subs = {}) msg = send(field) if msg.is_a?(Array) msg.map { |m| m.is_a?(PlaceholderTemplate) ? m.to_display(subs) : m }.join("\n") elsif msg.is_a?(PlaceholderTemplate) msg.to_display(subs) else msg end end |
#match(field, str) ⇒ Object
793 794 795 796 797 798 799 800 |
# File 'documented/gemstone/creature.rb', line 793 def match(field, str) msg = send(field) if msg.is_a?(PlaceholderTemplate) msg.match(str) else msg == str ? {} : nil end end |
#normalize(value) ⇒ Object
770 771 772 773 774 775 776 777 778 779 780 |
# File 'documented/gemstone/creature.rb', line 770 def normalize(value) if value.is_a?(Array) value.map { |v| normalize(v) } elsif value.is_a?(String) && value.match?(/\{[a-zA-Z_]+\}/) phs = value.scan(/\{([a-zA-Z_]+)\}/).flatten.map(&:to_sym) placeholders = phs.map { |ph| [ph, PLACEHOLDER_MAP[ph] || []] }.to_h PlaceholderTemplate.new(value, placeholders) else value end end |