rvpacker-txt 1.2.1 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 366c510ab91e885534a8dd5d3c7421b3b6c68f03beaad2bcc7e5e160ba05bbf8
4
- data.tar.gz: 6d93ab447d98bd285d738b0e5183ffadd8c59bb0e078a8b2a42db8fc3c463153
3
+ metadata.gz: 2b17d69aea817f8b41bc154daf4a4f6c6f4c2a0200427cefefadf593c8fae715
4
+ data.tar.gz: 79a5a1f73df2a44a7571df5fb47bb76c234ecf774946cbdeb51d6a23265a7e13
5
5
  SHA512:
6
- metadata.gz: ba4567fab07d8d079b9a5b60663c9a45ed006edba0006c48dfebf7d4bef70ad5fa5f338f7bd6ed8211530c8f69861c309d14d8f07a59b747e65d21d5227b2f12
7
- data.tar.gz: cb0d9fe0cab421d58c0d6d867b6602974d5b94191b0fa421171ccf0d87ea5a93ef821838ece9f4d6990dd50542ccd0d82d566f184c2e5b66d180f6462e3f6e0a
6
+ metadata.gz: 5ef9f467c491d122c582f0af55ded8757de79e1bc41eb92b9fdb40617a83b8b06d0cb57dae3d8ae7fc5e397004977b308d303b4489446654022b19ba79279d91
7
+ data.tar.gz: 00fa12e46f27a7c225bf76179431f4e680d9e4da2c85c48ff0e2355b257254eab80c31d5e07e9be1681982c450d4bfbb3d8d48d41e9e1ab2343af9e7872bcb20
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in rvpacker-txt.gemspec
4
- gemspec
4
+ gemspec
5
+ gem 'rubocop', group: 'development', require: false
data/Rakefile CHANGED
@@ -1,2 +1 @@
1
- require "bundler/gem_tasks"
2
-
1
+ require 'bundler/gem_tasks'
data/bin/rvpacker-txt CHANGED
@@ -1,52 +1,55 @@
1
1
  #!/usr/bin/env ruby
2
- require 'RGSS'
2
+ require 'classes'
3
3
  require 'optparse'
4
4
 
5
5
  $logging = false
6
6
  $shuffle = 0
7
- $no = [true, true, true, true] # 0 is whether to process maps, 1 is other, 2 is system, 3 is scripts
7
+ $no = [false, false, false, false] # 0 is whether to NOT process maps, 1 is other, 2 is system, 3 is scripts
8
8
 
9
- opts = {}
10
- OptionParser.new do |options|
11
- options.banner = "This tool allows to parse RPG Maker project to .txt files and back.\n\nUsage: rvpacker-txt COMMAND [options]\n\nCOMMANDS:\n read - Parses RPG Maker game files to .txt\n write - Writes parsed files back to their initial form\nOPTIONS:\n"
9
+ options = {}
10
+ OptionParser.new do |command|
11
+ command.banner = "This tool allows to parse RPG Maker project to .txt files and back.\n\nUsage: rvpacker-txt COMMAND [options]\n\nCOMMANDS:\n read - Parses RPG Maker game files to .txt\n write - Writes parsed files back to their initial form\nOPTIONS:\n"
12
12
 
13
- options.on('-d', '--input-dir DIRECTORY', 'Input directory of RPG Maker project.',
13
+ command.on('-d',
14
+ '--input-dir DIRECTORY',
15
+ 'Input directory of RPG Maker project.',
14
16
  'Must contain "Data" or "original" folder to read,',
15
- 'and additionally "translation" with "maps" and "other" subdirectories to write.') do |dir|
16
- opts[:input_dir] = dir
17
- end
17
+ 'and additionally "translation" with "maps" and "other" subdirectories to write.') { |dir| options[:input_dir] = dir }
18
18
 
19
- options.on('--no', "Don't process specified files.", 'Takes multiple values separated by a comma.', 'Allowed values: maps, other, system, plugins') do |files|
19
+ command.on('--no',
20
+ "Don't process specified files.",
21
+ 'Takes multiple values separated by a comma.',
22
+ 'Allowed values: maps, other, system, plugins') do |files|
20
23
  actual_files = files.split(',')
21
24
 
22
25
  actual_files.each do |file|
23
26
  case file
24
27
  when "maps"
25
- $no[0] = false
28
+ $no[0] = true
26
29
  when "other"
27
- $no[1] = false
30
+ $no[1] = true
28
31
  when "system"
29
- $no[2] = false
32
+ $no[2] = true
30
33
  when "scripts"
31
- $no[3] = false
34
+ $no[3] = true
32
35
  else
33
- nil
36
+ puts "Wrong value for no argument: #{file}.\nAllowed values: maps, other, system, plugins"
37
+ exit
34
38
  end
35
39
  end
36
40
  end
37
41
 
38
- options.on('-s', '--shuffle NUMBER', 'At value 1: Shuffles all lines in strings, at value 2: shuffles all lines and words in strings.') do |number|
39
- $shuffle = number
40
- end
42
+ command.on('-s',
43
+ '--shuffle NUMBER',
44
+ 'At value 1: Shuffles all lines in strings, at value 2: shuffles all lines and words in strings.') { |number| $shuffle = number }
41
45
 
