rvpacker-txt 1.8.5 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4be9adddaac27a84654c48292e0fa8949daf9b48a6b97520585e5bc9678c4593
4
- data.tar.gz: a108f9445ec1e2151c39eeda9f262c2505e763efbbc790b8c7a788bf9ffdd1bf
3
+ metadata.gz: ea9153be0a603a97b9e717c2406e5ca7dd650973b6905d2189fa9025fce0e596
4
+ data.tar.gz: 4505485e158a91d4f57d81da8ef5faf19ae74d152dae5da99d6f7fa3cd28401d
5
5
  SHA512:
6
- metadata.gz: 318bedbdef111ee55225cb8cc71c5cb9f0751c186daa314722f6f09900e69ee2ffaedf11850185d484189c7879630c900d19a586dad6b0c948daa023991c8d45
7
- data.tar.gz: ffb4a43103686e875a3de87964c53f2d7ae81b1d64f06433164992bc25a7f31a603837a8358a8e33b7b84be9fb3343e4690f5f9c901d1c50cfbe9c3192bdc243
6
+ metadata.gz: b2b12ddb9a56f214daa46f8e4f47186ce44336713a98fbeebc279c9c8616f99c042100ff5be3d28cad99f35624cc52849a7abffbe68e19714e2454d211039df9
7
+ data.tar.gz: b2d1b0bdb6e74e68a26591fb11b06eb4ef964122a2bc251e36b0be40dbec24e8153fbbca0b15bfe7c56bad96377c489fe556cc0332311aa22ac5d94168d91447
data/README.md CHANGED
@@ -21,26 +21,27 @@ You can get a help message on usage using `rvpacker-txt -h`.
21
21
 
22
22
  ```
23
23
  $ rvpacker-txt -h
24
- This tool allows to parse RPG Maker project to .txt files and back.
24
+ This tool allows to parse RPG Maker games to .txt files and write them back to their initial form.
25
25
 
26
- Usage: rvpacker-txt COMMAND [options]
26
+ Usage: rvpacker-txt COMMAND [OPTIONS]
27
27
 
28
28
  COMMANDS:
29
- read - Parses RPG Maker game files to .txt
30
- write - Writes parsed files back to their initial form
29
+ read - Parses files from "original" or "data" folders of input directory to "translation" folder of output directory.
30
+ write - Writes translated files using original files from "original" or "data" folder of input directory and writes results to "output" folder of output directory.
31
31
  OPTIONS:
32
- -i, --input-dir DIR Input directory of RPG Maker project
33
- -o, --output-dir DIR Output directory of parsed/written files
34
- --disable-processing FILES Don't process specified files (maps, other, system, scripts)
35
- -s, --shuffle NUM Shuffle level (1: lines, 2: lines and words)
36
- --disable-custom-processing Disables built-in custom parsing/writing for some games
37
- -l, --log Log information while processing
38
- -f, --force Force rewrite all files. Cannot be used with --append
39
- USE WITH CAUTION!
40
- -a, --append When you update the rvpacker-txt, you probably should re-read
41
- your files with append, as some new text might be added to parser
42
- Cannot be used with --force
43
- -h, --help Show help message
32
+ -i, --input-dir PATH When reading: Input directory, containing folders "original" or "data" with original game files.
33
+ When writing: Input directory, containing folders "original" or "data" and "translation" with original game files and .txt files with translation respectively.
34
+ -o, --output-dir PATH When reading: Output directory, where a "translation" folder will be created, containing parsed .txt files with the text from the game.
35
+ When writing: Output directory, where an "output" folder will be created, containing compiled RPG Maker files with your translation.
36
+ --disable-processing FILES Skips processing specified files.
37
+ Example: --disable-processing=maps,other,system.
38
+ [Allowed values: maps, other, system, scripts]
39
+ --disable-custom-processing Disables built-in custom parsing/writing for some games.
40
+ -r, --romanize When reading: If you parsing text from a Japanese game, that contains symbols like 「」,
41
+ which are just the Japanese quotation marks, it automatically replaces these symbols by their roman equivalents.
42
+ When writing: Use to correctly write files back if you have parsed them with --romanize flag.
43
+ -l, --log Enables logging.
44
+ -h, --help Prints the program's help message or for the entered subcommand.
44
45
  ```
45
46
 
46
47
  For example, to read a RPG Maker VX Ace project in E:/Documents/RPGMakerGame to .txt files:
data/bin/rvpacker-txt CHANGED
@@ -7,28 +7,79 @@ require 'fileutils'
7
7
  require 'classes'
8
8
 
9
9
  def self.parse_options
10
- options = { disable_processing: {}, input_dir: './', output_dir: './', shuffle_level: 0 }
10
+ options = { action: nil,
11
+ input_path: './',
12
+ output_path: './',
13
+ disable_processing: {
14
+ maps: false,
15
+ other: false,
16
+ system: false,
17
+ scripts: false
18
+ },
19
+ disable_custom_processing: false,
20
+ romanize: false,
21
+ logging: false,
22
+ force: false,
23
+ append: false,
24
+ shuffle_level: 0 }
25
+
26
+ options[:action] = ARGV[0]
27
+
28
+ unless %w[read write].include?(options[:action])
29
+ if %w[-h --help].include?(options[:action])
30
+ options[:action] = 'none'
31
+ elsif options[:action].nil?
32
+ raise 'COMMAND argument is required. Use rvpacker-txt -h for help.'
33
+ else
34
+ raise 'Invalid command. Allowed commands: read, write.'
35
+ end
36
+ end
11
37
 
12
38
  read_command_description = 'Parses files from "original" or "data" folders of input directory to "translation" folder of output directory.'
13
39
  write_command_description = 'Writes translated files using original files from "original" or "data" folder of input directory and writes results to "output" folder of output directory.'
14
- banner_text = "This tool allows to parse RPG Maker games to .txt files and write them back to their initial form.\n\nUsage: rvpacker-txt COMMAND [options]\n\nCOMMANDS:\n read - #{read_command_description}\n write - #{write_command_description}\nOPTIONS:\n"
40
+ banner_text = "This tool allows to parse RPG Maker games to .txt files and write them back to their initial form.\n\nUsage: rvpacker-txt COMMAND [OPTIONS]\n\nCOMMANDS:\n read - #{read_command_description}\n write - #{write_command_description}\nOPTIONS:"
41
+
42
+ banner,
43
+ input_dir_description,
44
+ output_dir_description,
45
+ romanize_description =
46
+ case options[:action]
47
+ when 'read'
48
+ ["#{read_command_description}\n\nOPTIONS:\n",
49
+ ['Input directory, containing folders "original" or "data" with original game files.'],
50
+ ['Output directory, where a "translation" folder will be created, containing parsed .txt files with the text from the game.'],
51
+ ['If you parsing text from a Japanese game, that contains symbols like 「」, which are just the Japanese quotation marks,',
52
+ 'it automatically replaces these symbols by their roman equivalents.']]
53
+ when 'write'
54
+ ["#{write_command_description}\n\nOPTIONS:\n",
55
+ ['Input directory, containing folders "original" or "data" and "translation" with original game files and .txt files with translation respectively.'],
56
+ ['Output directory, where an "output" folder will be created, containing compiled RPG Maker files with your translation.'],
57
+ ['Use to correctly write files back if you have parsed them with --romanize flag.']]
58
+ else
59
+ [banner_text,
60
+ ['When reading: Input directory, containing folders "original" or "data" with original game files.',
61
+ 'When writing: Input directory, containing folders "original" or "data" and "translation" with original game files and .txt files with translation respectively.'],
62
+ ['When reading: Output directory, where a "translation" folder will be created, containing parsed .txt files with the text from the game.',
63
+ 'When writing: Output directory, where an "output" folder will be created, containing compiled RPG Maker files with your translation.'],
64
+ ['When reading: If you parsing text from a Japanese game, that contains symbols like 「」,',
65
+ 'which are just the Japanese quotation marks, it automatically replaces these symbols by their roman equivalents.',
66
+ 'When writing: Use to correctly write files back if you have parsed them with --romanize flag.']]
67
+ end
15
68
 
