rvpacker-txt 1.0.0 → 1.2.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: 23d385ac1a1e31fb6b845b028746ca52e58c882aed04ffd23721dfe513934451
4
- data.tar.gz: 138b367cdd190e4edfbc8f1449b7b5129f03d2d614e8f17f7dbb9599c7c3aeb9
3
+ metadata.gz: 0504a1427ffcd718aedc6a6db70bce63331ef54046b9e5abe0037d60ffbb0445
4
+ data.tar.gz: fa94b889274185fa2c6adfb1bd539ded6a8ecf7b1e05702bdf49a557376e9d7d
5
5
  SHA512:
6
- metadata.gz: c1273a05232251e539300f9c5cef0c1b082c041e5ecd3e7f4284f933ea5df29641808395d08e344dcd825f8cca727701e3f8e61fb9280016e47d60eecc8f2dfb
7
- data.tar.gz: bd29920e41d1fd3871879d4a541863b078329f57338adfcc12fe08aeee6970b4e36b568747a06d0105388ae280482365039c98f8ee6bdf43e05550359fda0d17
6
+ metadata.gz: 9d16fa9c8cecf327cbc947250fe8b9f84b4cf0656a80d12caded68d74c2037f7971a8630469389542b8548b5737ff110aa2cdd0936eb34b822d646e3bc661a21
7
+ data.tar.gz: c0fb36404458b2fc15546c10782ca43841e9179d139e65ced2f12478345911e7d67ad2751e4f43ea7756490b032c43b34777493161f75187de51686fa7ee223d
data/README.md CHANGED
@@ -20,6 +20,8 @@ Usage
20
20
 
21
21
  ```
22
22
  $ rvpacker-txt -h
23
+ This tool allows to parse RPG Maker project to .txt files and back.
24
+
23
25
  Usage: rvpacker-txt COMMAND [options]
24
26
 
25
27
  COMMANDS:
@@ -29,15 +31,18 @@ OPTIONS:
29
31
  -d, --input-dir DIRECTORY Input directory of RPG Maker project.
30
32
  Must contain "Data" or "original" folder to read,
31
33
  and additionally "translation" with "maps" and "other" subdirectories to write.
32
- -l, --log Log information while processing.
34
+ --no Don't process specified files.
35
+ Takes multiple values separated by a comma.
36
+ Allowed values: maps, other, system, plugins
33
37
  -s, --shuffle NUMBER At value 1: Shuffles all lines in strings, at value 2: shuffles all lines and words in strings.
38
+ -l, --log Log information while processing.
34
39
  -h, --help Show help message.
35
40
  ```
36
41
 
37
42
  For example, to read a RPG Maker VX Ace project in E:/Documents/RPGMakerGame to .txt files:
38
43
 
39
44
  ```
40
- $ rvpacker read --input-dir E:/Documents/RPGMakerGame
45
+ $ rvpacker-txt read --input-dir E:/Documents/RPGMakerGame
41
46
  ```
42
47
 
43
48
  Program determines game engine automatically.
@@ -49,7 +54,7 @@ Lines from Scripts file will be parsed into translation/other/scripts.txt file a
49
54
  To write previously parsed project back to its initial form:
50
55
 
51
56
  ```
52
- $ rvpacker write --input-dir E:/Documents/RPGMakerGame
57
+ $ rvpacker-txt write --input-dir E:/Documents/RPGMakerGame
53
58
  ```
54
59
 
55
60
  This will take all of translation lines from _trans files from the translation subdirectories and repack all of them
data/bin/rvpacker-txt CHANGED
@@ -1,6 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
- require('RGSS')
3
- require('optparse')
2
+ require 'RGSS'
3
+ require 'optparse'
4
+
5
+ $logging = false
6
+ $no = [true, true, true, true] # 0 is whether to process maps, 1 is other, 2 is system, 3 is scripts
4
7
 
5
8
  opts = {}
6
9
  OptionParser.new do |options|
@@ -12,14 +15,33 @@ OptionParser.new do |options|
12
15
  opts[:input_dir] = dir
13
16
  end
14
17
 
15
- options.on('-l', '--log', 'Log information while processing.') do
16
- opts[:log] = true
18
+ options.on('--no', "Don't process specified files.", 'Takes multiple values separated by a comma.', 'Allowed values: maps, other, system, plugins') do |files|
19
+ actual_files = files.split(',')
20
+
21
+ actual_files.each do |file|
22
+ case file
23
+ when "maps"
24
+ $no[0] = false
25
+ when "other"
26
+ $no[1] = false
27
+ when "system"
28
+ $no[2] = false
29
+ when "scripts"
30
+ $no[3] = false
31
+ else
32
+ nil
33
+ end
34
+ end
17
35
  end