42
- options.on('-l', '--log', 'Log information while processing.') do
43
- $logging = true
44
- end
46
+ command.on('-l',
47
+ '--log',
48
+ 'Log information while processing.') { $logging = true }
45
49
 
46
- options.on_tail('-h', '--help', 'Show help message.') do
47
- puts options
48
- exit
49
- end
50
+ command.on_tail('-h',
51
+ '--help',
52
+ 'Show help message.') { puts command; exit }
50
53
  end.parse!(ARGV)
51
54
 
52
55
  if ARGV.empty?
@@ -54,37 +57,27 @@ if ARGV.empty?
54
57
  exit
55
58
  end
56
59
 
57
- opts[:action] = ARGV.shift
60
+ options[:action] = ARGV.shift
58
61
 
59
- unless %w[read write].include?(opts[:action])
62
+ unless %w[read write].include?(options[:action])
60
63
  puts 'Invalid command. Allowed commands are: read, write.'
61
64
  exit
62
65
  end
63
66
 
64
- project_types = { 'vx' => :vx, 'ace' => :ace, 'xp' => :xp }
65
-
66
- directory = opts[:input_dir]
67
+ directory = options[:input_dir]
67
68
  raise "#{directory} not found" unless File.exist?(directory)
68
69
 
69
- original_directory = Dir.foreach(directory).find { |filename| filename.downcase == 'original' } ||
70
- Dir.foreach(directory).find { |filename| filename.downcase == 'data' }
70
+ original_directory = Dir.foreach(directory).find { |dirname| dirname.downcase == 'original' || dirname.downcase == 'data' }
71
71
  raise '"Data" or "original" directory not found within input directory.' if original_directory.nil?
72
72
 
73
- types = %w[vx ace xp]
74
-
75
- type = types.find do |type_|
76
- case type_
77
- when 'xp'
78
- break project_types[type_] if File.exist?(File.join(directory, original_directory, 'System.rxdata'))
79
- when 'vx'
80
- break project_types[type_] if File.exist?(File.join(directory, original_directory, 'System.rvdata'))
81
- when 'ace'
82
- break project_types[type_] if File.exist?(File.join(directory, original_directory, 'System.rvdata2'))
83
- else
84
- break nil
85
- end
86
- end
87
-
88
- raise 'Couldn\'t determine project engine.' if type.nil?
89
-
90
- RGSS.serialize(type, opts[:action], directory, original_directory)
73
+ engine = if File.exist?(File.join(directory, original_directory, 'System.rxdata'))
74
+ :xp
75
+ elsif File.exist?(File.join(directory, original_directory, 'System.rvdata'))
76
+ :vx
77
+ elsif File.exist?(File.join(directory, original_directory, 'System.rvdata2'))
78
+ :ace
79
+ else
80
+ raise "Couldn't determine project engine."
81
+ end
82
+
83
+ RGSS.serialize(engine, options[:action], directory, original_directory,)
@@ -78,48 +78,10 @@ class Rect
78
78
  end
79
79
  end
80
80
 
81
- module RGSS
82
- def self.remove_defined_method(scope, name)
83
- if scope.instance_methods(false).include?(name)
84
- scope.send(:remove_method, name)
85
- end
86
- end
87
-
88
- def self.reset_method(scope, name, method)
89
- remove_defined_method(scope, name)
90
- scope.send(:define_method, name, method)
91
- end
92
-
93
- def self.reset_const(scope, symbol, value)
94
- scope.send(:remove_const, symbol) if scope.const_defined?(symbol)
95
- scope.send(:const_set, symbol, value)
96
- end
97
-
98
- def self.array_to_hash(array, &block)
99
- hash = {}
100
-
101
- array.each_with_index do |value, index|
102
- r = block_given? ? block.call(value) : value
103
- hash[index] = r unless r.nil?
104
- end
105
-
106
- unless array.empty?
107
- last = array.length - 1
108
- hash[last] = nil unless hash.has_key?(last)
109
- end
110
-
111
- hash
112
- end
113
-
114
- def self.hash_to_array(hash)
115
- array = []
116
- hash.each { |key, value| array[key] = value }
117
- array
118
- end
119
-
120
- require 'RGSS/BasicCoder'
121
- require 'RPG'
81
+ module RPG
82
+ end
122
83
 
84
+ module RGSS
123
85
  # creates an empty class in a potentially nested scope
124
86
  def self.process(root, name, *args)
125
87
  if !args.empty?
@@ -156,6 +118,7 @@ module RGSS
156
118
  %i[RPG Event Page],
157
119
  %i[RPG Event Page Condition],
158
120
  %i[RPG Event Page Graphic],
121
+ %i[RPG EventCommand],
159
122
  %i[RPG Item],
160
123
  %i[RPG Map],
161
124
  %i[RPG Map Encounter],
@@ -166,6 +129,7 @@ module RGSS
166
129
  %i[RPG SE],
167
130
  %i[RPG Skill],
168
131
  %i[RPG State],
132
+ %i[RPG System],
169
133
  %i[RPG System Terms],
170
134
  %i[RPG System TestBattler],
171
135
  %i[RPG System Vehicle],
@@ -178,103 +142,8 @@ module RGSS
178
142
  %i[RPG UsableItem],
179
143
  %i[RPG UsableItem Damage],
180
144
  %i[RPG UsableItem Effect],
