Class: TyranoDsl::ElementsWriters::CharactersWriter

Inherits:
Object
  • Object
show all
Includes:
ElementsWritersModule
Defined in:
lib/tyrano_dsl/elements_writers/characters_writer.rb

Overview

Write things where all characters are implied

Instance Method Summary collapse

Instance Method Details

#write(world) ⇒ Array

Parameters:

Returns:

  • (Array)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/tyrano_dsl/elements_writers/characters_writer.rb', line 12

def write(world)
  log {'Writing characters'}
  chara_define_content = ''
  world.characters.values.collect do |character|
    chara_define_content << "[chara_new name=\"#{character.name}\" jname=\"#{character.name}\" storage=\"chara\/#{character.default_stance.short_target_file_name}\"]\n"
  end
  chara_define_content << "\n"
  chara_define_content << "[iscript]\n"
  world.variables.values.collect do |variable|
    chara_define_content << "f['#{variable.target_name}']=#{variable.initial_value};\n"
  end
  chara_define_content << "[endscript]\n"

  builder_config_content = {}
  world.characters.values.each do |character|
    builder_config_content[character.name] = character.index
  end

  [
      TyranoDsl::FileActions::CreateFile.new(
          File.join('data', 'scenario', 'system', 'chara_define.ks'),
          chara_define_content
      ),
      TyranoDsl::FileActions::JsonPatch.new(
          'builder_config.json',
          ['map_chara'],
          builder_config_content
      )
  ]
end