dsp_blueprint_parser 0.1.1 → 0.1.2
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/.rubocop.yml +21 -21
- data/Gemfile +15 -15
- data/Gemfile.lock +3 -3
- data/README.md +48 -46
- data/Rakefile +16 -12
- data/bin/console +15 -15
- data/dsp_blueprint_parser.gemspec +39 -37
- data/ext/md5f/extconf.rb +3 -0
- data/ext/md5f/md5f.c +311 -0
- data/lib/dsp_blueprint_parser.rb +40 -29
- data/lib/dsp_blueprint_parser/area.rb +30 -30
- data/lib/dsp_blueprint_parser/binary_reader.rb +46 -46
- data/lib/dsp_blueprint_parser/blueprint_data.rb +69 -69
- data/lib/dsp_blueprint_parser/building.rb +79 -79
- data/lib/dsp_blueprint_parser/data_sections.rb +40 -0
- data/lib/dsp_blueprint_parser/icon_layout.rb +23 -23
- data/lib/dsp_blueprint_parser/parser.rb +119 -144
- data/lib/dsp_blueprint_parser/version.rb +5 -5
- data/lib/md5f.so +0 -0
- metadata +12 -7
data/lib/dsp_blueprint_parser.rb
CHANGED
@@ -1,29 +1,40 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'date'
|
4
|
-
require 'zlib'
|
5
|
-
require 'stringio'
|
6
|
-
require 'base64'
|
7
|
-
|
8
|
-
|
9
|
-
require_relative 'dsp_blueprint_parser/
|
10
|
-
require_relative 'dsp_blueprint_parser/
|
11
|
-
require_relative 'dsp_blueprint_parser/
|
12
|
-
require_relative 'dsp_blueprint_parser/
|
13
|
-
require_relative 'dsp_blueprint_parser/
|
14
|
-
require_relative 'dsp_blueprint_parser/
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
require 'zlib'
|
5
|
+
require 'stringio'
|
6
|
+
require 'base64'
|
7
|
+
require 'md5f'
|
8
|
+
|
9
|
+
require_relative 'dsp_blueprint_parser/version'
|
10
|
+
require_relative 'dsp_blueprint_parser/blueprint_data'
|
11
|
+
require_relative 'dsp_blueprint_parser/icon_layout'
|
12
|
+
require_relative 'dsp_blueprint_parser/area'
|
13
|
+
require_relative 'dsp_blueprint_parser/building'
|
14
|
+
require_relative 'dsp_blueprint_parser/binary_reader'
|
15
|
+
require_relative 'dsp_blueprint_parser/parser'
|
16
|
+
require_relative 'dsp_blueprint_parser/data_sections'
|
17
|
+
|
18
|
+
# module to receive a Dyson Sphere Program blueprint string and parse it
|
19
|
+
module DspBlueprintParser
|
20
|
+
class Error < StandardError; end
|
21
|
+
|
22
|
+
# @param str_blueprint [String]
|
23
|
+
# @return [BlueprintData]
|
24
|
+
def self.parse(str_blueprint)
|
25
|
+
return if str_blueprint.size < 28
|
26
|
+
return unless str_blueprint.start_with? 'BLUEPRINT:'
|
27
|
+
|
28
|
+
parser = Parser.new(str_blueprint)
|
29
|
+
parser.blueprint
|
30
|
+
end
|
31
|
+
|
32
|
+
# @param input [String]
|
33
|
+
# @return [Boolean]
|
34
|
+
def self.is_valid?(input)
|
35
|
+
sections = DataSections.new(input)
|
36
|
+
hash = MD5F::compute(sections.hashed_string)
|
37
|
+
|
38
|
+
return sections.hash == hash
|
39
|
+
end
|
40
|
+
end
|
@@ -1,30 +1,30 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module DspBlueprintParser
|
4
|
-
# data class for parsed area
|
5
|
-
class Area
|
6
|
-
# @return [Integer]
|
7
|
-
attr_accessor :index
|
8
|
-
|
9
|
-
# @return [Integer]
|
10
|
-
attr_accessor :parent_index
|
11
|
-
|
12
|
-
# @return [Integer]
|
13
|
-
attr_accessor :tropic_anchor
|
14
|
-
|
15
|
-
# @return [Integer]
|
16
|
-
attr_accessor :area_segments
|
17
|
-
|
18
|
-
# @return [Integer]
|
19
|
-
attr_accessor :anchor_local_offset_x
|
20
|
-
|
21
|
-
# @return [Integer]
|
22
|
-
attr_accessor :anchor_local_offset_y
|
23
|
-
|
24
|
-
# @return [Integer]
|
25
|
-
attr_accessor :width
|
26
|
-
|
27
|
-
# @return [Integer]
|
28
|
-
attr_accessor :height
|
29
|
-
end
|
30
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DspBlueprintParser
|
4
|
+
# data class for parsed area
|
5
|
+
class Area
|
6
|
+
# @return [Integer]
|
7
|
+
attr_accessor :index
|
8
|
+
|
9
|
+
# @return [Integer]
|
10
|
+
attr_accessor :parent_index
|
11
|
+
|
12
|
+
# @return [Integer]
|
13
|
+
attr_accessor :tropic_anchor
|
14
|
+
|
15
|
+
# @return [Integer]
|
16
|
+
attr_accessor :area_segments
|
17
|
+
|
18
|
+
# @return [Integer]
|
19
|
+
attr_accessor :anchor_local_offset_x
|
20
|
+
|
21
|
+
# @return [Integer]
|
22
|
+
attr_accessor :anchor_local_offset_y
|
23
|
+
|
24
|
+
# @return [Integer]
|
25
|
+
attr_accessor :width
|
26
|
+
|
27
|
+
# @return [Integer]
|
28
|
+
attr_accessor :height
|
29
|
+
end
|
30
|
+
end
|
@@ -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,79 @@
|
|
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 [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
|