Class: Gamefic::Scene::Base

Inherits:
Object show all
Extended by:
Gamefic::Serialize
Includes:
Gamefic::Serialize
Defined in:
lib/gamefic/scene/base.rb

Overview

The Base Scene is not intended for instantiation. Other Scene classes should inherit from it.

Direct Known Subclasses

Activity, Custom

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gamefic::Serialize

instances, serialized_class, string_to_constant, to_serial

Constructor Details

#initialize(actor, **data) ⇒ Base

Returns a new instance of Base.



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

def initialize actor, **data
  @actor = actor
  @data = data
  post_initialize
end

Class Attribute Details

.tracked=(value) ⇒ Object (writeonly)

Sets the attribute tracked

Parameters:

  • value

    the value to set the attribute tracked to.



129
130
131
# File 'lib/gamefic/scene/base.rb', line 129

def tracked=(value)
  @tracked = value
end

Instance Attribute Details

#actorGamefic::Actor (readonly)

The scene’s primary actor.

Returns:



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

def actor
  @actor
end

#dataHash{Symbol => Object} (readonly)

Returns:



30
31
32
# File 'lib/gamefic/scene/base.rb', line 30

def data
  @data
end

#inputString (readonly)

The input received from the actor.

Returns:



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

def input
  @input
end

#promptString

Get the prompt to be displayed to the user when accepting input.

Returns:

  • (String)

    The text to be displayed.



104
105
106
# File 'lib/gamefic/scene/base.rb', line 104

def prompt
  @prompt ||= '>'
end

#typeString

Get a String that describes the type of scene.

Returns:



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

def type
  @type ||= 'Scene'
end

Class Method Details

.on_start {|| ... } ⇒ Object

Yield Parameters:



116
117
118
# File 'lib/gamefic/scene/base.rb', line 116

def self.on_start &block
  @start_block = block
end

.start_blockObject



131
132
133
# File 'lib/gamefic/scene/base.rb', line 131

def start_block
  @start_block
end

.subclass {|| ... } ⇒ Class<Gamefic::Scene::Base>

Yield Parameters:

Returns:



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

def self.subclass &block
  c = Class.new(self) do
    on_start &block
  end
  c
end

.tracked?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/gamefic/scene/base.rb', line 135

def tracked?
  @tracked ||= false
end

Instance Method Details

#[](key) ⇒ Object

A shortcut for the #data hash.

Parameters:

Returns:



42
43
44
# File 'lib/gamefic/scene/base.rb', line 42

def [] key
  data[key]
end

#finishObject

Finish the scene.



71
72
73
74
# File 'lib/gamefic/scene/base.rb', line 71

def finish
  @finish_block.call @actor, self unless @finish_block.nil?
  @finished = true
end

#finished?Boolean

Determine whether the scene’s execution is finished.

Returns:

  • (Boolean)


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

def finished?
  @finished ||= false
end

#on_finish(&block) ⇒ Object

Set a proc to be executed at the end of the scene.



51
52
53
# File 'lib/gamefic/scene/base.rb', line 51

def on_finish &block
  @finish_block = block
end

#post_initializeObject



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

def post_initialize
end

#startObject

Start the scene.



64
65
66
67
# File 'lib/gamefic/scene/base.rb', line 64

def start
  self.class.start_block.call @actor, self unless self.class.start_block.nil?
  @actor.entered self if tracked?
end

#stateHash

Get a hash that describes the current state of the scene.

Returns:



86
87
88
89
90
# File 'lib/gamefic/scene/base.rb', line 86

def state
  {
    scene: type, prompt: prompt
  }
end

#tracked=(bool) ⇒ Object



124
125
126
# File 'lib/gamefic/scene/base.rb', line 124

def tracked= bool
  self.class.tracked = bool
end

#tracked?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/gamefic/scene/base.rb', line 120

def tracked?
  self.class.tracked?
end

#updateObject

Update the scene.



57
58
59
60
# File 'lib/gamefic/scene/base.rb', line 57

def update
  @input = actor.queue.shift
  finish
end