18
36
 
19
37
  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|
20
38
  opts[:shuffle] = number
21
39
  end
22
40
 
41
+ options.on('-l', '--log', 'Log information while processing.') do
42
+ $logging = true
43
+ end
44
+
23
45
  options.on_tail('-h', '--help', 'Show help message.') do
24
46
  puts options
25
47
  exit
@@ -39,25 +61,24 @@ unless %w[read write].include?(opts[:action])
39
61
  end
40
62
 
41
63
  project_types = { 'vx' => :vx, 'ace' => :ace, 'xp' => :xp }
42
- $logging = opts[:log]
43
64
 
44
65
  directory = opts[:input_dir]
45
66
  raise "#{directory} not found" unless File.exist?(directory)
46
67
 
47
- data_folder = Dir.foreach(directory).find { |filename| filename.downcase == 'original' }
48
- data_folder = Dir.foreach(directory).find { |filename| filename.downcase == 'data' } if data_folder.nil?
49
- raise '"Data" directory not found within input directory.' if data_folder.nil?
68
+ original_directory = Dir.foreach(directory).find { |filename| filename.downcase == 'original' } ||
69
+ Dir.foreach(directory).find { |filename| filename.downcase == 'data' }
70
+ raise '"Data" or "original" directory not found within input directory.' if original_directory.nil?
50
71
 
51
- types = %i[vx ace xp]
72
+ types = %w[vx ace xp]
52
73
 
53
- type = types.find do |_type|
54
- case _type
55
- when 'vx'
56
- break project_types[_type] if File.exist?(File.join(directory, data_folder, 'System.rxdata'))
74
+ type = types.find do |type_|
75
+ case type_
57
76
  when 'xp'
58
- break project_types[_type] if File.exist?(File.join(directory, data_folder, 'System.rvdata'))
77
+ break project_types[type_] if File.exist?(File.join(directory, original_directory, 'System.rxdata'))
78
+ when 'vx'
79
+ break project_types[type_] if File.exist?(File.join(directory, original_directory, 'System.rvdata'))
59
80
  when 'ace'
60
- break project_types[_type] if File.exist?(File.join(directory, data_folder, 'System.rvdata2'))
81
+ break project_types[type_] if File.exist?(File.join(directory, original_directory, 'System.rvdata2'))
61
82
  else
62
83
  break nil
63
84
  end
@@ -65,12 +86,4 @@ end
65
86
 
66
87
  raise 'Couldn\'t determine project engine.' if type.nil?
67
88
 
68
- RGSS.serialize(
69
- type,
70
- opts[:action],
71
- directory,
72
- {
73
- line_width: -1,
74
- table_width: -1,
75
- }
76
- )
89
+ RGSS.serialize(type, opts[:action], directory, original_directory)
@@ -1,51 +1,28 @@
1
1
  module RGSS
2
2
  module BasicCoder
3
- def encode_with(coder)
4
- ivars.each do |var|
5
- name = var.to_s.sub(/^@/, '')
6
- value = instance_variable_get(var)
7
- coder[name] = encode(name, value)
8
- end
9
- end
10
-
11
- def encode(name, value)
12
- return value
13
- end
14
-
15
- def init_with(coder)
16
- coder.map.each do |key, value|
17
- sym = "@#{key}".to_sym
18
- instance_variable_set(sym, decode(key, value))
19
- end
20
- end
21
-
22
- def decode(name, value)
23
- return value
24
- end
25
-
26
3
  def ivars
27
- return instance_variables
4
+ instance_variables
28
5
  end
29
6
 
30
7
  INCLUDED_CLASSES = []
31
8
 
32
- def self.included(mod)
33
- INCLUDED_CLASSES.push(mod)
9
+ def self.included(module_)
10
+ INCLUDED_CLASSES.push(module_)
34
11
  end
35
12
 
36
- def self.set_ivars_methods(version)
37
- INCLUDED_CLASSES.each do |c|
13
+ def self.ivars_methods_set(version)
14
+ INCLUDED_CLASSES.each do |class_|
38
15
  if version == :ace
39
16
  RGSS.reset_method(
40
- c,
17
+ class_,
41
18
  :ivars,
42
- -> { return instance_variables }
19
+ -> { instance_variables }
43
20
  )
