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

Activity, 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.



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

def prompt
  @prompt ||= '>'
end

#typeObject



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

def type
  @type ||= 'Scene'
end

Class Method Details

.on_start(&block) ⇒ Object



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

def self.on_start &block
  @start_block = block
end

.start_blockObject



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

def start_block
  @start_block
end

.subclass(&block) ⇒ Object



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

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

Instance Method Details

#finishObject



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

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

#finished?Boolean

Returns:

  • (Boolean)


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

def finished?
  @finished ||= false
end

#flushObject



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

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.start_block.call @actor, self unless self.class.start_block.nil?
end

#stateObject



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

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

#updateObject



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

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