Class: Gamefic::Scene::Base

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

Active, Custom

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actor) ⇒ Base

Returns a new instance of Base.



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

def initialize actor
  @actor = actor
  post_initialize
end

Instance Attribute Details

#actorObject (readonly)

Returns the value of attribute actor.



7
8
9
# File 'lib/gamefic/scene/base.rb', line 7

def actor
  @actor
end

#inputObject (readonly)

Returns the value of attribute input.



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

def input
  @input
end

#promptString

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

Returns:

  • (String)

    The text to be displayed.



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

def prompt
  @prompt ||= '>'
end

#typeObject



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

def type
  @type ||= 'Scene'
end

Class Method Details

.initialize_blockObject



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

def initialize_block
  @initialize_block
end

.on_initialize(&block) ⇒ Object



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

def self.on_initialize &block
  @initialize_block = block
end

.subclass(&block) ⇒ Object



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

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

Instance Method Details

#finishObject



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

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

#flushObject



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

def flush
  @state.clear
end

#on_finish(&block) ⇒ Object



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

def on_finish &block
  @finish_block = block
end

#post_initializeObject



17
18
# File 'lib/gamefic/scene/base.rb', line 17

def post_initialize
end

#startObject



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

def start
  self.class.initialize_block.call @actor, self unless self.class.initialize_block.nil?
end

#stateObject



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

def state
  {
    scene: type, prompt: prompt, input: input #, output: actor.messages, busy: !actor.queue.empty?

  }
end

#updateObject



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

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