181
- %i[RPG Weapon],
182
- # Script classes serialized in save game files
183
- [:Game_ActionResult],
184
- [:Game_Actor],
185
- [:Game_Actors],
186
- [:Game_BaseItem],
187
- [:Game_BattleAction],
188
- [:Game_CommonEvent],
189
- [:Game_Enemy],
190
- [:Game_Event],
191
- [:Game_Follower],
192
- [:Game_Followers],
193
- [:Game_Interpreter],
194
- [:Game_Map],
195
- [:Game_Message],
196
- [:Game_Party],
197
- [:Game_Picture],
198
- [:Game_Pictures],
199
- [:Game_Player],
200
- [:Game_System],
201
- [:Game_Timer],
202
- [:Game_Troop],
203
- [:Game_Screen],
204
- [:Game_Vehicle],
205
- [:Interpreter]
145
+ %i[RPG Weapon]
206
146
  ].each { |symbol_array| process(Object, *symbol_array) }
207
-
208
- def self.setup_classes(version)
209
- # change version_id to fixed number
210
- reset_method(
211
- RPG::System,
212
- :reduce_string,
213
- ->(string) do
214
- return nil if string.nil?
215
-
216
- stripped = string.strip
217
- stripped.empty? ? nil : stripped
218
- end
219
- )
220
-
221
- # These magic numbers should be different. If they are the same, the saved version
222
- # of the map in save files will be used instead of any updated version of the map
223
- reset_method(
224
- RPG::System,
225
- :map_version,
226
- ->(_ignored) { 12_345_678 }
227
- )
228
-
229
- reset_method(
230
- Game_System,
231
- :map_version,
232
- ->(_ignored) { 87_654_321 }
233
- )
234
-
235
- # Game_Interpreter is marshalled differently in VX Ace
236
- if version == :ace
237
- reset_method(Game_Interpreter, :marshal_dump, -> { @data })
238
- reset_method(
239
- Game_Interpreter,
240
- :marshal_load,
241
- ->(obj) { @data = obj }
242
- )
243
- else
244
- remove_defined_method(Game_Interpreter, :marshal_dump)
245
- remove_defined_method(Game_Interpreter, :marshal_load)
246
- end
247
-
248
- reset_method(
249
- RPG::EventCommand,
250
- :clean,
251
- -> { @parameters[0].rstrip! if @code == 401 }
252
- )
253
-
254
- reset_const(
255
- RPG::EventCommand,
256
- :MOVE_LIST_CODE,
257
- version == :xp ? 209 : 205
258
- )
259
-
260
- BasicCoder.ivars_methods_set(version)
261
- end
262
-
263
- class Game_Switches
264
- include RGSS::BasicCoder
265
- end
266
-
267
- class Game_Variables
268
- include RGSS::BasicCoder
269
- end
270
-
271
- class Game_SelfSwitches
272
- include RGSS::BasicCoder
273
- end
274
-
275
- class Game_System
276
- include RGSS::BasicCoder
277
- end
278
-
279
- require 'RGSS/serialize'
280
147
  end
148
+
149
+ require 'serialize'
@@ -65,8 +65,8 @@ module RGSS
65
65
 
66
66
  game_title.downcase!
67
67
 
68
- if game_title.include?("lisa")
69
- return "lisa"
68
+ if game_title.include?('lisa')
69
+ return 'lisa'
70
70
  end
71
71
 
72
72
  nil
@@ -76,8 +76,8 @@ module RGSS
76
76
  case code
77
77
  when 401, 405
78
78
  case $game_type
79
- when "lisa"
80
- match = parameter.scan(/^\\et\[[0-9]+\]|\\nbt/)
79
+ when 'lisa'
80
+ match = parameter.scan(/^(\\et\[[0-9]+\]|\\nbt)/)
81
81
  parameter = parameter.slice((match[0].length)..) if match
82
82
  else
83
83
  nil
@@ -98,7 +98,7 @@ module RGSS
98
98
  variable = variable.gsub(/\r?\n/, '\#')
99
99
 
100
100
  case $game_type
101
- when "lisa"
101
+ when 'lisa'
102
102
  unless variable.split('\#').all? { |line| line.match?(/^<.*>\.?$/) || line.length.nil? }
103
103
  return nil
104
104
  end
@@ -119,7 +119,7 @@ module RGSS
119
119
 
120
120
  object_map.each do |filename, object|
121
121
  display_name = object.instance_variable_get(:@display_name)
122
- lines[1].add(display_name) unless display_name.nil? || display_name.empty?
122
+ lines[1].add(display_name) if display_name.is_a?(String) && !display_name.empty?
123
123
 
124
124
  events = object.instance_variable_get(:@events)
125
125
  next if events.nil?
@@ -174,9 +174,9 @@ module RGSS
174
174
  end
175
175
 
176
176
  File.write("#{output_path}/maps.txt", lines[0].join("\n"))
177
- File.write("#{output_path}/maps_trans.txt", "\n" * (!lines[0].empty? ? lines[0].length - 1 : 0))
177
+ File.write("#{output_path}/maps_trans.txt", "\n" * (lines[0].empty? ? 0 : lines[0].length - 1))
178
178
  File.write("#{output_path}/names.txt", lines[1].join("\n"))
