Class: Gamefic::Scene::Default
- Inherits:
-
Object
- Object
- Gamefic::Scene::Default
show all
- Defined in:
- lib/gamefic/scene/default.rb
Overview
The base class for scenes. Authors can instantiate this class directly and customize it with on_start and on_finish blocks.
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, narrative, on_start: nil, on_finish: nil) {|| ... } ⇒ Default
Returns a new instance of Default.
17
18
19
20
21
22
23
24
25
|
# File 'lib/gamefic/scene/default.rb', line 17
def initialize name, narrative, on_start: nil, on_finish: nil
@name = name
@narrative = narrative
@start_blocks = []
@finish_blocks = []
@start_blocks.push on_start if on_start
@finish_blocks.push on_finish if on_finish
yield(self) if block_given?
end
|
Instance Attribute Details
#name ⇒ Symbol
10
11
12
|
# File 'lib/gamefic/scene/default.rb', line 10
def name
@name
end
|
Class Method Details
.props_class ⇒ Object
67
68
69
|
# File 'lib/gamefic/scene/default.rb', line 67
def self.props_class
@props_class ||= Props::Default
end
|
Instance Method Details
#conclusion? ⇒ Boolean
71
72
73
|
# File 'lib/gamefic/scene/default.rb', line 71
def conclusion?
is_a?(Conclusion)
end
|
#finish(actor, props) ⇒ void
This method returns an undefined value.
55
56
57
|
# File 'lib/gamefic/scene/default.rb', line 55
def finish actor, props
props.input = actor.queue.shift&.strip
end
|
#new_props(**context) ⇒ Object
32
33
34
|
# File 'lib/gamefic/scene/default.rb', line 32
def new_props(**context)
self.class.props_class.new(self, **context)
end
|
#on_finish(&block) ⇒ Object
40
41
42
|
# File 'lib/gamefic/scene/default.rb', line 40
def on_finish &block
@finish_blocks.push block
end
|
#on_start(&block) ⇒ Object
36
37
38
|
# File 'lib/gamefic/scene/default.rb', line 36
def on_start &block
@start_blocks.push block
end
|
#run_finish_blocks(actor, props) ⇒ Object
63
64
65
|
# File 'lib/gamefic/scene/default.rb', line 63
def run_finish_blocks actor, props
@finish_blocks.each { |blk| Stage.run(@narrative, actor, props, &blk) }
end
|
#run_start_blocks(actor, props) ⇒ Object
59
60
61
|
# File 'lib/gamefic/scene/default.rb', line 59
def run_start_blocks actor, props
@start_blocks.each { |blk| Stage.run(@narrative, actor, props, &blk) }
end
|
#start(actor, props) ⇒ void
This method returns an undefined value.
47
48
49
50
|
# File 'lib/gamefic/scene/default.rb', line 47
def start actor, props
props.output[:scene] = to_hash
props.output[:prompt] = props.prompt
end
|
#to_hash ⇒ Object
75
76
77
|
# File 'lib/gamefic/scene/default.rb', line 75
def to_hash
{ name: name, type: type }
end
|
28
29
30
|
# File 'lib/gamefic/scene/default.rb', line 28
def type
@type ||= self.class.to_s.sub(/^Gamefic::Scene::/, '')
end
|