lib/gamefic/plot.rb in gamefic-1.5.1 vs lib/gamefic/plot.rb in gamefic-1.6.0

- old
+ new

@@ -1,49 +1,46 @@ # TODO: JSON support is currently experimental. #require 'gamefic/entityloader' -require 'gamefic/stage' require 'gamefic/tester' require 'gamefic/source' require 'gamefic/script' require 'gamefic/query' module Gamefic class Plot - autoload :SceneMount, 'gamefic/plot/scene_mount' - autoload :CommandMount, 'gamefic/plot/command_mount' - autoload :Entities, 'gamefic/plot/entities' - autoload :ArticleMount, 'gamefic/plot/article_mount' - autoload :YouMount, 'gamefic/plot/you_mount' - autoload :Snapshot, 'gamefic/plot/snapshot' - autoload :Host, 'gamefic/plot/host' - autoload :Players, 'gamefic/plot/players' - autoload :Playbook, 'gamefic/plot/playbook' - autoload :Callbacks, 'gamefic/plot/callbacks' + autoload :Scenes, 'gamefic/plot/scenes' + autoload :Commands, 'gamefic/plot/commands' + autoload :Entities, 'gamefic/plot/entities' + autoload :Articles, 'gamefic/plot/articles' + autoload :YouMount, 'gamefic/plot/you_mount' + autoload :Snapshot, 'gamefic/plot/snapshot' + autoload :Host, 'gamefic/plot/host' + autoload :Players, 'gamefic/plot/players' + autoload :Playbook, 'gamefic/plot/playbook' + autoload :Callbacks, 'gamefic/plot/callbacks' + autoload :Theater, 'gamefic/plot/theater' attr_reader :commands, :imported_scripts, :source # TODO: Metadata could use better protection attr_accessor :metadata - include Stage - # @!parse include Gamefic, Tester, Players, SceneMount, CommandMount, Entities - mount Gamefic, Tester, Players, SceneMount, CommandMount, Entities - # @!parse include ArticleMount, YouMount, Snapshot, Host, Callbacks - mount ArticleMount, YouMount, Snapshot, Host, Callbacks - expose :script, :metadata + include Theater + include Gamefic, Tester, Players, Scenes, Commands, Entities + include Articles, YouMount, Snapshot, Host, Callbacks - # @param [Source::Base] + # @param source [Source::Base] def initialize(source = nil) @source = source || Source::Text.new({}) @working_scripts = [] @imported_scripts = [] @running = false - @playbook = Playbook.new post_initialize end + # @return [Gamefic::Plot::Playbook] def playbook - @playbook ||= Playbook.new + @playbook ||= Gamefic::Plot::Playbook.new end def running? @running end @@ -77,11 +74,13 @@ end # Update the Plot's current turn of gameplay. # This method is typically called by the Engine that manages game execution. def update - p_players.each { |p| process_input p } + entities.each { |e| e.flush } + call_before_player_update + p_players.each { |p| p.scene.update } p_entities.each { |e| e.update } call_player_update call_update p_subplots.each { |s| s.update unless s.concluded? } p_subplots.delete_if { |s| s.concluded? } @@ -104,26 +103,21 @@ if imported_script.nil? raise LoadError.new("cannot load script -- #{path}") end if !@working_scripts.include?(imported_script) and !imported_scripts.include?(imported_script) @working_scripts.push imported_script - stage imported_script.read, imported_script.absolute_path + # @hack Arguments need to be in different order if source returns proc + if imported_script.read.kind_of?(Proc) + stage &imported_script.read + else + stage imported_script.read, imported_script.absolute_path + end @working_scripts.pop imported_scripts.push imported_script true else false end - end - - private - - def process_input player - line = player.queue.shift - if !line.nil? - player.scene.finish player, line - end - end - + end end end