lib/gamefic/chapter.rb in gamefic-3.4.0 vs lib/gamefic/chapter.rb in gamefic-3.5.0
- old
+ new
@@ -4,85 +4,68 @@
# Chapters are plot extensions that manage their own namespaces. Authors can
# use them to encapsulate related content in a separate object instead of
# adding the required instance variables, methods, and attributes to the
# plot.
#
- # Chapters are similar to subplots with a few important exceptions:
- # * Chapters persist for the duration of the plot.
+ # Chapters are similar to subplots with three important exceptions:
+ # * Chapters normally persist for the duration of a plot.
# * Players do not need to be introduced to a chapter.
- # * Scripts in chapters apply to the parent plot's rulebook.
- # * Using `make` to create an entity in a chapter adds it to the parent
- # plot's entity list.
+ # * Chapters share their plot's entities, players, and rulebook.
#
# @example
# class MyChapter < Gamefic::Chapter
- # seed do
- # @thing = make Gamefic::Entity, name: 'chapter thing'
+ # def thing
+ # @thing ||= make Gamefic::Entity, name: 'chapter thing'
# end
# end
#
# class MyPlot < Gamefic::Plot
# append MyChapter
# end
#
# plot = MyPlot.new
- # plot.entities #=> [<#Gamefic::Entity a chapter thing>]
- # plot.instance_exec { @thing } #=> nil
+ # plot.entities #=> [<#Gamefic::Entity a chapter thing>]
+ # plot.thing # raises NoMethodError
+ # plot.chapters.first.thing #=> <#Gamefic::Entity a chapter thing>
#
- class Chapter
- extend Scriptable
+ class Chapter < Narrative
+ extend Scriptable::PlotProxies
- include Scriptable::Actions
- include Scriptable::Events
- include Scriptable::Proxy
- include Scriptable::Queries
- include Scriptable::Scenes
-
# @return [Plot]
attr_reader :plot
# @param plot [Plot]
- def initialize plot
+ def initialize(plot)
@plot = plot
+ # The plot is responsible for hydrating chapters
+ super(hydrate: false)
end
- def included_blocks
- self.class.included_blocks - plot.included_blocks
- end
-
- def seed
- included_blocks.select(&:seed?).each { |blk| Stage.run self, &blk.code }
- end
-
def script
included_blocks.select(&:script?).each { |blk| Stage.run self, &blk.code }
end
+ def included_blocks
+ self.class.included_blocks - plot.included_blocks
+ end
+
def rulebook
plot.rulebook
end
- def make klass, **opts
- plot.make klass, **opts
+ def entity_vault
+ plot.entity_vault
end
- def entities
- plot.entities
+ def player_vault
+ plot.player_vault
end
- def players
- plot.players
+ def subplots
+ plot.subplots
end
- def destroy entity
- plot.destroy entity
- end
-
- def pick description
- plot.pick description
- end
-
- def pick! description
- plot.pick! description
+ def branch(...)
+ plot.branch(...)
end
end
end