44
21
  else
45
22
  RGSS.reset_method(
46
- c,
23
+ class_,
47
24
  :ivars,
48
- -> { return instance_variables.sort }
25
+ -> { instance_variables.sort }
49
26
  )
50
27
  end
51
28
  end
@@ -50,6 +50,10 @@ class IndexedSet
50
50
  def length
51
51
  @index.length
52
52
  end
53
+
54
+ def empty?
55
+ @index.empty?
56
+ end
53
57
  end
54
58
 
55
59
  module RGSS
@@ -68,13 +72,13 @@ module RGSS
68
72
  nil
69
73
  end
70
74
 
71
- def parse_parameter(code, parameter)
75
+ def self.parse_parameter(code, parameter)
72
76
  case code
73
77
  when 401, 405
74
78
  case $game_type
75
79
  when "lisa"
76
- match = parameter.match(/^\\et\[[0-9]+\]|\\nbt/)
77
- parameter = parameter[match[0].length..] if match
80
+ match = parameter.scan(/^\\et\[[0-9]+\]|\\nbt/)
81
+ parameter = parameter.slice(match[0].length) if match
78
82
  else
79
83
  nil
80
84
  end
@@ -156,11 +160,9 @@ module RGSS
156
160
  lines[0].add(parsed) unless parsed.nil?
157
161
  end
158
162
  end
159
- elsif code == 356
160
- if parameter.is_a?(String) && !parameter.empty?
161
- parsed = parse_parameter(code, parameter)
162
- lines[0].add(parsed.gsub(/\r?\n/, '\#')) unless parsed.nil?
163
- end
163
+ elsif code == 356 && parameter.is_a?(String) && !parameter.empty?
164
+ parsed = parse_parameter(code, parameter)
165
+ lines[0].add(parsed.gsub(/\r?\n/, '\#')) unless parsed.nil?
164
166
  end
165
167
  end
166
168
  end
@@ -172,9 +174,9 @@ module RGSS
172
174
  end
173
175
 
174
176
  File.write("#{output_path}/maps.txt", lines[0].join("\n"))
175
- File.write("#{output_path}/maps_trans.txt", "\n" * (lines[0].length.positive? ? lines[0].length - 1 : 0))
177
+ File.write("#{output_path}/maps_trans.txt", "\n" * (!lines[0].empty? ? lines[0].length - 1 : 0))
176
178
  File.write("#{output_path}/names.txt", lines[1].join("\n"))
177
- File.write("#{output_path}/names_trans.txt", "\n" * (lines[1].length.positive? ? lines[1].length - 1 : 0))
179
+ File.write("#{output_path}/names_trans.txt", "\n" * (!lines[1].empty? ? lines[1].length - 1 : 0))
178
180
  end
179
181
 
180
182
  def self.read_other(original_other_files, output_path)
@@ -250,7 +252,7 @@ module RGSS
250
252
  puts "Parsed #{filename}" if $logging
251
253
 
252
254
  File.write("#{output_path}/#{processed_filename}.txt", lines.join("\n"))
253
- File.write("#{output_path}/#{processed_filename}_trans.txt", "\n" * (lines.length.positive? ? lines.length - 1 : 0))
255
+ File.write("#{output_path}/#{processed_filename}_trans.txt", "\n" * (!lines.empty? ? lines.length - 1 : 0))
254
256
  end
255
257
  end
256
258
 
@@ -278,6 +280,12 @@ module RGSS
278
280
 
279
281
  terms.instance_variables.each do |variable|
280
282
  value = terms.instance_variable_get(variable)
283
+
284
+ if value.is_a?(String)
285
+ lines.add(value) unless value.empty?
286
+ next
287
+ end
288
+
281
289
  value.each { |string| lines.add(string) unless string.is_a?(String) && string.empty? }
282
290
  end
283
291
 
@@ -286,21 +294,74 @@ module RGSS
286
294
  puts "Parsed #{filename}" if $logging
287
295
 
288
296
  File.write("#{output_path}/#{basename}.txt", lines.join("\n"), mode: 'wb')