16
- OptionParser.new(banner_text) do |cmd|
69
+ OptionParser.new(banner) do |cmd|
17
70
  cmd.on('-i', '--input-dir PATH', String,
18
- 'When reading: Input directory, containing folders "original" or "data" with original game files.',
19
- 'When writing: Input directory, containing folders "original" or "data" and "translation" with original game files and .txt files with translation respectively.') do |dir|
20
- options[:input_dir] = File.exist?(dir) ? File.realpath(dir) : (raise "#{dir} not found")
21
- options[:output_dir] = options[:input_dir]
71
+ *input_dir_description) do |dir|
72
+ options[:input_path] = File.exist?(dir) ? File.realpath(dir) : (raise "#{dir} not found")
73
+ options[:output_path] = options[:input_path]
22
74
  end
23
75
 
24
76
  cmd.on('-o', '--output-dir PATH', String,
25
- 'When reading: Output directory, where an "output" folder will be created, containing compiled RPG Maker files with your translation.',
26
- 'When writing: Output directory, where a "translation" folder will be created, containing parsed .txt files with the text from the game.') do |dir|
27
- options[:output_dir] = File.exist?(dir) ? File.realpath(dir) : (raise "#{dir} not found")
77
+ *output_dir_description) do |dir|
78
+ options[:output_path] = File.exist?(dir) ? File.realpath(dir) : (raise "#{dir} not found")
28
79
  end
29
80
 
30
81
  cmd.on('--disable-processing FILES', Array,
31
- 'Skips processing the specified files.',
82
+ 'Skips processing specified files.',
32
83
  'Example: --disable-processing=maps,other,system.',
33
84
  '[Allowed values: maps, other, system, scripts]') do |files|
34
85
  files.each do |file|
@@ -38,50 +89,51 @@ def self.parse_options
38
89
  end
39
90
  end
40
91
 
41
- cmd.on('-s', '--shuffle-level NUMBER', Integer,
42
- 'With value 1, shuffles all translation lines. With value 2, shuffles all words and lines in translation text.',
43
- 'Example: --shuffle-level 1.',
44
- '[Allowed values: 0, 1, 2]',
45
- '[Default value: 0]',
46
- '[Write flag]') do |num|
47
- raise 'Allowed values: 0, 1, 2' if num > 2
48
- options[:shuffle_level] = num
49
- end
50
-
51
- cmd.on('--disable-custom-processing', 'Disables built-in custom parsing/writing for some games.') do
92
+ cmd.on('--disable-custom-processing',
93
+ 'Disables built-in custom parsing/writing for some games.') do
52
94
  options[:disable_custom_processing] = true
53
95
  end
54
96
 
55
- cmd.on('-l', '--log', 'Enables logging.') do
56
- options[:logging] = true
97
+ cmd.on('-r', '--romanize',
98
+ *romanize_description) do
99
+ options[:romanize] = true
57
100
  end
58
101
 
59
- cmd.on('-f', '--force',
60
- 'Force rewrite all files. Cannot be used with --append.',
61
- 'USE WITH CAUTION!',
62
- '[Read flag]') do
63
- options[:force] = true
102
+ if options[:action] == 'read'
103
+ cmd.on('-f', '--force',
104
+ 'Force rewrite all files. Cannot be used with --append.',
105
+ 'USE WITH CAUTION!') do
106
+ options[:force] = true
107
+ end
108
+
109
+ cmd.on('-a', '--append',
110
+ "When the rvpacker-txt or the game which files you've parsed receives an update, you probably should re-read game files with --append,",
111
+ ' which will append any new text to your files without overwriting the progress.',
112
+ 'Cannot be used with --force.') do
113
+ raise '--append cannot be used with --force.' if options[:force]
114
+ options[:append] = true
115
+ end
116
+ elsif options[:action] == 'write'
117
+ cmd.on('-s', '--shuffle-level NUMBER', Integer,
118
+ 'With value 1, shuffles all translation lines. With value 2, shuffles all words and lines in translation text.',
119
+ 'Example: --shuffle-level 1.',
120
+ '[Allowed values: 0, 1, 2]',
121
+ '[Default value: 0]') do |num|
122
+ raise 'Allowed values: 0, 1, 2.' if num > 2
123
+ options[:shuffle_level] = num
124
+ end
64
125
  end
65
126
 
66
- cmd.on('-a', '--append',
67
- "When the rvpacker-txt or the game which files you've parsed receives an update,",
68
- 'you probably should re-read game files with --append, which will append any new text to your files without overwriting the progress',
69
- 'Cannot be used with --force',
70
- '[Read flag]') do
71
- raise '--append cannot be used with --force.' if options[:force]
72
- options[:append] = true
127
+ cmd.on('-l', '--log', 'Enables logging.') do
128
+ options[:logging] = true
73
129
  end
74
130
 
75
- cmd.on('-h', '--help', 'Show help message') do
131
+ cmd.on('-h', '--help', "Prints the program's help message or for the entered subcommand.") do
76
132
  puts cmd
77
133
  exit
78
134
  end
79
135
  end.parse!
80
136
 
81
- options[:action] = ARGV.shift
82
- raise 'COMMAND argument is required. Use rvpacker-txt -h for help.' if options[:action].nil?
83
- raise 'Invalid command. Allowed commands are: read, write.' unless %w[read write].include?(options[:action])
84
-
85
137
  options
86
138
  end
87
139
 
@@ -89,34 +141,44 @@ end
89
141
  # @return [String, nil]
90
142
  def self.get_game_type(system_file_path)
91
143
  object = Marshal.load(File.binread(system_file_path))
92
- game_title = object.instance_variable_get(:@game_title).to_s.downcase
144
+ game_title = object.game_title.to_s.downcase
93
145
  game_title.include?('lisa') ? 'lisa' : nil
94
146
  end
95
147
 
96
148
  start_time = Time.now
97
149
 
98
150
  options = parse_options
99
- input_dir = options[:input_dir]
100
- output_dir = options[:output_dir]
151
+ # @type [String]
152
+ input_path = options[:input_path]
153
+ # @type [String]
154
+ output_path = options[:output_path]
155
+ # @type [Boolean]
101
156
  disable_custom_processing = options[:disable_custom_processing]
157
+ # @type [Integer]
102
158
  shuffle_level = options[:shuffle_level]
159
+ # @type [Boolean]
103
160
  logging = options[:logging]
161
+ # @type [Hash{Symbol => Boolean}]
104
162
  disable_processing = options[:disable_processing]
163
+ # @type [Boolean]
105
164
  force = options[:force]
165
+ # @type [Boolean]
106
166
  append = options[:append]
167
+ # @type [Boolean]
168
+ romanize = options[:romanize]
107
169
 
108
170
  extensions = { xp: 'rxdata', vx: 'rvdata', ace: 'rvdata2' }
109
171
 
