R3EXS 1.0.2 → 1.0.3
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 +6 -0
- data/README.md +260 -260
- data/README_EN.md +260 -260
- data/bin/R3EXS +6 -4
- data/ext/rgss3a_rvdata2/rgss3a_rvdata2.c +616 -565
- data/lib/R3EXS/RGSS3.rb +1456 -1456
- data/lib/R3EXS/RGSS3_R3EXS.rb +95 -95
- data/lib/R3EXS/ast.rb +7 -7
- data/lib/R3EXS/error.rb +17 -0
- data/lib/R3EXS/extract_strings.rb +79 -79
- data/lib/R3EXS/json_rvdata2.rb +104 -104
- data/lib/R3EXS/utils.rb +970 -970
- data/lib/R3EXS/version.rb +1 -1
- metadata +2 -2
data/lib/R3EXS/RGSS3_R3EXS.rb
CHANGED
@@ -14,10 +14,10 @@ module R3EXS
|
|
14
14
|
# @param with_note [Boolean] 是否处理 note 字段
|
15
15
|
# @return [R3EXS::BaseItem]
|
16
16
|
def initialize(baseitem, index, with_note)
|
17
|
-
@index
|
18
|
-
@name
|
17
|
+
@index = index
|
18
|
+
@name = baseitem.name
|
19
19
|
@description = baseitem.description
|
20
|
-
@note
|
20
|
+
@note = baseitem.note
|
21
21
|
self.remove_instance_variable(:@note) unless with_note
|
22
22
|
end
|
23
23
|
|
@@ -26,9 +26,9 @@ module R3EXS
|
|
26
26
|
# @param baseitem [RPG::BaseItem] 待注入的 RPG::BaseItem 对象
|
27
27
|
# @return [void]
|
28
28
|
def inject_to(baseitem)
|
29
|
-
baseitem.name
|
29
|
+
baseitem.name = @name
|
30
30
|
baseitem.description = @description if self.instance_variable_defined?(:@description)
|
31
|
-
baseitem.note
|
31
|
+
baseitem.note = @note if self.instance_variable_defined?(:@note)
|
32
32
|
end
|
33
33
|
|
34
34
|
# 提取所有的字符串
|
@@ -47,9 +47,9 @@ module R3EXS
|
|
47
47
|
# @param hash [Hash<String, String>] 字符串翻译表
|
48
48
|
# @return [void]
|
49
49
|
def in_strings(hash)
|
50
|
-
@name
|
50
|
+
@name = hash[@name] || @name
|
51
51
|
@description = hash[@description] || @description if self.instance_variable_defined?(:@description)
|
52
|
-
@note
|
52
|
+
@note = hash[@note] || @note if self.instance_variable_defined?(:@note)
|
53
53
|
end
|
54
54
|
|
55
55
|
# 判断是否为空
|
@@ -144,7 +144,7 @@ module R3EXS
|
|
144
144
|
# @return [R3EXS::Animation]
|
145
145
|
def initialize(animation, index, _unused = nil)
|
146
146
|
@index = index
|
147
|
-
@name
|
147
|
+
@name = animation.name
|
148
148
|
end
|
149
149
|
|
150
150
|
# 注入到 RPG::Animation 对象
|
@@ -291,7 +291,7 @@ module R3EXS
|
|
291
291
|
# @return [R3EXS::Class::Learning]
|
292
292
|
def initialize(learning, index)
|
293
293
|
@index = index
|
294
|
-
@note
|
294
|
+
@note = learning.note
|
295
295
|
end
|
296
296
|
|
297
297
|
# 注入到 RPG::Class::Learning 对象
|
@@ -412,9 +412,9 @@ module R3EXS
|
|
412
412
|
# @return [R3EXS::MoveCommand]
|
413
413
|
def initialize(movecommand, index)
|
414
414
|
if movecommand.code == 45
|
415
|
-
@index
|
416
|
-
@code
|
417
|
-
@usage
|
415
|
+
@index = index
|
416
|
+
@code = 45
|
417
|
+
@usage = 'MoveCommandScript'
|
418
418
|
@parameter = movecommand.parameters[0]
|
419
419
|
else
|
420
420
|
@index = -1
|
@@ -543,18 +543,18 @@ module R3EXS
|
|
543
543
|
def initialize(eventcommand, index)
|
544
544
|
case eventcommand.code
|
545
545
|
when 102 # ShowChoices
|
546
|
-
@index
|
547
|
-
@code
|
548
|
-
@usage
|
546
|
+
@index = index
|
547
|
+
@code = 102
|
548
|
+
@usage = Utils::EVENT_COMMANDS[102]
|
549
549
|
@parameter = eventcommand.parameters[0]
|
550
550
|
when 108 # Comment
|
551
|
-
@index
|
552
|
-
@code
|
553
|
-
@usage
|
551
|
+
@index = index
|
552
|
+
@code = 108
|
553
|
+
@usage = Utils::EVENT_COMMANDS[108]
|
554
554
|
@parameter = eventcommand.parameters[0]
|
555
555
|
when 111 # ConditionalBranch
|
556
556
|
@index = index
|
557
|
-
@code
|
557
|
+
@code = 111
|
558
558
|
@usage = Utils::EVENT_COMMANDS[111]
|
559
559
|
if eventcommand.parameters[0] == 4 && eventcommand.parameters[2] == 1
|
560
560
|
@parameter = eventcommand.parameters[3]
|
@@ -564,81 +564,81 @@ module R3EXS
|
|
564
564
|
@index = -1
|
565
565
|
end
|
566
566
|
when 118 # Label
|
567
|
-
@index
|
568
|
-
@code
|
569
|
-
@usage
|
567
|
+
@index = index
|
568
|
+
@code = 118
|
569
|
+
@usage = Utils::EVENT_COMMANDS[118]
|
570
570
|
@parameter = eventcommand.parameters[0]
|
571
571
|
when 119 # JumpToLabel
|
572
|
-
@index
|
573
|
-
@code
|
574
|
-
@usage
|
572
|
+
@index = index
|
573
|
+
@code = 119
|
574
|
+
@usage = Utils::EVENT_COMMANDS[119]
|
575
575
|
@parameter = eventcommand.parameters[0]
|
576
576
|
when 122 # ControlVariables
|
577
577
|
if eventcommand.parameters[3] == 4
|
578
|
-
@index
|
579
|
-
@code
|
580
|
-
@usage
|
578
|
+
@index = index
|
579
|
+
@code = 122
|
580
|
+
@usage = Utils::EVENT_COMMANDS[122]
|
581
581
|
@parameter = eventcommand.parameters[4]
|
582
582
|
else
|
583
583
|
@index = -1
|
584
584
|
end
|
585
585
|
when 205 # SetMoveRoute
|
586
|
-
@index
|
587
|
-
@code
|
588
|
-
@usage
|
586
|
+
@index = index
|
587
|
+
@code = 205
|
588
|
+
@usage = Utils::EVENT_COMMANDS[205]
|
589
589
|
moveroute_r3exs = R3EXS::MoveRoute.new(eventcommand.parameters[1])
|
590
|
-
@parameter
|
590
|
+
@parameter = moveroute_r3exs.list unless moveroute_r3exs.empty?
|
591
591
|
if @parameter.nil?
|
592
592
|
@index = -1 # 如果没有可提取的 MoveCommand ,就将索引设为-1,empty? 将据此判断是否为空
|
593
593
|
end
|
594
594
|
when 320 # ChangeActorName
|
595
|
-
@index
|
596
|
-
@code
|
597
|
-
@usage
|
595
|
+
@index = index
|
596
|
+
@code = 320
|
597
|
+
@usage = Utils::EVENT_COMMANDS[320]
|
598
598
|
@parameter = eventcommand.parameters[1]
|
599
599
|
when 324 # ChangeActorNickname
|
600
|
-
@index
|
601
|
-
@code
|
602
|
-
@usage
|
600
|
+
@index = index
|
601
|
+
@code = 324
|
602
|
+
@usage = Utils::EVENT_COMMANDS[324]
|
603
603
|
@parameter = eventcommand.parameters[1]
|
604
604
|
when 355 # Script
|
605
|
-
@index
|
606
|
-
@code
|
607
|
-
@usage
|
605
|
+
@index = index
|
606
|
+
@code = 355
|
607
|
+
@usage = Utils::EVENT_COMMANDS[355]
|
608
608
|
@parameter = eventcommand.parameters[0]
|
609
609
|
when 401 # ShowText
|
610
|
-
@index
|
611
|
-
@code
|
612
|
-
@usage
|
610
|
+
@index = index
|
611
|
+
@code = 401
|
612
|
+
@usage = Utils::EVENT_COMMANDS[401]
|
613
613
|
@parameter = eventcommand.parameters[0]
|
614
614
|
when 402 # When
|
615
|
-
@index
|
616
|
-
@code
|
617
|
-
@usage
|
615
|
+
@index = index
|
616
|
+
@code = 402
|
617
|
+
@usage = Utils::EVENT_COMMANDS[402]
|
618
618
|
@parameter = eventcommand.parameters[1]
|
619
619
|
when 405 # ShowScrollingText
|
620
|
-
@index
|
621
|
-
@code
|
622
|
-
@usage
|
620
|
+
@index = index
|
621
|
+
@code = 405
|
622
|
+
@usage = Utils::EVENT_COMMANDS[405]
|
623
623
|
@parameter = eventcommand.parameters[0]
|
624
624
|
when 408 # CommentMore
|
625
|
-
@index
|
626
|
-
@code
|
627
|
-
@usage
|
625
|
+
@index = index
|
626
|
+
@code = 408
|
627
|
+
@usage = Utils::EVENT_COMMANDS[408]
|
628
628
|
@parameter = eventcommand.parameters[0]
|
629
629
|
when 505 # MoveRoute
|
630
630
|
if eventcommand.parameters[0].code == 45
|
631
|
-
@index
|
632
|
-
@code
|
633
|
-
@usage
|
631
|
+
@index = index
|
632
|
+
@code = 505
|
633
|
+
@usage = Utils::EVENT_COMMANDS[505]
|
634
634
|
@parameter = eventcommand.parameters[0].parameters[0]
|
635
635
|
else
|
636
636
|
@index = -1
|
637
637
|
end
|
638
638
|
when 655 # ScriptMore
|
639
|
-
@index
|
640
|
-
@code
|
641
|
-
@usage
|
639
|
+
@index = index
|
640
|
+
@code = 655
|
641
|
+
@usage = Utils::EVENT_COMMANDS[655]
|
642
642
|
@parameter = eventcommand.parameters[0]
|
643
643
|
else
|
644
644
|
@index = -1 # 如果不是以上的事件指令,就将索引设为-1,empty? 将据此判断是否为空
|
@@ -750,7 +750,7 @@ module R3EXS
|
|
750
750
|
|
751
751
|
# 事件指令参数
|
752
752
|
#
|
753
|
-
# @note 当 '@code' 为 102
|
753
|
+
# @note 当 '@code' 为 102 时, parameter 是一个字符串数组
|
754
754
|
# @return [String] if @code != 102
|
755
755
|
# @return [Array<String>] if @code == 102
|
756
756
|
attr_accessor :parameter
|
@@ -766,8 +766,8 @@ module R3EXS
|
|
766
766
|
# @return [R3EXS::CommonEvent]
|
767
767
|
def initialize(commonevent, index, _unused = nil)
|
768
768
|
@index = index
|
769
|
-
@name
|
770
|
-
@list
|
769
|
+
@name = commonevent.name
|
770
|
+
@list = []
|
771
771
|
commonevent.list.each_with_index do |eventcommand, eventcommand_index|
|
772
772
|
next if eventcommand == nil
|
773
773
|
eventcommand_r3exs = R3EXS::EventCommand.new(eventcommand, eventcommand_index)
|
@@ -976,7 +976,7 @@ module R3EXS
|
|
976
976
|
# @return [R3EXS::Event::Page]
|
977
977
|
def initialize(page, index)
|
978
978
|
@index = index
|
979
|
-
@list
|
979
|
+
@list = []
|
980
980
|
page.list.each_with_index do |eventcommand, eventcommand_index|
|
981
981
|
next if eventcommand == nil
|
982
982
|
eventcommand_r3exs = R3EXS::EventCommand.new(eventcommand, eventcommand_index)
|
@@ -1040,7 +1040,7 @@ module R3EXS
|
|
1040
1040
|
# @return [R3EXS::Event]
|
1041
1041
|
def initialize(event, index)
|
1042
1042
|
@index = index
|
1043
|
-
@name
|
1043
|
+
@name = event.name
|
1044
1044
|
@pages = []
|
1045
1045
|
event.pages.each_with_index do |page, page_index|
|
1046
1046
|
next if page == nil
|
@@ -1114,8 +1114,8 @@ module R3EXS
|
|
1114
1114
|
# @return [R3EXS::Map]
|
1115
1115
|
def initialize(map, with_note)
|
1116
1116
|
@display_name = map.display_name
|
1117
|
-
@note
|
1118
|
-
@events
|
1117
|
+
@note = map.note
|
1118
|
+
@events = []
|
1119
1119
|
map.events.each do |key, event|
|
1120
1120
|
next if event == nil
|
1121
1121
|
event_r3exs = R3EXS::Event.new(event, key)
|
@@ -1130,7 +1130,7 @@ module R3EXS
|
|
1130
1130
|
# @return [void]
|
1131
1131
|
def inject_to(map)
|
1132
1132
|
map.display_name = @display_name
|
1133
|
-
map.note
|
1133
|
+
map.note = @note if self.instance_variable_defined?(:@note)
|
1134
1134
|
@events.each do |event|
|
1135
1135
|
event.inject_to(map.events[event.index])
|
1136
1136
|
end
|
@@ -1155,7 +1155,7 @@ module R3EXS
|
|
1155
1155
|
# @return [void]
|
1156
1156
|
def in_strings(hash)
|
1157
1157
|
@display_name = hash[@display_name] || @display_name
|
1158
|
-
@note
|
1158
|
+
@note = hash[@note] || @note if self.instance_variable_defined?(:@note)
|
1159
1159
|
@events.each do |event|
|
1160
1160
|
event.in_strings(hash)
|
1161
1161
|
end
|
@@ -1186,7 +1186,7 @@ module R3EXS
|
|
1186
1186
|
# @return [R3EXS::MapInfo]
|
1187
1187
|
def initialize(mapinfo, index, _unused = nil)
|
1188
1188
|
@index = index
|
1189
|
-
@name
|
1189
|
+
@name = mapinfo.name
|
1190
1190
|
end
|
1191
1191
|
|
1192
1192
|
# 注入到 RPG::MapInfo 对象
|
@@ -1378,9 +1378,9 @@ module R3EXS
|
|
1378
1378
|
# @param terms [RPG::System::Terms] 待处理的 RPG::System::Terms 对象
|
1379
1379
|
# @return [R3EXS::System::Terms]
|
1380
1380
|
def initialize(terms)
|
1381
|
-
@basic
|
1382
|
-
@params
|
1383
|
-
@etypes
|
1381
|
+
@basic = terms.basic
|
1382
|
+
@params = terms.params
|
1383
|
+
@etypes = terms.etypes
|
1384
1384
|
@commands = terms.commands
|
1385
1385
|
end
|
1386
1386
|
|
@@ -1389,9 +1389,9 @@ module R3EXS
|
|
1389
1389
|
# @param terms [RPG::System::Terms] 待注入的 RPG::System::Terms 对象
|
1390
1390
|
# @return [void]
|
1391
1391
|
def inject_to(terms)
|
1392
|
-
terms.basic
|
1393
|
-
terms.params
|
1394
|
-
terms.etypes
|
1392
|
+
terms.basic = @basic
|
1393
|
+
terms.params = @params
|
1394
|
+
terms.etypes = @etypes
|
1395
1395
|
terms.commands = @commands
|
1396
1396
|
end
|
1397
1397
|
|
@@ -1444,15 +1444,15 @@ module R3EXS
|
|
1444
1444
|
# @param system [RPG::System] 待处理的 RPG::System 对象
|
1445
1445
|
# @return [R3EXS::System]
|
1446
1446
|
def initialize(system, _unused = nil)
|
1447
|
-
@game_title
|
1447
|
+
@game_title = system.game_title
|
1448
1448
|
@currency_unit = system.currency_unit
|
1449
|
-
@elements
|
1450
|
-
@skill_types
|
1451
|
-
@weapon_types
|
1452
|
-
@armor_types
|
1453
|
-
@switches
|
1454
|
-
@variables
|
1455
|
-
@terms
|
1449
|
+
@elements = system.elements
|
1450
|
+
@skill_types = system.skill_types
|
1451
|
+
@weapon_types = system.weapon_types
|
1452
|
+
@armor_types = system.armor_types
|
1453
|
+
@switches = system.switches
|
1454
|
+
@variables = system.variables
|
1455
|
+
@terms = R3EXS::System::Terms.new(system.terms)
|
1456
1456
|
end
|
1457
1457
|
|
1458
1458
|
# 注入到 RPG::System 对象
|
@@ -1460,14 +1460,14 @@ module R3EXS
|
|
1460
1460
|
# @param system [RPG::System] 待注入的 RPG::System 对象
|
1461
1461
|
# @return [void]
|
1462
1462
|
def inject_to(system)
|
1463
|
-
system.game_title
|
1463
|
+
system.game_title = @game_title
|
1464
1464
|
system.currency_unit = @currency_unit
|
1465
|
-
system.elements
|
1466
|
-
system.skill_types
|
1467
|
-
system.weapon_types
|
1468
|
-
system.armor_types
|
1469
|
-
system.switches
|
1470
|
-
system.variables
|
1465
|
+
system.elements = @elements
|
1466
|
+
system.skill_types = @skill_types
|
1467
|
+
system.weapon_types = @weapon_types
|
1468
|
+
system.armor_types = @armor_types
|
1469
|
+
system.switches = @switches
|
1470
|
+
system.variables = @variables
|
1471
1471
|
@terms.inject_to(system.terms)
|
1472
1472
|
end
|
1473
1473
|
|
@@ -1493,7 +1493,7 @@ module R3EXS
|
|
1493
1493
|
# @param hash [Hash<String, String>] 字符串翻译表
|
1494
1494
|
# @return [void]
|
1495
1495
|
def in_strings(hash)
|
1496
|
-
@game_title
|
1496
|
+
@game_title = hash[@game_title] || @game_title
|
1497
1497
|
@currency_unit = hash[@currency_unit] || @currency_unit
|
1498
1498
|
@elements.map! { |string| hash[string] || string }
|
1499
1499
|
@skill_types.map! { |string| hash[string] || string }
|
@@ -1561,8 +1561,8 @@ module R3EXS
|
|
1561
1561
|
# @return [R3EXS::Tileset]
|
1562
1562
|
def initialize(tileset, index, with_note)
|
1563
1563
|
@index = index
|
1564
|
-
@name
|
1565
|
-
@note
|
1564
|
+
@name = tileset.name
|
1565
|
+
@note = tileset.note
|
1566
1566
|
self.remove_instance_variable(:@note) unless with_note
|
1567
1567
|
end
|
1568
1568
|
|
@@ -1630,7 +1630,7 @@ module R3EXS
|
|
1630
1630
|
# @return [R3EXS::Troop::Page]
|
1631
1631
|
def initialize(page, index)
|
1632
1632
|
@index = index
|
1633
|
-
@list
|
1633
|
+
@list = []
|
1634
1634
|
page.list.each_with_index do |eventcommand, eventcommand_index|
|
1635
1635
|
next if eventcommand == nil
|
1636
1636
|
eventcommand_r3exs = R3EXS::EventCommand.new(eventcommand, eventcommand_index)
|
@@ -1693,7 +1693,7 @@ module R3EXS
|
|
1693
1693
|
# @return [R3EXS::Troop]
|
1694
1694
|
def initialize(troop, index, _unused = nil)
|
1695
1695
|
@index = index
|
1696
|
-
@name
|
1696
|
+
@name = troop.name
|
1697
1697
|
@pages = []
|
1698
1698
|
troop.pages.each_with_index do |page, page_index|
|
1699
1699
|
next if page == nil
|
data/lib/R3EXS/ast.rb
CHANGED
@@ -11,7 +11,7 @@ module R3EXS
|
|
11
11
|
# @param with_symbol [Boolean] 是否包含脚本中的符号
|
12
12
|
# @return [StringsExtractor]
|
13
13
|
def initialize(strings, with_symbol)
|
14
|
-
@strings
|
14
|
+
@strings = strings
|
15
15
|
@with_symbol = with_symbol
|
16
16
|
end
|
17
17
|
|
@@ -59,8 +59,8 @@ module R3EXS
|
|
59
59
|
# @return [Location]
|
60
60
|
def initialize(start_offset, length, content)
|
61
61
|
@start_offset = start_offset
|
62
|
-
@length
|
63
|
-
@content
|
62
|
+
@length = length
|
63
|
+
@content = content
|
64
64
|
end
|
65
65
|
|
66
66
|
# 字符串在二进制源文件中的起始位置
|
@@ -84,8 +84,8 @@ module R3EXS
|
|
84
84
|
# @return [StringsInjector]
|
85
85
|
def initialize(hash)
|
86
86
|
@strings_hash = hash
|
87
|
-
@content_loc
|
88
|
-
@code
|
87
|
+
@content_loc = []
|
88
|
+
@code = []
|
89
89
|
end
|
90
90
|
|
91
91
|
# 处理类型为 StringNode 的节点
|
@@ -94,7 +94,7 @@ module R3EXS
|
|
94
94
|
# @return [void]
|
95
95
|
def visit_string_node(node)
|
96
96
|
location = node.content_loc
|
97
|
-
value
|
97
|
+
value = location.slice
|
98
98
|
if @strings_hash.has_key?(value)
|
99
99
|
@content_loc << Location.new(location.start_offset, location.length, @strings_hash[value])
|
100
100
|
end
|
@@ -151,4 +151,4 @@ module R3EXS
|
|
151
151
|
|
152
152
|
end
|
153
153
|
|
154
|
-
end
|
154
|
+
end
|
data/lib/R3EXS/error.rb
CHANGED
@@ -36,6 +36,23 @@ module R3EXS
|
|
36
36
|
attr_reader :obj
|
37
37
|
end
|
38
38
|
|
39
|
+
# 用来处理 Game.rgss3a 文件加密格式不支持的异常
|
40
|
+
class RGSS3AFileError < StandardError
|
41
|
+
|
42
|
+
# @param msg [String] 异常信息
|
43
|
+
# @param rgss3a_path [String] 引发异常的 rgss3a 文件路径
|
44
|
+
# @return [Rvdata2DirError]
|
45
|
+
def initialize(msg = '', rgss3a_path)
|
46
|
+
super(msg)
|
47
|
+
@rgss3a_path = rgss3a_path
|
48
|
+
end
|
49
|
+
|
50
|
+
# 引发异常的 rgss3a 文件路径
|
51
|
+
#
|
52
|
+
# @return [String]
|
53
|
+
attr_reader :rgss3a_path
|
54
|
+
end
|
55
|
+
|
39
56
|
# 用来处理 rvdata2 文件损坏的异常
|
40
57
|
class Rvdata2FileError < StandardError
|
41
58
|
|
@@ -1,80 +1,80 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'zlib'
|
4
|
-
require_relative 'ast'
|
5
|
-
require_relative 'utils'
|
6
|
-
require_relative 'RGSS3_R3EXS'
|
7
|
-
|
8
|
-
module R3EXS
|
9
|
-
|
10
|
-
# 将 Ruby 源码中的字符串和符号提取出来
|
11
|
-
#
|
12
|
-
# @param target_dir [String] 目标目录
|
13
|
-
# @param with_symbol [Boolean] 是否包含脚本中的符号
|
14
|
-
#
|
15
|
-
# @raise [ScriptsDirError] Scripts 目录不存在
|
16
|
-
#
|
17
|
-
# @return [Array<String>]
|
18
|
-
def R3EXS.rb_ex_strings(target_dir, with_symbol)
|
19
|
-
full_dir = File.join(target_dir, 'Scripts')
|
20
|
-
Dir.exist?(full_dir) or raise ScriptsDirError.new(full_dir), "Scripts directory not found: #{full_dir}"
|
21
|
-
|
22
|
-
strings
|
23
|
-
strings_extractor = StringsExtractor.new(strings, with_symbol)
|
24
|
-
Dir.glob(File.join(full_dir, '*.rb')).each do |script_file_path|
|
25
|
-
print "#{Utils::ESCAPE}#{Utils::MAGENTA_COLOR}Exreacting from #{Utils::RESET_COLOR}#{script_file_path}...\r" if $global_options[:verbose]
|
26
|
-
|
27
|
-
strings_extractor.visit(Prism.parse_file(script_file_path).value)
|
28
|
-
|
29
|
-
print "#{Utils::ESCAPE}#{Utils::GREEN_COLOR}Exreacted #{Utils::RESET_COLOR}#{script_file_path}\n" if $global_options[:verbose]
|
30
|
-
end
|
31
|
-
strings
|
32
|
-
end
|
33
|
-
|
34
|
-
# 将指定目录下的所有已经序列化为 R3EXS 后的 JOSN 文件中的字符串提取出来
|
35
|
-
#
|
36
|
-
# @param target_dir [String] 目标目录
|
37
|
-
# @param output_dir [String] 输出目录
|
38
|
-
# @param with_scripts [Boolean] 是否包含脚本
|
39
|
-
# @param with_symbol [Boolean] 是否包含脚本中的符号
|
40
|
-
# @param with_scripts_separate [Boolean] 是否将脚本提取的字符串单独存放
|
41
|
-
#
|
42
|
-
# @raise [R3EXSJsonFileError] json 文件不是 R3EXS 模块中的对象
|
43
|
-
# @raise [JsonDirError] target_dir 不存在
|
44
|
-
# @raise [ScriptsDirError] Scripts 目录不存在
|
45
|
-
#
|
46
|
-
# @return [void]
|
47
|
-
def R3EXS.ex_strings(target_dir, output_dir, with_scripts, with_symbol, with_scripts_separate)
|
48
|
-
FileUtils.mkdir(output_dir) unless Dir.exist?(output_dir)
|
49
|
-
all_ex_strings = []
|
50
|
-
|
51
|
-
Utils.all_json_files(target_dir, :R3EXS) do |object, file_basename|
|
52
|
-
file_path = File.join(target_dir, "#{file_basename}.json")
|
53
|
-
print "#{Utils::ESCAPE}#{Utils::MAGENTA_COLOR}Extracting from #{Utils::RESET_COLOR}#{file_path}...\r" if $global_options[:verbose]
|
54
|
-
if object.is_a?(Array)
|
55
|
-
object.each do |obj|
|
56
|
-
all_ex_strings.concat(obj.ex_strings)
|
57
|
-
end
|
58
|
-
else
|
59
|
-
all_ex_strings.concat(object.ex_strings)
|
60
|
-
end
|
61
|
-
print "#{Utils::ESCAPE}#{Utils::GREEN_COLOR}Extracted #{Utils::RESET_COLOR}#{file_basename}\n" if $global_options[:verbose]
|
62
|
-
end
|
63
|
-
|
64
|
-
if with_scripts
|
65
|
-
scripts_strings = rb_ex_strings(target_dir, with_symbol)
|
66
|
-
if with_scripts_separate
|
67
|
-
# 去除 nil 元素
|
68
|
-
scripts_strings.compact!
|
69
|
-
Utils.object_json(scripts_strings.each_with_object({}) { |item, h| h[item] = item }, File.join(output_dir, 'ManualTransFile_scripts.json'))
|
70
|
-
else
|
71
|
-
all_ex_strings.concat(scripts_strings)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
# 去除 nil 元素
|
76
|
-
all_ex_strings.compact!
|
77
|
-
Utils.object_json(all_ex_strings.each_with_object({}) { |item, h| h[item] = item }, File.join(output_dir, "ManualTransFile.json"))
|
78
|
-
end
|
79
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'zlib'
|
4
|
+
require_relative 'ast'
|
5
|
+
require_relative 'utils'
|
6
|
+
require_relative 'RGSS3_R3EXS'
|
7
|
+
|
8
|
+
module R3EXS
|
9
|
+
|
10
|
+
# 将 Ruby 源码中的字符串和符号提取出来
|
11
|
+
#
|
12
|
+
# @param target_dir [String] 目标目录
|
13
|
+
# @param with_symbol [Boolean] 是否包含脚本中的符号
|
14
|
+
#
|
15
|
+
# @raise [ScriptsDirError] Scripts 目录不存在
|
16
|
+
#
|
17
|
+
# @return [Array<String>]
|
18
|
+
def R3EXS.rb_ex_strings(target_dir, with_symbol)
|
19
|
+
full_dir = File.join(target_dir, 'Scripts')
|
20
|
+
Dir.exist?(full_dir) or raise ScriptsDirError.new(full_dir), "Scripts directory not found: #{full_dir}"
|
21
|
+
|
22
|
+
strings = []
|
23
|
+
strings_extractor = StringsExtractor.new(strings, with_symbol)
|
24
|
+
Dir.glob(File.join(full_dir, '*.rb')).each do |script_file_path|
|
25
|
+
print "#{Utils::ESCAPE}#{Utils::MAGENTA_COLOR}Exreacting from #{Utils::RESET_COLOR}#{script_file_path}...\r" if $global_options[:verbose]
|
26
|
+
|
27
|
+
strings_extractor.visit(Prism.parse_file(script_file_path).value)
|
28
|
+
|
29
|
+
print "#{Utils::ESCAPE}#{Utils::GREEN_COLOR}Exreacted #{Utils::RESET_COLOR}#{script_file_path}\n" if $global_options[:verbose]
|
30
|
+
end
|
31
|
+
strings
|
32
|
+
end
|
33
|
+
|
34
|
+
# 将指定目录下的所有已经序列化为 R3EXS 后的 JOSN 文件中的字符串提取出来
|
35
|
+
#
|
36
|
+
# @param target_dir [String] 目标目录
|
37
|
+
# @param output_dir [String] 输出目录
|
38
|
+
# @param with_scripts [Boolean] 是否包含脚本
|
39
|
+
# @param with_symbol [Boolean] 是否包含脚本中的符号
|
40
|
+
# @param with_scripts_separate [Boolean] 是否将脚本提取的字符串单独存放
|
41
|
+
#
|
42
|
+
# @raise [R3EXSJsonFileError] json 文件不是 R3EXS 模块中的对象
|
43
|
+
# @raise [JsonDirError] target_dir 不存在
|
44
|
+
# @raise [ScriptsDirError] Scripts 目录不存在
|
45
|
+
#
|
46
|
+
# @return [void]
|
47
|
+
def R3EXS.ex_strings(target_dir, output_dir, with_scripts, with_symbol, with_scripts_separate)
|
48
|
+
FileUtils.mkdir(output_dir) unless Dir.exist?(output_dir)
|
49
|
+
all_ex_strings = []
|
50
|
+
|
51
|
+
Utils.all_json_files(target_dir, :R3EXS) do |object, file_basename|
|
52
|
+
file_path = File.join(target_dir, "#{file_basename}.json")
|
53
|
+
print "#{Utils::ESCAPE}#{Utils::MAGENTA_COLOR}Extracting from #{Utils::RESET_COLOR}#{file_path}...\r" if $global_options[:verbose]
|
54
|
+
if object.is_a?(Array)
|
55
|
+
object.each do |obj|
|
56
|
+
all_ex_strings.concat(obj.ex_strings)
|
57
|
+
end
|
58
|
+
else
|
59
|
+
all_ex_strings.concat(object.ex_strings)
|
60
|
+
end
|
61
|
+
print "#{Utils::ESCAPE}#{Utils::GREEN_COLOR}Extracted #{Utils::RESET_COLOR}#{file_basename}\n" if $global_options[:verbose]
|
62
|
+
end
|
63
|
+
|
64
|
+
if with_scripts
|
65
|
+
scripts_strings = rb_ex_strings(target_dir, with_symbol)
|
66
|
+
if with_scripts_separate
|
67
|
+
# 去除 nil 元素
|
68
|
+
scripts_strings.compact!
|
69
|
+
Utils.object_json(scripts_strings.each_with_object({}) { |item, h| h[item] = item }, File.join(output_dir, 'ManualTransFile_scripts.json'))
|
70
|
+
else
|
71
|
+
all_ex_strings.concat(scripts_strings)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# 去除 nil 元素
|
76
|
+
all_ex_strings.compact!
|
77
|
+
Utils.object_json(all_ex_strings.each_with_object({}) { |item, h| h[item] = item }, File.join(output_dir, "ManualTransFile.json"))
|
78
|
+
end
|
79
|
+
|
80
80
|
end
|