289
- File.write("#{output_path}/#{basename}_trans.txt", "\n" * (lines.length.positive? ? lines.length - 1 : 0),
297
+ File.write("#{output_path}/#{basename}_trans.txt", "\n" * (!lines.empty? ? lines.length - 1 : 0),
290
298
  mode: 'wb')
291
299
  end
292
300
 
301
+ def self.extract_quoted_strings(input)
302
+ result = []
303
+ in_quotes = false
304
+ quote_type = nil
305
+ buffer = []
306
+
307
+ input.each_char.with_index do |char, index|
308
+ if char == '#' && (index == 0 || input[index - 1] == "\n")
309
+ index = input.index("\n", index) || input.length
310
+ next
311
+ end
312
+
313
+ if char == '"' || char == "'"
314
+ if in_quotes
315
+ if char == quote_type
316
+ result.push(buffer.join)
317
+ buffer.clear
318
+ in_quotes = false
319
+ quote_type = nil
320
+ else
321
+ buffer.push(char)
322
+ end
323
+ else
324
+ in_quotes = true
325
+ quote_type = char
326
+ end
327
+
328
+ next
329
+ end
330
+
331
+ if in_quotes
332
+ if char != "\r"
333
+ if char == "\n"
334
+ buffer.push('\#')
335
+ next
336
+ end
337
+
338
+ buffer.push(char)
339
+ end
340
+ end
341
+ end
342
+
343
+ result
344
+ end
345
+
293
346
  def self.read_scripts(scripts_file_path, output_path)
294
347
  script_entries = Marshal.load(File.read(scripts_file_path, mode: 'rb'))
295
- strings = []
348
+ strings = IndexedSet.new
296
349
 
297
350
  script_entries.each do |script|
298
351
  code = Zlib::Inflate.inflate(script[2]).force_encoding('UTF-8')
299
- code.scan(/".*"/) { |string| strings.push(string) }
352
+
353
+ extract_quoted_strings(code).each do |string|
354
+ next if string.strip! || (string.empty? || string.delete('  ').empty?)
355
+
356
+ next if string.start_with?(/(#|\!?\$|@|(Graphics|Data|Audio|CG|Movies)\/)/) ||
357
+ string.match?(/^\d+$|^(.)\1{2,}$|^false|true$|^(wb|rb)$|^[A-Za-z0-9\-]+$|^[\.\(\)\+\-:;\|\[\]\^~%&!\*\/→×?\?x%▼]$|#\{|\\(?!#)|\+?=?=|\{|\}|_|r[vx]data|[<>]|\.split/) ||
358
+
359
+ strings.add(string)
360
+ end
300
361
  end
301
362
 
302
363
  File.write("#{output_path}/scripts.txt", strings.join("\n"), mode: 'wb')
303
- File.write("#{output_path}/scripts_trans.txt", "\n" * (strings.length.positive? ? strings.length - 1 : 0), mode: 'wb')
364
+ File.write("#{output_path}/scripts_trans.txt", "\n" * (!strings.empty? ? strings.length - 1 : 0), mode: 'wb')
304
365
  end
305
366
 
306
367
  def self.merge_seq(object_array)
@@ -357,7 +418,7 @@ module RGSS
357
418
  end
358
419
  end
359
420
 
360
- return object
421
+ object
361
422
  end
362
423
 
363
424
  def self.merge_other(object_array)
@@ -380,6 +441,8 @@ module RGSS
380
441
  object.instance_variable_set(:@list, merge_seq(list))
381
442
  end
382
443
  end
444
+
445
+ object_array
383
446
  end
384
447
 
385
448
  def self.get_translated(code, parameter, hashmap)
@@ -599,9 +662,14 @@ module RGSS
599
662
  terms.instance_variables.each do |variable|
600
663
  value = terms.instance_variable_get(variable)
601
664
 
602
- value.each_with_index do |string, i|
603
- translated = system_translation_map[string]
604
- value[i] = translated unless translated.nil?
665
+ if value.is_a?(String)
666
+ translated = system_translation_map[value]
667
+ value = translated unless translated.nil?
668
+ elsif value.is_a?(Array)
669
+ value.each_with_index do |string, i|
670
+ translated = system_translation_map[string]
671
+ value[i] = translated unless translated.nil?
672
+ end
605
673
  end
606
674
 
607
675
  terms.instance_variable_set(variable, value)
@@ -635,23 +703,15 @@ module RGSS
635
703
  File.write("#{output_path}/#{File.basename(scripts_file)}", Marshal.dump(script_entries), mode: 'wb')
636
704
  end
637
705
 
638
- def self.serialize(version, action, directory, options = {})
706
+ def self.serialize(engine, action, directory, original_directory)
639
707
  start_time = Time.now
640
708
 
641
- setup_classes(version, options)
642
-
643
- options = options.clone
644
- options[:sort] = true if %i[vx xp].include?(version)
645
- options[:flow_classes] = [Color, Tone, RPG::BGM, RPG::BGS, RPG::MoveCommand, RPG::SE].freeze
646
- options[:line_width] ||= 130
647
-
648
- table_width = options[:table_width]
649
- RGSS.reset_const(Table, :MAX_ROW_LENGTH, table_width || 20)
709
+ setup_classes(engine)
650
710
 
651
711
  absolute_path = File.realpath(directory)
652
712
 
653
713
  paths = {
654
- original_path: File.join(absolute_path, 'Data'),
714
+ original_path: File.join(absolute_path, original_directory),
655
715
  translation_path: File.join(absolute_path, 'translation'),
656
716
  maps_path: File.join(absolute_path, 'translation/maps'),
657
717
  other_path: File.join(absolute_path, 'translation/other'),
@@ -665,14 +725,14 @@ module RGSS
665
725
  files = (
666
726
  Dir
667
727
  .children(paths[:original_path])
668
- .select { |filename| File.extname(filename) == extensions[version] }
728
+ .select { |filename| File.extname(filename) == extensions[engine] }
669
729
  .map { |filename| "#{paths[:original_path]}/#{filename}" }
670
730
  )
671
731
 
672
732
  maps_files = []
673
733
  other_files = []
674
- system_file = "#{paths[:original_path]}/System#{extensions[version]}"
675
- scripts_file = "#{paths[:original_path]}/Scripts#{extensions[version]}"
734
+ system_file = "#{paths[:original_path]}/System#{extensions[engine]}"
735
+ scripts_file = "#{paths[:original_path]}/Scripts#{extensions[engine]}"
676
736
 
677
737
  $game_type = get_game_type(system_file)
678
738
 
@@ -687,15 +747,15 @@ module RGSS
687
747
  end
688
748
 
689
749
  if action == 'read'
690
- read_map(maps_files, paths[:maps_path])
691
- read_other(other_files, paths[:other_path])
692
- read_system(system_file, paths[:other_path])
693
- read_scripts(scripts_file, paths[:other_path])
750
+ read_map(maps_files, paths[:maps_path]) unless $no[0]
751
+ read_other(other_files, paths[:other_path]) unless $no[1]
752
+ read_system(system_file, paths[:other_path]) unless $no[2]
753
+ read_scripts(scripts_file, paths[:other_path]) unless $no[3]
694
754
  else
695
- write_map(maps_files, paths[:maps_path], paths[:output_path])
696
- write_other(other_files, paths[:other_path], paths[:output_path])
697
- write_system(system_file, paths[:other_path], paths[:output_path])
698
- write_scripts(scripts_file, paths[:other_path], paths[:output_path])
755
+ write_map(maps_files, paths[:maps_path], paths[:output_path]) unless $no[0]
756
+ write_other(other_files, paths[:other_path], paths[:output_path]) unless $no[1]
757
+ write_system(system_file, paths[:other_path], paths[:output_path]) unless $no[2]
758
+ write_scripts(scripts_file, paths[:other_path], paths[:output_path]) unless $no[3]
699
759
  end
700
760
 
701
761
  puts "Done in #{(Time.now - start_time)}"
data/lib/RGSS.rb CHANGED
@@ -18,62 +18,17 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
18
18
  DEALINGS IN THE SOFTWARE.
19
19
  =end
20
20
 
21
- require 'scanf'
22
-
23
21
  class Table
24
22
  def initialize(bytes)
25
23
  @dim, @x, @y, @z, items, *@data = bytes.unpack('L5 S*')
26
- unless items == @data.length
27
- raise 'Size mismatch loading Table from data'
28
- end
29
- unless @x * @y * @z == items
30
- raise 'Size mismatch loading Table from data'
31
- end
32
- end
33
-
34
- MAX_ROW_LENGTH = 20
35
-
36
- def encode_with(coder)
37
- coder.style = Psych::Nodes::Mapping::BLOCK
38
-
39
- coder['dim'] = @dim
40
- coder['x'] = @x
41
- coder['y'] = @y
42
- coder['z'] = @z
43
-
44
- if @x * @y * @z > 0
45
- stride = @x < 2 ? (@y < 2 ? @z : @y) : @x
46
- rows = @data.each_slice(stride).to_a
47
- if MAX_ROW_LENGTH != -1 && stride > MAX_ROW_LENGTH
48
- block_length = (stride + MAX_ROW_LENGTH - 1) / MAX_ROW_LENGTH
49
- row_length = (stride + block_length - 1) / block_length
50
- rows =
51
- rows
52
- .collect { |x| x.each_slice(row_length).to_a }
53
- .flatten(1)
54
- end
55
- rows = rows.collect { |x| x.collect { |y| '%04x' % y }.join(' ') }
56
- coder['data'] = rows
57
- else
58
- coder['data'] = []
59
- end
60
- end
61
24
 
62
- def init_with(coder)
63
- @dim = coder['dim']
64
- @x = coder['x']
65
- @y = coder['y']
66
- @z = coder['z']
67
- @data =
68
- coder['data'].collect { |x| x.split(' ').collect(&:hex) }.flatten
69
- items = @x * @y * @z
70
- unless items == @data.length
71
- raise 'Size mismatch loading Table from YAML'
25
+ unless items == @data.length && @x * @y * @z == items
26
+ raise 'Size mismatch loading Table from data'
72
27
  end
73
28
  end
74
29
 
75
- def _dump(*ignored)
76
- return [@dim, @x, @y, @z, @x * @y * @z, *@data].pack('L5 S*')
30
+ def _dump(*_ignored)
31
+ [@dim, @x, @y, @z, @x * @y * @z, *@data].pack('L5 S*')
77
32
  end
78
33
 
79
34
  def self._load(bytes)
@@ -86,8 +41,8 @@ class Color
86
41
  @r, @g, @b, @a = *bytes.unpack('D4')
87
42
  end
88
43
 
89
- def _dump(*ignored)
90
- return [@r, @g, @b, @a].pack('D4')
44
+ def _dump(*_ignored)
45
+ [@r, @g, @b, @a].pack('D4')
91
46
  end
92
47
 
93
48
  def self._load(bytes)
@@ -100,8 +55,8 @@ class Tone
100
55
  @r, @g, @b, @a = *bytes.unpack('D4')
101
56
  end
102
57
 
103
- def _dump(*ignored)
104
- return [@r, @g, @b, @a].pack('D4')
58
+ def _dump(*_ignored)
59
+ [@r, @g, @b, @a].pack('D4')
105
60
  end
106
61
 
107
62
  def self._load(bytes)
@@ -114,8 +69,8 @@ class Rect
114
69
  @x, @y, @width, @height = *bytes.unpack('i4')
115
70
  end
116
71
 
117
- def _dump(*ignored)
118
- return [@x, @y, @width, @height].pack('i4')
72
+ def _dump(*_ignored)
73
+ [@x, @y, @width, @height].pack('i4')
119
74
  end
120
75
 
121
76
  def self._load(bytes)
@@ -135,28 +90,31 @@ module RGSS
135
90
  scope.send(:define_method, name, method)
136
91
  end
137
92
 
138
- def self.reset_const(scope, sym, value)
139
- scope.send(:remove_const, sym) if scope.const_defined?(sym)
140
- scope.send(:const_set, sym, value)
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)
141
96
  end
142
97
 
143
- def self.array_to_hash(arr, &block)
144
- h = {}
145
- arr.each_with_index do |val, index|
146
- r = block_given? ? block.call(val) : val
147
- h[index] = r unless r.nil?
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?
148
104
  end
149
- if arr.length > 0
150
- last = arr.length - 1
151
- h[last] = nil unless h.has_key?(last)
105
+
106
+ unless array.empty?
107
+ last = array.length - 1
108
+ hash[last] = nil unless hash.has_key?(last)
152
109
  end
153
- return h
110
+
111
+ hash
154
112
  end
155
113
 
156
114
  def self.hash_to_array(hash)
157
- arr = []
158
- hash.each { |k, v| arr[k] = v }
159
- return arr
115
+ array = []
116
+ hash.each { |key, value| array[key] = value }
117
+ array
160
118
  end
161
119
 
162
120
  require 'RGSS/BasicCoder'
@@ -164,7 +122,7 @@ module RGSS
164
122
 
165
123
  # creates an empty class in a potentially nested scope
166
124
  def self.process(root, name, *args)
167
- if args.length > 0
125
+ if !args.empty?
168
126
  process(root.const_get(name), *args)
169
127
  else
170
128
  unless root.const_defined?(name, false)
@@ -245,43 +203,35 @@ module RGSS
245
203
  [:Game_Screen],
246
204
  [:Game_Vehicle],
247
205
  [:Interpreter]
248
- ].each { |x| process(Object, *x) }
249
-
250
- def self.setup_system(version, options)
251
- # convert variable and switch name arrays to a hash when serialized
252
- # if round_trip isn't set change version_id to fixed number
253
- if options[:round_trip]
254
- iso = ->(val) { return val }
255
- reset_method(RPG::System, :reduce_string, iso)
256
- reset_method(RPG::System, :map_version, iso)
257
- reset_method(Game_System, :map_version, iso)
258
- else
259
- reset_method(
260
- RPG::System,
261
- :reduce_string,
262
- ->(str) do
263
- return nil if str.nil?
264
- stripped = str.strip
265
- return stripped.empty? ? nil : stripped
266
- end
267
- )
206
+ ].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
+ )
268
220
 
269
- # These magic numbers should be different. If they are the same, the saved version
270
- # of the map in save files will be used instead of any updated version of the map
271
- reset_method(
272
- RPG::System,
273
- :map_version,
274
- ->(ignored) { return 12_345_678 }
275
- )
276
- reset_method(
277
- Game_System,
278
- :map_version,
279
- ->(ignored) { return 87_654_321 }
280
- )
281
- end
282
- end
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
+ )
283
234
 
