rvpacker-txt 1.5.2 → 1.6.0
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 +4 -4
- data/README.md +5 -4
- data/bin/rvpacker-txt +32 -29
- data/lib/classes.rb +0 -1
- data/lib/read.rb +225 -167
- data/lib/write.rb +295 -242
- data/rvpacker-txt.gemspec +1 -1
- metadata +2 -2
data/lib/read.rb
CHANGED
|
@@ -2,32 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
require 'zlib'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
class Hash
|
|
6
|
+
def insert_at_index(index, key, value)
|
|
7
|
+
return self[key] = value if index >= size
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
temp_array = to_a
|
|
10
|
+
temp_array.insert(index, [key, value])
|
|
11
|
+
replace(temp_array.to_h)
|
|
12
|
+
end
|
|
12
13
|
end
|
|
13
14
|
|
|
15
|
+
# @param [String] string A parsed scripts code string, containing raw Ruby code
|
|
16
|
+
# @return [IndexSet<String>] Hash of parsed from code strings and their start indices
|
|
14
17
|
def self.extract_quoted_strings(string)
|
|
15
|
-
|
|
16
|
-
result = {}
|
|
18
|
+
result = IndexSet.new
|
|
17
19
|
|
|
18
20
|
skip_block = false
|
|
19
21
|
in_quotes = false
|
|
20
22
|
quote_type = nil
|
|
21
23
|
buffer = []
|
|
22
24
|
|
|
23
|
-
# I hope this calculates index correctly
|
|
24
|
-
current_string_index = 0
|
|
25
25
|
string.each_line do |line|
|
|
26
26
|
stripped = line.strip
|
|
27
27
|
|
|
28
|
-
if stripped[0] == '#' || stripped.start_with?(/(Win|Lose)|_Fanfare/)
|
|
29
|
-
next
|
|
30
|
-
end
|
|
28
|
+
next if stripped[0] == '#' || stripped.start_with?(/(Win|Lose)|_Fanfare/)
|
|
31
29
|
|
|
32
30
|
skip_block = true if stripped.start_with?('=begin')
|
|
33
31
|
skip_block = false if stripped.start_with?('=end')
|
|
@@ -45,61 +43,73 @@ def self.extract_quoted_strings(string)
|
|
|
45
43
|
|
|
46
44
|
quote_type = char
|
|
47
45
|
in_quotes = !in_quotes
|
|
48
|
-
result
|
|
46
|
+
result.add(buffer.join)
|
|
49
47
|
buffer.clear
|
|
50
48
|
next
|
|
51
49
|
end
|
|
52
50
|
|
|
53
|
-
if in_quotes
|
|
54
|
-
buffer.push(char)
|
|
55
|
-
end
|
|
51
|
+
buffer.push(char) if in_quotes
|
|
56
52
|
end
|
|
57
|
-
|
|
58
|
-
current_string_index += line.length
|
|
59
53
|
end
|
|
60
54
|
|
|
61
55
|
result
|
|
62
56
|
end
|
|
63
57
|
|
|
58
|
+
# @param [Integer] code
|
|
59
|
+
# @param [String] parameter
|
|
60
|
+
# @param [String] game_type
|
|
61
|
+
# @return [String]
|
|
64
62
|
def self.parse_parameter(code, parameter, game_type)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
63
|
+
unless game_type.nil?
|
|
64
|
+
case code
|
|
65
|
+
when 401, 405
|
|
66
|
+
case game_type
|
|
67
|
+
when 'lisa'
|
|
68
|
+
match = parameter.scan(/^(\\et\[[0-9]+\]|\\nbt)/)
|
|
69
|
+
parameter = parameter.slice((match[0].length)..) unless match.empty?
|
|
70
|
+
else
|
|
71
|
+
nil
|
|
72
|
+
end
|
|
73
|
+
when 102
|
|
74
|
+
# Implement some custom parsing
|
|
75
|
+
when 356
|
|
76
|
+
# Implement some custom parsing
|
|
77
|
+
else
|
|
78
|
+
return nil
|
|
79
|
+
end
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
parameter
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
+
# @param [String] variable
|
|
86
|
+
# @param [String] game_type
|
|
87
|
+
# @return [String]
|
|
85
88
|
def self.parse_variable(variable, game_type)
|
|
86
|
-
|
|
89
|
+
unless game_type.nil?
|
|
90
|
+
lines_count = variable.count("\n")
|
|
87
91
|
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
if lines_count.positive?
|
|
93
|
+
variable = variable.gsub(/\r?\n/, '\#')
|
|
90
94
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
case game_type
|
|
96
|
+
when 'lisa'
|
|
97
|
+
return nil unless variable.split('\#').all? { |line| line.match?(/^<.*>\.?$/) || line.empty? }
|
|
98
|
+
else
|
|
99
|
+
nil
|
|
100
|
+
end
|
|
96
101
|
end
|
|
97
102
|
end
|
|
98
103
|
|
|
99
104
|
variable
|
|
100
105
|
end
|
|
101
106
|
|
|
102
|
-
|
|
107
|
+
# @param [Array<String>] maps_files_paths
|
|
108
|
+
# @param [String] output_path
|
|
109
|
+
# @param [Boolean] logging
|
|
110
|
+
# @param [String] game_type
|
|
111
|
+
# @param [String] processing_type
|
|
112
|
+
def self.read_map(maps_files_paths, output_path, logging, game_type, processing_type)
|
|
103
113
|
maps_output_path = File.join(output_path, 'maps.txt')
|
|
104
114
|
names_output_path = File.join(output_path, 'names.txt')
|
|
105
115
|
maps_trans_output_path = File.join(output_path, 'maps_trans.txt')
|
|
@@ -110,7 +120,7 @@ def self.read_map(maps_files, output_path, logging, game_type, processing_type)
|
|
|
110
120
|
return
|
|
111
121
|
end
|
|
112
122
|
|
|
113
|
-
maps_object_map = Hash[
|
|
123
|
+
maps_object_map = Hash[maps_files_paths.map do |filename|
|
|
114
124
|
[File.basename(filename), Marshal.load(File.binread(filename))]
|
|
115
125
|
end]
|
|
116
126
|
|
|
@@ -122,8 +132,10 @@ def self.read_map(maps_files, output_path, logging, game_type, processing_type)
|
|
|
122
132
|
|
|
123
133
|
if processing_type == 'append'
|
|
124
134
|
if File.exist?(maps_trans_output_path)
|
|
125
|
-
maps_translation_map = Hash[File.readlines(maps_output_path, chomp: true)
|
|
126
|
-
|
|
135
|
+
maps_translation_map = Hash[File.readlines(maps_output_path, chomp: true)
|
|
136
|
+
.zip(File.readlines(maps_trans_output_path, chomp: true))]
|
|
137
|
+
names_translation_map = Hash[File.readlines(names_output_path, chomp: true)
|
|
138
|
+
.zip(File.readlines(names_trans_output_path, chomp: true))]
|
|
127
139
|
else
|
|
128
140
|
puts "Files aren't already parsed. Continuing as if --append flag was omitted."
|
|
129
141
|
processing_type = 'default'
|
|
@@ -133,12 +145,15 @@ def self.read_map(maps_files, output_path, logging, game_type, processing_type)
|
|
|
133
145
|
maps_object_map.each do |filename, object|
|
|
134
146
|
display_name = object.instance_variable_get(:@display_name)
|
|
135
147
|
|
|
136
|
-
if display_name.is_a?(String)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
148
|
+
if display_name.is_a?(String)
|
|
149
|
+
display_name = display_name.strip
|
|
150
|
+
|
|
151
|
+
unless display_name.empty?
|
|
152
|
+
names_translation_map.insert_at_index(names_lines.length, display_name, '') if processing_type == 'append' &&
|
|
153
|
+
!names_translation_map.include?(display_name)
|
|
140
154
|
|
|
141
|
-
|
|
155
|
+
names_lines.add(display_name)
|
|
156
|
+
end
|
|
142
157
|
end
|
|
143
158
|
|
|
144
159
|
events = object.instance_variable_get(:@events)
|
|
@@ -161,21 +176,19 @@ def self.read_map(maps_files, output_path, logging, game_type, processing_type)
|
|
|
161
176
|
|
|
162
177
|
parameters.each do |parameter|
|
|
163
178
|
if code == 401
|
|
164
|
-
|
|
165
|
-
in_sequence = true
|
|
179
|
+
next unless parameter.is_a?(String) && !parameter.empty?
|
|
166
180
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
end
|
|
181
|
+
in_sequence = true
|
|
182
|
+
line.push(parameter)
|
|
170
183
|
else
|
|
171
184
|
if in_sequence
|
|
172
|
-
joined = line.join('\#')
|
|
185
|
+
joined = line.join('\#').strip
|
|
186
|
+
parsed = parse_parameter(401, joined, game_type)
|
|
173
187
|
|
|
174
|
-
if processing_type == 'append' &&
|
|
175
|
-
|
|
176
|
-
end
|
|
188
|
+
maps_translation_map.insert_at_index(maps_lines.length, parsed, '') if processing_type == 'append' &&
|
|
189
|
+
!maps_translation_map.include?(parsed)
|
|
177
190
|
|
|
178
|
-
maps_lines.add(
|
|
191
|
+
maps_lines.add(parsed)
|
|
179
192
|
|
|
180
193
|
line.clear
|
|
181
194
|
in_sequence = false
|
|
@@ -183,30 +196,36 @@ def self.read_map(maps_files, output_path, logging, game_type, processing_type)
|
|
|
183
196
|
|
|
184
197
|
if code == 102 && parameter.is_a?(Array)
|
|
185
198
|
parameter.each do |subparameter|
|
|
186
|
-
|
|
187
|
-
parsed = parse_parameter(code, subparameter, game_type)
|
|
199
|
+
next unless subparameter.is_a?(String)
|
|
188
200
|
|
|
189
|
-
|
|
190
|
-
if processing_type == 'append' && !maps_translation_map.include?(parsed)
|
|
191
|
-
insert_at_index(maps_translation_map, maps_lines.length, parsed, '')
|
|
192
|
-
end
|
|
201
|
+
subparameter = subparameter.strip
|
|
193
202
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
203
|
+
next if subparameter.empty?
|
|
204
|
+
|
|
205
|
+
parsed = parse_parameter(code, subparameter, game_type)
|
|
206
|
+
|
|
207
|
+
next if parsed.nil?
|
|
208
|
+
|
|
209
|
+
maps_translation_map.insert_at_index(maps_lines.length, parsed, '') if processing_type == 'append' &&
|
|
210
|
+
!maps_translation_map.include?(parsed)
|
|
211
|
+
|
|
212
|
+
maps_lines.add(parsed)
|
|
197
213
|
end
|
|
198
|
-
elsif code == 356 && parameter.is_a?(String)
|
|
214
|
+
elsif code == 356 && parameter.is_a?(String)
|
|
215
|
+
parameter = parameter.strip
|
|
216
|
+
|
|
217
|
+
next if parameter.empty?
|
|
218
|
+
|
|
199
219
|
parsed = parse_parameter(code, parameter, game_type)
|
|
200
220
|
|
|
201
|
-
|
|
202
|
-
subbed = parsed.gsub(/\r?\n/, '\#')
|
|
221
|
+
next if parsed.nil?
|
|
203
222
|
|
|
204
|
-
|
|
205
|
-
insert_at_index(maps_translation_map, maps_lines.length, parsed, '')
|
|
206
|
-
end
|
|
223
|
+
parsed = parsed.gsub(/\r?\n/, '\#')
|
|
207
224
|
|
|
208
|
-
|
|
209
|
-
|
|
225
|
+
maps_translation_map.insert_at_index(maps_lines.length, parsed, '') if processing_type == 'append' &&
|
|
226
|
+
!maps_translation_map.include?(parsed)
|
|
227
|
+
|
|
228
|
+
maps_lines.add(parsed)
|
|
210
229
|
end
|
|
211
230
|
end
|
|
212
231
|
end
|
|
@@ -238,16 +257,17 @@ def self.read_map(maps_files, output_path, logging, game_type, processing_type)
|
|
|
238
257
|
File.binwrite(names_trans_output_path, names_translated_content)
|
|
239
258
|
end
|
|
240
259
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
260
|
+
# @param [Array<String>] other_files_paths
|
|
261
|
+
# @param [String] output_path
|
|
262
|
+
# @param [Boolean] logging
|
|
263
|
+
# @param [String] game_type
|
|
264
|
+
# @param [String] processing_type
|
|
265
|
+
def self.read_other(other_files_paths, output_path, logging, game_type, processing_type)
|
|
266
|
+
other_object_array_map = Hash[other_files_paths.map do |filename|
|
|
267
|
+
[File.basename(filename), Marshal.load(File.binread(filename))]
|
|
248
268
|
end]
|
|
249
269
|
|
|
250
|
-
|
|
270
|
+
inner_processing_type = processing_type
|
|
251
271
|
|
|
252
272
|
other_object_array_map.each do |filename, other_object_array|
|
|
253
273
|
processed_filename = File.basename(filename, '.*').downcase
|
|
@@ -265,11 +285,12 @@ def self.read_other(other_files, output_path, logging, game_type, processing_typ
|
|
|
265
285
|
|
|
266
286
|
if processing_type == 'append'
|
|
267
287
|
if File.exist?(other_trans_output_path)
|
|
268
|
-
|
|
269
|
-
other_translation_map = Hash[File.readlines(other_output_path, chomp: true)
|
|
288
|
+
inner_processing_type == 'append'
|
|
289
|
+
other_translation_map = Hash[File.readlines(other_output_path, chomp: true)
|
|
290
|
+
.zip(File.readlines(other_trans_output_path, chomp: true))]
|
|
270
291
|
else
|
|
271
292
|
puts "Files aren't already parsed. Continuing as if --append flag was omitted."
|
|
272
|
-
|
|
293
|
+
inner_processing_type = 'default'
|
|
273
294
|
end
|
|
274
295
|
end
|
|
275
296
|
|
|
@@ -281,17 +302,22 @@ def self.read_other(other_files, output_path, logging, game_type, processing_typ
|
|
|
281
302
|
note = object.instance_variable_get(:@note)
|
|
282
303
|
|
|
283
304
|
[name, nickname, description, note].each do |variable|
|
|
284
|
-
|
|
285
|
-
parsed = parse_variable(variable, game_type)
|
|
305
|
+
next unless variable.is_a?(String)
|
|
286
306
|
|
|
287
|
-
|
|
288
|
-
if internal_processing_type == 'append' && !other_translation_map.include?(parsed)
|
|
289
|
-
insert_at_index(other_translation_map, other_lines.length, parsed, '')
|
|
290
|
-
end
|
|
307
|
+
variable = variable.strip
|
|
291
308
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
309
|
+
next if variable.empty?
|
|
310
|
+
|
|
311
|
+
parsed = parse_variable(variable, game_type)
|
|
312
|
+
|
|
313
|
+
next if parsed.nil?
|
|
314
|
+
|
|
315
|
+
parsed = parsed.gsub(/\r?\n/, '\#')
|
|
316
|
+
|
|
317
|
+
other_translation_map.insert_at_index(other_lines.length, parsed, '') if inner_processing_type == 'append' &&
|
|
318
|
+
!other_translation_map.include?(parsed)
|
|
319
|
+
|
|
320
|
+
other_lines.add(parsed)
|
|
295
321
|
end
|
|
296
322
|
end
|
|
297
323
|
else
|
|
@@ -312,15 +338,16 @@ def self.read_other(other_files, output_path, logging, game_type, processing_typ
|
|
|
312
338
|
|
|
313
339
|
parameters.each do |parameter|
|
|
314
340
|
if [401, 405].include?(code)
|
|
341
|
+
next unless parameter.is_a?(String) && !parameter.empty?
|
|
342
|
+
|
|
315
343
|
in_sequence = true
|
|
316
|
-
line.push(parameter.gsub(/\r?\n/, '\#'))
|
|
344
|
+
line.push(parameter.gsub(/\r?\n/, '\#'))
|
|
317
345
|
else
|
|
318
346
|
if in_sequence
|
|
319
|
-
joined = line.join('\#')
|
|
347
|
+
joined = line.join('\#').strip
|
|
320
348
|
|
|
321
|
-
if
|
|
322
|
-
|
|
323
|
-
end
|
|
349
|
+
other_translation_map.insert_at_index(other_lines.length, joined, '') if inner_processing_type == 'append' &&
|
|
350
|
+
!other_translation_map.include?(joined)
|
|
324
351
|
|
|
325
352
|
other_lines.add(joined)
|
|
326
353
|
|
|
@@ -332,25 +359,31 @@ def self.read_other(other_files, output_path, logging, game_type, processing_typ
|
|
|
332
359
|
when 102
|
|
333
360
|
if parameter.is_a?(Array)
|
|
334
361
|
parameter.each do |subparameter|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
362
|
+
next unless subparameter.is_a?(String)
|
|
363
|
+
|
|
364
|
+
subparameter = subparameter.strip
|
|
365
|
+
|
|
366
|
+
next if subparameter.empty?
|
|
339
367
|
|
|
340
|
-
|
|
341
|
-
|
|
368
|
+
other_translation_map.insert_at_index(other_lines.length, subparameter, '') if inner_processing_type == 'append' &&
|
|
369
|
+
!other_translation_map.include?(subparameter)
|
|
370
|
+
|
|
371
|
+
other_lines.add(subparameter)
|
|
342
372
|
end
|
|
343
373
|
end
|
|
344
374
|
when 356
|
|
345
|
-
|
|
346
|
-
subbed = parameter.gsub(/\r?\n/, '\#')
|
|
375
|
+
next unless parameter.is_a?(String)
|
|
347
376
|
|
|
348
|
-
|
|
349
|
-
insert_at_index(other_translation_map, other_lines.length, subbed, '')
|
|
350
|
-
end
|
|
377
|
+
parameter = parameter.strip
|
|
351
378
|
|
|
352
|
-
|
|
353
|
-
|
|
379
|
+
next if parameter.empty?
|
|
380
|
+
|
|
381
|
+
parameter = parameter.gsub(/\r?\n/, '\#')
|
|
382
|
+
|
|
383
|
+
other_translation_map.insert_at_index(other_lines.length, parameter, '') if inner_processing_type == 'append' &&
|
|
384
|
+
!other_translation_map.include?(parameter)
|
|
385
|
+
|
|
386
|
+
other_lines.add(parameter)
|
|
354
387
|
else
|
|
355
388
|
nil
|
|
356
389
|
end
|
|
@@ -364,9 +397,11 @@ def self.read_other(other_files, output_path, logging, game_type, processing_typ
|
|
|
364
397
|
puts "Parsed #{filename}" if logging
|
|
365
398
|
|
|
366
399
|
original_content, translated_content = if processing_type == 'append'
|
|
367
|
-
[other_translation_map.keys.join("\n"),
|
|
400
|
+
[other_translation_map.keys.join("\n"),
|
|
401
|
+
other_translation_map.values.join("\n")]
|
|
368
402
|
else
|
|
369
|
-
[other_lines.join("\n"),
|
|
403
|
+
[other_lines.join("\n"),
|
|
404
|
+
"\n" * (other_lines.empty? ? 0 : other_lines.length - 1)]
|
|
370
405
|
end
|
|
371
406
|
|
|
372
407
|
File.binwrite(other_output_path, original_content)
|
|
@@ -374,17 +409,23 @@ def self.read_other(other_files, output_path, logging, game_type, processing_typ
|
|
|
374
409
|
end
|
|
375
410
|
end
|
|
376
411
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
end
|
|
412
|
+
# @param [String] ini_file_path
|
|
413
|
+
def self.read_ini_title(ini_file_path)
|
|
414
|
+
file_lines = File.readlines(ini_file_path, chomp: true)
|
|
415
|
+
file_lines.each do |line|
|
|
416
|
+
if line.start_with?('title')
|
|
417
|
+
parts = line.partition('=')
|
|
418
|
+
break parts[2].strip
|
|
385
419
|
end
|
|
386
420
|
end
|
|
421
|
+
end
|
|
387
422
|
|
|
423
|
+
# @param [String] system_file_path
|
|
424
|
+
# @param [String] ini_file_path
|
|
425
|
+
# @param [String] output_path
|
|
426
|
+
# @param [Boolean] logging
|
|
427
|
+
# @param [String] processing_type
|
|
428
|
+
def self.read_system(system_file_path, ini_file_path, output_path, logging, processing_type)
|
|
388
429
|
system_filename = File.basename(system_file_path)
|
|
389
430
|
system_basename = File.basename(system_file_path, '.*').downcase
|
|
390
431
|
|
|
@@ -403,7 +444,8 @@ def self.read_system(system_file_path, ini_file_path, output_path, logging, proc
|
|
|
403
444
|
|
|
404
445
|
if processing_type == 'append'
|
|
405
446
|
if File.exist?(system_trans_output_path)
|
|
406
|
-
system_translation_map = Hash[File.readlines(system_output_path, chomp: true)
|
|
447
|
+
system_translation_map = Hash[File.readlines(system_output_path, chomp: true)
|
|
448
|
+
.zip(File.readlines(system_trans_output_path, chomp: true))]
|
|
407
449
|
else
|
|
408
450
|
puts "Files aren't already parsed. Continuing as if --append flag was omitted."
|
|
409
451
|
processing_type = 'default'
|
|
@@ -421,32 +463,39 @@ def self.read_system(system_file_path, ini_file_path, output_path, logging, proc
|
|
|
421
463
|
next if array.nil?
|
|
422
464
|
|
|
423
465
|
array.each do |string|
|
|
424
|
-
|
|
425
|
-
if processing_type == 'append' && !system_translation_map.include?(string)
|
|
426
|
-
insert_at_index(system_translation_map, system_lines.length, string, '')
|
|
427
|
-
end
|
|
466
|
+
next unless string.is_a?(String)
|
|
428
467
|
|
|
429
|
-
|
|
430
|
-
|
|
468
|
+
string = string.strip
|
|
469
|
+
|
|
470
|
+
next if string.empty?
|
|
471
|
+
|
|
472
|
+
system_translation_map.insert_at_index(system_lines.length, string, '') if processing_type == 'append' &&
|
|
473
|
+
!system_translation_map.include?(string)
|
|
474
|
+
|
|
475
|
+
system_lines.add(string)
|
|
431
476
|
end
|
|
432
477
|
end
|
|
433
478
|
|
|
434
|
-
if currency_unit.is_a?(String)
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
479
|
+
if currency_unit.is_a?(String)
|
|
480
|
+
currency_unit = currency_unit.strip
|
|
481
|
+
|
|
482
|
+
unless currency_unit.empty?
|
|
483
|
+
system_translation_map.insert_at_index(system_lines.length, currency_unit, '') if processing_type == 'append' &&
|
|
484
|
+
!system_translation_map.include?(currency_unit)
|
|
438
485
|
|
|
439
|
-
|
|
486
|
+
system_lines.add(currency_unit)
|
|
487
|
+
end
|
|
440
488
|
end
|
|
441
489
|
|
|
442
490
|
terms.instance_variables.each do |variable|
|
|
443
491
|
value = terms.instance_variable_get(variable)
|
|
444
492
|
|
|
445
493
|
if value.is_a?(String)
|
|
494
|
+
value = value.strip
|
|
495
|
+
|
|
446
496
|
unless value.empty?
|
|
447
|
-
if processing_type == 'append' &&
|
|
448
|
-
|
|
449
|
-
end
|
|
497
|
+
system_translation_map.insert_at_index(system_lines.length, value, '') if processing_type == 'append' &&
|
|
498
|
+
!system_translation_map.include?(value)
|
|
450
499
|
|
|
451
500
|
system_lines.add(value)
|
|
452
501
|
end
|
|
@@ -455,39 +504,47 @@ def self.read_system(system_file_path, ini_file_path, output_path, logging, proc
|
|
|
455
504
|
end
|
|
456
505
|
|
|
457
506
|
value.each do |string|
|
|
458
|
-
|
|
459
|
-
if processing_type == 'append' && !system_translation_map.include?(string)
|
|
460
|
-
insert_at_index(system_translation_map, system_lines.length, string, '')
|
|
461
|
-
end
|
|
507
|
+
next unless string.is_a?(String)
|
|
462
508
|
|
|
463
|
-
|
|
464
|
-
|
|
509
|
+
string = string.strip
|
|
510
|
+
|
|
511
|
+
next if string.empty?
|
|
512
|
+
|
|
513
|
+
system_translation_map.insert_at_index(system_lines.length, string, '') if processing_type == 'append' &&
|
|
514
|
+
!system_translation_map.include?(string)
|
|
515
|
+
|
|
516
|
+
system_lines.add(string)
|
|
465
517
|
end
|
|
466
518
|
end
|
|
467
519
|
|
|
468
520
|
# Game title from System file and ini file may differ, but requesting user request to determine which line do they want is LAME
|
|
469
521
|
# So just throw that ini ass and continue
|
|
470
522
|
_game_title = system_object.instance_variable_get(:@game_title)
|
|
471
|
-
ini_game_title = read_ini_title(ini_file_path)
|
|
523
|
+
ini_game_title = read_ini_title(ini_file_path).strip
|
|
472
524
|
|
|
473
|
-
if processing_type == 'append' &&
|
|
474
|
-
|
|
475
|
-
end
|
|
525
|
+
system_translation_map.insert_at_index(system_lines.length, ini_game_title, '') if processing_type == 'append' &&
|
|
526
|
+
!system_translation_map.include?(ini_game_title)
|
|
476
527
|
|
|
477
528
|
system_lines.add(ini_game_title)
|
|
478
529
|
|
|
479
530
|
puts "Parsed #{system_filename}" if logging
|
|
480
531
|
|
|
481
532
|
original_content, translated_content = if processing_type == 'append'
|
|
482
|
-
[system_translation_map.keys.join("\n"),
|
|
533
|
+
[system_translation_map.keys.join("\n"),
|
|
534
|
+
system_translation_map.values.join("\n")]
|
|
483
535
|
else
|
|
484
|
-
[system_lines.join("\n"),
|
|
536
|
+
[system_lines.join("\n"),
|
|
537
|
+
"\n" * (system_lines.empty? ? 0 : system_lines.length - 1)]
|
|
485
538
|
end
|
|
486
539
|
|
|
487
540
|
File.binwrite(system_output_path, original_content)
|
|
488
541
|
File.binwrite(system_trans_output_path, translated_content)
|
|
489
542
|
end
|
|
490
543
|
|
|
544
|
+
# @param [String] scripts_file_path
|
|
545
|
+
# @param [String] output_path
|
|
546
|
+
# @param [Boolean] logging
|
|
547
|
+
# @param [String] processing_type
|
|
491
548
|
def self.read_scripts(scripts_file_path, output_path, logging, processing_type)
|
|
492
549
|
scripts_filename = File.basename(scripts_file_path)
|
|
493
550
|
scripts_basename = File.basename(scripts_file_path, '.*').downcase
|
|
@@ -508,7 +565,8 @@ def self.read_scripts(scripts_file_path, output_path, logging, processing_type)
|
|
|
508
565
|
|
|
509
566
|
if processing_type == 'append'
|
|
510
567
|
if File.exist?(scripts_trans_output_path)
|
|
511
|
-
scripts_translation_map = Hash[File.readlines(scripts_output_path, chomp: true)
|
|
568
|
+
scripts_translation_map = Hash[File.readlines(scripts_output_path, chomp: true)
|
|
569
|
+
.zip(File.readlines(scripts_trans_output_path, chomp: true))]
|
|
512
570
|
else
|
|
513
571
|
puts "Files aren't already parsed. Continuing as if --append flag was omitted."
|
|
514
572
|
processing_type = 'default'
|
|
@@ -521,32 +579,31 @@ def self.read_scripts(scripts_file_path, output_path, logging, processing_type)
|
|
|
521
579
|
code = Zlib::Inflate.inflate(script[2]).force_encoding('UTF-8')
|
|
522
580
|
codes_content.push(code)
|
|
523
581
|
|
|
524
|
-
extract_quoted_strings(code).
|
|
525
|
-
string.strip!
|
|
526
|
-
|
|
582
|
+
extract_quoted_strings(code).each do |string|
|
|
527
583
|
# Removes the U+3000 Japanese typographical space to check if string, when stripped, is truly empty
|
|
528
|
-
|
|
584
|
+
string = string.strip.delete(' ')
|
|
585
|
+
|
|
586
|
+
next if string.empty?
|
|
529
587
|
|
|
530
588
|
# Maybe this mess will remove something that mustn't be removed, but it needs to be tested
|
|
589
|
+
|
|
531
590
|
next if string.start_with?(/([#!?$@]|(\.\/)?(Graphics|Data|Audio|CG|Movies|Save)\/)/) ||
|
|
532
591
|
string.match?(/^\d+$/) ||
|
|
533
592
|
string.match?(/^(.)\1{2,}$/) ||
|
|
534
593
|
string.match?(/^(false|true)$/) ||
|
|
535
594
|
string.match?(/^[wr]b$/) ||
|
|
536
595
|
string.match?(/^(?=.*\d)[A-Za-z0-9\-]+$/) ||
|
|
537
|
-
string.match?(/^[A-Z\-()\/ +'&]*$/) ||
|
|
538
596
|
string.match?(/^[a-z\-()\/ +'&]*$/) ||
|
|
539
597
|
string.match?(/^[A-Za-z]+[+-]$/) ||
|
|
540
598
|
string.match?(/^[.()+-:;\[\]^~%&!*\/→×??x%▼|]$/) ||
|
|
541
599
|
string.match?(/^Tile.*[A-Z]$/) ||
|
|
542
|
-
string.match?(
|
|
543
|
-
string.match?(/^[a-zA-Z]+([A-Z][a-z]*)+$/) ||
|
|
600
|
+
string.match?(/^[a-zA-Z][a-z]+([A-Z][a-z]*)+$/) ||
|
|
544
601
|
string.match?(/^Cancel Action$|^Invert$|^End$|^Individual$|^Missed File$|^Bitmap$|^Audio$/) ||
|
|
545
602
|
string.match?(/\.(mp3|ogg|jpg|png|ini)$/) ||
|
|
546
603
|
string.match?(/\/(\d.*)?$/) ||
|
|
547
604
|
string.match?(/FILE$/) ||
|
|
548
605
|
string.match?(/#\{/) ||
|
|
549
|
-
string.match?(
|
|
606
|
+
string.match?(/(?<!\\)\\(?!\\|G|#)/) ||
|
|
550
607
|
string.match?(/\+?=?=/) ||
|
|
551
608
|
string.match?(/[}{_<>]/) ||
|
|
552
609
|
string.match?(/r[vx]data/) ||
|
|
@@ -570,9 +627,8 @@ def self.read_scripts(scripts_file_path, output_path, logging, processing_type)
|
|
|
570
627
|
string.match?(/Clear image/) ||
|
|
571
628
|
string.match?(/Can Collapse/)
|
|
572
629
|
|
|
573
|
-
if processing_type == 'append' &&
|
|
574
|
-
|
|
575
|
-
end
|
|
630
|
+
scripts_translation_map.insert_at_index(scripts_lines.length, string, '') if processing_type == 'append' &&
|
|
631
|
+
!scripts_translation_map.include?(string)
|
|
576
632
|
|
|
577
633
|
scripts_lines.add(string)
|
|
578
634
|
end
|
|
@@ -583,9 +639,11 @@ def self.read_scripts(scripts_file_path, output_path, logging, processing_type)
|
|
|
583
639
|
File.binwrite(scripts_plain_output_path, codes_content.join("\n"))
|
|
584
640
|
|
|
585
641
|
original_content, translated_content = if processing_type == 'append'
|
|
586
|
-
[scripts_translation_map.keys.join("\n"),
|
|
642
|
+
[scripts_translation_map.keys.join("\n"),
|
|
643
|
+
scripts_translation_map.values.join("\n")]
|
|
587
644
|
else
|
|
588
|
-
[scripts_lines.join("\n"),
|
|
645
|
+
[scripts_lines.join("\n"),
|
|
646
|
+
"\n" * (scripts_lines.empty? ? 0 : scripts_lines.length - 1)]
|
|
589
647
|
end
|
|
590
648
|
|
|
591
649
|
File.binwrite(scripts_output_path, original_content)
|