global
def self.write_system(system_file_path, ini_file_path, other_path, output_path, shuffle_level, romanize, logging)
-
logging
(Boolean
) -- Whether to log -
romanize
(Boolean
) -- If files were read with romanize, this option will romanize original game text to compare -
shuffle_level
(Integer
) -- Level of shuffle -
output_path
(String
) -- -
other_path
(String
) -- -
ini_file_path
(String
) -- -
system_file_path
(String
) --
def self.write_system(system_file_path, ini_file_path, other_path, output_path, shuffle_level, romanize, logging) system_basename = File.basename(system_file_path) # @type [System] system_object = Marshal.load(File.binread(system_file_path)) # @type [Array<String>] system_original_text = File.readlines(File.join(other_path, 'system.txt'), encoding: 'UTF-8', chomp: true).map(&:strip).freeze # @type [Array<String>] system_translated_text = File.readlines(File.join(other_path, 'system_trans.txt'), encoding: 'UTF-8', chomp: true).map(&:strip) if shuffle_level.positive? system_translated_text.shuffle! system_translated_text = shuffle_words(system_translated_text) if shuffle_level == 2 end # @type [Hash{String => String}] system_translation_map = Hash[system_original_text.zip(system_translated_text)].freeze elements = system_object.elements skill_types = system_object.skill_types weapon_types = system_object.weapon_types armor_types = system_object.armor_types currency_unit = system_object.currency_unit terms_vocabulary = system_object.terms || system_object.words arrays = [elements, skill_types, weapon_types, armor_types] attributes = %i[elements skill_types weapon_types armor_types] arrays .zip(attributes) .each do |array, attr| next unless array.is_a?(Array) array.each_with_index do |string, i| string = string.strip next if string.empty? string = convert_to_utf8(string) string = romanize_string(string) if romanize translated = system_translation_map[string] array[i] = translated if translated && !translated.empty? end system_object.send("#{attr}=", array) end if currency_unit currency_unit = romanize_string(currency_unit) if romanize currency_unit_translated = system_translation_map[currency_unit] system_object.currency_unit = currency_unit_translated if currency_unit.is_a?(String) && currency_unit_translated && !currency_unit_translated.empty? end terms_vocabulary.instance_variables.each do |variable| # @type [String | Array<String>] value = terms_vocabulary.instance_variable_get(variable) if value.is_a?(String) value = value.strip next if value.empty? value = convert_to_utf8(value) value = romanize_string(value) if romanize translated = system_translation_map[value] value = translated if translated && !translated.empty? elsif value.is_a?(Array) value.each_with_index do |string, i| string = string.strip next if string.empty? string = convert_to_utf8(string) string = romanize_string(string) if romanize translated = system_translation_map[string] value[i] = translated if translated && !translated.empty? end end terms_vocabulary.instance_variable_set(variable, value) end if !system_object.terms system_object.words = terms_vocabulary else system_object.terms = terms_vocabulary end game_title_translated = system_translated_text.last if game_title_translated && !game_title_translated.empty? system_object.game_title = game_title_translated write_ini_title(ini_file_path, game_title_translated) end File.binwrite(File.join(output_path, system_basename), Marshal.dump(system_object)) puts "Written #{system_basename}" if logging end