284
- def self.setup_interpreter(version)
285
235
  # Game_Interpreter is marshalled differently in VX Ace
286
236
  if version == :ace
287
237
  reset_method(Game_Interpreter, :marshal_dump, -> { return @data })
@@ -294,115 +244,36 @@ module RGSS
294
244
  remove_defined_method(Game_Interpreter, :marshal_dump)
295
245
  remove_defined_method(Game_Interpreter, :marshal_load)
296
246
  end
297
- end
298
247
 
299
- def self.setup_event_command(version, options)
300
- # format event commands to flow style for the event codes that aren't move commands
301
- if options[:round_trip]
302
- reset_method(RPG::EventCommand, :clean, -> {})
303
- else
304
- reset_method(
305
- RPG::EventCommand,
306
- :clean,
307
- -> { @parameters[0].rstrip! if @code == 401 }
308
- )
309
- end
248
+ reset_method(
249
+ RPG::EventCommand,
250
+ :clean,
251
+ -> { @parameters[0].rstrip! if @code == 401 }
252
+ )
253
+
310
254
  reset_const(
311
255
  RPG::EventCommand,
312
256
  :MOVE_LIST_CODE,
313
257
  version == :xp ? 209 : 205
314
258
  )
315
- end
316
-
317
- def self.setup_classes(version, options)
318
- setup_system(version, options)
319
- setup_interpreter(version)
320
- setup_event_command(version, options)
321
- BasicCoder.set_ivars_methods(version)
322
- end
323
259
 
