rvpacker-txt 1.10.0 → 1.11.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 +4 -1
- data/bin/rvpacker-txt +9 -9
- data/lib/classes.rb +10 -0
- data/lib/extensions.rb +120 -0
- data/lib/read.rb +48 -108
- data/lib/write.rb +59 -99
- data/rvpacker-txt.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0be6dfc912a9d15dd4be7c37ecee0c316d650ca10f89eb99af19d5baf38addf2
|
|
4
|
+
data.tar.gz: a0ed09eac3d11c36db6d9014e4c0bc6ffa2408ac8c4a78f55fdfbb08285b759a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bfc00222eff1dc676c73e62bc9048a89a4ea01fdce63eda1e7373a8d4f5a4d9975418111844704127cae24f2d01848d8486ba544f8f2de409346801f9563325c
|
|
7
|
+
data.tar.gz: 473d0707b8359f54dd49ed665addf7cbfedf4a80ccadfaf6f7d997db9e4f691ae05a4882187a5dad3c8a6dc37231c11efb6e997a573bd89a70bc3f366f6e8695
|
data/README.md
CHANGED
|
@@ -36,7 +36,10 @@ OPTIONS:
|
|
|
36
36
|
--disable-processing FILES Skips processing specified files.
|
|
37
37
|
Example: --disable-processing=maps,other,system.
|
|
38
38
|
[Allowed values: maps, other, system, scripts]
|
|
39
|
-
--disable-custom-processing Disables built-in custom
|
|
39
|
+
--disable-custom-processing Disables built-in custom text processing for some games.
|
|
40
|
+
This flag will automatically be used when writing if you parsed game text with it.
|
|
41
|
+
-r, --romanize If you parsing text from a Japanese game, that contains symbols like 「」, which are just the Japanese quotation marks,
|
|
42
|
+
it automatically replaces these symbols by their roman equivalents (in this case, "").
|
|
40
43
|
This flag will automatically be used when writing if you parsed game text with it.
|
|
41
44
|
-l, --log Enables logging.
|
|
42
45
|
-h, --help Prints the program's help message or for the entered subcommand.
|
data/bin/rvpacker-txt
CHANGED
|
@@ -85,19 +85,19 @@ def self.parse_options
|
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
cmd.on('--disable-custom-processing',
|
|
88
|
-
'Disables built-in custom
|
|
88
|
+
'Disables built-in custom text processing for some games.',
|
|
89
89
|
'This flag will automatically be used when writing if you parsed game text with it.') do
|
|
90
90
|
options[:disable_custom_processing] = true
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
end
|
|
93
|
+
cmd.on('-r', '--romanize',
|
|
94
|
+
'If you parsing text from a Japanese game, that contains symbols like 「」, which are just the Japanese quotation marks,',
|
|
95
|
+
'it automatically replaces these symbols by their roman equivalents (in this case, "").',
|
|
96
|
+
'This flag will automatically be used when writing if you parsed game text with it.') do
|
|
97
|
+
options[:romanize] = true
|
|
98
|
+
end
|
|
100
99
|
|
|
100
|
+
if options[:action] == 'read'
|
|
101
101
|
cmd.on('-f', '--force',
|
|
102
102
|
'Force rewrite all files. Cannot be used with --append.',
|
|
103
103
|
'USE WITH CAUTION!') do
|
|
@@ -256,7 +256,7 @@ else
|
|
|
256
256
|
end
|
|
257
257
|
|
|
258
258
|
if metadata[:disable_custom_processing] && !game_type.nil?
|
|
259
|
-
puts 'Disabling custom
|
|
259
|
+
puts 'Disabling custom processing according to the metadata from previous read.'
|
|
260
260
|
game_type = nil
|
|
261
261
|
end
|
|
262
262
|
end
|
data/lib/classes.rb
CHANGED
|
@@ -112,6 +112,16 @@ class IndexSet
|
|
|
112
112
|
end
|
|
113
113
|
end
|
|
114
114
|
|
|
115
|
+
class Hash
|
|
116
|
+
def insert_at_index(index, key, value)
|
|
117
|
+
return self[key] = value if index >= size
|
|
118
|
+
|
|
119
|
+
temp_array = to_a
|
|
120
|
+
temp_array.insert(index, [key, value])
|
|
121
|
+
replace(temp_array.to_h)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
115
125
|
module RPG
|
|
116
126
|
class Map
|
|
117
127
|
attr_accessor :display_name, :events
|
data/lib/extensions.rb
CHANGED
|
@@ -43,6 +43,8 @@ def self.romanize_string(string)
|
|
|
43
43
|
string[i] = '!'
|
|
44
44
|
when '※'
|
|
45
45
|
string[i] = '*'
|
|
46
|
+
when ' '
|
|
47
|
+
string[i] = ' '
|
|
46
48
|
when 'Ⅰ'
|
|
47
49
|
string[i] = 'I'
|
|
48
50
|
when 'ⅰ'
|
|
@@ -114,3 +116,121 @@ def self.romanize_string(string)
|
|
|
114
116
|
|
|
115
117
|
string
|
|
116
118
|
end
|
|
119
|
+
|
|
120
|
+
# @param [Array<String>] array Array of strings
|
|
121
|
+
# @return [Array<String>] Array of shuffled strings
|
|
122
|
+
def self.shuffle_words(array)
|
|
123
|
+
array.each do |string|
|
|
124
|
+
select_words_re = /\S+/
|
|
125
|
+
words = string.scan(select_words_re).shuffle
|
|
126
|
+
string.gsub(select_words_re) { words.pop || '' }
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# @param [String] string A parsed scripts code string, containing raw Ruby code
|
|
131
|
+
# @param [Symbol] mode Mode to extract quoted strings
|
|
132
|
+
# @return [IndexSet<String>] Set of extracted strings
|
|
133
|
+
def extract_quoted_strings(string, mode)
|
|
134
|
+
if mode == :read
|
|
135
|
+
result = IndexSet.new
|
|
136
|
+
|
|
137
|
+
skip_block = false
|
|
138
|
+
in_quotes = false
|
|
139
|
+
quote_type = nil
|
|
140
|
+
buffer = []
|
|
141
|
+
|
|
142
|
+
string.each_line do |line|
|
|
143
|
+
stripped = line.strip
|
|
144
|
+
|
|
145
|
+
next if stripped[0] == '#' ||
|
|
146
|
+
(!in_quotes && !stripped.match?(/["']/)) ||
|
|
147
|
+
stripped.start_with?(/(Win|Lose)|_Fanfare/) ||
|
|
148
|
+
stripped.match?(/eval\(/)
|
|
149
|
+
|
|
150
|
+
skip_block = true if stripped.start_with?('=begin')
|
|
151
|
+
skip_block = false if stripped.start_with?('=end')
|
|
152
|
+
|
|
153
|
+
next if skip_block
|
|
154
|
+
|
|
155
|
+
line.each_char do |char|
|
|
156
|
+
if %w[' "].include?(char)
|
|
157
|
+
unless quote_type.nil? || char == quote_type
|
|
158
|
+
buffer.push(char)
|
|
159
|
+
next
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
quote_type = char
|
|
163
|
+
in_quotes = !in_quotes
|
|
164
|
+
result.add(buffer.join)
|
|
165
|
+
buffer.clear
|
|
166
|
+
next
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
next unless in_quotes
|
|
170
|
+
|
|
171
|
+
if char == "\r"
|
|
172
|
+
next
|
|
173
|
+
elsif char == "\n"
|
|
174
|
+
buffer.push('\#')
|
|
175
|
+
next
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
buffer.push(char)
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
result
|
|
183
|
+
else
|
|
184
|
+
strings_array = []
|
|
185
|
+
indices_array = []
|
|
186
|
+
|
|
187
|
+
skip_block = false
|
|
188
|
+
in_quotes = false
|
|
189
|
+
quote_type = nil
|
|
190
|
+
buffer = []
|
|
191
|
+
|
|
192
|
+
current_string_index = 0
|
|
193
|
+
string.each_line do |line|
|
|
194
|
+
stripped = line.strip
|
|
195
|
+
|
|
196
|
+
if stripped[0] == '#' || stripped.start_with?(/(Win|Lose)|_Fanfare/)
|
|
197
|
+
current_string_index += line.length
|
|
198
|
+
next
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
skip_block = true if stripped.start_with?('=begin')
|
|
202
|
+
skip_block = false if stripped.start_with?('=end')
|
|
203
|
+
|
|
204
|
+
if skip_block
|
|
205
|
+
current_string_index += line.length
|
|
206
|
+
next
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
buffer.push('\#') if in_quotes
|
|
210
|
+
|
|
211
|
+
line.each_char.each_with_index do |char, index|
|
|
212
|
+
if %w[' "].include?(char)
|
|
213
|
+
unless quote_type.nil? || char == quote_type
|
|
214
|
+
buffer.push(char)
|
|
215
|
+
next
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
quote_type = char
|
|
219
|
+
in_quotes = !in_quotes
|
|
220
|
+
|
|
221
|
+
strings_array.push(buffer.join)
|
|
222
|
+
indices_array.push(current_string_index + index)
|
|
223
|
+
|
|
224
|
+
buffer.clear
|
|
225
|
+
next
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
buffer.push(char) if in_quotes
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
current_string_index += line.length
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
[strings_array, indices_array]
|
|
235
|
+
end
|
|
236
|
+
end
|
data/lib/read.rb
CHANGED
|
@@ -3,72 +3,9 @@
|
|
|
3
3
|
require 'zlib'
|
|
4
4
|
require_relative 'extensions'
|
|
5
5
|
|
|
6
|
-
STRING_IS_ONLY_SYMBOLS_RE = /^[.()+\-:;\[\]^~%&!№$@`*\/→×??x%▼|♥♪!:〜『』「」〽。…‥=゠、,【】[]{}()〔〕⦅⦆〘〙〈〉《》・\\#'"<>=_ー※▶ⅠⅰⅡⅱⅢⅲⅣⅳⅤⅴⅥⅵⅦⅶⅧⅷⅨⅸⅩⅹⅪⅺⅫⅻⅬⅼⅭⅽⅮⅾⅯⅿ\
|
|
6
|
+
STRING_IS_ONLY_SYMBOLS_RE = /^[.()+\-:;\[\]^~%&!№$@`*\/→×??x%▼|♥♪!:〜『』「」〽。…‥=゠、,【】[]{}()〔〕⦅⦆〘〙〈〉《》・\\#'"<>=_ー※▶ⅠⅰⅡⅱⅢⅲⅣⅳⅤⅴⅥⅵⅦⅶⅧⅷⅨⅸⅩⅹⅪⅺⅫⅻⅬⅼⅭⅽⅮⅾⅯⅿ\s0-9]+$/
|
|
7
7
|
APPEND_FLAG_OMIT_MSG = "Files aren't already parsed. Continuing as if --append flag was omitted."
|
|
8
8
|
|
|
9
|
-
class Hash
|
|
10
|
-
def insert_at_index(index, key, value)
|
|
11
|
-
return self[key] = value if index >= size
|
|
12
|
-
|
|
13
|
-
temp_array = to_a
|
|
14
|
-
temp_array.insert(index, [key, value])
|
|
15
|
-
replace(temp_array.to_h)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# @param [String] string A parsed scripts code string, containing raw Ruby code
|
|
20
|
-
# @return [IndexSet<String>] Set of extracted strings
|
|
21
|
-
def self.extract_quoted_strings(string)
|
|
22
|
-
result = IndexSet.new
|
|
23
|
-
|
|
24
|
-
skip_block = false
|
|
25
|
-
in_quotes = false
|
|
26
|
-
quote_type = nil
|
|
27
|
-
buffer = []
|
|
28
|
-
|
|
29
|
-
string.each_line do |line|
|
|
30
|
-
stripped = line.strip
|
|
31
|
-
|
|
32
|
-
next if stripped[0] == '#' ||
|
|
33
|
-
(!in_quotes && !stripped.match?(/["']/)) ||
|
|
34
|
-
stripped.start_with?(/(Win|Lose)|_Fanfare/) ||
|
|
35
|
-
stripped.match?(/eval\(/)
|
|
36
|
-
|
|
37
|
-
skip_block = true if stripped.start_with?('=begin')
|
|
38
|
-
skip_block = false if stripped.start_with?('=end')
|
|
39
|
-
|
|
40
|
-
next if skip_block
|
|
41
|
-
|
|
42
|
-
line.each_char do |char|
|
|
43
|
-
if %w[' "].include?(char)
|
|
44
|
-
unless quote_type.nil? || char == quote_type
|
|
45
|
-
buffer.push(char)
|
|
46
|
-
next
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
quote_type = char
|
|
50
|
-
in_quotes = !in_quotes
|
|
51
|
-
result.add(buffer.join)
|
|
52
|
-
buffer.clear
|
|
53
|
-
next
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
next unless in_quotes
|
|
57
|
-
|
|
58
|
-
if char == "\r"
|
|
59
|
-
next
|
|
60
|
-
elsif char == "\n"
|
|
61
|
-
buffer.push('\#')
|
|
62
|
-
next
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
buffer.push(char)
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
result
|
|
70
|
-
end
|
|
71
|
-
|
|
72
9
|
# @param [Integer] code
|
|
73
10
|
# @param [String] parameter
|
|
74
11
|
# @param [String] game_type
|
|
@@ -108,21 +45,19 @@ end
|
|
|
108
45
|
# @param [String] _game_type
|
|
109
46
|
# @return [String]
|
|
110
47
|
def self.parse_variable(variable, type, _game_type)
|
|
111
|
-
variable = variable.gsub(/\r?\n/,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
48
|
+
variable = variable.gsub(/\r?\n/, "\n")
|
|
49
|
+
# for some reason it returns true if multi-line string contains carriage returns (wtf?)
|
|
50
|
+
return nil if variable.match?(STRING_IS_ONLY_SYMBOLS_RE)
|
|
51
|
+
|
|
52
|
+
if variable.split("\n").all? do |line|
|
|
53
|
+
line.empty? ||
|
|
54
|
+
line.match?(/^#? ?<.*>.?$/) ||
|
|
55
|
+
line.match?(/^[a-z][0-9]$/)
|
|
56
|
+
end
|
|
57
|
+
return nil
|
|
121
58
|
end
|
|
122
59
|
|
|
123
|
-
return nil if
|
|
124
|
-
|
|
125
|
-
return nil if variable.match?(/^[+-]?[0-9]*$/) ||
|
|
60
|
+
return nil if variable.match?(/^[+-]?[0-9]+$/) ||
|
|
126
61
|
variable.match?(/---/) ||
|
|
127
62
|
variable.match?(/restrict eval/)
|
|
128
63
|
|
|
@@ -213,9 +148,9 @@ def self.read_map(maps_files_paths, output_path, romanize, logging, game_type, p
|
|
|
213
148
|
list.each do |item|
|
|
214
149
|
code = item.code
|
|
215
150
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
joined = line.join('\#')
|
|
151
|
+
if in_sequence && code != 401
|
|
152
|
+
unless line.empty?
|
|
153
|
+
joined = line.join("\n").strip.gsub("\n", '\#')
|
|
219
154
|
parsed = parse_parameter(401, joined, game_type)
|
|
220
155
|
|
|
221
156
|
unless parsed.nil?
|
|
@@ -225,21 +160,22 @@ def self.read_map(maps_files_paths, output_path, romanize, logging, game_type, p
|
|
|
225
160
|
!maps_translation_map.include?(parsed)
|
|
226
161
|
|
|
227
162
|
maps_lines.add(parsed)
|
|
228
|
-
|
|
229
|
-
line.clear
|
|
230
|
-
in_sequence = false
|
|
231
163
|
end
|
|
232
164
|
end
|
|
233
|
-
|
|
165
|
+
|
|
166
|
+
line.clear
|
|
167
|
+
in_sequence = false
|
|
234
168
|
end
|
|
235
169
|
|
|
170
|
+
next unless allowed_codes.include?(code)
|
|
171
|
+
|
|
236
172
|
parameters = item.parameters
|
|
237
173
|
|
|
238
174
|
if code == 401
|
|
239
175
|
next unless parameters[0].is_a?(String) && !parameters[0].empty?
|
|
240
176
|
|
|
241
177
|
in_sequence = true
|
|
242
|
-
line.push(parameters[0])
|
|
178
|
+
line.push(parameters[0].gsub(' ', ' ').strip)
|
|
243
179
|
elsif parameters[0].is_a?(Array)
|
|
244
180
|
parameters[0].each do |subparameter|
|
|
245
181
|
next unless subparameter.is_a?(String)
|
|
@@ -264,7 +200,6 @@ def self.read_map(maps_files_paths, output_path, romanize, logging, game_type, p
|
|
|
264
200
|
parsed = parse_parameter(code, parameter, game_type)
|
|
265
201
|
next if parsed.nil?
|
|
266
202
|
|
|
267
|
-
parsed = parsed.gsub(/\r?\n/, '\#')
|
|
268
203
|
parsed = romanize_string(parsed) if romanize
|
|
269
204
|
|
|
270
205
|
maps_translation_map.insert_at_index(maps_lines.length, parsed, '') if processing_mode == :append &&
|
|
@@ -350,22 +285,28 @@ def self.read_other(other_files_paths, output_path, romanize, logging, game_type
|
|
|
350
285
|
description = object.description
|
|
351
286
|
note = object.note
|
|
352
287
|
|
|
353
|
-
|
|
354
|
-
|
|
288
|
+
catch :next_object do
|
|
289
|
+
[name, nickname, description, note].each_with_index do |variable, type|
|
|
290
|
+
next unless variable.is_a?(String)
|
|
355
291
|
|
|
356
|
-
|
|
357
|
-
|
|
292
|
+
variable = variable.strip
|
|
293
|
+
next if variable.empty?
|
|
358
294
|
|
|
359
|
-
|
|
360
|
-
next if parsed.nil?
|
|
295
|
+
parsed = parse_variable(variable, type, game_type)
|
|
361
296
|
|
|
362
|
-
|
|
363
|
-
|
|
297
|
+
if !parsed.nil?
|
|
298
|
+
parsed = romanize_string(parsed) if romanize
|
|
364
299
|
|
|
365
|
-
|
|
366
|
-
!other_translation_map.include?(parsed)
|
|
300
|
+
parsed = parsed.split("\n").map(&:strip).join('\#')
|
|
367
301
|
|
|
368
|
-
|
|
302
|
+
other_translation_map.insert_at_index(other_lines.length, parsed, '') if inner_processing_type == :append &&
|
|
303
|
+
!other_translation_map.include?(parsed)
|
|
304
|
+
|
|
305
|
+
other_lines.add(parsed)
|
|
306
|
+
elsif type.zero?
|
|
307
|
+
throw :next_object
|
|
308
|
+
end
|
|
309
|
+
end
|
|
369
310
|
end
|
|
370
311
|
end
|
|
371
312
|
else
|
|
@@ -385,9 +326,9 @@ def self.read_other(other_files_paths, output_path, romanize, logging, game_type
|
|
|
385
326
|
list.each do |item|
|
|
386
327
|
code = item.code
|
|
387
328
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
joined = line.join('\#')
|
|
329
|
+
if in_sequence && ![401, 405].include?(code)
|
|
330
|
+
unless line.empty?
|
|
331
|
+
joined = line.join("\n").strip.gsub("\n", '\#')
|
|
391
332
|
parsed = parse_parameter(401, joined, game_type)
|
|
392
333
|
|
|
393
334
|
unless parsed.nil?
|
|
@@ -397,21 +338,22 @@ def self.read_other(other_files_paths, output_path, romanize, logging, game_type
|
|
|
397
338
|
!other_translation_map.include?(parsed)
|
|
398
339
|
|
|
399
340
|
other_lines.add(parsed)
|
|
400
|
-
|
|
401
|
-
line.clear
|
|
402
|
-
in_sequence = false
|
|
403
341
|
end
|
|
404
342
|
end
|
|
405
|
-
|
|
343
|
+
|
|
344
|
+
line.clear
|
|
345
|
+
in_sequence = false
|
|
406
346
|
end
|
|
407
347
|
|
|
348
|
+
next unless allowed_codes.include?(code)
|
|
349
|
+
|
|
408
350
|
parameters = item.parameters
|
|
409
351
|
|
|
410
352
|
if [401, 405].include?(code)
|
|
411
353
|
next unless parameters[0].is_a?(String) && !parameters[0].empty?
|
|
412
354
|
|
|
413
355
|
in_sequence = true
|
|
414
|
-
line.push(parameters[0].gsub(
|
|
356
|
+
line.push(parameters[0].gsub(' ', ' ').strip)
|
|
415
357
|
elsif parameters[0].is_a?(Array)
|
|
416
358
|
parameters[0].each do |subparameter|
|
|
417
359
|
next unless subparameter.is_a?(String)
|
|
@@ -436,7 +378,6 @@ def self.read_other(other_files_paths, output_path, romanize, logging, game_type
|
|
|
436
378
|
parsed = parse_parameter(code, parameter, game_type)
|
|
437
379
|
next if parsed.nil?
|
|
438
380
|
|
|
439
|
-
parsed = parsed.gsub(/\r?\n/, '\#')
|
|
440
381
|
parsed = romanize_string(parsed) if romanize
|
|
441
382
|
|
|
442
383
|
other_translation_map.insert_at_index(other_lines.length, parsed, '') if inner_processing_type == :append &&
|
|
@@ -450,7 +391,6 @@ def self.read_other(other_files_paths, output_path, romanize, logging, game_type
|
|
|
450
391
|
parsed = parse_parameter(code, parameter, game_type)
|
|
451
392
|
next if parsed.nil?
|
|
452
393
|
|
|
453
|
-
parsed = parsed.gsub(/\r?\n/, '\#')
|
|
454
394
|
parsed = romanize_string(parsed) if romanize
|
|
455
395
|
|
|
456
396
|
other_translation_map.insert_at_index(other_lines.length, parsed, '') if inner_processing_type == :append &&
|
|
@@ -670,7 +610,7 @@ def self.read_scripts(scripts_file_path, output_path, romanize, logging, process
|
|
|
670
610
|
end
|
|
671
611
|
end
|
|
672
612
|
|
|
673
|
-
extract_quoted_strings(code).each do |string|
|
|
613
|
+
extract_quoted_strings(code, :read).each do |string|
|
|
674
614
|
# Removes the U+3000 Japanese typographical space to check if string, when stripped, is truly empty
|
|
675
615
|
string = string.strip.delete(' ')
|
|
676
616
|
|
data/lib/write.rb
CHANGED
|
@@ -3,79 +3,21 @@
|
|
|
3
3
|
require 'zlib'
|
|
4
4
|
require_relative 'extensions'
|
|
5
5
|
|
|
6
|
-
# @param [String] string A parsed scripts code string, containing raw Ruby code
|
|
7
|
-
# @return [Array<Array<String, Integer>>] Hash of parsed from code strings and their start indices
|
|
8
|
-
def self.extract_quoted_strings(string)
|
|
9
|
-
strings_array = []
|
|
10
|
-
indices_array = []
|
|
11
|
-
|
|
12
|
-
skip_block = false
|
|
13
|
-
in_quotes = false
|
|
14
|
-
quote_type = nil
|
|
15
|
-
buffer = []
|
|
16
|
-
|
|
17
|
-
current_string_index = 0
|
|
18
|
-
string.each_line do |line|
|
|
19
|
-
stripped = line.strip
|
|
20
|
-
|
|
21
|
-
if stripped[0] == '#' || stripped.start_with?(/(Win|Lose)|_Fanfare/)
|
|
22
|
-
current_string_index += line.length
|
|
23
|
-
next
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
skip_block = true if stripped.start_with?('=begin')
|
|
27
|
-
skip_block = false if stripped.start_with?('=end')
|
|
28
|
-
|
|
29
|
-
if skip_block
|
|
30
|
-
current_string_index += line.length
|
|
31
|
-
next
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
buffer.push('\#') if in_quotes
|
|
35
|
-
|
|
36
|
-
line.each_char.each_with_index do |char, index|
|
|
37
|
-
if %w[' "].include?(char)
|
|
38
|
-
unless quote_type.nil? || char == quote_type
|
|
39
|
-
buffer.push(char)
|
|
40
|
-
next
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
quote_type = char
|
|
44
|
-
in_quotes = !in_quotes
|
|
45
|
-
|
|
46
|
-
strings_array.push(buffer.join)
|
|
47
|
-
indices_array.push(current_string_index + index)
|
|
48
|
-
|
|
49
|
-
buffer.clear
|
|
50
|
-
next
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
buffer.push(char) if in_quotes
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
current_string_index += line.length
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
[strings_array, indices_array]
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
# @param [Array<String>] array Array of strings
|
|
63
|
-
# @return [Array<String>] Array of shuffled strings
|
|
64
|
-
def self.shuffle_words(array)
|
|
65
|
-
array.each do |string|
|
|
66
|
-
select_words_re = /\S+/
|
|
67
|
-
words = string.scan(select_words_re).shuffle
|
|
68
|
-
string.gsub(select_words_re) { words.pop || '' }
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
6
|
# @param [Integer] code
|
|
73
7
|
# @param [String] parameter
|
|
74
8
|
# @param [Hash{String => String}] hashmap Translation hashmap (as everything in Ruby passed by reference, this pass is free!)
|
|
75
9
|
# @param [String] game_type
|
|
76
10
|
def self.get_parameter_translated(code, parameter, hashmap, game_type)
|
|
11
|
+
remaining_strings = []
|
|
12
|
+
insert_positions = []
|
|
13
|
+
|
|
77
14
|
ends_with_if = parameter[/ if\(.*\)$/]
|
|
78
|
-
|
|
15
|
+
|
|
16
|
+
if ends_with_if
|
|
17
|
+
parameter = parameter.chomp(ends_with_if)
|
|
18
|
+
remaining_strings.push(ends_with_if)
|
|
19
|
+
insert_positions.push(1)
|
|
20
|
+
end
|
|
79
21
|
|
|
80
22
|
unless game_type.nil?
|
|
81
23
|
case game_type
|
|
@@ -85,11 +27,8 @@ def self.get_parameter_translated(code, parameter, hashmap, game_type)
|
|
|
85
27
|
prefix = parameter[/^(\\et\[[0-9]+\]|\\nbt)/]
|
|
86
28
|
parameter = parameter.sub(prefix, '') if prefix
|
|
87
29
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
translated = prefix + translated if prefix
|
|
92
|
-
return translated
|
|
30
|
+
remaining_strings.push(prefix)
|
|
31
|
+
insert_positions.push(0)
|
|
93
32
|
when 102, 402
|
|
94
33
|
# Implement some custom parsing
|
|
95
34
|
when 356
|
|
@@ -105,16 +44,26 @@ def self.get_parameter_translated(code, parameter, hashmap, game_type)
|
|
|
105
44
|
|
|
106
45
|
translated = hashmap[parameter]
|
|
107
46
|
return nil if translated.nil? || translated.empty?
|
|
108
|
-
|
|
47
|
+
|
|
48
|
+
remaining_strings.zip(insert_positions).each do |string, position|
|
|
49
|
+
case position
|
|
50
|
+
when 0
|
|
51
|
+
translated = string + translated
|
|
52
|
+
when 1
|
|
53
|
+
translated += string
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
109
57
|
translated
|
|
110
58
|
end
|
|
111
59
|
|
|
112
60
|
# @param [String] variable
|
|
113
|
-
#
|
|
61
|
+
# @param [Integer] type
|
|
62
|
+
# @param [String] filename
|
|
114
63
|
# @param [Hash{String => String}] hashmap Translation hashmap (as everything in Ruby passed by reference, this pass is free!)
|
|
115
64
|
# @param [String] _game_type
|
|
116
65
|
# @return [String]
|
|
117
|
-
def self.get_variable_translated(variable, type, hashmap, _game_type)
|
|
66
|
+
def self.get_variable_translated(variable, type, _filename, hashmap, _game_type)
|
|
118
67
|
variable = variable.gsub(/\r?\n/, "\n")
|
|
119
68
|
|
|
120
69
|
case type
|
|
@@ -197,14 +146,14 @@ def self.write_map(original_files_paths, maps_path, output_path, shuffle_level,
|
|
|
197
146
|
list.each_with_index do |item, it|
|
|
198
147
|
code = item.code
|
|
199
148
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
joined = line.join(
|
|
149
|
+
if in_sequence && code != 401
|
|
150
|
+
unless line.empty?
|
|
151
|
+
joined = line.join("\n").strip
|
|
203
152
|
joined = romanize_string(joined) if romanize
|
|
204
153
|
|
|
205
154
|
translated = get_parameter_translated(401, joined, maps_translation_map, game_type)
|
|
206
155
|
|
|
207
|
-
|
|
156
|
+
if !translated.nil? && !translated.empty?
|
|
208
157
|
split = translated.split('\#')
|
|
209
158
|
|
|
210
159
|
split_length = split.length
|
|
@@ -219,16 +168,20 @@ def self.write_map(original_files_paths, maps_path, output_path, shuffle_level,
|
|
|
219
168
|
end
|
|
220
169
|
end
|
|
221
170
|
end
|
|
222
|
-
|
|
171
|
+
|
|
172
|
+
line.clear
|
|
173
|
+
in_sequence = false
|
|
223
174
|
end
|
|
224
175
|
|
|
176
|
+
next unless allowed_codes.include?(code)
|
|
177
|
+
|
|
225
178
|
parameters = item.parameters
|
|
226
179
|
|
|
227
180
|
if code == 401
|
|
228
181
|
next unless parameters[0].is_a?(String) && !parameters[0].empty?
|
|
229
182
|
|
|
230
183
|
in_sequence = true
|
|
231
|
-
line.push(parameters[0])
|
|
184
|
+
line.push(parameters[0].gsub(' ', ' ').strip)
|
|
232
185
|
item_indices.push(it)
|
|
233
186
|
elsif parameters[0].is_a?(Array)
|
|
234
187
|
parameters[0].each_with_index do |subparameter, sp|
|
|
@@ -240,7 +193,7 @@ def self.write_map(original_files_paths, maps_path, output_path, shuffle_level,
|
|
|
240
193
|
subparameter = romanize_string(subparameter) if romanize
|
|
241
194
|
|
|
242
195
|
translated = get_parameter_translated(code, subparameter, maps_translation_map, game_type)
|
|
243
|
-
parameters[0][sp] = translated
|
|
196
|
+
parameters[0][sp] = translated if !translated.nil? && !translated.empty?
|
|
244
197
|
end
|
|
245
198
|
elsif parameters[0].is_a?(String)
|
|
246
199
|
parameter = parameters[0].strip
|
|
@@ -249,7 +202,7 @@ def self.write_map(original_files_paths, maps_path, output_path, shuffle_level,
|
|
|
249
202
|
parameter = romanize_string(parameter) if romanize
|
|
250
203
|
|
|
251
204
|
translated = get_parameter_translated(code, parameter, maps_translation_map, game_type)
|
|
252
|
-
parameters[0] = translated
|
|
205
|
+
parameters[0] = translated if !translated.nil? && !translated.empty?
|
|
253
206
|
elsif parameters[1].is_a?(String)
|
|
254
207
|
parameter = parameters[1].strip
|
|
255
208
|
next if parameter.empty?
|
|
@@ -257,7 +210,7 @@ def self.write_map(original_files_paths, maps_path, output_path, shuffle_level,
|
|
|
257
210
|
parameter = romanize_string(parameter) if romanize
|
|
258
211
|
|
|
259
212
|
translated = get_parameter_translated(code, parameter, maps_translation_map, game_type)
|
|
260
|
-
parameters[1] = translated
|
|
213
|
+
parameters[1] = translated if !translated.nil? && !translated.empty?
|
|
261
214
|
end
|
|
262
215
|
|
|
263
216
|
item.parameters = parameters
|
|
@@ -328,9 +281,12 @@ def self.write_other(original_files_paths, other_path, output_path, shuffle_leve
|
|
|
328
281
|
next if variable.empty?
|
|
329
282
|
|
|
330
283
|
variable = romanize_string(variable) if romanize
|
|
331
|
-
translated = get_variable_translated(variable, type, other_translation_map, game_type)
|
|
332
284
|
|
|
333
|
-
|
|
285
|
+
variable = variable.split("\n").map(&:strip).join("\n")
|
|
286
|
+
|
|
287
|
+
translated = get_variable_translated(variable, type, filename, other_translation_map, game_type)
|
|
288
|
+
|
|
289
|
+
if !translated.nil? && !translated.empty?
|
|
334
290
|
if type.zero?
|
|
335
291
|
object.name = translated
|
|
336
292
|
elsif type == 1
|
|
@@ -361,14 +317,14 @@ def self.write_other(original_files_paths, other_path, output_path, shuffle_leve
|
|
|
361
317
|
list.each_with_index do |item, it|
|
|
362
318
|
code = item.code
|
|
363
319
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
joined = line.join(
|
|
320
|
+
if in_sequence && ![401, 405].include?(code)
|
|
321
|
+
unless line.empty?
|
|
322
|
+
joined = line.join("\n").strip
|
|
367
323
|
joined = romanize_string(joined) if romanize
|
|
368
324
|
|
|
369
325
|
translated = get_parameter_translated(401, joined, other_translation_map, game_type)
|
|
370
326
|
|
|
371
|
-
|
|
327
|
+
if !translated.nil? && !translated.empty?
|
|
372
328
|
split = translated.split('\#')
|
|
373
329
|
|
|
374
330
|
split_length = split.length
|
|
@@ -383,16 +339,20 @@ def self.write_other(original_files_paths, other_path, output_path, shuffle_leve
|
|
|
383
339
|
end
|
|
384
340
|
end
|
|
385
341
|
end
|
|
386
|
-
|
|
342
|
+
|
|
343
|
+
line.clear
|
|
344
|
+
in_sequence = false
|
|
387
345
|
end
|
|
388
346
|
|
|
347
|
+
next unless allowed_codes.include?(code)
|
|
348
|
+
|
|
389
349
|
parameters = item.parameters
|
|
390
350
|
|
|
391
351
|
if [401, 405].include?(code)
|
|
392
352
|
next unless parameters[0].is_a?(String) && !parameters[0].empty?
|
|
393
353
|
|
|
394
354
|
in_sequence = true
|
|
395
|
-
line.push(parameters[0])
|
|
355
|
+
line.push(parameters[0].gsub(' ', ' ').strip)
|
|
396
356
|
item_indices.push(it)
|
|
397
357
|
elsif parameters[0].is_a?(Array)
|
|
398
358
|
parameters[0].each_with_index do |subparameter, sp|
|
|
@@ -404,7 +364,7 @@ def self.write_other(original_files_paths, other_path, output_path, shuffle_leve
|
|
|
404
364
|
subparameter = romanize_string(subparameter) if romanize
|
|
405
365
|
|
|
406
366
|
translated = get_parameter_translated(code, subparameter, other_translation_map, game_type)
|
|
407
|
-
parameters[0][sp] = translated
|
|
367
|
+
parameters[0][sp] = translated if !translated.nil? && !translated.empty?
|
|
408
368
|
end
|
|
409
369
|
elsif parameters[0].is_a?(String)
|
|
410
370
|
parameter = parameters[0].strip
|
|
@@ -413,7 +373,7 @@ def self.write_other(original_files_paths, other_path, output_path, shuffle_leve
|
|
|
413
373
|
parameter = romanize_string(parameter) if romanize
|
|
414
374
|
|
|
415
375
|
translated = get_parameter_translated(code, parameter, other_translation_map, game_type)
|
|
416
|
-
parameters[0] = translated
|
|
376
|
+
parameters[0] = translated if !translated.nil? && !translated.empty?
|
|
417
377
|
elsif parameters[1].is_a?(String)
|
|
418
378
|
parameter = parameters[1].strip
|
|
419
379
|
next if parameter.empty?
|
|
@@ -421,7 +381,7 @@ def self.write_other(original_files_paths, other_path, output_path, shuffle_leve
|
|
|
421
381
|
parameter = romanize_string(parameter) if romanize
|
|
422
382
|
|
|
423
383
|
translated = get_parameter_translated(code, parameter, other_translation_map, game_type)
|
|
424
|
-
parameters[1] = translated
|
|
384
|
+
parameters[1] = translated if !translated.nil? && !translated.empty?
|
|
425
385
|
end
|
|
426
386
|
|
|
427
387
|
item.parameters = parameters
|
|
@@ -498,7 +458,7 @@ def self.write_system(system_file_path, ini_file_path, other_path, output_path,
|
|
|
498
458
|
string = romanize_string(string) if romanize
|
|
499
459
|
|
|
500
460
|
translated = system_translation_map[string]
|
|
501
|
-
array[i] = translated
|
|
461
|
+
array[i] = translated if !translated.nil? && !translated.empty?
|
|
502
462
|
end
|
|
503
463
|
|
|
504
464
|
if i.zero?
|
|
@@ -527,7 +487,7 @@ def self.write_system(system_file_path, ini_file_path, other_path, output_path,
|
|
|
527
487
|
value = romanize_string(value) if romanize
|
|
528
488
|
|
|
529
489
|
translated = system_translation_map[value]
|
|
530
|
-
value = translated
|
|
490
|
+
value = translated if !translated.nil? && !translated.empty?
|
|
531
491
|
elsif value.is_a?(Array)
|
|
532
492
|
value.each_with_index do |string, i|
|
|
533
493
|
string = string.strip
|
|
@@ -536,7 +496,7 @@ def self.write_system(system_file_path, ini_file_path, other_path, output_path,
|
|
|
536
496
|
string = romanize_string(string) if romanize
|
|
537
497
|
|
|
538
498
|
translated = system_translation_map[string]
|
|
539
|
-
value[i] = translated
|
|
499
|
+
value[i] = translated if !translated.nil? && !translated.empty?
|
|
540
500
|
end
|
|
541
501
|
end
|
|
542
502
|
|
|
@@ -599,7 +559,7 @@ def self.write_scripts(scripts_file_path, other_path, output_path, romanize, log
|
|
|
599
559
|
end
|
|
600
560
|
|
|
601
561
|
# this shit finally works and requires NO further changes
|
|
602
|
-
string_array, index_array = extract_quoted_strings(code)
|
|
562
|
+
string_array, index_array = extract_quoted_strings(code, :write)
|
|
603
563
|
|
|
604
564
|
string_array.zip(index_array).reverse_each do |string, index|
|
|
605
565
|
string = string.strip.delete(' ')
|
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
|
+
spec.version = '1.11.0'
|
|
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.
|
|
4
|
+
version: 1.11.0
|
|
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-
|
|
15
|
+
date: 2024-07-28 00:00:00.000000000 Z
|
|
16
16
|
dependencies: []
|
|
17
17
|
description:
|
|
18
18
|
email:
|