R3EXS 1.0.4 → 1.1.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/CHANGELOG.md +12 -0
- data/README.md +260 -260
- data/README_EN.md +260 -260
- data/bin/R3EXS +10 -16
- data/ext/rgss3a_rvdata2/rgss3a_rvdata2.c +616 -616
- data/lib/R3EXS/RGSS3.rb +1456 -1456
- data/lib/R3EXS/RGSS3_R3EXS.rb +18 -11
- data/lib/R3EXS/ast.rb +12 -17
- data/lib/R3EXS/error.rb +1 -18
- data/lib/R3EXS/extract_strings.rb +76 -79
- data/lib/R3EXS/inject_strings.rb +37 -36
- data/lib/R3EXS/json_rvdata2.rb +115 -104
- data/lib/R3EXS/rvdata2_json.rb +47 -17
- data/lib/R3EXS/utils.rb +1080 -970
- data/lib/R3EXS/version.rb +1 -1
- metadata +5 -5
data/lib/R3EXS/json_rvdata2.rb
CHANGED
@@ -1,105 +1,116 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'zlib'
|
4
|
-
require_relative 'utils'
|
5
|
-
require_relative 'RGSS3_R3EXS'
|
6
|
-
|
7
|
-
module R3EXS
|
8
|
-
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# @param
|
12
|
-
# @param
|
13
|
-
#
|
14
|
-
# @
|
15
|
-
# @
|
16
|
-
#
|
17
|
-
# @
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'zlib'
|
4
|
+
require_relative 'utils'
|
5
|
+
require_relative 'RGSS3_R3EXS'
|
6
|
+
|
7
|
+
module R3EXS
|
8
|
+
|
9
|
+
# 将指定目录下的所有JSON文件转换为 rvdata2 文件
|
10
|
+
#
|
11
|
+
# @param [Pathname] target_dir 目标目录
|
12
|
+
# @param [Pathname] output_dir 输出目录
|
13
|
+
# @param [Pathname] original_dir 原始 rvdata2 文件目录
|
14
|
+
# @param [Boolean] complete 是否完全转换
|
15
|
+
# @param [Boolean] with_scripts 是否转换Scripts
|
16
|
+
#
|
17
|
+
# @raise [RPGJsonFileError] json 文件不是 RPG 模块中的对象
|
18
|
+
# @raise [R3EXSJsonFileError] json 文件不是 R3EXS 模块中的对象
|
19
|
+
# @raise [Rvdata2FileError] 原始 rvdata2 文件可能损坏
|
20
|
+
# @raise [JsonDirError] target_dir 不存在
|
21
|
+
# @raise [Rvdata2DirError] original_dir 不存在
|
22
|
+
# @raise [ScriptsInfoPathError] Scripts_info.json 文件不存在
|
23
|
+
#
|
24
|
+
# @return [void]
|
25
|
+
def R3EXS.json_rvdata2(target_dir, output_dir, original_dir, complete, with_scripts)
|
26
|
+
# 处理常规的 JSON 文件
|
27
|
+
Utils.all_json_files(target_dir, (complete) ? :RPG : :R3EXS) do |object, file_basename, parent_relative_dir|
|
28
|
+
output_file_path = output_dir.join(parent_relative_dir, "#{file_basename}.rvdata2")
|
29
|
+
if complete
|
30
|
+
print "#{Utils::ESCAPE}#{Utils::MAGENTA_COLOR}Serializing to #{Utils::RESET_COLOR}#{output_file_path}...\r" if $global_options[:verbose]
|
31
|
+
Utils.object_rvdata2(object, output_file_path)
|
32
|
+
else
|
33
|
+
# 检查 original_dir 是否存在
|
34
|
+
original_dir.exist? or raise Rvdata2DirError.new(original_dir.to_s), "Original rvdata2 directory not found: #{original_dir}"
|
35
|
+
original_file_path = original_dir.join(parent_relative_dir, "#{file_basename}.rvdata2")
|
36
|
+
print "#{Utils::ESCAPE}#{Utils::BLUE_COLOR}Reading and Deserializing #{Utils::RESET_COLOR}#{original_file_path}...\r" if $global_options[:verbose]
|
37
|
+
original_object = Marshal.load(original_file_path.binread)
|
38
|
+
|
39
|
+
# 这里的类型检查要用紧凑模式,因为 rvdata2 文件中可能存在 nil 元素,必须忽略
|
40
|
+
begin
|
41
|
+
Utils.check_type(original_object, file_basename, true, :RPG)
|
42
|
+
rescue RPGTypeError
|
43
|
+
raise Rvdata2FileError.new(original_file_path.to_s), "Invalid rvdata2 file: #{original_file_path}"
|
44
|
+
end
|
45
|
+
|
46
|
+
print "#{Utils::ESCAPE}#{Utils::MAGENTA_COLOR}Serializing to #{Utils::RESET_COLOR}#{output_file_path}...\r" if $global_options[:verbose]
|
47
|
+
|
48
|
+
# 根据是否为数组进行不同的处理
|
49
|
+
if object.is_a?(Array)
|
50
|
+
object.each do |obj|
|
51
|
+
obj.inject_to(original_object[obj.index])
|
52
|
+
end
|
53
|
+
else
|
54
|
+
object.inject_to(original_object)
|
55
|
+
end
|
56
|
+
Utils.object_rvdata2(original_object, output_file_path)
|
57
|
+
end
|
58
|
+
print "#{Utils::ESCAPE}#{Utils::GREEN_COLOR}Serialized #{Utils::RESET_COLOR}#{output_file_path}\n" if $global_options[:verbose]
|
59
|
+
end
|
60
|
+
|
61
|
+
# 处理 CommonEvent_\d{5}.json 文件
|
62
|
+
Utils.all_commonevent_json_files(target_dir, (complete) ? :RPG : :R3EXS) do |commonevents, _, parent_relative_dir|
|
63
|
+
output_file_path = output_dir.join(parent_relative_dir.parent, 'CommonEvents.rvdata2')
|
64
|
+
if complete
|
65
|
+
print "#{Utils::ESCAPE}#{Utils::MAGENTA_COLOR}Serializing to #{Utils::RESET_COLOR}#{output_file_path}...\r" if $global_options[:verbose]
|
66
|
+
Utils.object_rvdata2(commonevents, output_file_path)
|
67
|
+
else
|
68
|
+
# 检查 original_dir 是否存在
|
69
|
+
original_dir.exist? or raise Rvdata2DirError.new(original_dir.to_s), "Original rvdata2 directory not found: #{original_dir}"
|
70
|
+
original_file_path = original_dir.join(parent_relative_dir.parent, 'CommonEvents.rvdata2')
|
71
|
+
print "#{Utils::ESCAPE}#{Utils::BLUE_COLOR}Reading and Deserializing #{Utils::RESET_COLOR}#{original_file_path}...\r" if $global_options[:verbose]
|
72
|
+
original_object = Marshal.load(original_file_path.binread)
|
73
|
+
|
74
|
+
# 这里的类型检查要用紧凑模式,因为 rvdata2 文件中可能存在 nil 元素,必须忽略
|
75
|
+
begin
|
76
|
+
Utils.check_type(original_object, 'CommonEvents', true, :RPG)
|
77
|
+
rescue RPGTypeError
|
78
|
+
raise Rvdata2FileError.new(original_file_path.to_s), "Invalid rvdata2 file: #{original_file_path}"
|
79
|
+
end
|
80
|
+
|
81
|
+
print "#{Utils::ESCAPE}#{Utils::MAGENTA_COLOR}Serializing to #{Utils::RESET_COLOR}#{output_file_path}...\r" if $global_options[:verbose]
|
82
|
+
|
83
|
+
commonevents.each do |commonevent|
|
84
|
+
commonevent.inject_to(original_object[commonevent.index])
|
85
|
+
end
|
86
|
+
|
87
|
+
Utils.object_rvdata2(original_object, output_file_path)
|
88
|
+
end
|
89
|
+
print "#{Utils::ESCAPE}#{Utils::GREEN_COLOR}Serialized #{Utils::RESET_COLOR}#{output_file_path}\n" if $global_options[:verbose]
|
90
|
+
end
|
91
|
+
|
92
|
+
# 处理 \d{5}.rb 文件
|
93
|
+
if with_scripts
|
94
|
+
Utils.all_rb_files(target_dir) do |scripts, _, parent_relative_dir|
|
95
|
+
output_file_path = output_dir.join(parent_relative_dir.parent, 'Scripts.rvdata2')
|
96
|
+
script_info_file_path = target_dir.join(parent_relative_dir, 'Scripts_info.json')
|
97
|
+
script_info_file_path.exist? or raise ScriptsInfoPathError.new(script_info_file_path.to_s), "Scripts_info.json not found: #{script_info_file_path}"
|
98
|
+
|
99
|
+
print "#{Utils::ESCAPE}#{Utils::MAGENTA_COLOR}Serializing to #{Utils::RESET_COLOR}#{output_file_path}...\r" if $global_options[:verbose]
|
100
|
+
|
101
|
+
print "#{Utils::ESCAPE}#{Utils::YELLOW_COLOR}Reading from #{Utils::RESET_COLOR}#{script_info_file_path}...\r" if $global_options[:verbose]
|
102
|
+
scripts_info_array = Oj.load_file(script_info_file_path.to_s)
|
103
|
+
|
104
|
+
output_scripts_array = []
|
105
|
+
scripts_info_array.each do |script_info|
|
106
|
+
index = script_info[:index]
|
107
|
+
script = scripts[index]
|
108
|
+
output_scripts_array << [114514, script_info[:name], Zlib::Deflate.deflate(script)]
|
109
|
+
end
|
110
|
+
Utils.object_rvdata2(output_scripts_array, output_file_path)
|
111
|
+
print "#{Utils::ESCAPE}#{Utils::GREEN_COLOR}Serialized #{Utils::RESET_COLOR}#{output_file_path}\n" if $global_options[:verbose]
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
105
116
|
end
|
data/lib/R3EXS/rvdata2_json.rb
CHANGED
@@ -8,32 +8,63 @@ module R3EXS
|
|
8
8
|
|
9
9
|
# 将 Script 对象数组序列化为 Ruby 源码
|
10
10
|
#
|
11
|
-
# @param scripts [Array<
|
12
|
-
# @param output_dir [
|
11
|
+
# @param scripts [Array<Object>] 待转换的 Script 对象数组
|
12
|
+
# @param output_dir [Pathname] 输出目录
|
13
13
|
# @return [void]
|
14
14
|
def R3EXS.scripts_rb(scripts, output_dir)
|
15
|
-
|
16
|
-
full_dir =
|
17
|
-
|
15
|
+
output_dir.mkpath unless output_dir.exist?
|
16
|
+
full_dir = output_dir.join('Scripts')
|
17
|
+
full_dir.mkdir unless full_dir.exist?
|
18
18
|
|
19
19
|
scripts_info_array = []
|
20
20
|
scripts.each_with_index do |script, index|
|
21
21
|
next if script.nil?
|
22
22
|
scripts_info_array << { index: index, name: script[1] }
|
23
|
-
script_file_path =
|
23
|
+
script_file_path = full_dir.join("#{format('%03d', index)}.rb")
|
24
24
|
print "#{Utils::ESCAPE}#{Utils::MAGENTA_COLOR}Serializing to #{Utils::RESET_COLOR}#{script_file_path}...\r" if $global_options[:verbose]
|
25
|
-
|
25
|
+
script_file_path.write(Zlib::Inflate.inflate(script[2]).encode(universal_newline: true))
|
26
|
+
print "#{Utils::ESCAPE}#{Utils::GREEN_COLOR}Serialized #{Utils::RESET_COLOR}#{script_file_path}\n" if $global_options[:verbose]
|
26
27
|
end
|
27
28
|
|
28
|
-
script_info_file_path =
|
29
|
+
script_info_file_path = full_dir.join('Scripts_info.json')
|
29
30
|
print "#{Utils::ESCAPE}#{Utils::MAGENTA_COLOR}Serializing to #{Utils::RESET_COLOR}#{script_info_file_path}\r" if $global_options[:verbose]
|
30
31
|
Utils.object_json(scripts_info_array, script_info_file_path)
|
32
|
+
print "#{Utils::ESCAPE}#{Utils::GREEN_COLOR}Serialized #{Utils::RESET_COLOR}#{script_info_file_path}\n" if $global_options[:verbose]
|
33
|
+
end
|
34
|
+
|
35
|
+
# 将 CommonEvents 对象数组序列化为分开的 JSON 文件
|
36
|
+
#
|
37
|
+
# @param commonevents [Array<Object>] 待转换的 CommonEvents 对象数组
|
38
|
+
# @param output_dir [Pathname] 输出目录
|
39
|
+
# @param complete [Boolean] 是否序列化所有内容
|
40
|
+
# @param with_notes [Boolean] 是否包含备注
|
41
|
+
# @return [void]
|
42
|
+
def R3EXS.commonevents_json(commonevents, output_dir, complete, with_notes)
|
43
|
+
full_dir = output_dir.join('CommonEvents')
|
44
|
+
|
45
|
+
if complete
|
46
|
+
commonevents.each_with_index do |commonevent, index|
|
47
|
+
commonevent_file_path = full_dir.join("#{format('CommonEvent_%05d', index)}.json")
|
48
|
+
print "#{Utils::ESCAPE}#{Utils::MAGENTA_COLOR}Serializing to #{Utils::RESET_COLOR}#{commonevent_file_path}...\r" if $global_options[:verbose]
|
49
|
+
Utils.object_json(commonevent, commonevent_file_path)
|
50
|
+
print "#{Utils::ESCAPE}#{Utils::GREEN_COLOR}Serialized #{Utils::RESET_COLOR}#{commonevent_file_path}\n" if $global_options[:verbose]
|
51
|
+
end
|
52
|
+
else
|
53
|
+
commonevents = Utils.rpg_r3exs(commonevents, 'CommonEvents', with_notes)
|
54
|
+
commonevents.each do |commonevent|
|
55
|
+
index = commonevent.index
|
56
|
+
commonevent_file_path = full_dir.join("#{format('CommonEvent_%05d', index)}.json")
|
57
|
+
print "#{Utils::ESCAPE}#{Utils::MAGENTA_COLOR}Serializing to #{Utils::RESET_COLOR}#{commonevent_file_path}...\r" if $global_options[:verbose]
|
58
|
+
Utils.object_json(commonevent, commonevent_file_path)
|
59
|
+
print "#{Utils::ESCAPE}#{Utils::GREEN_COLOR}Serialized #{Utils::RESET_COLOR}#{commonevent_file_path}\n" if $global_options[:verbose]
|
60
|
+
end
|
61
|
+
end
|
31
62
|
end
|
32
63
|
|
33
64
|
# 将指定目录下的所有 rvdata2 文件序列化为 JSON 格式
|
34
65
|
#
|
35
|
-
# @param target_dir [
|
36
|
-
# @param output_dir [
|
66
|
+
# @param target_dir [Pathname] 目标目录
|
67
|
+
# @param output_dir [Pathname] 输出目录
|
37
68
|
# @param complete [Boolean] 是否序列化所有内容
|
38
69
|
# @param with_scripts [Boolean] 是否包含脚本
|
39
70
|
# @param with_notes [Boolean] 是否包含备注
|
@@ -43,21 +74,20 @@ module R3EXS
|
|
43
74
|
#
|
44
75
|
# @return [void]
|
45
76
|
def R3EXS.rvdata2_json(target_dir, output_dir, complete, with_scripts, with_notes)
|
46
|
-
|
47
|
-
Utils.all_rvdata2_files(target_dir) do |object, file_basename|
|
77
|
+
Utils.all_rvdata2_files(target_dir) do |object, file_basename, parent_relative_dir|
|
48
78
|
if file_basename == 'Scripts'
|
49
|
-
|
50
|
-
|
51
|
-
|
79
|
+
scripts_rb(object, output_dir.join(parent_relative_dir)) if with_scripts
|
80
|
+
elsif file_basename == 'CommonEvents'
|
81
|
+
commonevents_json(object, output_dir.join(parent_relative_dir), complete, with_notes)
|
52
82
|
else
|
53
|
-
file_path =
|
83
|
+
file_path = output_dir.join(parent_relative_dir, "#{file_basename}.json")
|
54
84
|
print "#{Utils::ESCAPE}#{Utils::MAGENTA_COLOR}Serializing to #{Utils::RESET_COLOR}#{file_path}...\r" if $global_options[:verbose]
|
55
85
|
if complete
|
56
86
|
Utils.object_json(object, file_path)
|
57
87
|
else
|
58
88
|
Utils.object_json(Utils.rpg_r3exs(object, file_basename, with_notes), file_path)
|
59
89
|
end
|
60
|
-
print "#{Utils::ESCAPE}#{Utils::GREEN_COLOR}Serialized #{Utils::RESET_COLOR}#{
|
90
|
+
print "#{Utils::ESCAPE}#{Utils::GREEN_COLOR}Serialized #{Utils::RESET_COLOR}#{file_path}\n" if $global_options[:verbose]
|
61
91
|
end
|
62
92
|
end
|
63
93
|
end
|