324
- FLOW_CLASSES = [Color, Tone, RPG::BGM, RPG::BGS, RPG::MoveCommand, RPG::SE]
325
-
326
- SCRIPTS_BASE = 'Scripts'
327
-
328
- ACE_DATA_EXT = '.rvdata2'
329
- VX_DATA_EXT = '.rvdata'
330
- XP_DATA_EXT = '.rxdata'
331
- YAML_EXT = '.yaml'
332
- RUBY_EXT = '.rb'
333
-
334
- def self.get_data_directory(base)
335
- return File.join(base, 'Data')
336
- end
337
-
338
- def self.get_yaml_directory(base)
339
- return File.join(base, 'YAML')
340
- end
341
-
342
- def self.get_script_directory(base)
343
- return File.join(base, 'Scripts')
260
+ BasicCoder.ivars_methods_set(version)
344
261
  end
345
262
 
346
263
  class Game_Switches
347
264
  include RGSS::BasicCoder
348
-
349
- def encode(name, value)
350
- return array_to_hash(value)
351
- end
352
-
353
- def decode(name, value)
354
- return hash_to_array(value)
355
- end
356
265
  end
357
266
 
358
267
  class Game_Variables
359
268
  include RGSS::BasicCoder
360
-
361
- def encode(name, value)
362
- return array_to_hash(value)
363
- end
364
-
365
- def decode(name, value)
366
- return hash_to_array(value)
367
- end
368
269
  end
