Class: Gamefic::Scene::Base

Inherits:
Object show all
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

Constructor Details

#initialize(actor, **data) ⇒ Base



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

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

Class Attribute Details

.tracked=(value) ⇒ Object (writeonly)

Sets the attribute tracked



126
127
128
# File 'lib/gamefic/scene/base.rb', line 126

def tracked=(value)
  @tracked = value
end

Instance Attribute Details

#actorGamefic::Actor (readonly)

The scene’s primary actor.



9
10
11
# File 'lib/gamefic/scene/base.rb', line 9

def actor
  @actor
end

#dataHash{Symbol => Object} (readonly)



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

def data
  @data
end

#inputString (readonly)

The input received from the actor.



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

def input
  @input
end

#promptString

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



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

def prompt
  @prompt ||= '>'
end

#typeString

Get a String that describes the type of scene.



108
109
110
# File 'lib/gamefic/scene/base.rb', line 108

def type
  @type ||= 'Scene'
end

Class Method Details

.on_start {|| ... } ⇒ Object

Yield Parameters:



113
114
115
# File 'lib/gamefic/scene/base.rb', line 113

def self.on_start &block
  @start_block = block
end

.start_blockObject



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

def start_block
  @start_block
end

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

Yield Parameters:



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

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

.tracked?Boolean



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

def tracked?
  @tracked ||= false
end

Instance Method Details

#[](key) ⇒ Object

A shortcut for the #data hash.



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

def [] key
  data[key]
end

#finishObject

Finish the scene.



68
69
70
71
# File 'lib/gamefic/scene/base.rb', line 68

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

#finished?Boolean

Determine whether the scene’s execution is finished.



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

def finished?
  @finished ||= false
end

#on_finish(&block) ⇒ Object

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



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

def on_finish &block
  @finish_block = block
end

#post_initializeObject



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

def post_initialize
end

#startObject

Start the scene.



61
62
63
64
# File 'lib/gamefic/scene/base.rb', line 61

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.



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

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

#tracked=(bool) ⇒ Object



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

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

#tracked?Boolean



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

def tracked?
  self.class.tracked?
end

#updateObject

Update the scene.



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

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