Class: Gamefic::Scene::Base
- Inherits:
-
Object
- Object
- Gamefic::Scene::Base
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.
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.
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
.context ⇒ Object
Returns the value of attribute context.
74
75
76
|
# File 'lib/gamefic/scene/base.rb', line 74
def context
@context
end
|
.nickname ⇒ Object
Returns the value of attribute nickname.
74
75
76
|
# File 'lib/gamefic/scene/base.rb', line 74
def nickname
@nickname
end
|
Instance Attribute Details
#actor ⇒ Object
Returns the value of attribute actor.
12
13
14
|
# File 'lib/gamefic/scene/base.rb', line 12
def actor
@actor
end
|
#context ⇒ Object
Returns the value of attribute context.
12
13
14
|
# File 'lib/gamefic/scene/base.rb', line 12
def context
@context
end
|
#name ⇒ Object
24
25
26
|
# File 'lib/gamefic/scene/base.rb', line 24
def name
@name ||= self.class.nickname
end
|
#narrative ⇒ Object
Returns the value of attribute narrative.
12
13
14
|
# File 'lib/gamefic/scene/base.rb', line 12
def narrative
@narrative
end
|
#props ⇒ Object
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_blocks ⇒ Array<Proc>
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
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
102
103
104
|
# File 'lib/gamefic/scene/base.rb', line 102
def on_start(&block)
start_blocks.push block
end
|
.props_class ⇒ Object
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_blocks ⇒ Array<Proc>
89
90
91
|
# File 'lib/gamefic/scene/base.rb', line 89
def start_blocks
@start_blocks ||= []
end
|
.type ⇒ Object
76
77
78
|
# File 'lib/gamefic/scene/base.rb', line 76
def type
'Base'
end
|
Instance Method Details
#finish ⇒ void
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
|
38
39
40
41
|
# File 'lib/gamefic/scene/base.rb', line 38
def start
run_start_blocks
props
end
|
#to_hash ⇒ Object
48
49
50
|
# File 'lib/gamefic/scene/base.rb', line 48
def to_hash
{ name: name, type: type }
end
|
33
34
35
|
# File 'lib/gamefic/scene/base.rb', line 33
def type
self.class.type
end
|