369
270
 
370
271
  class Game_SelfSwitches
371
272
  include RGSS::BasicCoder
372
-
373
- def encode(name, value)
374
- return(
375
- Hash[
376
- value.collect do |pair|
377
- key, value = pair
378
- next ['%03d %03d %s' % key, value]
379
- end
380
- ]
381
- )
382
- end
383
-
384
- def decode(name, value)
385
- return(
386
- Hash[
387
- value.collect do |pair|
388
- key, value = pair
389
- next [key.scanf('%d %d %s'), value]
390
- end
391
- ]
392
- )
393
- end
394
273
  end
395
274
 
396
275
  class Game_System
397
276
  include RGSS::BasicCoder
398
-
399
- def encode(name, value)
400
- if name == 'version_id'
401
- return map_version(value)
402
- else
403
- return value
404
- end
405
- end
406
277
  end
407
278
 
408
279
  require 'RGSS/serialize'
data/lib/RPG.rb CHANGED
@@ -2,54 +2,8 @@ require 'RGSS'
2
2
  module RPG
3
3
  class System
4
4
  include RGSS::BasicCoder
5
- HASHED_VARS = %w[variables switches]
6
- end
7
-
8
- def self.array_to_hash(arr, &block)
9
- h = {}
10
- arr.each_with_index do |val, index|
11
- r = block_given? ? block.call(val) : val
12
- h[index] = r unless r.nil?
13
- end
14
- if arr.length > 0
15
- last = arr.length - 1
16
- h[last] = nil unless h.has_key?(last)
17
- end
18
- return h
19
- end
20
-
21
- def encode(name, value)
22
- if HASHED_VARS.include?(name)
23
- return array_to_hash(value) { |val| reduce_string(val) }
24
- elsif name == 'version_id'
25
- return map_version(value)
26
- else
27
- return value
28
- end
29
- end
30
-
31
- def decode(name, value)
32
- if HASHED_VARS.include?(name)
33
- return hash_to_array(value)
34
- else
35
- return value
36
- end
37
5
  end
