dsp_blueprint_parser 0.1.3 → 0.2.1

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.
@@ -1,46 +1,46 @@
1
- # frozen_string_literal: true
2
-
3
- module DspBlueprintParser
4
- # class to manage the position of byte array while parsing data out of it
5
- class BinaryReader
6
- # @param data [Array<byte>]
7
- def initialize(data)
8
- @data = data
9
- @position = 0
10
- end
11
-
12
- def read_i32
13
- get_integer(4, 'l<')
14
- end
15
-
16
- def read_i16
17
- get_integer(2, 's<')
18
- end
19
-
20
- def read_i8
21
- get_integer(1, 'c')
22
- end
23
-
24
- def read_single
25
- get_integer(4, 'e')
26
- end
27
-
28
- private
29
-
30
- # @param byte_count [Integer]
31
- # @return [String]
32
- def get_string(byte_count)
33
- value = @data[@position..@position + byte_count].pack('C*').force_encoding('UTF-8')
34
- @position += byte_count
35
-
36
- value
37
- end
38
-
39
- # @param byte_count [Integer]
40
- # @param format [String]
41
- # @return [Integer]
42
- def get_integer(byte_count, format)
43
- get_string(byte_count).unpack1(format)
44
- end
45
- end
46
- end
1
+ # frozen_string_literal: true
2
+
3
+ module DspBlueprintParser
4
+ # class to manage the position of byte array while parsing data out of it
5
+ class BinaryReader
6
+ # @param data [Array<byte>]
7
+ def initialize(data)
8
+ @data = data
9
+ @position = 0
10
+ end
11
+
12
+ def read_i32
13
+ get_integer(4, 'l<')
14
+ end
15
+
16
+ def read_i16
17
+ get_integer(2, 's<')
18
+ end
19
+
20
+ def read_i8
21
+ get_integer(1, 'c')
22
+ end
23
+
24
+ def read_single
25
+ get_integer(4, 'e')
26
+ end
27
+
28
+ private
29
+
30
+ # @param byte_count [Integer]
31
+ # @return [String]
32
+ def get_string(byte_count)
33
+ value = @data[@position..@position + byte_count].pack('C*').force_encoding('UTF-8')
34
+ @position += byte_count
35
+
36
+ value
37
+ end
38
+
39
+ # @param byte_count [Integer]
40
+ # @param format [String]
41
+ # @return [Integer]
42
+ def get_integer(byte_count, format)
43
+ get_string(byte_count).unpack1(format)
44
+ end
45
+ end
46
+ end
@@ -1,69 +1,69 @@
1
- # frozen_string_literal: true
2
-
3
- module DspBlueprintParser
4
- # data class for parsed blueprint
5
- class BlueprintData
6
- def initialize
7
- @areas = []
8
- @buildings = []
9
- end
10
-
11
- # @return [DateTime]
12
- attr_accessor :time
13
-
14
- # @return [String]
15
- attr_accessor :game_version
16
-
17
- # @return [String]
18
- attr_accessor :short_description
19
-
20
- # @return [String]
21
- attr_accessor :description
22
-
23
- # Integer is a const value from IconLayout
24
- # @return [Integer]
25
- attr_accessor :icon_layout
26
-
27
- # @return [Integer]
28
- attr_accessor :icon0
29
-
30
- # @return [Integer]
31
- attr_accessor :icon1
32
-
33
- # @return [Integer]
34
- attr_accessor :icon2
35
-
36
- # @return [Integer]
37
- attr_accessor :icon3
38
-
39
- # @return [Integer]
40
- attr_accessor :icon4
41
-
42
- # @return [Integer]
43
- attr_accessor :cursor_offset_x
44
-
45
- # @return [Integer]
46
- attr_accessor :cursor_offset_y
47
-
48
- # @return [Integer]
49
- attr_accessor :cursor_target_area
50
-
51
- # @return [Integer]
52
- attr_accessor :drag_box_size_x
53
-
54
- # @return [Integer]
55
- attr_accessor :drag_box_size_y
56
-
57
- # @return [Integer]
58
- attr_accessor :primary_area_idx
59
-
60
- # @return [Array<Area>]
61
- attr_accessor :areas
62
-
63
- # @return [Array<Building>]
64
- attr_accessor :buildings
65
-
66
- # @return [Integer]
67
- attr_accessor :version
68
- end
69
- end
1
+ # frozen_string_literal: true
2
+
3
+ module DspBlueprintParser
4
+ # data class for parsed blueprint
5
+ class BlueprintData
6
+ def initialize
7
+ @areas = []
8
+ @buildings = []
9
+ end
10
+
11
+ # @return [DateTime]
12
+ attr_accessor :time
13
+
14
+ # @return [String]
15
+ attr_accessor :game_version
16
+
17
+ # @return [String]
18
+ attr_accessor :short_description
19
+
20
+ # @return [String]
21
+ attr_accessor :description
22
+
23
+ # Integer is a const value from IconLayout
24
+ # @return [Integer]
25
+ attr_accessor :icon_layout
26
+
27
+ # @return [Integer]
28
+ attr_accessor :icon0
29
+
30
+ # @return [Integer]
31
+ attr_accessor :icon1
32
+
33
+ # @return [Integer]
34
+ attr_accessor :icon2
35
+
36
+ # @return [Integer]
37
+ attr_accessor :icon3
38
+
39
+ # @return [Integer]
40
+ attr_accessor :icon4
41
+
42
+ # @return [Integer]
43
+ attr_accessor :cursor_offset_x
44
+
45
+ # @return [Integer]
46
+ attr_accessor :cursor_offset_y
47
+
48
+ # @return [Integer]
49
+ attr_accessor :cursor_target_area
50
+
51
+ # @return [Integer]
52
+ attr_accessor :drag_box_size_x
53
+
54
+ # @return [Integer]
55
+ attr_accessor :drag_box_size_y
56
+
57
+ # @return [Integer]
58
+ attr_accessor :primary_area_idx
59
+
60
+ # @return [Array<Area>]
61
+ attr_accessor :areas
62
+
63
+ # @return [Array<Building>]
64
+ attr_accessor :buildings
65
+
66
+ # @return [Integer]
67
+ attr_accessor :version
68
+ end
69
+ end
@@ -1,79 +1,91 @@
1
- # frozen_string_literal: true
2
-
3
- module DspBlueprintParser
4
- # data class for parsed building
5
- class Building
6
- def initialize
7
- @parameters = []
8
- end
9
-
10
- # @return [Integer]
11
- attr_accessor :index
12
-
13
- # @return [Integer]
14
- attr_accessor :area_index
15
-
16
- # @return [Float]
17
- attr_accessor :local_offset_x
18
-
19
- # @return [Float]
20
- attr_accessor :local_offset_y
21
-
22
- # @return [Float]
23
- attr_accessor :local_offset_z
24
-
25
- # @return [Float]
26
- attr_accessor :local_offset_x2
27
-
28
- # @return [Float]
29
- attr_accessor :local_offset_y2
30
-
31
- # @return [Float]
32
- attr_accessor :local_offset_z2
33
-
34
- # @return [Float]
35
- attr_accessor :yaw
36
-
37
- # @return [Float]
38
- attr_accessor :yaw2
39
-
40
- # @return [Integer]
41
- attr_accessor :item_id
42
-
43
- # @return [Integer]
44
- attr_accessor :model_index
45
-
46
- # @return [Integer]
47
- attr_accessor :temp_output_obj_idx
48
-
49
- # @return [Integer]
50
- attr_accessor :temp_input_obj_idx
51
-
52
- # @return [Integer]
53
- attr_accessor :output_to_slot
54
-
55
- # @return [Integer]
56
- attr_accessor :input_from_slot
57
-
58
- # @return [Integer]
59
- attr_accessor :output_from_slot
60
-
61
- # @return [Integer]
62
- attr_accessor :input_to_slot
63
-
64
- # @return [Integer]
65
- attr_accessor :output_offset
66
-
67
- # @return [Integer]
68
- attr_accessor :input_offset
69
-
70
- # @return [Integer]
71
- attr_accessor :recipe_id
72
-
73
- # @return [Integer]
74
- attr_accessor :filter_fd
75
-
76
- # @return [Array<Integer>]
77
- attr_accessor :parameters
78
- end
79
- end
1
+ # frozen_string_literal: true
2
+
3
+ module DspBlueprintParser
4
+ # data class for parsed building
5
+ class Building
6
+ def initialize
7
+ @parameters = []
8
+ end
9
+
10
+ # @return [Integer]
11
+ attr_accessor :index
12
+
13
+ # @return [Integer]
14
+ attr_accessor :area_index
15
+
16
+ # @return [Float]
17
+ attr_accessor :local_offset_x
18
+
19
+ # @return [Float]
20
+ attr_accessor :local_offset_y
21
+
22
+ # @return [Float]
23
+ attr_accessor :local_offset_z
24
+
25
+ # @return [Float]
26
+ attr_accessor :local_offset_x2
27
+
28
+ # @return [Float]
29
+ attr_accessor :local_offset_y2
30
+
31
+ # @return [Float]
32
+ attr_accessor :local_offset_z2
33
+
34
+ # @return [Float]
35
+ attr_accessor :yaw
36
+
37
+ # @return [Float]
38
+ attr_accessor :yaw2
39
+
40
+ # @return [Float]
41
+ attr_accessor :tilt
42
+
43
+ # @return [Float]
44
+ attr_accessor :tilt2
45
+
46
+ # @return [Float]
47
+ attr_accessor :pitch
48
+
49
+ # @return [Float]
50
+ attr_accessor :pitch2
51
+
52
+ # @return [Integer]
53
+ attr_accessor :item_id
54
+
55
+ # @return [Integer]
56
+ attr_accessor :model_index
57
+
58
+ # @return [Integer]
59
+ attr_accessor :temp_output_obj_idx
60
+
61
+ # @return [Integer]
62
+ attr_accessor :temp_input_obj_idx
63
+
64
+ # @return [Integer]
65
+ attr_accessor :output_to_slot
66
+
67
+ # @return [Integer]
68
+ attr_accessor :input_from_slot
69
+
70
+ # @return [Integer]
71
+ attr_accessor :output_from_slot
72
+
73
+ # @return [Integer]
74
+ attr_accessor :input_to_slot
75
+
76
+ # @return [Integer]
77
+ attr_accessor :output_offset
78
+
79
+ # @return [Integer]
80
+ attr_accessor :input_offset
81
+
82
+ # @return [Integer]
83
+ attr_accessor :recipe_id
84
+
85
+ # @return [Integer]
86
+ attr_accessor :filter_fd
87
+
88
+ # @return [Array<Integer>]
89
+ attr_accessor :parameters
90
+ end
91
+ end
@@ -0,0 +1,227 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DspBlueprintParser
4
+ # class to orchestrate building parsing
5
+ class BuildingParser
6
+ class << self
7
+ # @param [BlueprintData] blueprint
8
+ # @param [BinaryReader] reader
9
+ # @return [void]
10
+ def process!(blueprint, reader)
11
+ reader.read_i32.times do
12
+ path_num = reader.read_i32
13
+ building = if path_num <= -102
14
+ path_102(reader)
15
+ elsif path_num <= -101
16
+ path_101(reader)
17
+ elsif path_num <= -100
18
+ path_100(reader)
19
+ else
20
+ path_default(reader, path_num)
21
+ end
22
+
23
+ blueprint.buildings << building
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ # @param [BinaryReader] reader
30
+ # @return [Building]
31
+ def path_102(reader)
32
+ building = Building.new
33
+ building.index = reader.read_i32
34
+ building.item_id = reader.read_i16
35
+ building.model_index = reader.read_i16
36
+ building.area_index = reader.read_i8
37
+ building.local_offset_x = reader.read_single
38
+ building.local_offset_y = reader.read_single
39
+ building.local_offset_z = reader.read_single
40
+ building.yaw = reader.read_single
41
+
42
+ if building.item_id > 2000 && building.item_id < 2010
43
+ building.tilt = reader.read_single
44
+ building.pitch = 0.0
45
+ building.local_offset_x2 = building.local_offset_x
46
+ building.local_offset_y2 = building.local_offset_y
47
+ building.local_offset_z2 = building.local_offset_z
48
+ building.yaw2 = building.yaw
49
+ building.tilt2 = building.tilt
50
+ building.pitch2 = 0.0
51
+ elsif building.item_id > 2010 && building.item_id < 2020
52
+ building.tilt = reader.read_single
53
+ building.pitch = reader.read_single
54
+ building.local_offset_x2 = reader.read_single
55
+ building.local_offset_y2 = reader.read_single
56
+ building.local_offset_z2 = reader.read_single
57
+ building.yaw2 = reader.read_single
58
+ building.tilt2 = reader.read_single
59
+ building.pitch2 = reader.read_single
60
+ else
61
+ building.tilt = 0.0
62
+ building.pitch = 0.0
63
+ building.local_offset_x2 = building.local_offset_x
64
+ building.local_offset_y2 = building.local_offset_y
65
+ building.local_offset_z2 = building.local_offset_z
66
+ building.yaw2 = building.yaw
67
+ building.tilt2 = 0.0
68
+ building.pitch2 = 0.0
69
+ end
70
+
71
+ building.temp_output_obj_idx = reader.read_i32
72
+ building.temp_input_obj_idx = reader.read_i32
73
+ building.output_to_slot = reader.read_i8
74
+ building.input_from_slot = reader.read_i8
75
+ building.output_from_slot = reader.read_i8
76
+ building.input_to_slot = reader.read_i8
77
+ building.output_offset = reader.read_i8
78
+ building.input_offset = reader.read_i8
79
+ building.recipe_id = reader.read_i16
80
+ building.filter_fd = reader.read_i16
81
+
82
+ reader.read_i16.times do
83
+ building.parameters << reader.read_i32
84
+ end
85
+
86
+ building
87
+ end
88
+
89
+ # @param [BinaryReader] reader
90
+ # @return [Building]
91
+ def path_101(reader)
92
+ building = Building.new
93
+ building.index = reader.read_i32
94
+ building.item_id = reader.read_i16
95
+ building.model_index = reader.read_i16
96
+ building.area_index = reader.read_i8
97
+ building.local_offset_x = reader.read_single
98
+ building.local_offset_y = reader.read_single
99
+ building.local_offset_z = reader.read_single
100
+ building.yaw = reader.read_single
101
+
102
+ if building.item_id > 2000 && building.item_id < 2010
103
+ building.tilt = reader.read_single
104
+ building.pitch = 0.0
105
+ building.local_offset_x2 = building.local_offset_x
106
+ building.local_offset_y2 = building.local_offset_y
107
+ building.local_offset_z2 = building.local_offset_z
108
+ building.yaw2 = building.yaw
109
+ building.tilt2 = building.tilt
110
+ building.pitch2 = 0.0
111
+ elsif building.item_id > 2010 && building.item_id < 2020
112
+ building.tilt = reader.read_single
113
+ building.pitch = reader.read_single
114
+ building.local_offset_x2 = reader.read_single
115
+ building.local_offset_y2 = reader.read_single
116
+ building.local_offset_z2 = reader.read_single
117
+ building.yaw2 = reader.read_single
118
+ building.tilt2 = reader.read_single
119
+ building.pitch2 = reader.read_single
120
+ else
121
+ building.tilt = 0.0
122
+ building.pitch = 0.0
123
+ building.local_offset_x2 = building.local_offset_x
124
+ building.local_offset_y2 = building.local_offset_y
125
+ building.local_offset_z2 = building.local_offset_z
126
+ building.yaw2 = building.yaw
127
+ building.tilt2 = 0.0
128
+ building.pitch2 = 0.0
129
+ end
130
+
131
+ building.temp_output_obj_idx = reader.read_i32
132
+ building.temp_input_obj_idx = reader.read_i32
133
+ building.output_to_slot = reader.read_i8
134
+ building.input_from_slot = reader.read_i8
135
+ building.output_from_slot = reader.read_i8
136
+ building.input_to_slot = reader.read_i8
137
+ building.output_offset = reader.read_i8
138
+ building.input_offset = reader.read_i8
139
+ building.recipe_id = reader.read_i16
140
+ building.filter_fd = reader.read_i16
141
+
142
+ reader.read_i16.times do
143
+ building.parameters << reader.read_i32
144
+ end
145
+
146
+ building
147
+ end
148
+
149
+ # @param [BinaryReader] reader
150
+ # @return [Building]
151
+ def path_100(reader)
152
+ building = Building.new
153
+ building.index = reader.read_i32
154
+ building.area_index = reader.read_i8
155
+ building.local_offset_x = reader.read_single
156
+ building.local_offset_y = reader.read_single
157
+ building.local_offset_z = reader.read_single
158
+ building.local_offset_x2 = reader.read_single
159
+ building.local_offset_y2 = reader.read_single
160
+ building.local_offset_z2 = reader.read_single
161
+ building.pitch = 0.0
162
+ building.pitch2 = 0.0
163
+ building.yaw = reader.read_single
164
+ building.yaw2 = reader.read_single
165
+ building.tilt = reader.read_single
166
+ building.tilt2 = 0.0
167
+ building.item_id = reader.read_i16
168
+ building.model_index = reader.read_i16
169
+ building.temp_output_obj_idx = reader.read_i32
170
+ building.temp_input_obj_idx = reader.read_i32
171
+ building.output_to_slot = reader.read_i8
172
+ building.input_from_slot = reader.read_i8
173
+ building.output_from_slot = reader.read_i8
174
+ building.input_to_slot = reader.read_i8
175
+ building.output_offset = reader.read_i8
176
+ building.input_offset = reader.read_i8
177
+ building.recipe_id = reader.read_i16
178
+ building.filter_fd = reader.read_i16
179
+
180
+ reader.read_i16.times do
181
+ building.parameters << reader.read_i32
182
+ end
183
+
184
+ building
185
+ end
186
+
187
+ # @param [BinaryReader] reader
188
+ # @param [Integer] index
189
+ # @return [Building]
190
+ def path_default(reader, index)
191
+ building = Building.new
192
+ building.index = index
193
+ building.area_index = reader.read_i8
194
+ building.local_offset_x = reader.read_single
195
+ building.local_offset_y = reader.read_single
196
+ building.local_offset_z = reader.read_single
197
+ building.local_offset_x2 = reader.read_single
198
+ building.local_offset_y2 = reader.read_single
199
+ building.local_offset_z2 = reader.read_single
200
+ building.pitch = 0.0
201
+ building.pitch2 = 0.0
202
+ building.yaw = reader.read_single
203
+ building.yaw2 = reader.read_single
204
+ building.tilt = 0.0
205
+ building.tilt2 = 0.0
206
+ building.item_id = reader.read_i16
207
+ building.model_index = reader.read_i16
208
+ building.temp_output_obj_idx = reader.read_i32
209
+ building.temp_input_obj_idx = reader.read_i32
210
+ building.output_to_slot = reader.read_i8
211
+ building.input_from_slot = reader.read_i8
212
+ building.output_from_slot = reader.read_i8
213
+ building.input_to_slot = reader.read_i8
214
+ building.output_offset = reader.read_i8
215
+ building.input_offset = reader.read_i8
216
+ building.recipe_id = reader.read_i16
217
+ building.filter_fd = reader.read_i16
218
+
219
+ reader.read_i16.times do
220
+ building.parameters << reader.read_i32
221
+ end
222
+
223
+ building
224
+ end
225
+ end
226
+ end
227
+ end