rvpacker-txt 1.5.1 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3cdabd3e6867b3a5736a998345b2df35273565179c720c03acfb294bb121644
4
- data.tar.gz: dd8ebfa554210a573d6aceef337ae4009759828a6fa53f5d19ad412c936165d0
3
+ metadata.gz: 7e7d7d8c4329390fb8ffd7bf1f8cf3edaf6f8cd19319ab64d10731a84f021d4b
4
+ data.tar.gz: d9db81d1f003f20ce10fb1cb064c60cab274980f26c8931e1c98bbfdf4042b58
5
5
  SHA512:
6
- metadata.gz: 6146633f8ac594f5db5cdc7b9fd1914c3e011e242531f943c2dbcad48c00ee8bda79f06511db125e588be4cc6c6869e3c9bfccc24a7c1820418d4cd7688f5c6d
7
- data.tar.gz: db7a233da1abe10a24c0c5180a06f022f46cf07685e33e3a7081ac8dc5082210c14042f7605482c7d5ad99a4efabad870a01c55e0efac3f3ec8249aec998d888
6
+ metadata.gz: 9ec02c23d5fe3b8a66bc8b858607028d54f04119c4fb1ffa73d947eebf4bcc738d4b7c952e4e107d0783271790282f19b0262f9bfebe0738cd02813edcbae86c
7
+ data.tar.gz: 2396ac744536f2fc268fa98dd503d81c58df20cc797ef0cbfb77b793a89137828224a834c67b56697d7527d7de82c016cf6d9b87fb89d0bb0c0914284529a83f
data/README.md CHANGED
@@ -31,13 +31,14 @@ COMMANDS:
31
31
  OPTIONS:
32
32
  -i, --input-dir DIR Input directory of RPG Maker project
33
33
  -o, --output-dir DIR Output directory of parsed/written files
34
- --disable-processing FILES Don't process specified files (maps, other, system, plugins)
34
+ --disable-processing FILES Don't process specified files (maps, other, system, scripts)
35
35
  -s, --shuffle NUM Shuffle level (1: lines, 2: lines and words)
36
- --disable_custom_processing Disables built-in custom parsing/writing for some games
36
+ --disable-custom-processing Disables built-in custom parsing/writing for some games
37
37
  -l, --log Log information while processing
38
- -f, --force Force rewrite all files. Cannot be used with --append.
38
+ -f, --force Force rewrite all files. Cannot be used with --append
39
39
  USE WITH CAUTION!
40
- -a, --append When you update the rvpacker-txt, you probably should re-read your files with append, as some new text might be added to parser.
40
+ -a, --append When you update the rvpacker-txt, you probably should re-read
41
+ your files with append, as some new text might be added to parser
41
42
  Cannot be used with --force
42
43
  -h, --help Show help message