38
6
 
39
7
  class EventCommand
40
- def encode_with(coder)
41
- case @code
42
- when MOVE_LIST_CODE
43
- # move list
44
- coder.style = Psych::Nodes::Mapping::BLOCK
45
- else
46
- coder.style = Psych::Nodes::Mapping::FLOW
47
- end
48
- coder['i'], coder['c'], coder['p'] = @indent, @code, @parameters
49
- end
50
-
51
- def init_with(coder)
52
- @indent, @code, @parameters = coder['i'], coder['c'], coder['p']
53
- end
54
8
  end
55
9
  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.0.0'
3
+ spec.version = '1.2.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'
@@ -15,5 +15,4 @@ Gem::Specification.new do |spec|
15
15
 
16
16
  spec.add_development_dependency 'bundler', '>= 2.5.14'
17
17
  spec.add_development_dependency 'rake', '>= 13.0.6'
18
- spec.add_dependency 'scanf', '>= 1.0.0'
19
18
  end
data/sig/rgss.rbs CHANGED
@@ -21,11 +21,11 @@ module RGSS
21
21
 
22
22
  def self.read_scripts: (String, String) -> void
23
23
 
24
- def self.serialize: (Symbol, string, string, Hash[untyped, untyped]) -> void
24
+ def self.serialize: (Symbol, String, String, String) -> void
25
25
 
26
- def self.write_map: (String, Array[String], String) -> void
26
+ def self.write_map: (Array[String], String, String) -> void
27
27
 
28
- def self.write_other: (String, Array[String], String) -> void
28
+ def self.write_other: (Array[String], String, String) -> void
29
29
 
30
30
  def self.write_system: (String, String, String) -> void
31
31
 
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.0.0
4
+ version: 1.2.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-01 00:00:00.000000000 Z
15
+ date: 2024-07-03 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bundler
@@ -42,20 +42,6 @@ dependencies:
42
42
  - - ">="
43
43
  - !ruby/object:Gem::Version
44
44
  version: 13.0.6
45
- - !ruby/object:Gem::Dependency
46
- name: scanf
47
- requirement: !ruby/object:Gem::Requirement
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- version: 1.0.0
52
- type: :runtime
53
- prerelease: false
54
- version_requirements: !ruby/object:Gem::Requirement
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- version: 1.0.0
59
45
  description:
60
46
  email:
61
47
  - savannstm@gmail.com
@@ -73,7 +59,6 @@ files:
73
59
  - lib/RGSS/BasicCoder.rb
74
60
  - lib/RGSS/serialize.rb
75
61
  - lib/RPG.rb
76
- - lib/rvpacker/version.rb
77
62
  - rvpacker-txt.gemspec
78
63
  - sig/rgss.rbs
79
64
  homepage: https://github.com/savannstm/rvpacker-txt
@@ -1,3 +0,0 @@
1
- module RVPACKER
2
- VERSION = '1.3.2'.freeze
3
- end