Class: Gamefic::Scene::Default

Inherits:
Object
  • Object
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.

Direct Known Subclasses

Activity, Conclusion, MultipleChoice, Pause

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.

Parameters:

  • name (Symbol)
  • narrative (Narrative)
  • on_start (Proc, nil) (defaults to: nil)
  • on_finish (Proc, nil) (defaults to: nil)

Yield Parameters:

  • (self)


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

#nameSymbol (readonly)

Returns:

  • (Symbol)


10
11
12
# File 'lib/gamefic/scene/default.rb', line 10

def name
  @name
end

Class Method Details

.props_classObject



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

Returns:

  • (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.

Parameters:



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.

Parameters:



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_hashObject



75
76
77
# File 'lib/gamefic/scene/default.rb', line 75

def to_hash
  { name: name, type: type }
end

#typeString

Returns:



28
29
30
# File 'lib/gamefic/scene/default.rb', line 28

def type
  @type ||= self.class.to_s.sub(/^Gamefic::Scene::/, '')
end