Class: Gamefic::Active::Epic
- Inherits:
-
Object
- Object
- Gamefic::Active::Epic
- Includes:
- Logging
- Defined in:
- lib/gamefic/active/epic.rb
Overview
A collection of narratives.
Instance Attribute Summary collapse
- #narratives ⇒ Set<Narrative> readonly
Instance Method Summary collapse
- #add(narrative) ⇒ Object
- #delete(narrative) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Epic
constructor
A new instance of Epic.
- #one? ⇒ Boolean
- #responses_for(*verbs) ⇒ Array<Response>
- #rulebooks ⇒ Array<Rulebook>
- #select_scene(name) ⇒ Scene
- #synonyms ⇒ Array<Symbol>
- #syntaxes ⇒ Object
- #verbs ⇒ Array<Symbol>
Methods included from Logging
Constructor Details
#initialize ⇒ Epic
Returns a new instance of Epic.
13 14 15 |
# File 'lib/gamefic/active/epic.rb', line 13 def initialize @narratives = Set.new end |
Instance Attribute Details
#narratives ⇒ Set<Narrative> (readonly)
11 12 13 |
# File 'lib/gamefic/active/epic.rb', line 11 def narratives @narratives end |
Instance Method Details
#add(narrative) ⇒ Object
18 19 20 |
# File 'lib/gamefic/active/epic.rb', line 18 def add narrative narratives.add narrative end |
#delete(narrative) ⇒ Object
23 24 25 |
# File 'lib/gamefic/active/epic.rb', line 23 def delete narrative narratives.delete narrative end |
#empty? ⇒ Boolean
42 43 44 |
# File 'lib/gamefic/active/epic.rb', line 42 def empty? narratives.empty? end |
#one? ⇒ Boolean
46 47 48 |
# File 'lib/gamefic/active/epic.rb', line 46 def one? narratives.one? end |
#responses_for(*verbs) ⇒ Array<Response>
55 56 57 58 59 |
# File 'lib/gamefic/active/epic.rb', line 55 def responses_for(*verbs) rulebooks.to_a .reverse .flat_map { |rb| rb.responses_for(*verbs) } end |
#rulebooks ⇒ Array<Rulebook>
28 29 30 |
# File 'lib/gamefic/active/epic.rb', line 28 def rulebooks narratives.map(&:rulebook) end |
#select_scene(name) ⇒ Scene
63 64 65 66 67 68 69 70 71 |
# File 'lib/gamefic/active/epic.rb', line 63 def select_scene name scenes = rulebooks.map { |rlbk| rlbk.scenes[name] } .compact raise ArgumentError, "Scene named `#{name}` does not exist" if scenes.empty? logger.warn "Found #{scenes.length} scenes named `#{name}`" unless scenes.one? scenes.last end |
#synonyms ⇒ Array<Symbol>
38 39 40 |
# File 'lib/gamefic/active/epic.rb', line 38 def synonyms rulebooks.flat_map(&:synonyms).uniq end |
#syntaxes ⇒ Object
50 51 52 |
# File 'lib/gamefic/active/epic.rb', line 50 def syntaxes rulebooks.flat_map(&:syntaxes) end |
#verbs ⇒ Array<Symbol>
33 34 35 |
# File 'lib/gamefic/active/epic.rb', line 33 def verbs rulebooks.flat_map(&:verbs).uniq end |