43
44
  ```
data/bin/rvpacker-txt CHANGED
@@ -5,11 +5,9 @@ require 'optparse'
5
5
  require 'fileutils'
6
6
 
7
7
  require 'classes'
8
- require 'read'
9
- require 'write'
10
8
 
11
9
  def self.parse_options
12
- options = { disable_processing: Array.new(4, false) }
10
+ options = { disable_processing: {}, input_dir: './', output_dir: './', shuffle_level: 0 }
13
11
 
14
12
  OptionParser.new do |cmd|
15
13
  cmd.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"
@@ -23,10 +21,11 @@ def self.parse_options
23
21
  options[:output_dir] = File.exist?(dir) ? File.realpath(dir) : (raise "#{dir} not found")
24
22
  end
25
23
 
26
- cmd.on('--disable-processing FILES', Array, 'Don\'t process specified files (maps, other, system, plugins)') do |files|
24
+ cmd.on('--disable-processing FILES', Array, "Don't process specified files (maps, other, system, scripts)") do |files|
27
25
  files.each do |file|
28
- index = %w[maps other system scripts].index(file)
29
- options[:disable_processing][index] = true if index
26
+ files = %w[maps other system scripts]
27
+ index = files.index(file)
28
+ options[:disable_processing][files[index]] = true if index
30
29
  end
31
30
  end
32
31
 
@@ -34,7 +33,7 @@ def self.parse_options
34
33
  options[:shuffle_level] = num
35
34
  end
36
35
 
37
- cmd.on('--disable_custom_processing', 'Disables built-in custom parsing/writing for some games') do
36
+ cmd.on('--disable-custom-processing', 'Disables built-in custom parsing/writing for some games') do
38
37
  options[:disable_custom_processing] = true
39
38
  end
40
39
 
@@ -42,11 +41,11 @@ def self.parse_options
42
41
  options[:logging] = true
43
42
  end
44
43
 
45
- cmd.on('-f', '--force', 'Force rewrite all files. Cannot be used with --append.', 'USE WITH CAUTION!') do
44
+ cmd.on('-f', '--force', 'Force rewrite all files. Cannot be used with --append', 'USE WITH CAUTION!') do
46
45
  options[:force] = true
47
46
  end
48
47
 
49
- cmd.on('-a', '--append', 'When you update the rvpacker-txt, you probably should re-read your files with append, as some new text might be added to parser.', 'Cannot be used with --force') do
48
+ cmd.on('-a', '--append', 'When you update the rvpacker-txt, you probably should re-read', 'your files with append, as some new text might be added to parser', 'Cannot be used with --force') do
50
49
  raise '--append cannot be used beside --force.' if options[:force]
51
50
  options[:append] = true
52
51
  end
@@ -64,6 +63,8 @@ def self.parse_options
64
63
  options
65
64
  end
66
65
 
66
+ # @param [String] system_file_path
67
+ # @return [String, nil]
67
68
  def self.get_game_type(system_file_path)
68
69
  object = Marshal.load(File.binread(system_file_path))
69
70
  game_title = object.instance_variable_get(:@game_title).to_s.downcase
@@ -87,21 +88,17 @@ extensions = { xp: '.rxdata', vx: 'rvdata', ace: 'rvdata2' }
87
88
  original_directory = Dir.glob(File.join(input_dir, '{data,original}'), File::FNM_CASEFOLD).first
88
89
  raise '"Data" or "original" directory not found within input directory.' unless original_directory
89
90
 
90
- paths = {
91
- original_path: original_directory,
92
- translation_path: File.join(input_dir, 'translation'),
93
- maps_path: File.join(input_dir, 'translation', 'maps'),
94
- other_path: File.join(input_dir, 'translation', 'other'),
95
- output_path: File.join(output_dir, 'output')
96
- }
91
+ maps_path = File.join(input_dir, 'translation', 'maps')
92
+ other_path = File.join(input_dir, 'translation', 'other')
97
93
 
98
- paths.each_value { |path| FileUtils.mkdir_p(path) }
94
+ FileUtils.mkdir_p(maps_path)
95
+ FileUtils.mkdir_p(other_path)
99
96
 
100
- engine = extensions.find do |symbol, extension|
101
- symbol if File.exist?(File.join(paths[:original_path], "System.#{extension}"))
97
+ engine = extensions.find do |_symbol, extension|
98
+ File.exist?(File.join(original_directory, "System.#{extension}"))
102
99
  end || (raise "Couldn't determine project engine.")
103
100
 
104
- files = Dir.glob("#{paths[:original_path]}/*#{extensions[engine]}")
101
+ files = Dir.glob("#{original_directory}/*#{extensions[engine[0]]}")
105
102
 
106
103
  maps_files_paths = []
107
104
  other_files_paths = []
@@ -110,6 +107,7 @@ scripts_file_path = nil
110
107
 
111
108
  files.each do |file|
112
109
  basename = File.basename(file)
110
+ next unless basename.end_with?(extensions[engine[0]])
113
111
 
114
112
  if basename.start_with?(/Map[0-9]/)
115
113
  maps_files_paths.push(file)
@@ -122,7 +120,7 @@ files.each do |file|
122
120
  end
123
121
  end
124
122
 
125
- ini_file_path = File.join(input_dir, "Game.ini")
123
+ ini_file_path = File.join(input_dir, 'Game.ini')
126
124
 
127
125
  game_type = disable_custom_processing ? nil : get_game_type(system_file_path)
128
126
 
@@ -130,7 +128,7 @@ wait_time = 0
130
128
  processing_type = if force
131
129
  wait_time_start = Time.now
132
130
 
133
- puts "WARNING! You\'re about to forcefully rewrite all your translation files, including _trans files.\nIf you really want to do it, make sure you've made a backup of your _trans files, if you made some changes in them already.\nInput 'Y' to continue."
131
+ puts "WARNING! You're about to forcefully rewrite all your translation files, including _trans files.\nIf you really want to do it, make sure you've made a backup of your _trans files, if you made some changes in them already.\nInput 'Y' to continue."
134
132
  exit unless gets.chomp == 'Y'
135
133
 
136
134
  wait_time = Time.now - wait_time_start
@@ -142,18 +140,23 @@ processing_type = if force
142
140
  puts 'Custom processing for this game is enabled. Use --disable-custom-processing to disable it.' unless game_type.nil?
143
141
 
144
142
  if options[:action] == 'read'
145
- read_map(maps_files_paths, paths[:maps_path], logging, game_type, processing_type) unless disable_processing[0]
146
- read_other(other_files_paths, paths[:other_path], logging, game_type, processing_type) unless disable_processing[1]
147
- read_system(system_file_path, ini_file_path, paths[:other_path], logging, processing_type) unless disable_processing[2]
148
- read_scripts(scripts_file_path, paths[:other_path], logging, processing_type) unless disable_processing[3]
143
+ require 'read'
144
+ read_map(maps_files_paths, maps_path, logging, game_type, processing_type) unless disable_processing[:maps]
145
+ read_other(other_files_paths, other_path, logging, game_type, processing_type) unless disable_processing[:other]
146
+ read_system(system_file_path, ini_file_path, other_path, logging, processing_type) unless disable_processing[:system]
147
+ read_scripts(scripts_file_path, other_path, logging, processing_type) unless disable_processing[:scripts]
149
148
  else
150
- write_map(maps_files_paths, paths[:maps_path], paths[:output_path], shuffle_level, logging, game_type, processing_type) unless disable_processing[0]
151
- write_other(other_files_paths, paths[:other_path], paths[:output_path], shuffle_level, logging, game_type, processing_type) unless disable_processing[1]
152
- write_system(system_file_path, ini_file_path, paths[:other_path], paths[:output_path], shuffle_level, logging, processing_type) unless disable_processing[2]
153
- write_scripts(scripts_file_path, paths[:other_path], paths[:output_path], logging, processing_type) unless disable_processing[3]
149
+ require 'write'
150
+ output_path = File.join(output_dir, 'output')
151
+ FileUtils.mkdir_p(output_path)
152
+
153
+ write_map(maps_files_paths, maps_path, output_path, shuffle_level, logging, game_type) unless disable_processing[:maps]
154
+ write_other(other_files_paths, other_path, output_path, shuffle_level, logging, game_type) unless disable_processing[:other]
155
+ write_system(system_file_path, ini_file_path, other_path, output_path, shuffle_level, logging) unless disable_processing[:system]
156
+ write_scripts(scripts_file_path, other_path, output_path, logging) unless disable_processing[:scripts]
154
157
  end
155
158
 
156
159
  $wait_time = 0 if $wait_time.nil?
157
- end_time = Time.now - start_time - wait_time - $wait_time
160
+ elapsed_time = Time.now - start_time - wait_time - $wait_time
158
161
 
159
- puts "Done in #{end_time}"
162
+ puts "Done in #{elapsed_time}"
data/lib/classes.rb CHANGED
@@ -21,7 +21,6 @@ DEALINGS IN THE SOFTWARE.
21
21
  class Table
22
22
  def initialize(bytes)
23
23
  @dim, @x, @y, @z, items, *@data = bytes.unpack('L5 S*')
24
-
25
24
  raise 'Size mismatch loading Table from data' unless items == @data.length && @x * @y * @z == items
26
25
  end
27
26