Chapters
A Chapter
is a narrative fragment that can be appended to a Plot
. It’s a useful
way to organize your game code into discrete components.
Chapters share their parent plot’s players
array, but maintain their own scripts,
entities, methods, and instance variables.
A Simple Example
Add a chapter to your project:
# example/introduction.rb
module Example
class Introduction < Chapter
introduction do |actor|
actor.tell %(
This introduction gets added to plots when the chapter is appended.
)
end
end
end
Append it to your plot:
# example/plot.rb
module Example
class Plot < Gamefic::Plot
append Introduction
end
end
Configuring Chapters
module Example
class Plot
construct :alcove, Room, name: 'alcove'
append Parlor, from: alcove
end
class Parlor < Chapter
construct :parlor, Room, name: 'parlor', south: config[:from]
end
end
Accessing the Plot
Use the plot
method to access the parent plot.
In this example, the chapter connects a parlor to the plot’s alcove:
module Example
class Plot
construct :alcove, Room, name: 'alcove'
append Parlor
end
class Parlor < Chapter
construct :parlor, Room, name: 'parlor'
def configure
parlor.connect plot.alcove, direction: 'south'
end
end
end
You can also use the bind_from_plot
method for access to plot methods.
module Example
class Parlor < Chapter
bind_from_plot :alcove
make_seed Room, name: 'parlor', south: alcove
end
end