rvpacker-txt 1.10.0 → 1.12.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 +6 -33
- data/lib/extensions.rb +89 -0
- data/lib/read.rb +78 -165
- data/lib/write.rb +63 -110
- 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: dc893f5cf25ad608e961d2b85408d1acaedaed3e508eaf74688bc0814f4a740c
|
|
4
|
+
data.tar.gz: 8c157c1d2446add716a05615e1f1d10dd758bcbb30feba4938a2420b350e892d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3dd75b346fa21bcbc16b15c7e081b7fbd72a97796afac4343fc43c656b9d84ff504cdfc51962a771e4a54a9a17c29134a0e23fc3e158cab245c8226935c23035
|
|
7
|
+
data.tar.gz: 5fe5adf14cc73bd8681c61e16186a4652e22223581265784b207553ecc592252b574b15881f0f6964074c90fdd45b58a455ccb10469932248477ef79a91c07e5
|
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
|
@@ -75,40 +75,13 @@ class Rect
|
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
@hash = Hash.new
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def add(item)
|
|
85
|
-
return if @hash.include?(item)
|
|
86
|
-
@hash[item] = @hash.size
|
|
87
|
-
@hash
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def include?(item)
|
|
91
|
-
@hash.include?(item)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def each(&block)
|
|
95
|
-
@hash.each_key(&block)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def to_a
|
|
99
|
-
@hash.dup
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def join(delimiter = '')
|
|
103
|
-
@hash.keys.join(delimiter)
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def length
|
|
107
|
-
@hash.size
|
|
108
|
-
end
|
|
78
|
+
class Hash
|
|
79
|
+
def insert_at_index(index, key, value)
|
|
80
|
+
return self[key] = value if index >= size
|
|
109
81
|
|
|
110
|
-
|
|
111
|
-
|
|
82
|
+
temp_array = to_a
|
|
83
|
+
temp_array.insert(index, [key, value])
|
|
84
|
+
replace(temp_array.to_h)
|
|
112
85
|
end
|
|
113
86
|
end
|
|
114
87
|
|
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,90 @@ 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
|
+
def escaped?(line, index)
|
|
131
|
+
backslash_count = 0
|
|
132
|
+
|
|
133
|
+
(0..index).reverse_each do |i|
|
|
134
|
+
break if line[i] != '\\'
|
|
135
|
+
backslash_count += 1
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
backslash_count.even?
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# @param [String] ruby_code
|
|
142
|
+
def extract_strings(ruby_code, mode = false)
|
|
143
|
+
strings = mode ? [] : Set.new
|
|
144
|
+
indices = []
|
|
145
|
+
inside_string = false
|
|
146
|
+
inside_multiline_comment = false
|
|
147
|
+
string_start_index = 0
|
|
148
|
+
current_quote_type = ''
|
|
149
|
+
|
|
150
|
+
global_index = 0
|
|
151
|
+
ruby_code.each_line do |line|
|
|
152
|
+
stripped = line.strip
|
|
153
|
+
|
|
154
|
+
unless inside_string
|
|
155
|
+
if stripped[0] == '#'
|
|
156
|
+
global_index += line.length
|
|
157
|
+
next
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
if stripped.start_with?('=begin')
|
|
161
|
+
inside_multiline_comment = true
|
|
162
|
+
elsif stripped.start_with?('=end')
|
|
163
|
+
inside_multiline_comment = false
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
if inside_multiline_comment
|
|
168
|
+
global_index += line.length
|
|
169
|
+
next
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
i = 0
|
|
173
|
+
while i < line.length
|
|
174
|
+
char = line[i]
|
|
175
|
+
|
|
176
|
+
if !inside_string && char == '#'
|
|
177
|
+
break
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
if !inside_string && ['"', "'"].include?(char)
|
|
181
|
+
inside_string = true
|
|
182
|
+
string_start_index = global_index + i
|
|
183
|
+
current_quote_type = char
|
|
184
|
+
elsif inside_string && char == current_quote_type && escaped?(line, i - 1)
|
|
185
|
+
extracted_string = ruby_code[string_start_index + 1...global_index + i].gsub(/\r?\n/, '\#')
|
|
186
|
+
|
|
187
|
+
if mode
|
|
188
|
+
strings << extracted_string
|
|
189
|
+
indices << string_start_index + 1
|
|
190
|
+
else
|
|
191
|
+
strings.add(extracted_string)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
inside_string = false
|
|
195
|
+
current_quote_type = ''
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
i += 1
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
global_index += line.length
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
mode ? [strings, indices] : strings.to_a
|
|
205
|
+
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
|
|
|
@@ -157,8 +92,8 @@ def self.read_map(maps_files_paths, output_path, romanize, logging, game_type, p
|
|
|
157
92
|
|
|
158
93
|
maps_object_map = Hash[maps_files_paths.map { |f| [File.basename(f), Marshal.load(File.binread(f))] }]
|
|
159
94
|
|
|
160
|
-
maps_lines =
|
|
161
|
-
names_lines =
|
|
95
|
+
maps_lines = Set.new
|
|
96
|
+
names_lines = Set.new
|
|
162
97
|
|
|
163
98
|
maps_translation_map = nil
|
|
164
99
|
names_translation_map = nil
|
|
@@ -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,23 @@ 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
|
|
164
|
+
|
|
165
|
+
line.clear
|
|
232
166
|
end
|
|
233
|
-
|
|
167
|
+
|
|
168
|
+
in_sequence = false
|
|
234
169
|
end
|
|
235
170
|
|
|
171
|
+
next unless allowed_codes.include?(code)
|
|
172
|
+
|
|
236
173
|
parameters = item.parameters
|
|
237
174
|
|
|
238
175
|
if code == 401
|
|
239
176
|
next unless parameters[0].is_a?(String) && !parameters[0].empty?
|
|
240
177
|
|
|
241
178
|
in_sequence = true
|
|
242
|
-
line.push(parameters[0])
|
|
179
|
+
line.push(parameters[0].gsub(' ', ' ').strip)
|
|
243
180
|
elsif parameters[0].is_a?(Array)
|
|
244
181
|
parameters[0].each do |subparameter|
|
|
245
182
|
next unless subparameter.is_a?(String)
|
|
@@ -264,7 +201,6 @@ def self.read_map(maps_files_paths, output_path, romanize, logging, game_type, p
|
|
|
264
201
|
parsed = parse_parameter(code, parameter, game_type)
|
|
265
202
|
next if parsed.nil?
|
|
266
203
|
|
|
267
|
-
parsed = parsed.gsub(/\r?\n/, '\#')
|
|
268
204
|
parsed = romanize_string(parsed) if romanize
|
|
269
205
|
|
|
270
206
|
maps_translation_map.insert_at_index(maps_lines.length, parsed, '') if processing_mode == :append &&
|
|
@@ -327,7 +263,7 @@ def self.read_other(other_files_paths, output_path, romanize, logging, game_type
|
|
|
327
263
|
next
|
|
328
264
|
end
|
|
329
265
|
|
|
330
|
-
other_lines =
|
|
266
|
+
other_lines = Set.new
|
|
331
267
|
other_translation_map = nil
|
|
332
268
|
|
|
333
269
|
if processing_mode == :append
|
|
@@ -350,22 +286,28 @@ def self.read_other(other_files_paths, output_path, romanize, logging, game_type
|
|
|
350
286
|
description = object.description
|
|
351
287
|
note = object.note
|
|
352
288
|
|
|
353
|
-
|
|
354
|
-
|
|
289
|
+
catch :next_object do
|
|
290
|
+
[name, nickname, description, note].each_with_index do |variable, type|
|
|
291
|
+
next unless variable.is_a?(String)
|
|
292
|
+
|
|
293
|
+
variable = variable.strip
|
|
294
|
+
next if variable.empty?
|
|
355
295
|
|
|
356
|
-
|
|
357
|
-
next if variable.empty?
|
|
296
|
+
parsed = parse_variable(variable, type, game_type)
|
|
358
297
|
|
|
359
|
-
|
|
360
|
-
|
|
298
|
+
if !parsed.nil?
|
|
299
|
+
parsed = romanize_string(parsed) if romanize
|
|
361
300
|
|
|
362
|
-
|
|
363
|
-
parsed = romanize_string(parsed) if romanize
|
|
301
|
+
parsed = parsed.split("\n").map(&:strip).join('\#')
|
|
364
302
|
|
|
365
|
-
|
|
366
|
-
|
|
303
|
+
other_translation_map.insert_at_index(other_lines.length, parsed, '') if inner_processing_type == :append &&
|
|
304
|
+
!other_translation_map.include?(parsed)
|
|
367
305
|
|
|
368
|
-
|
|
306
|
+
other_lines.add(parsed)
|
|
307
|
+
elsif type.zero?
|
|
308
|
+
throw :next_object
|
|
309
|
+
end
|
|
310
|
+
end
|
|
369
311
|
end
|
|
370
312
|
end
|
|
371
313
|
else
|
|
@@ -385,9 +327,9 @@ def self.read_other(other_files_paths, output_path, romanize, logging, game_type
|
|
|
385
327
|
list.each do |item|
|
|
386
328
|
code = item.code
|
|
387
329
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
joined = line.join('\#')
|
|
330
|
+
if in_sequence && ![401, 405].include?(code)
|
|
331
|
+
unless line.empty?
|
|
332
|
+
joined = line.join("\n").strip.gsub("\n", '\#')
|
|
391
333
|
parsed = parse_parameter(401, joined, game_type)
|
|
392
334
|
|
|
393
335
|
unless parsed.nil?
|
|
@@ -397,21 +339,23 @@ def self.read_other(other_files_paths, output_path, romanize, logging, game_type
|
|
|
397
339
|
!other_translation_map.include?(parsed)
|
|
398
340
|
|
|
399
341
|
other_lines.add(parsed)
|
|
400
|
-
|
|
401
|
-
line.clear
|
|
402
|
-
in_sequence = false
|
|
403
342
|
end
|
|
343
|
+
|
|
344
|
+
line.clear
|
|
404
345
|
end
|
|
405
|
-
|
|
346
|
+
|
|
347
|
+
in_sequence = false
|
|
406
348
|
end
|
|
407
349
|
|
|
350
|
+
next unless allowed_codes.include?(code)
|
|
351
|
+
|
|
408
352
|
parameters = item.parameters
|
|
409
353
|
|
|
410
354
|
if [401, 405].include?(code)
|
|
411
355
|
next unless parameters[0].is_a?(String) && !parameters[0].empty?
|
|
412
356
|
|
|
413
357
|
in_sequence = true
|
|
414
|
-
line.push(parameters[0].gsub(
|
|
358
|
+
line.push(parameters[0].gsub(' ', ' ').strip)
|
|
415
359
|
elsif parameters[0].is_a?(Array)
|
|
416
360
|
parameters[0].each do |subparameter|
|
|
417
361
|
next unless subparameter.is_a?(String)
|
|
@@ -436,7 +380,6 @@ def self.read_other(other_files_paths, output_path, romanize, logging, game_type
|
|
|
436
380
|
parsed = parse_parameter(code, parameter, game_type)
|
|
437
381
|
next if parsed.nil?
|
|
438
382
|
|
|
439
|
-
parsed = parsed.gsub(/\r?\n/, '\#')
|
|
440
383
|
parsed = romanize_string(parsed) if romanize
|
|
441
384
|
|
|
442
385
|
other_translation_map.insert_at_index(other_lines.length, parsed, '') if inner_processing_type == :append &&
|
|
@@ -450,7 +393,6 @@ def self.read_other(other_files_paths, output_path, romanize, logging, game_type
|
|
|
450
393
|
parsed = parse_parameter(code, parameter, game_type)
|
|
451
394
|
next if parsed.nil?
|
|
452
395
|
|
|
453
|
-
parsed = parsed.gsub(/\r?\n/, '\#')
|
|
454
396
|
parsed = romanize_string(parsed) if romanize
|
|
455
397
|
|
|
456
398
|
other_translation_map.insert_at_index(other_lines.length, parsed, '') if inner_processing_type == :append &&
|
|
@@ -509,7 +451,7 @@ def self.read_system(system_file_path, ini_file_path, output_path, romanize, log
|
|
|
509
451
|
|
|
510
452
|
system_object = Marshal.load(File.binread(system_file_path))
|
|
511
453
|
|
|
512
|
-
system_lines =
|
|
454
|
+
system_lines = Set.new
|
|
513
455
|
system_translation_map = nil
|
|
514
456
|
|
|
515
457
|
if processing_mode == :append
|
|
@@ -635,7 +577,7 @@ def self.read_scripts(scripts_file_path, output_path, romanize, logging, process
|
|
|
635
577
|
|
|
636
578
|
script_entries = Marshal.load(File.binread(scripts_file_path))
|
|
637
579
|
|
|
638
|
-
scripts_lines =
|
|
580
|
+
scripts_lines = Set.new
|
|
639
581
|
scripts_translation_map = nil
|
|
640
582
|
|
|
641
583
|
if processing_mode == :append
|
|
@@ -653,8 +595,6 @@ def self.read_scripts(scripts_file_path, output_path, romanize, logging, process
|
|
|
653
595
|
# This code was fun before `that` game used Windows-1252 degree symbol
|
|
654
596
|
script_entries.each do |script|
|
|
655
597
|
code = Zlib::Inflate.inflate(script[2]).force_encoding('UTF-8')
|
|
656
|
-
# we're fucking cloning because of encoding issue
|
|
657
|
-
codes_content.push(code.clone)
|
|
658
598
|
|
|
659
599
|
# I figured how String#encode works - now everything is good
|
|
660
600
|
unless code.valid_encoding?
|
|
@@ -670,62 +610,35 @@ def self.read_scripts(scripts_file_path, output_path, romanize, logging, process
|
|
|
670
610
|
end
|
|
671
611
|
end
|
|
672
612
|
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
string = string.strip.delete(' ')
|
|
613
|
+
codes_content.push(code)
|
|
614
|
+
end
|
|
676
615
|
|
|
677
|
-
|
|
616
|
+
extracted = extract_strings(codes_content.join)
|
|
678
617
|
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
string.match?(/^\d+$/) ||
|
|
683
|
-
string.match?(/%.*(\d|\+|\*)d\]?:?$/) ||
|
|
684
|
-
string.match?(/^\[((ON|OFF)|P[EMRT])\]$/) ||
|
|
685
|
-
string.match?(/^\[\]$/) ||
|
|
686
|
-
string.match?(/^(.)\1{2,}$/) ||
|
|
687
|
-
string.match?(/^(false|true)$/) ||
|
|
688
|
-
string.match?(/^[wr]b$/) ||
|
|
689
|
-
string.match?(/^(?=.*\d)[A-Za-z0-9-]+$/) ||
|
|
690
|
-
string.match?(/^[a-z\-()\/ +'&]*$/) ||
|
|
691
|
-
string.match?(/^[A-Za-z]+[+-]$/) ||
|
|
692
|
-
string.match?(STRING_IS_ONLY_SYMBOLS_RE) ||
|
|
693
|
-
string.match?(/^Tile.*[A-Z]$/) ||
|
|
694
|
-
string.match?(/^[a-zA-Z][a-z]+([A-Z][a-z]*)+$/) ||
|
|
695
|
-
string.match?(/^Cancel Action$|^Invert$|^End$|^Individual$|^Missed File$|^Bitmap$|^Audio$/) ||
|
|
696
|
-
string.match?(/^(?=.*%d)(?=.*%m)(?=.*%Y).*$/) ||
|
|
697
|
-
string.match?(/^\\\\ALPHAC/) ||
|
|
698
|
-
string.match?(/^[A-Z]{,3}-[A-Z][A-Za-z]+/) ||
|
|
699
|
-
string.match?(/\.(mp3|ogg|jpg|png|ini|txt)$/i) ||
|
|
700
|
-
string.match?(/\/(\d.*)?$/) ||
|
|
701
|
-
string.match?(/FILE$/) ||
|
|
702
|
-
string.match?(/#\{/) ||
|
|
703
|
-
string.match?(/(?<!\\)\\(?![\\G#])/) ||
|
|
704
|
-
string.match?(/\+?=?=/) ||
|
|
705
|
-
string.match?(/[}{_<>]/) ||
|
|
706
|
-
string.match?(/r[vx]data/) ||
|
|
707
|
-
string.match?(/No such file or directory/) ||
|
|
708
|
-
string.match?(/level \*\*/) ||
|
|
709
|
-
string.match?(/Courier New|Comic Sans|Lucida|Verdana|Tahoma|Arial|Times New Roman/) ||
|
|
710
|
-
string.match?(/Player start location/) ||
|
|
711
|
-
string.match?(/Common event call has exceeded/) ||
|
|
712
|
-
string.match?(/se-/) ||
|
|
713
|
-
string.match?(/Start Pos/) ||
|
|
714
|
-
string.match?(/An error has occurred/) ||
|
|
715
|
-
string.match?(/Define it first/) ||
|
|
716
|
-
string.match?(/Process Skill/) ||
|
|
717
|
-
string.match?(/Wpn Only/) ||
|
|
718
|
-
string.match?(/Don't Wait/) ||
|
|
719
|
-
string.match?(/Clear image/) ||
|
|
720
|
-
string.match?(/Can Collapse/)
|
|
618
|
+
extracted.each do |string|
|
|
619
|
+
# Removes the U+3000 Japanese typographical space to check if string, when stripped, is truly empty
|
|
620
|
+
string = string.gsub(' ', ' ').strip
|
|
721
621
|
|
|
722
|
-
|
|
622
|
+
next if string.empty?
|
|
723
623
|
|
|
724
|
-
|
|
725
|
-
|
|
624
|
+
next if string.match?(/(Graphics|Data|Audio|Movies|System)\/.*\/?/) ||
|
|
625
|
+
string.match?(/r[xv]data2?$/) ||
|
|
626
|
+
string.match?(STRING_IS_ONLY_SYMBOLS_RE) ||
|
|
627
|
+
string.match?(/@window/) ||
|
|
628
|
+
string.match?(/\$game/) ||
|
|
629
|
+
string.match?(/_/) ||
|
|
630
|
+
string.match?(/^\\e/) ||
|
|
631
|
+
string.match?(/.*\(/) ||
|
|
632
|
+
string.match?(/^([d\d\p{P}+-]*|[d\p{P}+-]*)$/) ||
|
|
633
|
+
string.match?(/ALPHAC/) ||
|
|
634
|
+
string.match?(/^(Actor<id>|ExtraDropItem|EquipLearnSkill|GameOver|Iconset|Window|true|false|MActor%d|w[rb]|\\f|\\n|\[[A-Z]*\])$/)
|
|
726
635
|
|
|
727
|
-
|
|
728
|
-
|
|
636
|
+
string = romanize_string(string) if romanize
|
|
637
|
+
|
|
638
|
+
scripts_translation_map.insert_at_index(scripts_lines.length, string, '') if processing_mode == :append &&
|
|
639
|
+
!scripts_translation_map.include?(string)
|
|
640
|
+
|
|
641
|
+
scripts_lines.add(string)
|
|
729
642
|
end
|
|
730
643
|
|
|
731
644
|
puts "Parsed #{scripts_filename}" if logging
|
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
|
|
@@ -215,20 +164,24 @@ def self.write_map(original_files_paths, maps_path, output_path, shuffle_level,
|
|
|
215
164
|
end
|
|
216
165
|
|
|
217
166
|
if split_length > line_length
|
|
218
|
-
list[item_indices.last].parameters[0] = split[line_length..].join("\n")
|
|
167
|
+
list[item_indices.last].parameters[0] = split[line_length - 1..].join("\n")
|
|
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
|
|
@@ -379,20 +335,24 @@ def self.write_other(original_files_paths, other_path, output_path, shuffle_leve
|
|
|
379
335
|
end
|
|
380
336
|
|
|
381
337
|
if split_length > line_length
|
|
382
|
-
list[item_indices.last].parameters[0] = split[line_length..].join("\n")
|
|
338
|
+
list[item_indices.last].parameters[0] = split[line_length - 1..].join("\n")
|
|
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
|
|
|
@@ -576,15 +536,10 @@ def self.write_scripts(scripts_file_path, other_path, output_path, romanize, log
|
|
|
576
536
|
|
|
577
537
|
scripts_translation_map = Hash[scripts_original_text.zip(scripts_translated_text)]
|
|
578
538
|
|
|
579
|
-
# Shuffle can possibly break the game in scripts, so no shuffling
|
|
580
|
-
codes = []
|
|
581
|
-
|
|
582
|
-
# This code was fun before `that` game used Windows-1252 degree symbol
|
|
583
539
|
script_entries.each do |script|
|
|
584
540
|
code = Zlib::Inflate.inflate(script[2])
|
|
585
541
|
code.force_encoding('UTF-8')
|
|
586
542
|
|
|
587
|
-
# I figured how String#encode works - now everything is good
|
|
588
543
|
unless code.valid_encoding?
|
|
589
544
|
[Encoding::UTF_8, Encoding::WINDOWS_1252, Encoding::SHIFT_JIS].each do |encoding|
|
|
590
545
|
encoded = code.encode(code.encoding, encoding)
|
|
@@ -599,23 +554,21 @@ def self.write_scripts(scripts_file_path, other_path, output_path, romanize, log
|
|
|
599
554
|
end
|
|
600
555
|
|
|
601
556
|
# this shit finally works and requires NO further changes
|
|
602
|
-
string_array, index_array =
|
|
557
|
+
string_array, index_array = extract_strings(code, true)
|
|
603
558
|
|
|
604
559
|
string_array.zip(index_array).reverse_each do |string, index|
|
|
605
|
-
string = string.
|
|
560
|
+
string = string.gsub(' ', '').strip
|
|
606
561
|
next if string.empty? || !scripts_translation_map.include?(string)
|
|
607
562
|
|
|
608
563
|
string = romanize_string(string) if romanize
|
|
609
564
|
|
|
610
565
|
gotten = scripts_translation_map[string]
|
|
611
|
-
code[index
|
|
566
|
+
code[index, string.length] = gotten unless gotten.nil? || gotten.empty?
|
|
612
567
|
end
|
|
613
568
|
|
|
614
|
-
codes.push(code)
|
|
615
569
|
script[2] = Zlib::Deflate.deflate(code, Zlib::BEST_COMPRESSION)
|
|
616
570
|
end
|
|
617
571
|
|
|
618
|
-
# File.binwrite(File.join(output_path, 'scripts_plain.txt'), codes.join("\n")) - debug line
|
|
619
572
|
File.binwrite(File.join(output_path, scripts_basename), Marshal.dump(script_entries))
|
|
620
573
|
puts "Written #{scripts_basename}" if logging
|
|
621
574
|
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
|
+
spec.version = '1.12.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.12.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-
|
|
15
|
+
date: 2024-08-02 00:00:00.000000000 Z
|
|
16
16
|
dependencies: []
|
|
17
17
|
description:
|
|
18
18
|
email:
|