class TyranoDsl::ExportGame::WritingContext
Context for writing
Attributes
@return [Array<String>]
@return [Array<String>]
@return [Hash{String => Object}]
@return [TyranoDsl::Elements::World]
Public Class Methods
@param [TyranoDsl::Elements::World] world
# File lib/tyrano_dsl/export_game/writing_context.rb, line 21 def initialize(world) @logger = Logger.new(STDOUT) @world = world @file_actions = [] @current_scene_content = nil @current_scene_name = nil @current_scene_assets = nil @current_scene_labels = nil @scene_writer = TyranoDsl::ExportGame::ElementsWriters::SceneWriter.new end
Public Instance Methods
Add an asset to be loaded in the current scene
@param [Array<String>] word_location @param [String] asset_content @return [void] @raise [TyranoDsl::TyranoException]
# File lib/tyrano_dsl/export_game/writing_context.rb, line 49 def add_asset_loading(word_location, asset_content) check_in_scene(word_location) @current_scene_assets << asset_content end
Add an label in the current scene
@param [Array<String>] word_location @param [String] label_name @return [void] @raise [TyranoDsl::TyranoException]
# File lib/tyrano_dsl/export_game/writing_context.rb, line 60 def add_label(word_location, label_name) check_in_scene(word_location) if @current_scene_labels.include? label_name raise TyranoDsl::TyranoException, "Duplicated label [#{label_name}]" end @current_scene_labels << label_name end
Append some content to the current scene
@param [Array<String>] word_location @param [Array<String>] content @return [void] @raise [TyranoDsl::TyranoException]
# File lib/tyrano_dsl/export_game/writing_context.rb, line 38 def append_content(word_location, content) check_in_scene(word_location) @current_scene_content << content end
Bookkeeping stuff to end the writing @raise [TyranoDsl::TyranoException] @return [void]
# File lib/tyrano_dsl/export_game/writing_context.rb, line 82 def end_writing write_current_scene @current_scene_content = nil @current_scene_name = nil @current_scene_assets = nil @current_scene_labels = nil @world.validate log {"Writing is over, #{@file_actions.length} actions created"} end
Initialize a new scene @param [String] scene_name the scene name @return [void]
# File lib/tyrano_dsl/export_game/writing_context.rb, line 71 def init_new_scene(scene_name) write_current_scene @current_scene_content = [] @current_scene_name = scene_name @current_scene_assets = Set.new @current_scene_labels = [] end
Private Instance Methods
@param [Array<String>] word_location @return [void] @raise [TyranoDsl::TyranoException]
# File lib/tyrano_dsl/export_game/writing_context.rb, line 115 def check_in_scene(word_location) unless @current_scene_content exception = TyranoDsl::TyranoException.new('This action should take place in a scene') exception.set_backtrace word_location raise exception end end
# File lib/tyrano_dsl/export_game/writing_context.rb, line 108 def log @logger.info(self.class) {yield} end
# File lib/tyrano_dsl/export_game/writing_context.rb, line 94 def write_current_scene if @current_scene_name current_scene = @world.scenes[@current_scene_name] @file_actions.concat @scene_writer.write( current_scene, @current_scene_content, @current_scene_assets ) @current_scene_labels.each do |label| current_scene.labels << label end end end