110
- original_directory = Dir.glob(File.join(input_dir, '{data,original}'), File::FNM_CASEFOLD).first
172
+ original_directory = Dir.glob(File.join(input_path, '{data,original}'), File::FNM_CASEFOLD).first
111
173
  raise '"Data" or "original" directory not found within input directory.' unless original_directory
112
174
 
113
- maps_path = File.join(input_dir, 'translation', 'maps')
114
- other_path = File.join(input_dir, 'translation', 'other')
175
+ maps_path = File.join(input_path, 'translation', 'maps')
176
+ other_path = File.join(input_path, 'translation', 'other')
115
177
 
116
178
  FileUtils.mkdir_p(maps_path)
117
179
  FileUtils.mkdir_p(other_path)
118
180
 
119
- engine = extensions.each { |sym, ext| break sym if File.exist?(File.join(original_directory, "System.#{ext}")) } ||
181
+ engine = extensions.each_pair { |sym, ext| break sym if File.exist?(File.join(original_directory, "System.#{ext}")) } ||
120
182
  (raise "Couldn't determine project engine.")
121
183
 
122
184
  files = Dir.glob("#{original_directory}/*#{extensions[engine]}")
@@ -141,45 +203,47 @@ files.each do |file|
141
203
  end
142
204
  end
143
205
 
144
- ini_file_path = File.join(input_dir, 'Game.ini')
206
+ ini_file_path = File.join(input_path, 'Game.ini')
145
207
 
146
208
  game_type = disable_custom_processing ? nil : get_game_type(system_file_path)
147
209
 
148
- wait_time = 0
149
- processing_type = if force
150
- wait_time_start = Time.now
151
-
152
- puts "WARNING! You're about to forcefully rewrite all your translation files, including _trans files.",
153
- "If you really want to do it, make sure you've made a backup of your _trans files, if you made some changes in them already.",
154
- "Input 'Y' to continue."
155
- exit unless gets.chomp == 'Y'
156
-
157
- wait_time = Time.now - wait_time_start
158
- :force
159
- else
160
- append ? :append : :default
161
- end
162
-
163
210
  puts 'Custom processing for this game is enabled. Use --disable-custom-processing to disable it.' unless game_type.nil?
164
211
 
212
+ $wait_time = 0
213
+
165
214
  if options[:action] == 'read'
166
215
  require 'read'
167
- read_map(maps_files_paths, maps_path, logging, game_type, processing_type) unless disable_processing[:maps]
168
- read_other(other_files_paths, other_path, logging, game_type, processing_type) unless disable_processing[:other]
169
- read_system(system_file_path, ini_file_path, other_path, logging, processing_type) unless disable_processing[:system]
170
- read_scripts(scripts_file_path, other_path, logging, processing_type) unless disable_processing[:scripts]
216
+
217
+ processing_mode = if force
218
+ wait_time_start = Time.now
219
+
220
+ puts "WARNING! You're about to forcefully rewrite all your translation files, including _trans files.",
221
+ "If you really want to do it, make sure you've made a backup of your _trans files, if you made some changes in them already.",
222
+ "Input 'Y' to continue."
223
+ exit unless $stdin.gets.chomp == 'Y'
224
+
225
+ $wait_time += Time.now - wait_time_start
226
+ :force
227
+ elsif append
228
+ :append
229
+ else
230
+ :default
231
+ end
232
+
233
+ read_map(maps_files_paths, maps_path, romanize, logging, game_type, processing_mode) unless disable_processing[:maps]
234
+ read_other(other_files_paths, other_path, romanize, logging, game_type, processing_mode) unless disable_processing[:other]
235
+ read_system(system_file_path, ini_file_path, other_path, romanize, logging, processing_mode) unless disable_processing[:system]
236
+ read_scripts(scripts_file_path, other_path, romanize, logging, processing_mode) unless disable_processing[:scripts]
171
237
  else
172
238
  require 'write'
173
- output_path = File.join(output_dir, 'output')
239
+
240
+ output_path = File.join(output_path, 'output')
174
241
  FileUtils.mkdir_p(output_path)
175
242
 
176
- write_map(maps_files_paths, maps_path, output_path, shuffle_level, logging, game_type) unless disable_processing[:maps]
177
- write_other(other_files_paths, other_path, output_path, shuffle_level, logging, game_type) unless disable_processing[:other]
178
- write_system(system_file_path, ini_file_path, other_path, output_path, shuffle_level, logging) unless disable_processing[:system]
179
- write_scripts(scripts_file_path, other_path, output_path, logging) unless disable_processing[:scripts]
243
+ write_map(maps_files_paths, maps_path, output_path, shuffle_level, romanize, logging, game_type) unless disable_processing[:maps]
244
+ write_other(other_files_paths, other_path, output_path, shuffle_level, romanize, logging, game_type) unless disable_processing[:other]
245
+ write_system(system_file_path, ini_file_path, other_path, output_path, shuffle_level, romanize, logging) unless disable_processing[:system]
246
+ write_scripts(scripts_file_path, other_path, output_path, romanize, logging) unless disable_processing[:scripts]
180
247
  end
181
248
 
182
- $wait_time = 0 if $wait_time.nil?
183
- elapsed_time = Time.now - start_time - wait_time - $wait_time
184
-
185
- puts "Done in #{elapsed_time}"
249
+ puts "Done in #{Time.now - start_time - $wait_time}"
data/lib/classes.rb CHANGED
@@ -83,7 +83,7 @@ class IndexSet
83
83
 
84
84
  def add(item)
85
85
  return if @hash.include?(item)
86
- @hash[item] = hash.size
86
+ @hash[item] = @hash.size
87
87
  @hash
88
88
  end
89
89
 
@@ -188,7 +188,9 @@ module RGSS
188
188
  end
189
189
  end
190
190
 
