class TyranoDsl::ExportGame::Writer

Write the content that have been parsed

Public Class Methods

new() click to toggle source
# File lib/tyrano_dsl/export_game/writer.rb, line 15
def initialize
  @logger = Logger.new(STDOUT)
  @words = {}
  TyranoDsl::Vocabulary.get_words_class('export_game/writing_words') do |word, word_class|
    @words[word] = word_class.new
  end
end

Public Instance Methods

write(world, parsed_words) click to toggle source

@param [TyranoDsl::Elements::World] world @param [Array<TyranoDsl::ParsedWord>] parsed_words @return [TyranoDsl::ExportGame::WritingContext] @raise [TyranoDsl::TyranoException]

# File lib/tyrano_dsl/export_game/writer.rb, line 27
def write(world, parsed_words)
  log {'Writing content'}
  writing_context = TyranoDsl::ExportGame::WritingContext.new(world)
  write_title_screen(writing_context, world)
  write_backgrounds(writing_context, world)
  write_characters(writing_context, world)
  write_scenes(writing_context, world, parsed_words)
  write_variables(writing_context, world)
  writing_context.end_writing
  log {'Content written'}
  writing_context
end

Private Instance Methods

concat_file_actions(writing_context, file_actions) click to toggle source

@param [TyranoDsl::ExportGame::WritingContext] writing_context @param [Array] file_actions @return [void]

# File lib/tyrano_dsl/export_game/writer.rb, line 89
def concat_file_actions(writing_context, file_actions)
  writing_context.file_actions.concat(file_actions)
end
log() { || ... } click to toggle source
# File lib/tyrano_dsl/export_game/writer.rb, line 110
def log
  @logger.info(self.class) {yield}
end
write_backgrounds(writing_context, world) click to toggle source

@param [TyranoDsl::ExportGame::WritingContext] writing_context @param [TyranoDsl::Elements::World] world @return [void] @raise [TyranoDsl::TyranoException]

# File lib/tyrano_dsl/export_game/writer.rb, line 69
def write_backgrounds(writing_context, world)
  background_writer = TyranoDsl::ExportGame::ElementsWriters::BackgroundWriter.new
  concat_file_actions(writing_context, background_writer.init_actions)
  world.backgrounds.each_value do |background|
    concat_file_actions(writing_context, background_writer.write(background))
  end
end
write_characters(writing_context, world) click to toggle source

@param [TyranoDsl::ExportGame::WritingContext] writing_context @param [TyranoDsl::Elements::World] world @return [void] @raise [TyranoDsl::TyranoException]

# File lib/tyrano_dsl/export_game/writer.rb, line 55
def write_characters(writing_context, world)
  character_writer = TyranoDsl::ExportGame::ElementsWriters::CharacterWriter.new
  concat_file_actions(writing_context, character_writer.init_actions)
  world.characters.each_value do |character|
    concat_file_actions(writing_context, character_writer.write(character))
  end
  characters_writer = TyranoDsl::ExportGame::ElementsWriters::CharactersWriter.new
  concat_file_actions(writing_context, characters_writer.write(world))
end
write_scenes(writing_context, world, parsed_words) click to toggle source

@param [TyranoDsl::ExportGame::WritingContext] writing_context @param [Array<TyranoDsl::ParsedWord>] parsed_words @param [TyranoDsl::Elements::World] world @return [void] @raise [TyranoDsl::TyranoException]

# File lib/tyrano_dsl/export_game/writer.rb, line 98
def write_scenes(writing_context, world, parsed_words)
  parsed_words.each do |parsed_word|
    action_word = @words[parsed_word.word]
    action_word.run(
        writing_context,
        world,
        parsed_word.word_location,
        parsed_word.parameters
    )
  end
end
write_title_screen(writing_context, world) click to toggle source

@param [TyranoDsl::ExportGame::WritingContext] writing_context @param [TyranoDsl::Elements::World] world @return [void] @raise [TyranoDsl::TyranoException]

# File lib/tyrano_dsl/export_game/writer.rb, line 46
def write_title_screen(writing_context, world)
  title_screen_writer = TyranoDsl::ExportGame::ElementsWriters::TitleScreenWriter.new
  concat_file_actions(writing_context, title_screen_writer.write(world))
end
write_variables(writing_context, world) click to toggle source

@param [TyranoDsl::ExportGame::WritingContext] writing_context @param [TyranoDsl::Elements::World] world @return [void] @raise [TyranoDsl::TyranoException]

# File lib/tyrano_dsl/export_game/writer.rb, line 81
def write_variables(writing_context, world)
  variables_writer = TyranoDsl::ExportGame::ElementsWriters::VariablesWriter.new
  concat_file_actions(writing_context, variables_writer.write(world))
end