Class: Gamefic::Scene::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/gamefic/scene/base.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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actor, narrative = nil, props = nil, **context) ⇒ Base

Returns a new instance of Base.

Parameters:



17
18
19
20
21
22
# File 'lib/gamefic/scene/base.rb', line 17

def initialize(actor, narrative = nil, props = nil, **context)
  @actor = actor
  @narrative = narrative
  @props = props || self.class.props_class.new
  @context = context
end

Class Attribute Details

.contextObject

Returns the value of attribute context.



74
75
76
# File 'lib/gamefic/scene/base.rb', line 74

def context
  @context
end

.nicknameObject (readonly)

Returns the value of attribute nickname.



74
75
76
# File 'lib/gamefic/scene/base.rb', line 74

def nickname
  @nickname
end

Instance Attribute Details

#actorObject (readonly)

Returns the value of attribute actor.



12
13
14
# File 'lib/gamefic/scene/base.rb', line 12

def actor
  @actor
end

#contextObject (readonly)

Returns the value of attribute context.



12
13
14
# File 'lib/gamefic/scene/base.rb', line 12

def context
  @context
end

#nameObject



24
25
26
# File 'lib/gamefic/scene/base.rb', line 24

def name
  @name ||= self.class.nickname
end

#narrativeObject (readonly)

Returns the value of attribute narrative.



12
13
14
# File 'lib/gamefic/scene/base.rb', line 12

def narrative
  @narrative
end

#propsObject (readonly)

Returns the value of attribute props.



12
13
14
# File 'lib/gamefic/scene/base.rb', line 12

def props
  @props
end

Class Method Details

.finish_blocksArray<Proc>

Returns:



94
95
96
# File 'lib/gamefic/scene/base.rb', line 94

def finish_blocks
  @finish_blocks ||= []
end

.inherited(klass) ⇒ Object



52
53
54
55
56
57
# File 'lib/gamefic/scene/base.rb', line 52

def self.inherited(klass)
  super
  klass.use_props_class props_class
  klass.start_blocks.concat start_blocks
  klass.finish_blocks.concat finish_blocks
end

.on_finish {|actor, props, context| ... } ⇒ Object

Yield Parameters:

  • actor (Actor)

    The scene’s actor

  • props (Props::Default)

    The scene’s props

  • context (Hash)

    Additional context



110
111
112
# File 'lib/gamefic/scene/base.rb', line 110

def on_finish(&block)
  finish_blocks.push block
end

.on_start {|actor, props, context| ... } ⇒ Object

Yield Parameters:

  • actor (Actor)

    The scene’s actor

  • props (Props::Default)

    The scene’s props

  • context (Hash)

    Additional context



102
103
104
# File 'lib/gamefic/scene/base.rb', line 102

def on_start(&block)
  start_blocks.push block
end

.props_classObject



80
81
82
# File 'lib/gamefic/scene/base.rb', line 80

def props_class
  @props_class ||= Props::Default
end

.rename(nickname) ⇒ Object



84
85
86
# File 'lib/gamefic/scene/base.rb', line 84

def rename(nickname)
  @nickname = nickname
end

.start_blocksArray<Proc>

Returns:



89
90
91
# File 'lib/gamefic/scene/base.rb', line 89

def start_blocks
  @start_blocks ||= []
end

.typeObject



76
77
78
# File 'lib/gamefic/scene/base.rb', line 76

def type
  'Base'
end

Instance Method Details

#finishvoid

This method returns an undefined value.



44
45
46
# File 'lib/gamefic/scene/base.rb', line 44

def finish
  run_finish_blocks
end

#rename(name) ⇒ Object



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

def rename(name)
  @name = name
end

#startProps::Default

Returns:



38
39
40
41
# File 'lib/gamefic/scene/base.rb', line 38

def start
  run_start_blocks
  props
end

#to_hashObject



48
49
50
# File 'lib/gamefic/scene/base.rb', line 48

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

#typeString

Returns:



33
34
35
# File 'lib/gamefic/scene/base.rb', line 33

def type
  self.class.type
end