lib/gamefic/plot.rb in gamefic-0.6.1 vs lib/gamefic/plot.rb in gamefic-1.0.0
- old
+ new
@@ -3,50 +3,65 @@
require 'gamefic/stage'
require 'gamefic/tester'
require 'gamefic/source'
require 'gamefic/script'
require 'gamefic/query'
-require 'gamefic/plot/article_mount'
-require 'gamefic/plot/you_mount'
module Gamefic
class Plot
autoload :SceneMount, 'gamefic/plot/scene_mount'
autoload :CommandMount, 'gamefic/plot/command_mount'
autoload :EntityMount, 'gamefic/plot/entity_mount'
autoload :QueryMount, 'gamefic/plot/query_mount'
- #autoload :ArticleMount, 'gamefic/plot/article_mount'
- #autoload :YouMount, 'gamefic/plot/you_mount'
+ autoload :ArticleMount, 'gamefic/plot/article_mount'
+ autoload :YouMount, 'gamefic/plot/you_mount'
+ autoload :Snapshot, 'gamefic/plot/snapshot'
+
attr_reader :commands, :imported_scripts, :rules, :asserts, :source
- attr_accessor :default_scene
+ # TODO Metadata could use better protection
+ attr_accessor :default_scene, :metadata
include Stage
# TODO This include is only here to make the module's methods visible in the IDE.
# Gamefic Studio has a PlotStageMetaMapper that handles it, but it doesn't run if
# the plugin isn't activated.
- include Gamefic, Tester, SceneMount, CommandMount, EntityMount, QueryMount, ArticleMount, YouMount
- mount Gamefic, Tester, SceneMount, CommandMount, EntityMount, QueryMount, ArticleMount, YouMount
- expose :script, :introduction, :assert_action, :on_update, :on_player_update, :entities, :on_ready, :on_player_ready, :players
+ #include Gamefic, Tester, SceneMount, CommandMount, EntityMount, QueryMount, ArticleMount, YouMount, Snapshot
+ mount Gamefic, Tester, SceneMount, CommandMount, EntityMount, QueryMount, ArticleMount, YouMount, Snapshot
+ expose :script, :introduction, :assert_action, :before_player_update, :on_update, :on_player_update, :entities, :on_ready, :on_player_ready, :players, :scenes, :metadata
# @param [Source::Base]
def initialize(source = nil)
@source = source || Source::Text.new({})
- @commands = Hash.new
- @syntaxes = Array.new
- @ready_procs = Array.new
- @update_procs = Array.new
- @player_ready = Array.new
- @player_procs = Array.new
- @working_scripts = Array.new
- @imported_scripts = Array.new
- @entities = Array.new
- @players = Array.new
- @asserts = Hash.new
+ @commands = {}
+ @syntaxes = []
+ @ready_procs = []
+ @before_player_update_procs = []
+ @update_procs = []
+ @player_ready = []
+ @player_procs = []
+ @working_scripts = []
+ @imported_scripts = []
+ @entities = []
+ @players = []
+ @asserts = {}
@default_scene = :active
post_initialize
end
+
+ def scenes
+ if @scenes.nil?
+ @scenes = {}
+ @scenes[:active] = Scene::Active.new
+ @scenes[:concluded] = Scene::Conclusion.new
+ end
+ @scenes
+ end
+ def concluded?(actor)
+ scenes[actor.scene].kind_of?(Scene::Conclusion)
+ end
+
# Get an Array of all Actions defined in the Plot.
#
# @return Array[Action]
def actions
@commands.values.flatten
@@ -156,11 +171,11 @@
end
# TODO: There should probably be a default state specified
# by the plot, which would be :active by default. We could
# get it like player.cue nil.
if player.scene.nil?
- cue player, default_scene
+ player.cue :active
ready
update
end
end
@@ -173,27 +188,36 @@
# Prepare player scenes for the update.
@players.each { |player|
@player_ready.each { |block|
block.call player
}
- player.scene.start player
}
end
# Update the Plot's current turn of gameplay.
# This method is typically called by the Engine that manages game execution.
def update
# Update the plot.
@players.each { |player|
- process_input player
+ # TODO: This really doesn't belong here. We need a before_update in the plot.
+ @before_player_update_procs.each { |p|
+ p.call player
+ }
+ this_scene = player.next_scene || player.scene
+ player.prepare nil
+ if this_scene != player.scene
+ player.cue this_scene
+ player.queue.shift
+ else
+ process_input player
+ end
}
@entities.each { |e|
e.update
}
@players.each { |player|
update_player player
- cue player, player.scene.data.next_cue if !player.scene.data.next_cue.nil?
}
@update_procs.each { |p|
p.call
}
end
@@ -240,25 +264,28 @@
# @yieldparam [Character]
def on_player_update &block
@player_procs.push block
end
+ # Add a block to be executed for each player before the turn's update is
+ # performed.
+ #
+ # @yieldparam [Character]
+ def before_player_update &block
+ @before_player_update_procs.push block
+ end
+
private
def process_input player
line = player.queue.shift
if !line.nil?
- player.scene.finish player, line
- #cue player, player.scene.data.next_cue if !player.scene.data.next_cue.nil?
+ scenes[player.scene].finish player, line
end
end
def update_player player
@player_procs.each { |proc|
proc.call player
}
- # HACK Exception for running tests
- if player[:testing] == true
- cue player, :test
- end
end
def rem_entity(entity)
@entities.delete(entity)
end
def recursive_update(entity)