179
- File.write("#{output_path}/names_trans.txt", "\n" * (!lines[1].empty? ? lines[1].length - 1 : 0))
179
+ File.write("#{output_path}/names_trans.txt", "\n" * (lines[1].empty? ? 0 : lines[1].length - 1))
180
180
  end
181
181
 
182
182
  def self.read_other(original_other_files, output_path)
@@ -256,7 +256,7 @@ module RGSS
256
256
  puts "Parsed #{filename}" if $logging
257
257
 
258
258
  File.write("#{output_path}/#{processed_filename}.txt", lines.join("\n"))
259
- File.write("#{output_path}/#{processed_filename}_trans.txt", "\n" * (!lines.empty? ? lines.length - 1 : 0))
259
+ File.write("#{output_path}/#{processed_filename}_trans.txt", "\n" * (lines.empty? ? 0 : lines.length - 1))
260
260
  end
261
261
  end
262
262
 
@@ -298,7 +298,7 @@ module RGSS
298
298
  puts "Parsed #{filename}" if $logging
299
299
 
300
300
  File.write("#{output_path}/#{basename}.txt", lines.join("\n"), mode: 'wb')
301
- File.write("#{output_path}/#{basename}_trans.txt", "\n" * (!lines.empty? ? lines.length - 1 : 0),
301
+ File.write("#{output_path}/#{basename}_trans.txt", "\n" * (lines.empty? ? 0 : lines.length - 1),
302
302
  mode: 'wb')
303
303
  end
304
304
 
@@ -308,17 +308,15 @@ module RGSS
308
308
  words = string.scan(re)
309
309
  words.shuffle
310
310
 
311
- result = nil
312
-
313
311
  (0..(words.length)).each do |i|
314
- result = string.sub(string[i], words[i])
312
+ string.sub!(string[i], words[i])
315
313
  end
316
314
 
317
- result
315
+ string
318
316
  end
319
317
  end
320
318
 
321
- def self.extract_quoted_strings(input)
319
+ def self.extract_quoted_strings(string)
322
320
  result = []
323
321
 
324
322
  skip_block = false
@@ -326,12 +324,12 @@ module RGSS
326
324
  quote_type = nil
327
325
  buffer = []
328
326
 
329
- input.each_line(chomp: true) do |line|
327
+ string.each_line(chomp: true) do |line|
330
328
  line.strip!
331
329
  next if line[0] == '#' || line.start_with?(/(Win|Lose)|_Fanfare/)
332
330
 
333
- skip_block = true if line.start_with?("=begin")
334
- skip_block = false if line.start_with?("=end")
331
+ skip_block = true if line.start_with?('=begin')
332
+ skip_block = false if line.start_with?('=end')
335
333
 
336
334
  next if skip_block
337
335
 
@@ -339,7 +337,7 @@ module RGSS
339
337
 
340
338
  line.each_char do |char|
341
339
  if char == "'" || char == '"'
342
- if !quote_type.nil? && char != quote_type
340
+ unless quote_type.nil? || char == quote_type
343
341
  buffer.push(char)
344
342
  next
345
343
  end
@@ -375,11 +373,11 @@ module RGSS
375
373
  next if string.empty? || string.delete('  ').empty?
376
374
 
377
375
  # Maybe this mess will remove something that mustn't be removed, but it needs to be tested
378
- next if string.start_with?(/(#|!?\$|@|(\.\/)?(Graphics|Data|Audio|CG|Movies|Save)\/)/) ||
376
+ next if string.start_with?(/([#!?$@]|(\.\/)?(Graphics|Data|Audio|CG|Movies|Save)\/)/) ||
379
377
  string.match?(/^\d+$/) ||
380
378
  string.match?(/^(.)\1{2,}$/) ||
381
379
  string.match?(/^(false|true)$/) ||
382
- string.match?(/^(wb|rb)$/) ||
380
+ string.match?(/^[wr]b$/) ||
383
381
  string.match?(/^(?=.*\d)[A-Za-z0-9\-]+$/) ||
384
382
  string.match?(/^[A-Z\-()\/ +'&]*$/) ||
385
383
  string.match?(/^[a-z\-()\/ +'&]*$/) ||
@@ -388,15 +386,16 @@ module RGSS
388
386
  string.match?(/^Tile.*[A-Z]$/) ||
389
387
  string.match?(/^:?%.*[ds][:%]*?$/) ||
390
388
  string.match?(/^[a-zA-Z]+([A-Z][a-z]*)+$/) ||
389
+ string.match?(/^Cancel Action$|^Invert$|^End$|^Individual$|^Missed File$|^Bitmap$|^Audio$/) ||
391
390
  string.match?(/\.(mp3|ogg|jpg|png|ini)$/) ||
391
+ string.match?(/\/(\d.*)?$/) ||
392
+ string.match?(/FILE$/) ||
392
393
  string.match?(/#\{/) ||
393
394
  string.match?(/\\(?!#)/) ||
394
395
  string.match?(/\+?=?=/) ||
395
396
  string.match?(/[}{_<>]/) ||
396
397
  string.match?(/r[vx]data/) ||
397
- string.match?(/\/(\d.*)?$/) ||
398
- string.match?(/FILE$/) ||
399
- string.match?(/No such file or directory|level \*\*|Courier New|Comic Sans|Lucida|Verdana|Tahoma|Arial|Player start location|Common event call has exceeded|se-|Start Pos|An error has occurred|Define it first|Process Skill|Wpn Only|Don't Wait|Clear image|Can Collapse|^Cancel Action$|^Invert$|^End$|^Individual$|^Missed File$|^Bitmap$|^Audio$/)
398
+ string.match?(/No such file or directory|level \*\*|Courier New|Comic Sans|Lucida|Verdana|Tahoma|Arial|Player start location|Common event call has exceeded|se-|Start Pos|An error has occurred|Define it first|Process Skill|Wpn Only|Don't Wait|Clear image|Can Collapse/)
400
399
 
401
400
  strings.add(string)
402
401
  end
@@ -404,7 +403,7 @@ module RGSS
404
403
 
405
404
  File.write("#{output_path}/scripts_plain.txt", codes.join("\n"), mode: 'wb')
406
405
  File.write("#{output_path}/scripts.txt", strings.join("\n"), mode: 'wb')
407
- File.write("#{output_path}/scripts_trans.txt", "\n" * (!strings.empty? ? strings.length - 1 : 0), mode: 'wb')
406
+ File.write("#{output_path}/scripts_trans.txt", "\n" * (strings.empty? ? 0 : strings.length - 1), mode: 'wb')
408
407
  end
409
408
 
410
409
  def self.merge_seq(object_array)
@@ -428,7 +427,7 @@ module RGSS
428
427
  elsif i.positive? && in_sequence && !first.nil? && !number.negative?
429
428
  parameters = object_array[first].instance_variable_get(:@parameters)
430
429
  parameters[0] = string_array.join("\n")
431
- object_array[first].instance_variable_set(parameters)
430
+ object_array[first].instance_variable_set(:@parameters, parameters)
432
431
 
433
432
  start_index = first + 1
434
433
  items_to_delete = start_index + number
@@ -496,8 +495,8 @@ module RGSS
496
495
  case code
497
496
  when 401, 356, 405
498
497
  case $game_type
499
- when "lisa"
500
- match = parameter.scan(/^\\et\[[0-9]+\]/) || parameter.scan(/^\\nbt/)
498
+ when 'lisa'
499
+ match = parameter.scan(/^(\\et\[[0-9]+\]|\\nbt)/)
501
500
  lisa_start = match[0]
502
501
  parameter = parameter.slice((match[0].length)..) unless match.nil?
503
502
  else
@@ -512,7 +511,7 @@ module RGSS
512
511
  gotten = hashmap[parameter]
513
512
 
514
513
  case $game_type
515
- when "lisa"
514
+ when 'lisa'
516
515
  gotten = lisa_start + gotten unless lisa_start.nil?
517
516
  else
518
517
  nil
@@ -563,7 +562,8 @@ module RGSS
563
562
 
564
563
  object_map.each do |filename, object|
565
564
  display_name = object.instance_variable_get(:@display_name)
566
- object.instance_variable_set(:@display_name, names_translation_map[display_name]) if names_translation_map.key?(display_name)
565
+ display_name_gotten = names_translation_map[display_name]
566
+ object.instance_variable_set(:@display_name, display_name_gotten) unless display_name_gotten.nil?
567
567
 
568
568
  events = object.instance_variable_get(:@events)
569
569
  next if events.nil?
@@ -623,16 +623,14 @@ module RGSS
623
623
  object_array_map.each do |filename, object_array|
624
624
  processed_filename = File.basename(filename, '.*').downcase
625
625
 
626
- other_original_text = File.read("#{File.join(other_path, processed_filename)}.txt").split("\n").map do
627
- |line|
628
- line.gsub('\#', "\n")
629
- end
626
+ other_original_text = File.read("#{File.join(other_path, processed_filename)}.txt")
627
+ .split("\n")
628
+ .map { |line| line.gsub('\#', "\n") }
629
+ .freeze
630
630
 
631
- other_translated_text = File.read("#{File.join(other_path, processed_filename)}_trans.txt").split("\n")
632
- .map do
633
- |line|
634
- line.gsub('\#', "\n")
635
- end
631
+ other_translated_text = File.read("#{File.join(other_path, processed_filename)}_trans.txt")
632
+ .split("\n")
633
+ .map { |line| line.gsub('\#', "\n") }
636
634
 
637
635
  if $shuffle > 0
638
636
  other_translated_text.shuffle!
@@ -642,13 +640,13 @@ module RGSS
642
640
  end
643
641
  end
644
642
 
645
- other_translation_map = Hash[other_original_text.zip(other_translated_text)]
643
+ other_translation_map = Hash[other_original_text.zip(other_translated_text)].freeze
646
644
 
647
645
  if !filename.start_with?(/Common|Troops/)
648
646
  object_array.each do |object|
649
647
  next if object.nil?
650
648
 
651
- variables_symbols = %i[@name @nickname @description @note]
649
+ variables_symbols = %i[@name @nickname @description @note].freeze
652
650
 
653
651
  name = object.instance_variable_get(variables_symbols[0])
654
652
  nickname = object.instance_variable_get(variables_symbols[1])
@@ -686,7 +684,7 @@ module RGSS
686
684
  parameters[i] = translated unless translated.nil?
687
685
  end
688
686
  elsif parameter.is_a?(Array)
689
- parameter.each_with_index.map do |subparameter, j|
687
+ parameter.each_with_index do |subparameter, j|
690
688
  if subparameter.is_a?(String) && !subparameter.empty?
691
689
  translated = get_translated(code, subparameter, other_translation_map)
692
690
  parameters[i][j] = translated unless translated.nil?
@@ -711,8 +709,11 @@ module RGSS
711
709
  basename = File.basename(system_file_path)
712
710
  object = Marshal.load(File.read(system_file_path, mode: 'rb'))
713
711
 
714
- system_original_text = File.read("#{other_path}/system.txt").split("\n")
715
- system_translated_text = File.read("#{other_path}/system_trans.txt").split("\n")
712
+ system_original_text = File.read("#{other_path}/system.txt")
713
+ .split("\n")
714
+ .freeze
715
+ system_translated_text = File.read("#{other_path}/system_trans.txt")
716
+ .split("\n")
716
717
 
717
718
  if $shuffle > 0
718
719
  system_translated_text.shuffle!
@@ -722,30 +723,28 @@ module RGSS
722
723
  end
723
724
  end
724
725
 
725
- system_translation_map = Hash[system_original_text.zip(system_translated_text)]
726
+ system_translation_map = Hash[system_original_text.zip(system_translated_text)].freeze
726
727
 
727
- symbols = %i[@elements @skill_types @weapon_types @armor_types]
728
- elements = object.instance_variable_get(:@elements)
729
- skill_types = object.instance_variable_get(:@skill_types)
730
- weapon_types = object.instance_variable_get(:@weapon_types)
731
- armor_types = object.instance_variable_get(:@armor_types)
732
- currency_unit = object.instance_variable_get(:@currency_unit)
733
- terms = object.instance_variable_get(:@terms) || object.instance_variable_get(:@words)
734
- game_title = object.instance_variable_get(:@game_title)
728
+ symbols = %i[@elements @skill_types @weapon_types @armor_types @currency_unit @terms @words @game_title].freeze
735
729
 
736
- [elements, skill_types, weapon_types, armor_types].each_with_index.each do |array, i|
737
- next if array.nil?
730
+ elements = object.instance_variable_get(symbols[0])
731
+ skill_types = object.instance_variable_get(symbols[1])
732
+ weapon_types = object.instance_variable_get(symbols[2])
733
+ armor_types = object.instance_variable_get(symbols[3])
734
+ currency_unit = object.instance_variable_get(symbols[4])
735
+ terms = object.instance_variable_get(symbols[5]) || object.instance_variable_get(symbols[6])
736
+ game_title = object.instance_variable_get(symbols[7])
738
737
 
739
- array.each_with_index do |string, j|
740
- translated = system_translation_map[string]
741
- array[j] = translated unless translated.nil?
742
- end
738
+ [elements, skill_types, weapon_types, armor_types].each_with_index.each do |array, i|
739
+ next unless array.is_a?(Array)
743
740
 
741
+ array.map! { |string| system_translation_map[string] || string }
744
742
  object.instance_variable_set(symbols[i], array)
745
743
  end
746
744
 
747
- instance_variable_set(:@currency_unit, system_translation_map[currency_unit]) if !currency_unit.nil? &&
748
- system_translation_map.key?(currency_unit)
745
+ currency_unit_translated = system_translation_map[currency_unit]
746
+ object.instance_variable_set(symbols[4], currency_unit_translated) if currency_unit.is_a?(String) &&
747
+ !currency_unit_translated.nil?
749
748
 
750
749
  terms.instance_variables.each do |variable|
751
750
  value = terms.instance_variable_get(variable)
@@ -754,21 +753,18 @@ module RGSS
754
753
  translated = system_translation_map[value]
755
754
  value = translated unless translated.nil?
756
755
  elsif value.is_a?(Array)
757
- value.each_with_index do |string, i|
758
- translated = system_translation_map[string]
759
- value[i] = translated unless translated.nil?
760
- end
756
+ value.map! { |string| system_translation_map[string] || string }
761
757
  end
762
758
 
763
759
  terms.instance_variable_set(variable, value)
764
760
  end
765
761
 
766
- object.instance_variable_defined?(:@terms) ? object.instance_variable_set(:@terms, terms) : object
767
- .instance_variable_set(:@words, terms)
762
+ object.instance_variable_defined?(symbols[5]) ?
763
+ object.instance_variable_set(symbols[5], terms) :
764
+ object.instance_variable_set(symbols[6], terms)
768
765
 
769
- object.instance_variable_set(:@game_title, system_translation_map[game_title]) if !currency_unit.nil? &&
770
- system_translation_map
771
- .key?(game_title)
766
+ game_title_translated = system_translation_map[game_title]
767
+ object.instance_variable_set(symbols[7], game_title_translated) if currency_unit.is_a?(String) && !game_title_translated.nil?
772
768
 
773
769
  puts "Written #{basename}" if $logging
774
770
 
@@ -777,22 +773,25 @@ module RGSS
777
773
 
778
774
  def self.write_scripts(scripts_file, other_path, output_path)
779
775
  script_entries = Marshal.load(File.read(scripts_file, mode: 'rb'))
780
- original_strings = File.read("#{other_path}/scripts.txt", mode: 'rb')
781
- .force_encoding('UTF-8')
782
- .split("\n")
783
- .map { |line| line.gsub('\#', "\r\n") }
784
776
 
785
- translation_strings = File.read("#{other_path}/scripts_trans.txt", mode: 'rb')
786
- .force_encoding('UTF-8')
787
- .split("\n")
788
- .map { |line| line.gsub('\#', "\r\n") }
777
+ scripts_original_text = File.read("#{other_path}/scripts.txt", mode: 'rb')
778
+ .force_encoding('UTF-8')
779
+ .split("\n")
780
+ .map { |line| line.gsub('\#', "\r\n") }
781
+ .freeze
782
+
783
+ scripts_translated_text = File.read("#{other_path}/scripts_trans.txt", mode: 'rb')
784
+ .force_encoding('UTF-8')
785
+ .split("\n")
786
+ .map { |line| line.gsub('\#', "\r\n") }
787
+ .freeze
789
788
 
790
789
  # Shuffle can possibly break the game in scripts, so no shuffling
791
790
 
792
791
  script_entries.each do |script|
793
792
  code = Zlib::Inflate.inflate(script[2]).force_encoding('UTF-8')
794
793
 
795
- original_strings.zip(translation_strings).each do |original, translated|
794
+ scripts_original_text.zip(scripts_translated_text).each do |original, translated|
796
795
  code.gsub!(original, translated) unless translated.nil?
797
796
  end
798
797
 
@@ -805,9 +804,7 @@ module RGSS
805
804
  def self.serialize(engine, action, directory, original_directory)
806
805
  start_time = Time.now
807
806
 
808
- setup_classes(engine)
809
-
810
- absolute_path = File.realpath(directory)
807
+ absolute_path = File.realpath(directory).freeze
811
808
 
812
809
  paths = {
813
810
  original_path: File.join(absolute_path, original_directory),
@@ -819,21 +816,19 @@ module RGSS
819
816
 
820
817
  paths.each_value { |path| FileUtils.mkdir_p(path) }
821
818
 
822
- extensions = { ace: '.rvdata2', vx: '.rvdata', xp: '.rxdata' }
819
+ extensions = { ace: '.rvdata2', vx: '.rvdata', xp: '.rxdata' }.freeze
823
820
 
824
- files = (
825
- Dir
826
- .children(paths[:original_path])
827
- .select { |filename| File.extname(filename) == extensions[engine] }
828
- .map { |filename| "#{paths[:original_path]}/#{filename}" }
829
- )
821
+ files = Dir.children(paths[:original_path])
822
+ .select { |filename| File.extname(filename) == extensions[engine] }
823
+ .map { |filename| "#{paths[:original_path]}/#{filename}" }
824
+ .freeze
830
825
 
831
826
  maps_files = []
832
827
  other_files = []
833
- system_file = "#{paths[:original_path]}/System#{extensions[engine]}"
834
- scripts_file = "#{paths[:original_path]}/Scripts#{extensions[engine]}"
828
+ system_file = "#{paths[:original_path]}/System#{extensions[engine]}".freeze
829
+ scripts_file = "#{paths[:original_path]}/Scripts#{extensions[engine]}".freeze
835
830
 
836
- $game_type = get_game_type(system_file)
831
+ $game_type = get_game_type(system_file).freeze
837
832
 
838
833
  files.each do |file|
839
834
  basename = File.basename(file)
@@ -846,17 +841,17 @@ module RGSS
846
841
  end
847
842
 
848
843
  if action == 'read'
849
- read_map(maps_files, paths[:maps_path]) if $no[0]
850
- read_other(other_files, paths[:other_path]) if $no[1]
851
- read_system(system_file, paths[:other_path]) if $no[2]
852
- read_scripts(scripts_file, paths[:other_path]) if $no[3]
844
+ read_map(maps_files, paths[:maps_path]) unless $no[0]
845
+ read_other(other_files, paths[:other_path]) unless $no[1]
846
+ read_system(system_file, paths[:other_path]) unless $no[2]
847
+ read_scripts(scripts_file, paths[:other_path]) unless $no[3]
853
848
  else
854
- write_map(maps_files, paths[:maps_path], paths[:output_path]) if $no[0]
855
- write_other(other_files, paths[:other_path], paths[:output_path]) if $no[1]
856
- write_system(system_file, paths[:other_path], paths[:output_path]) if $no[2]
857
- write_scripts(scripts_file, paths[:other_path], paths[:output_path]) if $no[3]
849
+ write_map(maps_files, paths[:maps_path], paths[:output_path]) unless $no[0]
850
+ write_other(other_files, paths[:other_path], paths[:output_path]) unless $no[1]
851
+ write_system(system_file, paths[:other_path], paths[:output_path]) unless $no[2]
852
+ write_scripts(scripts_file, paths[:other_path], paths[:output_path]) unless $no[3]
858
853
  end
859
854
 
860
- puts "Done in #{(Time.now - start_time)}"
855
+ puts "Done in #{Time.now - start_time}"
861
856
  end
862
857
  end
data/rvpacker-txt.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'rvpacker-txt'
3
- spec.version = '1.2.1'
3
+ spec.version = '1.3.0'
4
4
  spec.authors = ['Howard Jeng', 'Andrew Kesterson', 'Solistra', 'Darkness9724', 'savannstm']
5
5
  spec.email = ['savannstm@gmail.com']
6
6
  spec.summary = 'Reads or writes RPG Maker XP/VX/VXAce game text to .txt files'
@@ -8,11 +8,12 @@ Gem::Specification.new do |spec|
8
8
  spec.license = 'MIT'
9
9
  spec.required_ruby_version = Gem::Requirement.new('>= 3.0.0')
10
10
 
11
+ spec.metadata = { 'homepage_uri' => 'https://github.com/savannstm/rvpacker-txt' }
12
+
11
13
  spec.files = `git ls-files -z`.split("\x0")
12
14
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
15
  spec.require_paths = ['lib']
15
16
 
16
- spec.add_development_dependency 'bundler', '>= 2.5.14'
17
- spec.add_development_dependency 'rake', '>= 13.0.6'
17
+ spec.add_development_dependency 'bundler', '~> 2.5'
18
+ spec.add_development_dependency 'rake', '~> 13.0'
18
19
  end
@@ -0,0 +1,4 @@
1
+ $logging: bool
2
+ $shuffle: Integer
3
+ $no: Array[bool]
4
+ $game_type: String | nil
data/sig/rgss.rbs CHANGED
@@ -1,14 +1,18 @@
1
1
  module RGSS
2
+ def self.extract_quoted_strings: (String) -> Array[String]
3
+
2
4
  def self.get_game_type: (String) -> (String | nil)
3
5
 
4
6
  def self.get_translated: (Integer, String, Hash[String, String]) -> (String | nil)
5
7
 
6
- def self.get_variable_translated: (String) -> (String | nil)
8
+ def self.get_variable_translated: (String, Hash[String, String]) -> (String | nil)
7
9
 
8
10
  def self.merge_map: (Object) -> Object
9
11
 
10
12
  def self.merge_other: (Array[Object]) -> Array[Object]
11
13
 
14
+ def self.merge_seq: (Array[Object]) -> Array[Object]
15
+
12
16
  def self.parse_parameter: (Integer, String) -> (String | nil)
13
17
 
14
18
  def self.parse_variable: (String) -> (String | nil)
@@ -23,6 +27,8 @@ module RGSS
23
27
 
24
28
  def self.serialize: (Symbol, String, String, String) -> void
25
29
 
30
+ def self.shuffle_words: (Array[String]) -> Array[String]
31
+
26
32
  def self.write_map: (Array[String], String, String) -> void
27
33
 
28
34
  def self.write_other: (Array[String], String, String) -> void
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.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Howard Jeng
@@ -12,36 +12,36 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2024-07-04 00:00:00.000000000 Z
15
+ date: 2024-07-05 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bundler
19
19
  requirement: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - ">="
21
+ - - "~>"
22
22
  - !ruby/object:Gem::Version
23
- version: 2.5.14
23
+ version: '2.5'
24
24
  type: :development
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
- - - ">="
28
+ - - "~>"
29
29
  - !ruby/object:Gem::Version
30
- version: 2.5.14
30
+ version: '2.5'
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: rake
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  requirements:
35
- - - ">="
35
+ - - "~>"
36
36
  - !ruby/object:Gem::Version
37
- version: 13.0.6
37
+ version: '13.0'
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
- - - ">="
42
+ - - "~>"
43
43
  - !ruby/object:Gem::Version
44
- version: 13.0.6
44
+ version: '13.0'
45
45
  description:
46
46
  email:
47
47
  - savannstm@gmail.com
@@ -55,16 +55,16 @@ files:
55
55
  - README.md
56
56
  - Rakefile
57
57
  - bin/rvpacker-txt
58
- - lib/RGSS.rb
59
- - lib/RGSS/BasicCoder.rb
60
- - lib/RGSS/serialize.rb
61
- - lib/RPG.rb
58
+ - lib/classes.rb
59
+ - lib/serialize.rb
62
60
  - rvpacker-txt.gemspec
61
+ - sig/global_variables.rbs
63
62
  - sig/rgss.rbs
64
63
  homepage: https://github.com/savannstm/rvpacker-txt
65
64
  licenses:
66
65
  - MIT
67
- metadata: {}
66
+ metadata:
67
+ homepage_uri: https://github.com/savannstm/rvpacker-txt
68
68
  post_install_message:
69
69
  rdoc_options: []
70
70
  require_paths:
@@ -1,31 +0,0 @@
1
- module RGSS
2
- module BasicCoder
3
- def ivars
4
- instance_variables
5
- end
6
-
7
- INCLUDED_CLASSES = []
8
-
9
- def self.included(module_)
10
- INCLUDED_CLASSES.push(module_)
11
- end
12
-
13
- def self.ivars_methods_set(version)
14
- INCLUDED_CLASSES.each do |class_|
15
- if version == :ace
16
- RGSS.reset_method(
17
- class_,
18
- :ivars,
19
- -> { instance_variables }
20
- )
21
- else
22
- RGSS.reset_method(
23
- class_,
24
- :ivars,
25
- -> { instance_variables.sort }
26
- )
27
- end
28
- end
29
- end
30
- end
31
- end
data/lib/RPG.rb DELETED
@@ -1,9 +0,0 @@
1
- require 'RGSS'
2
- module RPG
3
- class System
4
- include RGSS::BasicCoder
5
- end
6
-
7
- class EventCommand
8
- end
9
- end