R3EXS 1.0.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.
data/bin/R3EXS ADDED
@@ -0,0 +1,217 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'gli'
5
+ require 'R3EXS'
6
+
7
+ # 保存全局选项
8
+ $global_options = {}
9
+
10
+ class App
11
+ extend GLI::App
12
+
13
+ program_desc 'A tool for extracting and translating strings from the RGSS3 game engine'
14
+
15
+ version R3EXS::VERSION
16
+
17
+ subcommand_option_handling :normal
18
+ arguments :strict
19
+
20
+ desc 'Enable verbose mode'
21
+ switch [:v, :verbose]
22
+
23
+ desc 'Decrypt the Game.rgss3a file'
24
+ arg_name '<Game.rgss3a file path>'
25
+ command :decrypt do |c|
26
+ c.desc 'The *.rvdata2 output dir'
27
+ c.default_value './'
28
+ c.arg_name 'DIRECTORY'
29
+ c.flag [:o, :output_dir]
30
+
31
+ c.action do |global_options, options, args|
32
+ begin
33
+ R3EXS.rgss3a_rvdata2(args[0], options[:output_dir], global_options[:verbose])
34
+ puts "#{R3EXS::Utils::GREEN_COLOR}All rvdata2 files have been written to #{options[:output_dir]}#{R3EXS::Utils::RESET_COLOR}"
35
+ rescue TypeError => e
36
+ puts "#{R3EXS::Utils::RED_COLOR}#{e.message}#{R3EXS::Utils::RESET_COLOR}"
37
+ puts 'Please make sure the rgss3a file is not corrupted.'
38
+ end
39
+ end
40
+ end
41
+
42
+ desc 'Serialize rvdata2 files into JSON'
43
+ arg_name '<the *.rvdata2 dir>'
44
+ command :rvdata2_json do |c|
45
+ c.desc 'Enable complete serialization'
46
+ c.switch [:c, :complete]
47
+
48
+ c.desc 'Enable Scripts.rvdata2 serialization'
49
+ c.switch [:s, :with_scripts]
50
+
51
+ c.desc 'Enable notes attribute serialization'
52
+ c.switch [:n, :with_notes]
53
+
54
+ c.desc 'The *.json output dir'
55
+ c.default_value './JSON'
56
+ c.arg_name 'DIRECTORY'
57
+ c.flag [:o, :output_dir]
58
+
59
+ c.action do |global_options, options, args|
60
+ begin
61
+ R3EXS.rvdata2_json(args[0], options[:output_dir], options[:complete], options[:with_scripts], options[:with_notes])
62
+ $stderr.puts "#{R3EXS::Utils::GREEN_COLOR}All JSON files have been written to #{options[:output_dir]}#{R3EXS::Utils::RESET_COLOR}"
63
+ rescue R3EXS::Rvdata2FileError => e
64
+ $stderr.puts "#{R3EXS::Utils::RED_COLOR}#{e.message}#{R3EXS::Utils::RESET_COLOR}"
65
+ $stderr.puts 'Please make sure the rvdata2 files are not corrupted.'
66
+ rescue R3EXS::Rvdata2DirError => e
67
+ $stderr.puts "#{R3EXS::Utils::RED_COLOR}#{e.message}#{R3EXS::Utils::RESET_COLOR}"
68
+ end
69
+ end
70
+ end
71
+
72
+ desc 'Deserialize JSON files back into rvdata2'
73
+ arg_name '<the *.json dir>'
74
+ command :json_rvdata2 do |c|
75
+ c.desc 'Enable complete deserialization'
76
+ c.switch [:c, :complete]
77
+
78
+ c.desc 'Enable Scripts JSON deserialization'
79
+ c.switch [:s, :with_scripts]
80
+
81
+ c.desc 'The NEW *.rvdata2 output dir'
82
+ c.default_value './Data_NEW'
83
+ c.arg_name 'DIRECTORY'
84
+ c.flag [:o, :output_dir]
85
+
86
+ c.desc 'The ORIGINAL *.rvdata2 dir'
87
+ c.default_value './Data'
88
+ c.arg_name 'DIRECTORY'
89
+ c.flag [:r, :original_dir]
90
+
91
+ c.action do |global_options, options, args|
92
+ begin
93
+ R3EXS.json_rvdata2(args[0], options[:output_dir], options[:original_dir], options[:complete], options[:with_scripts])
94
+ $stderr.puts "#{R3EXS::Utils::GREEN_COLOR}All new rvdata2 files have been written to #{options[:output_dir]}#{R3EXS::Utils::RESET_COLOR}"
95
+ rescue R3EXS::RPGJsonFileError => e
96
+ $stderr.puts "#{R3EXS::Utils::RED_COLOR}#{e.message}#{R3EXS::Utils::RESET_COLOR}"
97
+ $stderr.puts 'Your JSON files are not in RPG module'
98
+ $stderr.puts "You are supposed to use '#{R3EXS::Utils::GREEN_COLOR}-c#{R3EXS::Utils::RESET_COLOR}' or '#{R3EXS::Utils::GREEN_COLOR}--complete#{R3EXS::Utils::RESET_COLOR}' to enable complete serialization in #{R3EXS::Utils::GREEN_COLOR}rvdata2_json#{R3EXS::Utils::RESET_COLOR} subcommand"
99
+ $stderr.puts "Or #{R3EXS::Utils::RED_COLOR}NOT#{R3EXS::Utils::RESET_COLOR} use '#{R3EXS::Utils::GREEN_COLOR}-c#{R3EXS::Utils::RESET_COLOR}' or '#{R3EXS::Utils::GREEN_COLOR}--complete#{R3EXS::Utils::RESET_COLOR}' to enable complete deserialization in #{R3EXS::Utils::GREEN_COLOR}json_rvdata2#{R3EXS::Utils::RESET_COLOR} subcommand"
100
+ $stderr.puts "For more information, please enter '#{R3EXS::Utils::GREEN_COLOR}R3EXS help json_rvdata2#{R3EXS::Utils::RESET_COLOR}'"
101
+ rescue R3EXS::R3EXSJsonFileError => e
102
+ $stderr.puts "#{R3EXS::Utils::RED_COLOR}#{e.message}#{R3EXS::Utils::RESET_COLOR}"
103
+ $stderr.puts 'Your JSON files are not in R3EXS module'
104
+ $stderr.puts "You are #{R3EXS::Utils::RED_COLOR}NOT#{R3EXS::Utils::RESET_COLOR} supposed to use '#{R3EXS::Utils::GREEN_COLOR}-c#{R3EXS::Utils::RESET_COLOR}' or '#{R3EXS::Utils::GREEN_COLOR}--complete#{R3EXS::Utils::RESET_COLOR}' to enable complete serialization in #{R3EXS::Utils::GREEN_COLOR}rvdata2_json#{R3EXS::Utils::RESET_COLOR} subcommand"
105
+ $stderr.puts "Or use '#{R3EXS::Utils::GREEN_COLOR}-c#{R3EXS::Utils::RESET_COLOR}' or '#{R3EXS::Utils::GREEN_COLOR}--complete#{R3EXS::Utils::RESET_COLOR}' to enable complete deserialization in #{R3EXS::Utils::GREEN_COLOR}json_rvdata2#{R3EXS::Utils::RESET_COLOR} subcommand"
106
+ $stderr.puts "For more information, please enter '#{R3EXS::Utils::GREEN_COLOR}R3EXS help json_rvdata2#{R3EXS::Utils::RESET_COLOR}'"
107
+ rescue R3EXS::Rvdata2FileError => e
108
+ $stderr.puts "#{R3EXS::Utils::RED_COLOR}#{e.message}#{R3EXS::Utils::RESET_COLOR}"
109
+ $stderr.puts "Your original rvdata2 file seem to be corrupted"
110
+ rescue R3EXS::JsonDirError => e
111
+ $stderr.puts "#{R3EXS::Utils::RED_COLOR}#{e.message}#{R3EXS::Utils::RESET_COLOR}"
112
+ rescue R3EXS::Rvdata2DirError => e
113
+ $stderr.puts "#{R3EXS::Utils::RED_COLOR}#{e.message}#{R3EXS::Utils::RESET_COLOR}"
114
+ $stderr.puts 'You are supposed to privide the original rvdata2 dir in complete deserialization mode'
115
+ rescue R3EXS::ScriptsDirError => e
116
+ $stderr.puts "#{R3EXS::Utils::RED_COLOR}#{e.message}#{R3EXS::Utils::RESET_COLOR}"
117
+ $stderr.puts "You are supposed to use '#{R3EXS::Utils::GREEN_COLOR}-s#{R3EXS::Utils::RESET_COLOR}' or '#{R3EXS::Utils::GREEN_COLOR}--scripts#{R3EXS::Utils::RESET_COLOR}' to enable serialization of Scripts in #{R3EXS::Utils::GREEN_COLOR}rvdata2_json#{R3EXS::Utils::RESET_COLOR} subcommand"
118
+ $stderr.puts "For more information, please enter '#{R3EXS::Utils::GREEN_COLOR}R3EXS help rvdata2_json#{R3EXS::Utils::RESET_COLOR}'"
119
+ rescue R3EXS::ScriptsInfoPathError => e
120
+ $stderr.puts "#{R3EXS::Utils::RED_COLOR}#{e.message}#{R3EXS::Utils::RESET_COLOR}"
121
+ $stderr.puts "You are supposed to use '#{R3EXS::Utils::GREEN_COLOR}-s#{R3EXS::Utils::RESET_COLOR}' or '#{R3EXS::Utils::GREEN_COLOR}--scripts#{R3EXS::Utils::RESET_COLOR}' to enable serialization of Scripts in #{R3EXS::Utils::GREEN_COLOR}rvdata2_json#{R3EXS::Utils::RESET_COLOR} subcommand"
122
+ $stderr.puts "For more information, please enter '#{R3EXS::Utils::GREEN_COLOR}R3EXS help rvdata2_json#{R3EXS::Utils::RESET_COLOR}'"
123
+ end
124
+ end
125
+ end
126
+
127
+ desc 'Extract all strings'
128
+ arg_name '<the *.json dir>'
129
+ command :ex_strings do |c|
130
+ c.desc 'Enable Scripts extraction'
131
+ c.switch [:s, :with_scripts]
132
+
133
+ c.desc 'Enable Symbol extraction in Scripts extraction'
134
+ c.switch [:y, :with_symbol]
135
+
136
+ c.desc 'Enable Scripts extraction into a separate ManualTransFile_scripts.json'
137
+ c.switch [:p, :with_scripts_separate]
138
+
139
+ c.desc 'The ManualTransFile.json or ManualTransFile_scripts.json output dir'
140
+ c.default_value './'
141
+ c.arg_name 'DIRECTORY'
142
+ c.flag [:o, :output_dir]
143
+
144
+ c.action do |global_options, options, args|
145
+ begin
146
+ R3EXS.ex_strings(args[0], options[:output_dir], options[:with_scripts], options[:with_symbol], options[:with_scripts_separate])
147
+ puts "#{R3EXS::Utils::GREEN_COLOR}All strings have been extracted to #{File.join(options[:output_dir], 'ManualTransFile.json')}#{R3EXS::Utils::RESET_COLOR}"
148
+ rescue R3EXS::R3EXSJsonFileError => e
149
+ puts "#{R3EXS::Utils::RED_COLOR}#{e.message}#{R3EXS::Utils::RESET_COLOR}"
150
+ $stderr.puts 'Your JSON files are not in R3EXS module'
151
+ $stderr.puts "You are #{R3EXS::Utils::RED_COLOR}NOT#{R3EXS::Utils::RESET_COLOR} supposed to use '#{R3EXS::Utils::GREEN_COLOR}-c#{R3EXS::Utils::RESET_COLOR}' or '#{R3EXS::Utils::GREEN_COLOR}--complete#{R3EXS::Utils::RESET_COLOR}' to enable complete serialization in #{R3EXS::Utils::GREEN_COLOR}rvdata2_json#{R3EXS::Utils::RESET_COLOR} subcommand"
152
+ $stderr.puts "For more information, please enter '#{R3EXS::Utils::GREEN_COLOR}R3EXS help json_rvdata2#{R3EXS::Utils::RESET_COLOR}'"
153
+ rescue R3EXS::JsonDirError => e
154
+ puts "#{R3EXS::Utils::RED_COLOR}#{e.message}#{R3EXS::Utils::RESET_COLOR}"
155
+ rescue R3EXS::ScriptsDirError => e
156
+ puts "#{R3EXS::Utils::RED_COLOR}#{e.message}#{R3EXS::Utils::RESET_COLOR}"
157
+ $stderr.puts "You are supposed to use '#{R3EXS::Utils::GREEN_COLOR}-s#{R3EXS::Utils::RESET_COLOR}' or '#{R3EXS::Utils::GREEN_COLOR}--scripts#{R3EXS::Utils::RESET_COLOR}' to enable serialization of Scripts in #{R3EXS::Utils::GREEN_COLOR}rvdata2_json#{R3EXS::Utils::RESET_COLOR} subcommand"
158
+ $stderr.puts "For more information, please enter '#{R3EXS::Utils::GREEN_COLOR}R3EXS help rvdata2_json#{R3EXS::Utils::RESET_COLOR}'"
159
+ end
160
+ end
161
+ end
162
+
163
+ desc 'Inject all strings'
164
+ arg_name '<the *.json dir>'
165
+ command :in_strings do |c|
166
+ c.desc 'Enable Scripts Injection'
167
+ c.switch [:s, :with_scripts]
168
+
169
+ c.desc 'The ManualTransFile.json path'
170
+ c.default_value './ManualTransFile.json'
171
+ c.arg_name 'FILE'
172
+ c.flag [:m, :manualtransfile_path]
173
+
174
+ c.desc 'The NEW *.json output dir'
175
+ c.default_value './JSON_NEW'
176
+ c.arg_name 'DIRECTORY'
177
+ c.flag [:o, :output_dir]
178
+
179
+ c.action do |global_options, options, args|
180
+ begin
181
+ R3EXS.in_strings(args[0], options[:output_dir], options[:manualtransfile_path], options[:with_scripts])
182
+ puts "#{R3EXS::Utils::GREEN_COLOR}All new JSON files have been written to #{options[:output_dir]}#{R3EXS::Utils::RESET_COLOR}"
183
+ rescue R3EXS::R3EXSJsonFileError => e
184
+ puts "#{R3EXS::Utils::RED_COLOR}#{e.message}#{R3EXS::Utils::RESET_COLOR}"
185
+ $stderr.puts 'Your JSON files are not in R3EXS module'
186
+ $stderr.puts "You are #{R3EXS::Utils::RED_COLOR}NOT#{R3EXS::Utils::RESET_COLOR} supposed to use '#{R3EXS::Utils::GREEN_COLOR}-c#{R3EXS::Utils::RESET_COLOR}' or '#{R3EXS::Utils::GREEN_COLOR}--complete#{R3EXS::Utils::RESET_COLOR}' to enable complete serialization in #{R3EXS::Utils::GREEN_COLOR}rvdata2_json#{R3EXS::Utils::RESET_COLOR} subcommand"
187
+ $stderr.puts "For more information, please enter '#{R3EXS::Utils::GREEN_COLOR}R3EXS help json_rvdata2#{R3EXS::Utils::RESET_COLOR}'"
188
+ rescue R3EXS::JsonDirError => e
189
+ puts "#{R3EXS::Utils::RED_COLOR}#{e.message}#{R3EXS::Utils::RESET_COLOR}"
190
+ rescue R3EXS::ScriptsDirError => e
191
+ puts "#{R3EXS::Utils::RED_COLOR}#{e.message}#{R3EXS::Utils::RESET_COLOR}"
192
+ $stderr.puts "You are supposed to use '#{R3EXS::Utils::GREEN_COLOR}-s#{R3EXS::Utils::RESET_COLOR}' or '#{R3EXS::Utils::GREEN_COLOR}--scripts#{R3EXS::Utils::RESET_COLOR}' to enable serialization of Scripts in #{R3EXS::Utils::GREEN_COLOR}rvdata2_json#{R3EXS::Utils::RESET_COLOR} subcommand"
193
+ $stderr.puts "For more information, please enter '#{R3EXS::Utils::GREEN_COLOR}R3EXS help rvdata2_json#{R3EXS::Utils::RESET_COLOR}'"
194
+ rescue R3EXS::ManualTransFilePathError => e
195
+ puts "#{R3EXS::Utils::RED_COLOR}#{e.message}#{R3EXS::Utils::RESET_COLOR}"
196
+ $stderr.puts "You are supposed to use #{R3EXS::Utils::GREEN_COLOR}ex_strings#{R3EXS::Utils::RESET_COLOR} subcommand to generate the ManualTransFile.json"
197
+ $stderr.puts "For more information, please enter '#{R3EXS::Utils::GREEN_COLOR}R3EXS help ex_strings#{R3EXS::Utils::RESET_COLOR}'"
198
+ end
199
+ end
200
+ end
201
+
202
+ pre do |global, command, options, args|
203
+ $global_options = global
204
+ true
205
+ end
206
+
207
+ post do |global, command, options, args|
208
+ end
209
+
210
+ on_error do |exception|
211
+ # Error logic here
212
+ # return false to skip default error handling
213
+ true
214
+ end
215
+ end
216
+
217
+ exit App.run(ARGV)
@@ -0,0 +1,3 @@
1
+ require 'mkmf'
2
+
3
+ create_makefile('R3EXS/rgss3a_rvdata2')