191
- classes_nested_array = [
191
+ # All used Ruby classes inside RPG Maker XP, VX, VX Ace games, that must be initialized to properly
192
+ # Marshal.load() files from these games
193
+ CLASSES_NESTED_ARRAY = [
192
194
  # RGSS data structures
193
195
  %i[RPG Actor],
194
196
  %i[RPG Animation],
@@ -239,7 +241,7 @@ module RGSS
239
241
  %i[RPG Weapon]
240
242
  ].freeze
241
243
 
242
- classes_nested_array.each do |symbol_array|
244
+ CLASSES_NESTED_ARRAY.each do |symbol_array|
243
245
  process(Object, *symbol_array)
244
246
  end
245
247
  end
data/lib/read.rb CHANGED
@@ -1,7 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'extensions'
3
4
  require 'zlib'
4
5
 
6
+ STRING_IS_ONLY_SYMBOLS_RE = /^[.()+-:;\[\]^~%&!*\/→×??x%▼| ]+$/
7
+ APPEND_FLAG_OMIT_MSG = "Files aren't already parsed. Continuing as if --append flag was omitted."
8
+
5
9
  class Hash
6
10
  def insert_at_index(index, key, value)
7
11
  return self[key] = value if index >= size
@@ -49,16 +53,16 @@ def self.extract_quoted_strings(string)
49
53
  next
50
54
  end
51
55
 
52
- if in_quotes
53
- if char == "\r"
54
- next
55
- elsif char == "\n"
56
- buffer.push('\#')
57
- next
58
- end
56
+ next unless in_quotes
59
57
 
60
- buffer.push(char)
58
+ if char == "\r"
59
+ next
60
+ elsif char == "\n"
61
+ buffer.push('\#')
62
+ next
61
63
  end
64
+
65
+ buffer.push(char)
62
66
  end
63
67
  end
64
68
 
@@ -70,7 +74,7 @@ end
70
74
  # @param [String] game_type
71
75
  # @return [String]
72
76
  def self.parse_parameter(code, parameter, game_type)
73
- return nil if parameter.match?(/^[.()+-:;\[\]^~%&!*\/→×??x%▼| ]+$/)
77
+ return nil if parameter.match?(STRING_IS_ONLY_SYMBOLS_RE)
74
78
 
75
79
  unless game_type.nil?
76
80
  case code
@@ -99,7 +103,7 @@ end
99
103
  # @param [String] _game_type
100
104
  # @return [String]
101
105
  def self.parse_variable(variable, _game_type)
102
- return nil if parameter.match?(/^[.()+-:;\[\]^~%&!*\/→×??x%▼| ]+$/)
106
+ return nil if variable.match?(STRING_IS_ONLY_SYMBOLS_RE)
103
107
  variable = variable.gsub(/\r?\n/, '\#') if variable.count("\n").positive?
104
108
 
105
109
  return nil if variable.split('\#').all? { |line| line.strip.match?(/(^#? ?<.*>\.?$)|^$/) }
@@ -110,18 +114,19 @@ def self.parse_variable(variable, _game_type)
110
114
  variable
111
115
  end
112
116
 
113
- # @param [Array<String>] maps_files_paths
114
- # @param [String] output_path
115
- # @param [Boolean] logging
116
- # @param [String] game_type
117
- # @param [String] processing_type
118
- def self.read_map(maps_files_paths, output_path, logging, game_type, processing_type)
117
+ # @param [Array<String>] maps_files_paths Array of paths to original maps files
118
+ # @param [String] output_path Path to output directory
119
+ # @param [Boolean] romanize Whether to romanize text
120
+ # @param [Boolean] logging Whether to log
121
+ # @param [String] game_type Game type for custom processing
122
+ # @param [String] processing_mode Whether to read in default mode, force rewrite or append new text to existing files
123
+ def self.read_map(maps_files_paths, output_path, romanize, logging, game_type, processing_mode)
119
124
  maps_output_path = File.join(output_path, 'maps.txt')
120
125
  names_output_path = File.join(output_path, 'names.txt')
121
126
  maps_trans_output_path = File.join(output_path, 'maps_trans.txt')
122
127
  names_trans_output_path = File.join(output_path, 'names_trans.txt')
123
128
 
124
- if processing_type == :default && (File.exist?(maps_trans_output_path) || File.exist?(names_trans_output_path))
129
+ if processing_mode == :default && (File.exist?(maps_trans_output_path) || File.exist?(names_trans_output_path))
125
130
  puts 'maps_trans.txt or names_trans.txt file already exists. If you want to forcefully re-read all files, use --force flag, or --append if you want append new text to already existing files.'
126
131
  return
127
132
  end
@@ -134,15 +139,15 @@ def self.read_map(maps_files_paths, output_path, logging, game_type, processing_
134
139
  maps_translation_map = nil
135
140
  names_translation_map = nil
136
141
 
137
- if processing_type == :append
142
+ if processing_mode == :append
138
143
  if File.exist?(maps_trans_output_path)
139
144
  maps_translation_map = Hash[File.readlines(maps_output_path, chomp: true)
140
145
  .zip(File.readlines(maps_trans_output_path, chomp: true))]
141
146
  names_translation_map = Hash[File.readlines(names_output_path, chomp: true)
142
147
  .zip(File.readlines(names_trans_output_path, chomp: true))]
143
148
  else
144
- puts "Files aren't already parsed. Continuing as if --append flag was omitted."
145
- processing_type = :default
149
+ puts APPEND_FLAG_OMIT_MSG
150
+ processing_mode = :default
146
151
  end
147
152
  end
148
153
 
@@ -158,7 +163,9 @@ def self.read_map(maps_files_paths, output_path, logging, game_type, processing_
158
163
  display_name = display_name.strip
159
164
 
160
165
  unless display_name.empty?
161
- names_translation_map.insert_at_index(names_lines.length, display_name, '') if processing_type == :append &&
166
+ display_name = romanize_string(display_name) if romanize
167
+
168
+ names_translation_map.insert_at_index(names_lines.length, display_name, '') if processing_mode == :append &&
162
169
  !names_translation_map.include?(display_name)
163
170
 
164
171
  names_lines.add(display_name)
@@ -187,13 +194,17 @@ def self.read_map(maps_files_paths, output_path, logging, game_type, processing_
187
194
  joined = line.join('\#').strip
188
195
  parsed = parse_parameter(401, joined, game_type)
189
196
 
190
- maps_translation_map.insert_at_index(maps_lines.length, parsed, '') if processing_type == :append &&
191
- !maps_translation_map.include?(parsed)
197
+ unless parsed.nil?
198
+ parsed = romanize_string(parsed) if romanize
192
199
 
193
- maps_lines.add(parsed)
200
+ maps_translation_map.insert_at_index(maps_lines.length, parsed, '') if processing_mode == :append &&
201
+ !maps_translation_map.include?(parsed)
202
+
203
+ maps_lines.add(parsed)
194
204
 
195
- line.clear
196
- in_sequence = false
205
+ line.clear
206
+ in_sequence = false
207
+ end
197
208
  end
198
209
  next
199
210
  end
@@ -215,7 +226,9 @@ def self.read_map(maps_files_paths, output_path, logging, game_type, processing_
215
226
  parsed = parse_parameter(code, subparameter, game_type)
216
227
  next if parsed.nil?
217
228
 
218
- maps_translation_map.insert_at_index(maps_lines.length, parsed, '') if processing_type == :append &&
229
+ parsed = romanize_string(parsed) if romanize
230
+
231
+ maps_translation_map.insert_at_index(maps_lines.length, parsed, '') if processing_mode == :append &&
219
232
  !maps_translation_map.include?(parsed)
220
233
 
221
234
  maps_lines.add(parsed)
@@ -228,8 +241,9 @@ def self.read_map(maps_files_paths, output_path, logging, game_type, processing_
228
241
  next if parsed.nil?
229
242
 
230
243
  parsed = parsed.gsub(/\r?\n/, '\#')
244
+ parsed = romanize_string(parsed) if romanize
231
245
 
232
- maps_translation_map.insert_at_index(maps_lines.length, parsed, '') if processing_type == :append &&
246
+ maps_translation_map.insert_at_index(maps_lines.length, parsed, '') if processing_mode == :append &&
233
247
  !maps_translation_map.include?(parsed)
234
248
 
235
249
  maps_lines.add(parsed)
@@ -244,7 +258,7 @@ def self.read_map(maps_files_paths, output_path, logging, game_type, processing_
244
258
  maps_original_content,
245
259
  maps_translated_content,
246
260
  names_original_content,
247
- names_translated_content = if processing_type == :append
261
+ names_translated_content = if processing_mode == :append
248
262
  [maps_translation_map.keys.join("\n"),
249
263
  maps_translation_map.values.join("\n"),
250
264
  names_translation_map.keys.join("\n"),
@@ -264,13 +278,14 @@ end
264
278
 
265
279
  # @param [Array<String>] other_files_paths
266
280
  # @param [String] output_path
267
- # @param [Boolean] logging
268
- # @param [String] game_type
269
- # @param [String] processing_type
270
- def self.read_other(other_files_paths, output_path, logging, game_type, processing_type)
281
+ # @param [Boolean] romanize Whether to romanize text
282
+ # @param [Boolean] logging Whether to log
283
+ # @param [String] game_type Game type for custom processing
284
+ # @param [String] processing_mode Whether to read in default mode, force rewrite or append new text to existing files
285
+ def self.read_other(other_files_paths, output_path, romanize, logging, game_type, processing_mode)
271
286
  other_object_array_map = Hash[other_files_paths.map { |f| [File.basename(f), Marshal.load(File.binread(f))] }]
272
287
 
273
- inner_processing_type = processing_type
288
+ inner_processing_type = processing_mode
274
289
  # 401 - dialogue lines
275
290
  # 405 - credits lines
276
291
  # 102 - dialogue choices array
@@ -283,7 +298,7 @@ def self.read_other(other_files_paths, output_path, logging, game_type, processi
283
298
  other_output_path = File.join(output_path, "#{processed_filename}.txt")
284
299
  other_trans_output_path = File.join(output_path, "#{processed_filename}_trans.txt")
285
300
 
286
- if processing_type == :default && File.exist?(other_trans_output_path)
301
+ if processing_mode == :default && File.exist?(other_trans_output_path)
287
302
  puts "#{processed_filename}_trans.txt file already exists. If you want to forcefully re-read all files, use --force flag, or --append if you want append new text to already existing files."
288
303
  next
289
304
  end
@@ -291,13 +306,13 @@ def self.read_other(other_files_paths, output_path, logging, game_type, processi
291
306
  other_lines = IndexSet.new
292
307
  other_translation_map = nil
293
308
 
294
- if processing_type == :append
309
+ if processing_mode == :append
295
310
  if File.exist?(other_trans_output_path)
296
311
  inner_processing_type == :append
297
312
  other_translation_map = Hash[File.readlines(other_output_path, chomp: true)
298
313
  .zip(File.readlines(other_trans_output_path, chomp: true))]
299
314
  else
300
- puts "Files aren't already parsed. Continuing as if --append flag was omitted."
315
+ puts APPEND_FLAG_OMIT_MSG
301
316
  inner_processing_type = :default
302
317
  end
303
318
  end
@@ -321,6 +336,7 @@ def self.read_other(other_files_paths, output_path, logging, game_type, processi
321
336
  next if parsed.nil?
322
337
 
323
338
  parsed = parsed.gsub(/\r?\n/, '\#')
339
+ parsed = romanize_string(parsed) if romanize
324
340
 
325
341
  other_translation_map.insert_at_index(other_lines.length, parsed, '') if inner_processing_type == :append &&
326
342
  !other_translation_map.include?(parsed)
@@ -350,13 +366,17 @@ def self.read_other(other_files_paths, output_path, logging, game_type, processi
350
366
  joined = line.join('\#').strip
351
367
  parsed = parse_parameter(401, joined, game_type)
352
368
 
353
- other_translation_map.insert_at_index(other_lines.length, parsed, '') if inner_processing_type == :append &&
354
- !other_translation_map.include?(parsed)
369
+ unless parsed.nil?
370
+ parsed = romanize_string(parsed) if romanize
355
371
 
356
- other_lines.add(parsed)
372
+ other_translation_map.insert_at_index(other_lines.length, parsed, '') if inner_processing_type == :append &&
373
+ !other_translation_map.include?(parsed)
357
374
 
358
- line.clear
359
- in_sequence = false
375
+ other_lines.add(parsed)
376
+
377
+ line.clear
378
+ in_sequence = false
379
+ end
360
380
  end
361
381
  next
362
382
  end
@@ -375,6 +395,8 @@ def self.read_other(other_files_paths, output_path, logging, game_type, processi
375
395
  subparameter = subparameter.strip
376
396
  next if subparameter.empty?
377
397
 
398
+ subparameter = romanize_string(subparameter) if romanize
399
+
378
400
  other_translation_map.insert_at_index(other_lines.length, subparameter, '') if inner_processing_type == :append &&
379
401
  !other_translation_map.include?(subparameter)
380
402
 
@@ -385,6 +407,7 @@ def self.read_other(other_files_paths, output_path, logging, game_type, processi
385
407
  next if parameter.empty?
386
408
 
387
409
  parameter = parameter.gsub(/\r?\n/, '\#')
410
+ parameter = romanize_string(parameter) if romanize
388
411
 
389
412
  other_translation_map.insert_at_index(other_lines.length, parameter, '') if inner_processing_type == :append &&
390
413
  !other_translation_map.include?(parameter)
@@ -395,6 +418,7 @@ def self.read_other(other_files_paths, output_path, logging, game_type, processi
395
418
  next if parameter.empty?
396
419
 
397
420
  parameter = parameter.gsub(/\r?\n/, '\#')
421
+ parameter = romanize_string(parameter) if romanize
398
422
 
399
423
  other_translation_map.insert_at_index(other_lines.length, parameter, '') if inner_processing_type == :append &&
400
424
  !other_translation_map.include?(parameter)
@@ -408,7 +432,7 @@ def self.read_other(other_files_paths, output_path, logging, game_type, processi
408
432
 
409
433
  puts "Parsed #{filename}" if logging
410
434
 
411
- original_content, translated_content = if processing_type == :append
435
+ original_content, translated_content = if processing_mode == :append
412
436
  [other_translation_map.keys.join("\n"),
413
437
  other_translation_map.values.join("\n")]
414
438
  else
@@ -435,16 +459,17 @@ end
435
459
  # @param [String] system_file_path
436
460
  # @param [String] ini_file_path
437
461
  # @param [String] output_path
438
- # @param [Boolean] logging
439
- # @param [String] processing_type
440
- def self.read_system(system_file_path, ini_file_path, output_path, logging, processing_type)
462
+ # @param [Boolean] romanize Whether to romanize text
463
+ # @param [Boolean] logging Whether to log
464
+ # @param [String] processing_mode Whether to read in default mode, force rewrite or append new text to existing files
465
+ def self.read_system(system_file_path, ini_file_path, output_path, romanize, logging, processing_mode)
441
466
  system_filename = File.basename(system_file_path)
442
467
  system_basename = File.basename(system_file_path, '.*').downcase
443
468
 
444
469
  system_output_path = File.join(output_path, "#{system_basename}.txt")
445
470
  system_trans_output_path = File.join(output_path, "#{system_basename}_trans.txt")
446
471
 
447
- if processing_type == :default && File.exist?(system_trans_output_path)
472
+ if processing_mode == :default && File.exist?(system_trans_output_path)
448
473
  puts 'system_trans.txt file already exists. If you want to forcefully re-read all files, use --force flag, or --append if you want append new text to already existing files.'
449
474
  return
450
475
  end
@@ -454,13 +479,13 @@ def self.read_system(system_file_path, ini_file_path, output_path, logging, proc
454
479
  system_lines = IndexSet.new
455
480
  system_translation_map = nil
456
481
 
457
- if processing_type == :append
482
+ if processing_mode == :append
458
483
  if File.exist?(system_trans_output_path)
459
484
  system_translation_map = Hash[File.readlines(system_output_path, chomp: true)
460
485
  .zip(File.readlines(system_trans_output_path, chomp: true))]
461
486
  else
462
- puts "Files aren't already parsed. Continuing as if --append flag was omitted."
463
- processing_type = :default
487
+ puts APPEND_FLAG_OMIT_MSG
488
+ processing_mode = :default
464
489
  end
465
490
  end
466
491
 
@@ -480,7 +505,9 @@ def self.read_system(system_file_path, ini_file_path, output_path, logging, proc
480
505
  string = string.strip
481
506
  next if string.empty?
482
507
 
483
- system_translation_map.insert_at_index(system_lines.length, string, '') if processing_type == :append &&
508
+ string = romanize_string(string) if romanize
509
+
510
+ system_translation_map.insert_at_index(system_lines.length, string, '') if processing_mode == :append &&
484
511
  !system_translation_map.include?(string)
485
512
 
486
513
  system_lines.add(string)
@@ -491,7 +518,9 @@ def self.read_system(system_file_path, ini_file_path, output_path, logging, proc
491
518
  currency_unit = currency_unit.strip
492
519
 
493
520
  unless currency_unit.empty?
494
- system_translation_map.insert_at_index(system_lines.length, currency_unit, '') if processing_type == :append &&
521
+ currency_unit = romanize_string(currency_unit) if romanize
522
+
523
+ system_translation_map.insert_at_index(system_lines.length, currency_unit, '') if processing_mode == :append &&
495
524
  !system_translation_map.include?(currency_unit)
496
525
 
497
526
  system_lines.add(currency_unit)
@@ -505,7 +534,9 @@ def self.read_system(system_file_path, ini_file_path, output_path, logging, proc
505
534
  value = value.strip
506
535
 
507
536
  unless value.empty?
508
- system_translation_map.insert_at_index(system_lines.length, value, '') if processing_type == :append &&
537
+ value = romanize_string(string) if romanize
538
+
539
+ system_translation_map.insert_at_index(system_lines.length, value, '') if processing_mode == :append &&
509
540
  !system_translation_map.include?(value)
510
541
 
511
542
  system_lines.add(value)
@@ -517,7 +548,9 @@ def self.read_system(system_file_path, ini_file_path, output_path, logging, proc
517
548
  string = string.strip
518
549
  next if string.empty?
519
550
 
520
- system_translation_map.insert_at_index(system_lines.length, string, '') if processing_type == :append &&
551
+ string = romanize_string(string) if romanize
552
+
553
+ system_translation_map.insert_at_index(system_lines.length, string, '') if processing_mode == :append &&
521
554
  !system_translation_map.include?(string)
522
555
 
523
556
  system_lines.add(string)
@@ -528,15 +561,16 @@ def self.read_system(system_file_path, ini_file_path, output_path, logging, proc
528
561
  # Game title from System file and ini file may differ, but requesting user request to determine which line do they want is LAME
529
562
  # So just throw that ini ass and continue
530
563
  ini_game_title = read_ini_title(ini_file_path).strip
564
+ ini_game_title = romanize_string(ini_game_title) if romanize
531
565
 
532
- system_translation_map.insert_at_index(system_lines.length, ini_game_title, '') if processing_type == :append &&
566
+ system_translation_map.insert_at_index(system_lines.length, ini_game_title, '') if processing_mode == :append &&
533
567
  !system_translation_map.include?(ini_game_title)
534
568
 
535
569
  system_lines.add(ini_game_title)
536
570
 
537
571
  puts "Parsed #{system_filename}" if logging
538
572
 
539
- original_content, translated_content = if processing_type == :append
573
+ original_content, translated_content = if processing_mode == :append
540
574
  [system_translation_map.keys.join("\n"),
541
575
  system_translation_map.values.join("\n")]
542
576
  else
@@ -550,9 +584,10 @@ end
550
584
 
551
585
  # @param [String] scripts_file_path
552
586
  # @param [String] output_path
553
- # @param [Boolean] logging
554
- # @param [String] processing_type
555
- def self.read_scripts(scripts_file_path, output_path, logging, processing_type)
587
+ # @param [Boolean] romanize Whether to romanize text
588
+ # @param [Boolean] logging Whether to log
589
+ # @param [String] processing_mode Whether to read in default mode, force rewrite or append new text to existing files
590
+ def self.read_scripts(scripts_file_path, output_path, romanize, logging, processing_mode)
556
591
  scripts_filename = File.basename(scripts_file_path)
557
592
  scripts_basename = File.basename(scripts_file_path, '.*').downcase
558
593
 
@@ -560,7 +595,7 @@ def self.read_scripts(scripts_file_path, output_path, logging, processing_type)
560
595
  scripts_output_path = File.join(output_path, "#{scripts_basename}.txt")
561
596
  scripts_trans_output_path = File.join(output_path, "#{scripts_basename}_trans.txt")
562
597
 
563
- if processing_type == :default && File.exist?(scripts_trans_output_path)
598
+ if processing_mode == :default && File.exist?(scripts_trans_output_path)
564
599
  puts 'scripts_trans.txt file already exists. If you want to forcefully re-read all files, use --force flag, or --append if you want append new text to already existing files.'
565
600
  return
566
601
  end
@@ -570,13 +605,13 @@ def self.read_scripts(scripts_file_path, output_path, logging, processing_type)
570
605
  scripts_lines = IndexSet.new
571
606
  scripts_translation_map = nil
572
607
 
573
- if processing_type == :append
608
+ if processing_mode == :append
574
609
  if File.exist?(scripts_trans_output_path)
575
610
  scripts_translation_map = Hash[File.readlines(scripts_output_path, chomp: true)
576
611
  .zip(File.readlines(scripts_trans_output_path, chomp: true))]
577
612
  else
578
- puts "Files aren't already parsed. Continuing as if --append flag was omitted."
579
- processing_type = :default
613
+ puts APPEND_FLAG_OMIT_MSG
614
+ processing_mode = :default
580
615
  end
581
616
  end
582
617
 
@@ -613,7 +648,7 @@ def self.read_scripts(scripts_file_path, output_path, logging, processing_type)
613
648
  string.match?(/^[^\p{L}]+$/) ||
614
649
  string.match?(/^\d+$/) ||
615
650
  string.match?(/%.*(\d|\+|\*)d\]?:?$/) ||
616
- string.match?(/^\[(ON|OFF)\]$/) ||
651
+ string.match?(/^\[((ON|OFF)|P[EMRT])\]$/) ||
617
652
  string.match?(/^\[\]$/) ||
618
653
  string.match?(/^(.)\1{2,}$/) ||
619
654
  string.match?(/^(false|true)$/) ||
@@ -621,10 +656,13 @@ def self.read_scripts(scripts_file_path, output_path, logging, processing_type)
621
656
  string.match?(/^(?=.*\d)[A-Za-z0-9\-]+$/) ||
622
657
  string.match?(/^[a-z\-()\/ +'&]*$/) ||
623
658
  string.match?(/^[A-Za-z]+[+-]$/) ||
624
- string.match?(/^[.()+-:;\[\]^~%&!*\/→×??x%▼| ]+$/) ||
659
+ string.match?(STRING_IS_ONLY_SYMBOLS_RE) ||
625
660
  string.match?(/^Tile.*[A-Z]$/) ||
626
661
  string.match?(/^[a-zA-Z][a-z]+([A-Z][a-z]*)+$/) ||
627
662
  string.match?(/^Cancel Action$|^Invert$|^End$|^Individual$|^Missed File$|^Bitmap$|^Audio$/) ||
663
+ string.match?(/^(?=.*%d)(?=.*%m)(?=.*%Y).*$/) ||
664
+ string.match?(/^\\\\ALPHAC/) ||
665
+ string.match?(/^[A-Z]{,3}-[A-Z][A-Za-z]+/) ||
628
666
  string.match?(/\.(mp3|ogg|jpg|png|ini|txt)$/i) ||
629
667
  string.match?(/\/(\d.*)?$/) ||
630
668
  string.match?(/FILE$/) ||
@@ -648,7 +686,9 @@ def self.read_scripts(scripts_file_path, output_path, logging, processing_type)
648
686
  string.match?(/Clear image/) ||
649
687
  string.match?(/Can Collapse/)
650
688
 
651
- scripts_translation_map.insert_at_index(scripts_lines.length, string, '') if processing_type == :append &&
689
+ string = romanize_string(string) if romanize
690
+
691
+ scripts_translation_map.insert_at_index(scripts_lines.length, string, '') if processing_mode == :append &&
652
692
  !scripts_translation_map.include?(string)
653
693
 
654
694
  scripts_lines.add(string)
@@ -659,7 +699,7 @@ def self.read_scripts(scripts_file_path, output_path, logging, processing_type)
659
699
 
660
700
  File.binwrite(scripts_plain_output_path, codes_content.join("\n"))
661
701
 
662
- original_content, translated_content = if processing_type == :append
702
+ original_content, translated_content = if processing_mode == :append
663
703
  [scripts_translation_map.keys.join("\n"),
664
704
  scripts_translation_map.values.join("\n")]
665
705
  else
data/lib/write.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'zlib'
4
+ require 'extensions'
4
5
 
5
6
  # @param [String] string A parsed scripts code string, containing raw Ruby code
6
7
  # @return [Array<Array<String, Integer>>] Hash of parsed from code strings and their start indices
@@ -58,8 +59,8 @@ def self.extract_quoted_strings(string)
58
59
  [strings_array, indices_array]
59
60
  end
60
61
 
61
- # @param [Array<String>] array
62
- # @return [Array<String>]
62
+ # @param [Array<String>] array Array of strings
63
+ # @return [Array<String>] Array of shuffled strings
63
64
  def self.shuffle_words(array)
64
65
  array.each do |string|
65
66
  select_words_re = /\S+/
@@ -70,7 +71,7 @@ end
70
71
 
71
72
  # @param [Integer] code
72
73
  # @param [String] parameter
73
- # @param [Hash{String => String}] hashmap
74
+ # @param [Hash{String => String}] hashmap Translation hashmap (as everything in Ruby passed by reference, this pass is free!)
74
75
  # @param [String] game_type
75
76
  def self.get_parameter_translated(code, parameter, hashmap, game_type)
76
77
  unless game_type.nil?
@@ -115,20 +116,21 @@ def self.get_parameter_translated(code, parameter, hashmap, game_type)
115
116
  end
116
117
 
117
118
  # @param [String] variable
118
- # @param [Hash{String => String}] hashmap
119
+ # @param [Hash{String => String}] hashmap Translation hashmap (as everything in Ruby passed by reference, this pass is free!)
119
120
  # @param [String] _game_type
120
121
  # @return [String]
121
122
  def self.get_variable_translated(variable, hashmap, _game_type)
122
123
  hashmap[variable]
123
124
  end
124
125
 
125
- # @param [Array<String>] original_files_paths
126
- # @param [String] maps_path
127
- # @param [String] output_path
128
- # @param [Integer] shuffle_level
129
- # @param [Boolean] logging
130
- # @param [String] game_type
131
- def self.write_map(original_files_paths, maps_path, output_path, shuffle_level, logging, game_type)
126
+ # @param [Array<String>] original_files_paths Array of paths to original files
127
+ # @param [String] maps_path Path to directory containing .txt maps files
128
+ # @param [String] output_path Path to output directory
129
+ # @param [Integer] shuffle_level Level of shuffle
130
+ # @param [Boolean] romanize If files were read with romanize, this option will romanize original game text to compare with parsed
131
+ # @param [Boolean] logging Whether to log
132
+ # @param [String] game_type Game type for custom parsing
133
+ def self.write_map(original_files_paths, maps_path, output_path, shuffle_level, romanize, logging, game_type)
132
134
  maps_object_map = Hash[original_files_paths.map { |f| [File.basename(f), Marshal.load(File.binread(f))] }]
133
135
 
134
136
  maps_original_text = File.readlines(File.join(maps_path, 'maps.txt'), encoding: 'UTF-8', chomp: true).map do |line|
@@ -192,6 +194,8 @@ def self.write_map(original_files_paths, maps_path, output_path, shuffle_level,
192
194
  unless allowed_codes.include?(code)
193
195
  if in_sequence
194
196
  joined = line.join('\#').strip
197
+ joined = romanize_string(joined) if romanize
198
+
195
199
  translated = get_parameter_translated(401, joined, maps_translation_map, game_type)
196
200
 
197
201
  unless translated.nil? || translated.empty?
@@ -225,6 +229,8 @@ def self.write_map(original_files_paths, maps_path, output_path, shuffle_level,
225
229
  subparameter = subparameter.strip
226
230
  next if subparameter.empty?
227
231
 
232
+ subparameter = romanize_string(subparameter) if romanize
233
+
228
234
  translated = get_parameter_translated(code, subparameter, maps_translation_map, game_type)
229
235
  parameters[0][sp] = translated unless translated.nil? || translated.empty?
230
236
  end
@@ -232,12 +238,16 @@ def self.write_map(original_files_paths, maps_path, output_path, shuffle_level,
232
238
  parameter = parameters[0].strip
233
239
  next if parameter.empty?
234
240
 
241
+ parameter = romanize_string(parameter) if romanize
242
+
235
243
  translated = get_parameter_translated(code, parameter, maps_translation_map, game_type)
236
244
  parameters[0] = translated unless translated.nil? || translated.empty?
237
245
  elsif parameters[1].is_a?(String)
238
246
  parameter = parameters[1].strip
239
247
  next if parameter.empty?
240
248
 
249
+ parameter = romanize_string(parameter) if romanize
250
+
241
251
  translated = get_parameter_translated(code, parameter, maps_translation_map, game_type)
242
252
  parameters[1] = translated unless translated.nil? || translated.empty?
243
253
  end
@@ -264,10 +274,11 @@ end
264
274
  # @param [Array<String>] original_files
265
275
  # @param [String] other_path
266
276
  # @param [String] output_path
267
- # @param [Integer] shuffle_level
268
- # @param [Boolean] logging
269
- # @param [String] game_type
270
- def self.write_other(original_files_paths, other_path, output_path, shuffle_level, logging, game_type)
277
+ # @param [Integer] shuffle_level Level of shuffle
278
+ # @param [Boolean] romanize If files were read with romanize, this option will romanize original game text to compare with parsed
279
+ # @param [Boolean] logging Whether to log
280
+ # @param [String] game_type Game type for custom parsing
281
+ def self.write_other(original_files_paths, other_path, output_path, shuffle_level, romanize, logging, game_type)
271
282
  other_object_array_map = Hash[original_files_paths.map { |f| [File.basename(f), Marshal.load(File.binread(f))] }]
272
283
 
273
284
  # 401 - dialogue lines
@@ -309,6 +320,8 @@ def self.write_other(original_files_paths, other_path, output_path, shuffle_leve
309
320
  next if variable.empty?
310
321
 
311
322
  variable = variable.gsub(/\r\n/, "\n")
323
+ variable = romanize_string(variable) if romanize
324
+
312
325
  translated = get_variable_translated(variable, other_translation_map, game_type)
313
326
 
314
327
  unless translated.nil? || translated.empty?
@@ -345,6 +358,8 @@ def self.write_other(original_files_paths, other_path, output_path, shuffle_leve
345
358
  unless allowed_codes.include?(code)
346
359
  if in_sequence
347
360
  joined = line.join('\#').strip
361
+ joined = romanize_string(joined) if romanize
362
+
348
363
  translated = get_parameter_translated(401, joined, other_translation_map, game_type)
349
364
 
350
365
  unless translated.nil? || translated.empty?
@@ -378,6 +393,8 @@ def self.write_other(original_files_paths, other_path, output_path, shuffle_leve
378
393
  subparameter = subparameter.strip
379
394
  next if subparameter.empty?
380
395
 
396
+ subparameter = romanize_string(subparameter) if romanize
397
+
381
398
  translated = get_parameter_translated(code, subparameter, other_translation_map, game_type)
382
399
  parameters[0][sp] = translated unless translated.nil? || translated.empty?
383
400
  end
@@ -385,12 +402,16 @@ def self.write_other(original_files_paths, other_path, output_path, shuffle_leve
385
402
  parameter = parameters[0].strip
386
403
  next if parameter.empty?
387
404
 
405
+ parameter = romanize_string(parameter) if romanize
406
+
388
407
  translated = get_parameter_translated(code, parameter, other_translation_map, game_type)
389
408
  parameters[0] = translated unless translated.nil? || translated.empty?
390
409
  elsif parameters[1].is_a?(String)
391
410
  parameter = parameters[1].strip
392
411
  next if parameter.empty?
393
412
 
413
+ parameter = romanize_string(parameter) if romanize
414
+
394
415
  translated = get_parameter_translated(code, parameter, other_translation_map, game_type)
395
416
  parameters[1] = translated unless translated.nil? || translated.empty?
396
417
  end
@@ -421,6 +442,7 @@ end
421
442
  def self.write_ini_title(ini_file_path, translated)
422
443
  file_lines = File.readlines(ini_file_path, chomp: true)
423
444
  title_line_index = file_lines.each_with_index { |line, i| break i if line.downcase.start_with?('title') }
445
+ return if title_line_index.is_a?(Array)
424
446
 
425
447
  file_lines[title_line_index] = translated
426
448
  File.binwrite(ini_file_path, file_lines.join("\n"))
@@ -430,9 +452,10 @@ end
430
452
  # @param [String] ini_file_path
431
453
  # @param [String] other_path
432
454
  # @param [String] output_path
433
- # @param [Integer] shuffle_level
434
- # @param [Boolean] logging
435
- def self.write_system(system_file_path, ini_file_path, other_path, output_path, shuffle_level, logging)
455
+ # @param [Integer] shuffle_level Level of shuffle
456
+ # @param [Boolean] romanize If files were read with romanize, this option will romanize original game text to compare with parsed
457
+ # @param [Boolean] logging Whether to log
458
+ def self.write_system(system_file_path, ini_file_path, other_path, output_path, shuffle_level, romanize, logging)
436
459
  system_basename = File.basename(system_file_path)
437
460
  system_object = Marshal.load(File.binread(system_file_path))
438
461
 
@@ -455,7 +478,7 @@ def self.write_system(system_file_path, ini_file_path, other_path, output_path,
455
478
  weapon_types = system_object.weapon_types
456
479
  armor_types = system_object.armor_types
457
480
  currency_unit = system_object.currency_unit
458
- terms = system_object.terms || system_object.words
481
+ terms_vocabulary = system_object.terms || system_object.words
459
482
 
460
483
  [elements, skill_types, weapon_types, armor_types].each_with_index do |array, i|
461
484
  next unless array.is_a?(Array)
@@ -464,6 +487,8 @@ def self.write_system(system_file_path, ini_file_path, other_path, output_path,
464
487
  string = string.strip
465
488
  next if string.empty?
466
489
 
490
+ string = romanize_string(string) if romanize
491
+
467
492
  translated = system_translation_map[string]
468
493
  array[i] = translated unless translated.nil? || translated.empty?
469
494
  end
@@ -479,35 +504,42 @@ def self.write_system(system_file_path, ini_file_path, other_path, output_path,
479
504
  end
480
505
  end
481
506
 
507
+ currency_unit = romanize_string(currency_unit) if romanize
482
508
  currency_unit_translated = system_translation_map[currency_unit]
483
509
  system_object.currency_unit = currency_unit_translated if currency_unit.is_a?(String) &&
484
510
  (!currency_unit_translated.nil? && !currency_unit_translated.empty?)
485
511
 
486
- terms.instance_variables.each do |variable|
487
- value = terms.instance_variable_get(variable)
512
+ terms_vocabulary.instance_variables.each do |variable|
513
+ value = terms_vocabulary.instance_variable_get(variable)
488
514
 
489
515
  if value.is_a?(String)
490
- stripped = value.strip
516
+ value = value.strip
491
517
  next if value.empty?
492
518
 
493
- translated = system_translation_map[stripped]
519
+ value = romanize_string(value) if romanize
520
+
521
+ translated = system_translation_map[value]
494
522
  value = translated unless translated.nil? || translated.empty?
495
523
  elsif value.is_a?(Array)
496
524
  value.each_with_index do |string, i|
497
525
  string = string.strip
498
526
  next if string.empty?
499
527
 
528
+ string = romanize_string(string) if romanize
529
+
500
530
  translated = system_translation_map[string]
501
531
  value[i] = translated unless translated.nil? || translated.empty?
502
532
  end
503
533
  end
504
534
 
505
- terms.instance_variable_set(variable, value)
535
+ terms_vocabulary.instance_variable_set(variable, value)
506
536
  end
507
537
 
508
- system_object.terms.nil? ?
509
- system_object.words = terms :
510
- system_object.terms = terms
538
+ if system_object.terms.nil?
539
+ system_object.words = terms_vocabulary
540
+ else
541
+ system_object.terms = terms_vocabulary
542
+ end
511
543
 
512
544
  game_title_translated = system_translated_text[-1]
513
545
 
@@ -523,8 +555,9 @@ end
523
555
  # @param [String] scripts_file_path Path to Scripts.*data file
524
556
  # @param [String] other_path Path to translation/other directory containing .txt files
525
557
  # @param [String] output_path Path to the output directory
558
+ # @param [Boolean] romanize If files were read with romanize, this option will romanize original game text to compare with parsed
526
559
  # @param [Boolean] logging Whether to log
527
- def self.write_scripts(scripts_file_path, other_path, output_path, logging)
560
+ def self.write_scripts(scripts_file_path, other_path, output_path, romanize, logging)
528
561
  scripts_basename = File.basename(scripts_file_path)
529
562
  script_entries = Marshal.load(File.binread(scripts_file_path))
530
563
 
@@ -564,6 +597,8 @@ def self.write_scripts(scripts_file_path, other_path, output_path, logging)
564
597
  string = string.strip.delete(' ')
565
598
  next if string.empty? || !scripts_translation_map.include?(string)
566
599
 
600
+ string = romanize_string(string) if romanize
601
+
567
602
  gotten = scripts_translation_map[string]
568
603
  code[index - string.length, string.length] = gotten unless gotten.nil? || gotten.empty?
569
604
  end
data/rvpacker-txt.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'rvpacker-txt'
5
- spec.version = '1.8.5'
5
+ spec.version = '1.9.1'
6
6
  spec.authors = ['Howard Jeng', 'Andrew Kesterson', 'Solistra', 'Darkness9724', 'savannstm']
7
7
  spec.email = ['savannstm@gmail.com']
8
8
  spec.summary = 'Reads RPG Maker XP/VX/VXAce game text to .txt files and writes them to their initial form.'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rvpacker-txt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.5
4
+ version: 1.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Howard Jeng
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2024-07-23 00:00:00.000000000 Z
15
+ date: 2024-07-25 00:00:00.000000000 Z
16
16
  dependencies: []
17
17
  description:
18
18
  email: