rvpacker-txt 1.5.0 → 1.5.2

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: 2b69421e26d7a2a85ce60f482712d941e23946887a3e9b8640752dd4441b4cea
4
- data.tar.gz: 66fdd2d16bbd06ae1210105684805c9ec4a2beefef7f859568ae1faa37f6051e
3
+ metadata.gz: 7f8d16cb7960ca2c4494b2b2e1c414114404403dac94acd7a7adeac4e7c24e12
4
+ data.tar.gz: dc10d4e2abdcbd70b8f4af452215d1540a5e7ab0775202fdca04ee28726c1e7c
5
5
  SHA512:
6
- metadata.gz: '068699415ee5fe5faa764a20f66f60b6d359610503aff909dda3b62b42f78c83abfe7e5049cc8aab03b7c4e5f3ff3e77a879ff43f6a059ad021bb97beed0d74d'
7
- data.tar.gz: e78c574fcf21bef8a4216f856ceeea67481281fe20047e78fd7a007c2b274e2e525a5a84a98c7bfcc1db8e4113c11b71837f6cd3f756002fde0c1ad4321811e3
6
+ metadata.gz: 9921e7a66d63e4784b5679329b0c7d02112396976c2ea9febbae7b21eff78e951dcb47f4ecf4eddc8b133af0790005f7acd50ccb49c1a1663662daa4b71eb7a2
7
+ data.tar.gz: 823cfe0171387ff3001b7bc6876fac636817d1b67cf6b0d5b23afe860b69635c7e2fe796ae24e7e1da7b7816c3e51daf4098cbb13a16b07801f99640bcd7c131
data/bin/rvpacker-txt CHANGED
@@ -23,7 +23,7 @@ def self.parse_options
23
23
  options[:output_dir] = File.exist?(dir) ? File.realpath(dir) : (raise "#{dir} not found")
24
24
  end
25
25
 
26
- cmd.on('--disable-processing FILES', Array, 'Don\'t process specified files (maps, other, system, plugins)') do |files|
26
+ cmd.on('--disable-processing FILES', Array, "Don't process specified files (maps, other, system, plugins)") do |files|
27
27
  files.each do |file|
28
28
  index = %w[maps other system scripts].index(file)
29
29
  options[:disable_processing][index] = true if index
@@ -34,7 +34,7 @@ def self.parse_options
34
34
  options[:shuffle_level] = num
35
35
  end
36
36
 
37
- cmd.on('--disable_custom_processing', 'Disables built-in custom parsing/writing for some games') do
37
+ cmd.on('--disable-custom-processing', 'Disables built-in custom parsing/writing for some games') do
38
38
  options[:disable_custom_processing] = true
39
39
  end
40
40
 
@@ -42,11 +42,11 @@ def self.parse_options
42
42
  options[:logging] = true
43
43
  end
44
44
 
45
- cmd.on('-f', '--force', 'Force rewrite all files. Cannot be used with --append.', 'USE WITH CAUTION!') do
45
+ cmd.on('-f', '--force', 'Force rewrite all files. Cannot be used with --append', 'USE WITH CAUTION!') do
46
46
  options[:force] = true
47
47
  end
48
48
 
49
- cmd.on('-a', '--append', 'When you update the rvpacker-txt, you probably should re-read your files with append, as some new text might be added to parser.', 'Cannot be used with --force') do
49
+ cmd.on('-a', '--append', 'When you update the rvpacker-txt, you probably should re-read', 'your files with append, as some new text might be added to parser', 'Cannot be used with --force') do
50
50
  raise '--append cannot be used beside --force.' if options[:force]
51
51
  options[:append] = true
52
52
  end
@@ -156,4 +156,4 @@ end
156
156
  $wait_time = 0 if $wait_time.nil?
157
157
  end_time = Time.now - start_time - wait_time - $wait_time
158
158
 
159
- puts "Done in #{end_time}"
159
+ puts "Done in #{end_time}"
data/lib/read.rb CHANGED
@@ -20,6 +20,7 @@ def self.extract_quoted_strings(string)
20
20
  quote_type = nil
21
21
  buffer = []
22
22
 
23
+ # I hope this calculates index correctly
23
24
  current_string_index = 0
24
25
  string.each_line do |line|
25
26
  stripped = line.strip
@@ -70,7 +71,9 @@ def self.parse_parameter(code, parameter, game_type)
70
71
  else
71
72
  nil
72
73
  end
73
- when 102, 356
74
+ when 102
75
+ # Implement some custom parsing
76
+ when 356
74
77
  # Implement some custom parsing
75
78
  else
76
79
  return nil
@@ -103,7 +106,7 @@ def self.read_map(maps_files, output_path, logging, game_type, processing_type)
103
106
  names_trans_output_path = File.join(output_path, 'names_trans.txt')
104
107
 
105
108
  if processing_type == 'default' && (File.exist?(maps_trans_output_path) || File.exist?(names_trans_output_path))
106
- puts 'maps.txt or maps_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.'
109
+ 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.'
107
110
  return
108
111
  end
109
112
 
@@ -111,38 +114,31 @@ def self.read_map(maps_files, output_path, logging, game_type, processing_type)
111
114
  [File.basename(filename), Marshal.load(File.binread(filename))]
112
115
  end]
113
116
 
114
- maps_lines = nil
117
+ maps_lines = IndexSet.new
118
+ names_lines = IndexSet.new
115
119
 
116
- maps_trans_map = nil
117
- names_trans_map = nil
120
+ maps_translation_map = nil
121
+ names_translation_map = nil
118
122
 
119
123
  if processing_type == 'append'
120
124
  if File.exist?(maps_trans_output_path)
121
- maps_trans_map = Hash[File.readlines(maps_output_path, chomp: true).zip(File.readlines(maps_trans_output_path, chomp: true))]
122
- names_trans_map = Hash[File.readlines(names_output_path, chomp: true).zip(File.readlines(names_trans_output_path, chomp: true))]
125
+ maps_translation_map = Hash[File.readlines(maps_output_path, chomp: true).zip(File.readlines(maps_trans_output_path, chomp: true))]
126
+ names_translation_map = Hash[File.readlines(names_output_path, chomp: true).zip(File.readlines(names_trans_output_path, chomp: true))]
123
127
  else
124
- puts 'Files aren\'t already parsed. Continuing as if --append flag was omitted.'
128
+ puts "Files aren't already parsed. Continuing as if --append flag was omitted."
125
129
  processing_type = 'default'
126
- maps_lines = [IndexSet.new, IndexSet.new]
127
130
  end
128
- else
129
- maps_lines = [IndexSet.new, IndexSet.new]
130
131
  end
131
132
 
132
- hash_index = 0
133
- names_hash_index = 0
134
-
135
133
  maps_object_map.each do |filename, object|
136
134
  display_name = object.instance_variable_get(:@display_name)
137
135
 
138
136
  if display_name.is_a?(String) && !display_name.empty?
139
- if processing_type == 'append'
140
- insert_at_index(names_trans_map, names_hash_index, display_name, '') unless names_trans_map.include?(display_name)
141
- else
142
- maps_lines[1].add(display_name)
137
+ if processing_type == 'append' && !names_translation_map.include?(display_name)
138
+ insert_at_index(names_translation_map, names_lines.length, display_name, '')
143
139
  end
144
140
 
145
- names_hash_index += 1
141
+ names_lines.add(display_name)
146
142
  end
147
143
 
148
144
  events = object.instance_variable_get(:@events)
@@ -175,16 +171,14 @@ def self.read_map(maps_files, output_path, logging, game_type, processing_type)
175
171
  if in_sequence
176
172
  joined = line.join('\#')
177
173
 
178
- if processing_type == 'append'
179
- insert_at_index(maps_trans_map, hash_index, joined, '') unless maps_trans_map.include?(joined)
180
- else
181
- maps_lines[0].add(joined)
174
+ if processing_type == 'append' && !maps_translation_map.include?(joined)
175
+ insert_at_index(maps_translation_map, maps_lines.length, joined, '')
182
176
  end
183
177
 
178
+ maps_lines.add(joined)
179
+
184
180
  line.clear
185
181
  in_sequence = false
186
-
187
- hash_index += 1
188
182
  end
189
183
 
190
184
  if code == 102 && parameter.is_a?(Array)
@@ -193,13 +187,11 @@ def self.read_map(maps_files, output_path, logging, game_type, processing_type)
193
187
  parsed = parse_parameter(code, subparameter, game_type)
194
188
 
195
189
  unless parsed.nil?
196
- if processing_type == 'append'
197
- insert_at_index(maps_trans_map, hash_index, parsed, '') unless maps_trans_map.include?(parsed)
198
- else
199
- maps_lines[0].add(parsed)
190
+ if processing_type == 'append' && !maps_translation_map.include?(parsed)
191
+ insert_at_index(maps_translation_map, maps_lines.length, parsed, '')
200
192
  end
201
193
 
202
- hash_index += 1
194
+ maps_lines.add(parsed)
203
195
  end
204
196
  end
205
197
  end
@@ -209,13 +201,11 @@ def self.read_map(maps_files, output_path, logging, game_type, processing_type)
209
201
  unless parsed.nil?
210
202
  subbed = parsed.gsub(/\r?\n/, '\#')
211
203
 
212
- if processing_type == 'append'
213
- insert_at_index(maps_trans_map, hash_index, parsed, '') unless maps_trans_map.include?(parsed)
214
- else
215
- maps_lines[0].add(subbed)
204
+ if processing_type == 'append' && !maps_translation_map.include?(parsed)
205
+ insert_at_index(maps_translation_map, maps_lines.length, parsed, '')
216
206
  end
217
207
 
218
- hash_index += 1
208
+ maps_lines.add(subbed)
219
209
  end
220
210
  end
221
211
  end
@@ -227,17 +217,25 @@ def self.read_map(maps_files, output_path, logging, game_type, processing_type)
227
217
  puts "Parsed #{filename}" if logging
228
218
  end
229
219
 
230
- if processing_type == 'append'
231
- File.binwrite(maps_output_path, maps_trans_map.keys.join("\n"))
232
- File.binwrite(maps_trans_output_path, maps_trans_map.values.join("\n"))
233
- File.binwrite(names_output_path, names_trans_map.keys.join("\n"))
234
- File.binwrite(names_trans_output_path, names_trans_map.values.join("\n"))
235
- else
236
- File.binwrite(maps_output_path, maps_lines[0].join("\n"))
237
- File.binwrite(maps_trans_output_path, "\n" * (maps_lines[0].empty? ? 0 : maps_lines[0].length - 1))
238
- File.binwrite(names_output_path, maps_lines[1].join("\n"))
239
- File.binwrite(names_trans_output_path, "\n" * (maps_lines[1].empty? ? 0 : maps_lines[1].length - 1))
240
- end
220
+ maps_original_content,
221
+ maps_translated_content,
222
+ names_original_content,
223
+ names_translated_content = if processing_type == 'append'
224
+ [maps_translation_map.keys.join("\n"),
225
+ maps_translation_map.values.join("\n"),
226
+ names_translation_map.keys.join("\n"),
227
+ names_translation_map.values.join("\n")]
228
+ else
229
+ [maps_lines.join("\n"),
230
+ "\n" * (maps_lines.empty? ? 0 : maps_lines.length - 1),
231
+ names_lines.join("\n"),
232
+ "\n" * (names_lines.empty? ? 0 : names_lines.length - 1)]
233
+ end
234
+
235
+ File.binwrite(maps_output_path, maps_original_content)
236
+ File.binwrite(maps_trans_output_path, maps_translated_content)
237
+ File.binwrite(names_output_path, names_original_content)
238
+ File.binwrite(names_trans_output_path, names_translated_content)
241
239
  end
242
240
 
243
241
  def self.read_other(other_files, output_path, logging, game_type, processing_type)
@@ -262,24 +260,20 @@ def self.read_other(other_files, output_path, logging, game_type, processing_typ
262
260
  next
263
261
  end
264
262
 
265
- other_lines = nil
266
- other_trans_map = nil
263
+ other_lines = IndexSet.new
264
+ other_translation_map = nil
267
265
 
268
266
  if processing_type == 'append'
269
267
  if File.exist?(other_trans_output_path)
270
268
  internal_processing_type == 'append'
271
- other_trans_map = Hash[File.readlines(other_output_path, chomp: true).zip(File.readlines(other_trans_output_path, chomp: true))]
269
+ other_translation_map = Hash[File.readlines(other_output_path, chomp: true).zip(File.readlines(other_trans_output_path, chomp: true))]
272
270
  else
273
- puts 'Files aren\'t already parsed. Continuing as if --append flag was omitted.'
271
+ puts "Files aren't already parsed. Continuing as if --append flag was omitted."
274
272
  internal_processing_type = 'default'
275
- other_lines = IndexSet.new
276
273
  end
277
- else
278
- other_lines = IndexSet.new
279
274
  end
280
275
 
281
276
  if !filename.start_with?(/Common|Troops/)
282
- hash_index = 0
283
277
  other_object_array.each do |object|
284
278
  name = object.instance_variable_get(:@name)
285
279
  nickname = object.instance_variable_get(:@nickname)
@@ -291,19 +285,16 @@ def self.read_other(other_files, output_path, logging, game_type, processing_typ
291
285
  parsed = parse_variable(variable, game_type)
292
286
 
293
287
  unless parsed.nil?
294
- if internal_processing_type == 'append'
295
- insert_at_index(other_trans_map, hash_index, parsed, '') unless other_trans_map.include?(parsed)
296
- else
297
- other_lines.add(parsed)
288
+ if internal_processing_type == 'append' && !other_translation_map.include?(parsed)
289
+ insert_at_index(other_translation_map, other_lines.length, parsed, '')
298
290
  end
299
291
 
300
- hash_index += 1
292
+ other_lines.add(parsed)
301
293
  end
302
294
  end
303
295
  end
304
296
  end
305
297
  else
306
- hash_index = 0
307
298
  other_object_array.each do |object|
308
299
  pages = object.instance_variable_get(:@pages)
309
300
  pages_length = pages.nil? ? 1 : pages.length
@@ -327,16 +318,14 @@ def self.read_other(other_files, output_path, logging, game_type, processing_typ
327
318
  if in_sequence
328
319
  joined = line.join('\#')
329
320
 
330
- if internal_processing_type == 'append'
331
- insert_at_index(other_trans_map, hash_index, joined, '') unless other_trans_map.include?(joined)
332
- else
333
- other_lines.add(joined)
321
+ if internal_processing_type == 'append' && !other_translation_map.include?(joined)
322
+ insert_at_index(other_translation_map, other_lines.length, joined, '')
334
323
  end
335
324
 
325
+ other_lines.add(joined)
326
+
336
327
  line.clear
337
328
  in_sequence = false
338
-
339
- hash_index += 1
340
329
  end
341
330
 
342
331
  case code
@@ -344,13 +333,11 @@ def self.read_other(other_files, output_path, logging, game_type, processing_typ
344
333
  if parameter.is_a?(Array)
345
334
  parameter.each do |subparameter|
346
335
  if subparameter.is_a?(String) && !subparameter.empty?
347
- if internal_processing_type == 'append'
348
- insert_at_index(other_trans_map, hash_index, subparameter, '') unless other_trans_map.include?(subparameter)
349
- else
350
- other_lines.add(subparameter)
336
+ if internal_processing_type == 'append' && !other_translation_map.include?(subparameter)
337
+ insert_at_index(other_translation_map, other_lines.length, subparameter, '')
351
338
  end
352
339
 
353
- hash_index += 1
340
+ other_lines.add(subparameter)
354
341
  end
355
342
  end
356
343
  end
@@ -359,12 +346,10 @@ def self.read_other(other_files, output_path, logging, game_type, processing_typ
359
346
  subbed = parameter.gsub(/\r?\n/, '\#')
360
347
 
361
348
  if internal_processing_type == 'append'
362
- insert_at_index(other_trans_map, hash_index, subbed, '')
363
- else
364
- other_lines.add(subbed)
349
+ insert_at_index(other_translation_map, other_lines.length, subbed, '')
365
350
  end
366
351
 
367
- hash_index += 1
352
+ other_lines.add(subbed)
368
353
  end
369
354
  else
370
355
  nil
@@ -378,13 +363,14 @@ def self.read_other(other_files, output_path, logging, game_type, processing_typ
378
363
 
379
364
  puts "Parsed #{filename}" if logging
380
365
 
381
- if processing_type == 'append'
382
- File.binwrite(other_output_path, other_trans_map.keys.join("\n"))
383
- File.binwrite(other_trans_output_path, other_trans_map.values.join("\n"))
384
- else
385
- File.binwrite(other_output_path, other_lines.join("\n"))
386
- File.binwrite(other_trans_output_path, "\n" * (other_lines.empty? ? 0 : other_lines.length - 1))
387
- end
366
+ original_content, translated_content = if processing_type == 'append'
367
+ [other_translation_map.keys.join("\n"), other_translation_map.values.join("\n")]
368
+ else
369
+ [other_lines.join("\n"), "\n" * (other_lines.empty? ? 0 : other_lines.length - 1)]
370
+ end
371
+
372
+ File.binwrite(other_output_path, original_content)
373
+ File.binwrite(other_trans_output_path, translated_content)
388
374
  end
389
375
  end
390
376
 
@@ -406,25 +392,22 @@ def self.read_system(system_file_path, ini_file_path, output_path, logging, proc
406
392
  system_trans_output_path = File.join(output_path, "#{system_basename}_trans.txt")
407
393
 
408
394
  if processing_type == 'default' && File.exist?(system_trans_output_path)
409
- 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."
395
+ 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.'
410
396
  return
411
397
  end
412
398
 
413
399
  system_object = Marshal.load(File.binread(system_file_path))
414
400
 
415
- system_lines = nil
416
- system_trans_map = nil
401
+ system_lines = IndexSet.new
402
+ system_translation_map = nil
417
403
 
418
404
  if processing_type == 'append'
419
405
  if File.exist?(system_trans_output_path)
420
- system_trans_map = Hash[File.readlines(system_output_path, chomp: true).zip(File.readlines(system_trans_output_path, chomp: true))]
406
+ system_translation_map = Hash[File.readlines(system_output_path, chomp: true).zip(File.readlines(system_trans_output_path, chomp: true))]
421
407
  else
422
- puts 'Files aren\'t already parsed. Continuing as if --append flag was omitted.'
423
- system_lines = IndexSet.new
408
+ puts "Files aren't already parsed. Continuing as if --append flag was omitted."
424
409
  processing_type = 'default'
425
410
  end
426
- else
427
- system_lines = IndexSet.new
428
411
  end
429
412
 
430
413
  elements = system_object.instance_variable_get(:@elements)
@@ -433,34 +416,27 @@ def self.read_system(system_file_path, ini_file_path, output_path, logging, proc
433
416
  armor_types = system_object.instance_variable_get(:@armor_types)
434
417
  currency_unit = system_object.instance_variable_get(:@currency_unit)
435
418
  terms = system_object.instance_variable_get(:@terms) || system_object.instance_variable_get(:@words)
436
- game_title = system_object.instance_variable_get(:@game_title)
437
-
438
- hash_index = 0
439
419
 
440
420
  [elements, skill_types, weapon_types, armor_types].each do |array|
441
421
  next if array.nil?
442
422
 
443
423
  array.each do |string|
444
424
  if string.is_a?(String) && !string.empty?
445
- if processing_type == 'append'
446
- insert_at_index(system_trans_map, hash_index, string, '') unless system_trans_map.include?(string)
447
- else
448
- system_lines.add(string)
425
+ if processing_type == 'append' && !system_translation_map.include?(string)
426
+ insert_at_index(system_translation_map, system_lines.length, string, '')
449
427
  end
450
428
 
451
- hash_index += 1
429
+ system_lines.add(string)
452
430
  end
453
431
  end
454
432
  end
455
433
 
456
434
  if currency_unit.is_a?(String) && !currency_unit.empty?
457
- if processing_type == 'append'
458
- insert_at_index(system_trans_map, hash_index, currency_unit, '') unless system_trans_map.include?(currency_unit)
459
- else
460
- system_lines.add(currency_unit)
435
+ if processing_type == 'append' && !system_translation_map.include?(currency_unit)
436
+ insert_at_index(system_translation_map, system_lines.length, currency_unit, '')
461
437
  end
462
438
 
463
- hash_index += 1
439
+ system_lines.add(currency_unit)
464
440
  end
465
441
 
466
442
  terms.instance_variables.each do |variable|
@@ -468,13 +444,11 @@ def self.read_system(system_file_path, ini_file_path, output_path, logging, proc
468
444
 
469
445
  if value.is_a?(String)
470
446
  unless value.empty?
471
- if processing_type == 'append'
472
- insert_at_index(system_trans_map, hash_index, value, '') unless system_trans_map.include?(value)
473
- else
474
- system_lines.add(value)
447
+ if processing_type == 'append' && !system_translation_map.include?(value)
448
+ insert_at_index(system_translation_map, system_lines.length, value, '')
475
449
  end
476
450
 
477
- hash_index += 1
451
+ system_lines.add(value)
478
452
  end
479
453
 
480
454
  next
@@ -482,64 +456,36 @@ def self.read_system(system_file_path, ini_file_path, output_path, logging, proc
482
456
 
483
457
  value.each do |string|
484
458
  if string.is_a?(String) && !string.empty?
485
- if processing_type == 'append'
486
- insert_at_index(system_trans_map, hash_index, string, '') unless system_trans_map.include?(string)
487
- else
488
- system_lines.add(string)
459
+ if processing_type == 'append' && !system_translation_map.include?(string)
460
+ insert_at_index(system_translation_map, system_lines.length, string, '')
489
461
  end
490
462
 
491
- hash_index += 1
463
+ system_lines.add(string)
492
464
  end
493
465
  end
494
466
  end
495
467
 
468
+ # Game title from System file and ini file may differ, but requesting user request to determine which line do they want is LAME
469
+ # So just throw that ini ass and continue
470
+ _game_title = system_object.instance_variable_get(:@game_title)
496
471
  ini_game_title = read_ini_title(ini_file_path)
497
472
 
498
- $wait_time = 0
499
-
500
- if ini_game_title != game_title
501
- if game_title.is_a?(String) && !game_title.empty?
502
- wait_time_start = Time.now
503
-
504
- puts "Game title from the Game.ini file and game title from the System file are different.\nWhich game title would you like to parse?\n(That doesn't affect anything major, just when you'll write the game back, translated game title will be applied both to the .ini and System file.)\n0, System title - #{game_title}\n1, Game.ini title - #{ini_game_title}"
505
- choice = gets.chomp.to_i
506
-
507
- $wait_time = Time.now - wait_time_start
508
-
509
- if choice == 0
510
- if processing_type == 'append'
511
- insert_at_index(system_trans_map, hash_index, game_title, '') unless system_trans_map.include?(game_title)
512
- else
513
- system_lines.add(game_title)
514
- end
515
- else
516
- if processing_type == 'append'
517
- insert_at_index(system_trans_map, hash_index, ini_game_title, '') unless system_trans_map.include?(ini_game_title)
518
- else
519
- system_lines.add(ini_game_title)
520
- end
521
- end
522
- else
523
- if processing_type == 'append'
524
- insert_at_index(system_trans_map, hash_index, ini_game_title, '') unless system_trans_map.include?(ini_game_title)
525
- else
526
- system_lines.add(ini_game_title)
527
- end
528
- end
529
-
530
- hash_index += 1
473
+ if processing_type == 'append' && !system_translation_map.include?(ini_game_title)
474
+ insert_at_index(system_translation_map, system_lines.length, ini_game_title, '')
531
475
  end
532
476
 
477
+ system_lines.add(ini_game_title)
478
+
533
479
  puts "Parsed #{system_filename}" if logging
534
480
 
535
- if processing_type == 'append'
536
- File.binwrite(system_output_path, system_trans_map.keys.join("\n"))
537
- File.binwrite(system_trans_output_path, system_trans_map.values.join("\n"))
538
- else
539
- File.binwrite(system_output_path, system_lines.join("\n"))
540
- File.binwrite(system_trans_output_path, "\n" * (system_lines.empty? ? 0 : system_lines.length - 1))
541
- end
481
+ original_content, translated_content = if processing_type == 'append'
482
+ [system_translation_map.keys.join("\n"), system_translation_map.values.join("\n")]
483
+ else
484
+ [system_lines.join("\n"), "\n" * (system_lines.empty? ? 0 : system_lines.length - 1)]
485
+ end
542
486
 
487
+ File.binwrite(system_output_path, original_content)
488
+ File.binwrite(system_trans_output_path, translated_content)
543
489
  end
544
490
 
545
491
  def self.read_scripts(scripts_file_path, output_path, logging, processing_type)
@@ -551,35 +497,31 @@ def self.read_scripts(scripts_file_path, output_path, logging, processing_type)
551
497
  scripts_trans_output_path = File.join(output_path, "#{scripts_basename}_trans.txt")
552
498
 
553
499
  if processing_type == 'default' && File.exist?(scripts_trans_output_path)
554
- 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."
500
+ 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.'
555
501
  return
556
502
  end
557
503
 
558
504
  script_entries = Marshal.load(File.binread(scripts_file_path))
559
505
 
560
- scripts_lines = nil
561
- scripts_trans_map = nil
506
+ scripts_lines = IndexSet.new
507
+ scripts_translation_map = nil
562
508
 
563
509
  if processing_type == 'append'
564
510
  if File.exist?(scripts_trans_output_path)
565
- scripts_trans_map = Hash[File.readlines(scripts_output_path, chomp: true).zip(File.readlines(scripts_trans_output_path, chomp: true))]
511
+ scripts_translation_map = Hash[File.readlines(scripts_output_path, chomp: true).zip(File.readlines(scripts_trans_output_path, chomp: true))]
566
512
  else
567
- puts 'Files aren\'t already parsed. Continuing as if --append flag was omitted.'
513
+ puts "Files aren't already parsed. Continuing as if --append flag was omitted."
568
514
  processing_type = 'default'
569
- scripts_lines = IndexSet.new
570
515
  end
571
- else
572
- scripts_lines = IndexSet.new
573
516
  end
574
517
 
575
518
  codes_content = []
576
- hash_index = 0
577
519
 
578
520
  script_entries.each do |script|
579
521
  code = Zlib::Inflate.inflate(script[2]).force_encoding('UTF-8')
580
522
  codes_content.push(code)
581
523
 
582
- extract_quoted_strings(code).keys.each do |string|
524
+ extract_quoted_strings(code).each_key do |string|
583
525
  string.strip!
584
526
 
585
527
  # Removes the U+3000 Japanese typographical space to check if string, when stripped, is truly empty
@@ -628,13 +570,11 @@ def self.read_scripts(scripts_file_path, output_path, logging, processing_type)
628
570
  string.match?(/Clear image/) ||
629
571
  string.match?(/Can Collapse/)
630
572
 
631
- if processing_type == 'append'
632
- insert_at_index(scripts_trans_map, hash_index, string, '') unless scripts_trans_map.include?(string)
633
- else
634
- scripts_lines.add(string)
573
+ if processing_type == 'append' && !scripts_translation_map.include?(string)
574
+ insert_at_index(scripts_translation_map, scripts_lines.length, string, '')
635
575
  end
636
576
 
637
- hash_index += 1
577
+ scripts_lines.add(string)
638
578
  end
639
579
  end
640
580
 
@@ -642,11 +582,12 @@ def self.read_scripts(scripts_file_path, output_path, logging, processing_type)
642
582
 
643
583
  File.binwrite(scripts_plain_output_path, codes_content.join("\n"))
644
584
 
645
- if processing_type == 'append'
646
- File.binwrite(scripts_output_path, scripts_trans_map.keys.join("\n"))
647
- File.binwrite(scripts_trans_output_path, scripts_trans_map.values.join("\n"))
648
- else
649
- File.binwrite(scripts_output_path, scripts_lines.join("\n"))
650
- File.binwrite(scripts_trans_output_path, "\n" * (scripts_lines.empty? ? 0 : scripts_lines.length - 1))
651
- end
585
+ original_content, translated_content = if processing_type == 'append'
586
+ [scripts_translation_map.keys.join("\n"), scripts_translation_map.values.join("\n")]
587
+ else
588
+ [scripts_lines.join("\n"), "\n" * (scripts_lines.empty? ? 0 : scripts_lines.length - 1)]
589
+ end
590
+
591
+ File.binwrite(scripts_output_path, original_content)
592
+ File.binwrite(scripts_trans_output_path, translated_content)
652
593
  end
data/lib/write.rb CHANGED
@@ -11,6 +11,7 @@ def self.extract_quoted_strings(string)
11
11
  quote_type = nil
12
12
  buffer = []
13
13
 
14
+ # I hope this calculates index correctly
14
15
  current_string_index = 0
15
16
  string.each_line do |line|
16
17
  stripped = line.strip
@@ -51,9 +52,11 @@ def self.extract_quoted_strings(string)
51
52
  result
52
53
  end
53
54
 
54
- def shuffle_words_in_array(array)
55
- array.map do |string|
56
- string.split.shuffle.join(' ')
55
+ def shuffle_words(array)
56
+ array.each do |string|
57
+ words = string.scan(/\S+/)
58
+ shuffled_words = words.shuffle
59
+ string.gsub(/\S+/) { shuffled_words.pop || "" }
57
60
  end
58
61
  end
59
62
 
@@ -144,7 +147,7 @@ def self.get_parameter_translated(code, parameter, hashmap, game_type)
144
147
  lisa_start = nil
145
148
 
146
149
  case code
147
- when 401, 356, 405
150
+ when 401, 405
148
151
  case game_type
149
152
  when 'lisa'
150
153
  match = parameter.scan(/^(\\et\[[0-9]+\]|\\nbt)/)
@@ -154,7 +157,9 @@ def self.get_parameter_translated(code, parameter, hashmap, game_type)
154
157
  nil
155
158
  end
156
159
  when 102, 402
157
- nil
160
+ # Implement some custom parsing
161
+ when 356
162
+ # Implement some custom parsing
158
163
  else
159
164
  nil
160
165
  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.5.0'
5
+ spec.version = '1.5.2'
6
6
  spec.authors = ['Howard Jeng', 'Andrew Kesterson', 'Solistra', 'Darkness9724', 'savannstm']
7
7
  spec.email = ['savannstm@gmail.com']
8
8
  spec.summary = 'Reads or writes RPG Maker XP/VX/VXAce game text to .txt files'
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.5.0
4
+ version: 1.5.2
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-12 00:00:00.000000000 Z
15
+ date: 2024-07-14 00:00:00.000000000 Z
16
16
  dependencies: []
17
17
  description:
18
18
  email: