dsp_blueprint_parser 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a41b4aaec5e4a7a852d8e605bd7374f9e042adfdaa524927d3664e24dea3f66e
4
+ data.tar.gz: 2b729108186e6a73e2446dc415e8d19a2098b90f993bbbed0c4bfec1787699fd
5
+ SHA512:
6
+ metadata.gz: 4adfcd16738fe259825577d67ad21312379d83de8e1b4a04950f5b6ddfe61d3f54ecaeec30b740181bfde33f0c716a7faa860205245bf1c92894c43fe327bd0f
7
+ data.tar.gz: c8e3cf285432a9d6db78415fd8bff050a427839ba6ec9e7829638cfc6797356e4f038ea187d846877f5400e01efe2bcbaaf3378cbf636d9e7d3f3d02452910f0
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Datasource local storage ignored files
5
+ /dataSources/
6
+ /dataSources.local.xml
7
+ # Editor-based HTTP Client requests
8
+ /httpRequests/
@@ -0,0 +1,77 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
+ </content>
12
+ <orderEntry type="inheritedJdk" />
13
+ <orderEntry type="sourceFolder" forTests="false" />
14
+ <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, ruby-3.0.2-p107) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.2.22, ruby-3.0.2-p107) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="coderay (v1.1.3, ruby-3.0.2-p107) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.4.4, ruby-3.0.2-p107) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="method_source (v1.0.0, ruby-3.0.2-p107) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="parallel (v1.20.1, ruby-3.0.2-p107) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="parser (v3.0.2.0, ruby-3.0.2-p107) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="pry (v0.14.1, ruby-3.0.2-p107) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="rainbow (v3.0.0, ruby-3.0.2-p107) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, ruby-3.0.2-p107) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="rbs (v1.0.4, ruby-3.0.2-p107) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.1.1, ruby-3.0.2-p107) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5, ruby-3.0.2-p107) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v3.10.0, ruby-3.0.2-p107) [gem]" level="application" />
28
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.10.1, ruby-3.0.2-p107) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.10.1, ruby-3.0.2-p107) [gem]" level="application" />
30
+ <orderEntry type="library" scope="PROVIDED" name="rspec-its (v1.3.0, ruby-3.0.2-p107) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.10.2, ruby-3.0.2-p107) [gem]" level="application" />
32
+ <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.10.2, ruby-3.0.2-p107) [gem]" level="application" />
33
+ <orderEntry type="library" scope="PROVIDED" name="rubocop (v1.18.4, ruby-3.0.2-p107) [gem]" level="application" />
34
+ <orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.8.0, ruby-3.0.2-p107) [gem]" level="application" />
35
+ <orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0, ruby-3.0.2-p107) [gem]" level="application" />
36
+ <orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.0.0, ruby-3.0.2-p107) [gem]" level="application" />
37
+ </component>
38
+ <component name="RakeTasksCache">
39
+ <option name="myRootTask">
40
+ <RakeTaskImpl id="rake">
41
+ <subtasks>
42
+ <RakeTaskImpl description="Build dsp_blueprint_parser-0.1.0.gem into the pkg directory" fullCommand="build" id="build" />
43
+ <RakeTaskImpl id="build">
44
+ <subtasks>
45
+ <RakeTaskImpl description="Generate SHA512 checksum if dsp_blueprint_parser-0.1.0.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
46
+ </subtasks>
47
+ </RakeTaskImpl>
48
+ <RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
49
+ <RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
50
+ <RakeTaskImpl description="Build and install dsp_blueprint_parser-0.1.0.gem into system gems" fullCommand="install" id="install" />
51
+ <RakeTaskImpl id="install">
52
+ <subtasks>
53
+ <RakeTaskImpl description="Build and install dsp_blueprint_parser-0.1.0.gem into system gems without network access" fullCommand="install:local" id="local" />
54
+ </subtasks>
55
+ </RakeTaskImpl>
56
+ <RakeTaskImpl description="Create tag v0.1.0 and build and push dsp_blueprint_parser-0.1.0.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
57
+ <RakeTaskImpl description="Run RuboCop" fullCommand="rubocop" id="rubocop" />
58
+ <RakeTaskImpl id="rubocop">
59
+ <subtasks>
60
+ <RakeTaskImpl description="Auto-correct RuboCop offenses" fullCommand="rubocop:auto_correct" id="auto_correct" />
61
+ </subtasks>
62
+ </RakeTaskImpl>
63
+ <RakeTaskImpl description="Run RSpec code examples" fullCommand="spec" id="spec" />
64
+ <RakeTaskImpl description="" fullCommand="default" id="default" />
65
+ <RakeTaskImpl description="" fullCommand="release" id="release" />
66
+ <RakeTaskImpl id="release">
67
+ <subtasks>
68
+ <RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
69
+ <RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
70
+ <RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
71
+ </subtasks>
72
+ </RakeTaskImpl>
73
+ </subtasks>
74
+ </RakeTaskImpl>
75
+ </option>
76
+ </component>
77
+ </module>
data/.idea/misc.xml ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="ruby-3.0.2-p107" project-jdk-type="RUBY_SDK" />
4
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/dsp_blueprint_parser.iml" filepath="$PROJECT_DIR$/.idea/dsp_blueprint_parser.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,22 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: single_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Metrics/MethodLength:
16
+ Max: 30
17
+
18
+ Metrics/BlockLength:
19
+ Max: 30
20
+
21
+ Metrics/AbcSize:
22
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-07-31
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in dsp_blueprint_parser.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+
10
+ gem 'rspec', '~> 3.0'
11
+
12
+ gem 'pry', '~> 0.14.0'
13
+ gem 'rspec-expectations', '~> 3.10.1'
14
+ gem 'rspec-its', '~> 1.3.0'
15
+ gem 'rubocop', '~> 1.7'
data/Gemfile.lock ADDED
@@ -0,0 +1,66 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dsp_blueprint_parser (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ coderay (1.1.3)
11
+ diff-lcs (1.4.4)
12
+ method_source (1.0.0)
13
+ parallel (1.20.1)
14
+ parser (3.0.2.0)
15
+ ast (~> 2.4.1)
16
+ pry (0.14.1)
17
+ coderay (~> 1.1)
18
+ method_source (~> 1.0)
19
+ rainbow (3.0.0)
20
+ rake (13.0.6)
21
+ regexp_parser (2.1.1)
22
+ rexml (3.2.5)
23
+ rspec (3.10.0)
24
+ rspec-core (~> 3.10.0)
25
+ rspec-expectations (~> 3.10.0)
26
+ rspec-mocks (~> 3.10.0)
27
+ rspec-core (3.10.1)
28
+ rspec-support (~> 3.10.0)
29
+ rspec-expectations (3.10.1)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.10.0)
32
+ rspec-its (1.3.0)
33
+ rspec-core (>= 3.0.0)
34
+ rspec-expectations (>= 3.0.0)
35
+ rspec-mocks (3.10.2)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-support (3.10.2)
39
+ rubocop (1.18.4)
40
+ parallel (~> 1.10)
41
+ parser (>= 3.0.0.0)
42
+ rainbow (>= 2.2.2, < 4.0)
43
+ regexp_parser (>= 1.8, < 3.0)
44
+ rexml
45
+ rubocop-ast (>= 1.8.0, < 2.0)
46
+ ruby-progressbar (~> 1.7)
47
+ unicode-display_width (>= 1.4.0, < 3.0)
48
+ rubocop-ast (1.8.0)
49
+ parser (>= 3.0.1.1)
50
+ ruby-progressbar (1.11.0)
51
+ unicode-display_width (2.0.0)
52
+
53
+ PLATFORMS
54
+ x64-mingw32
55
+
56
+ DEPENDENCIES
57
+ dsp_blueprint_parser!
58
+ pry (~> 0.14.0)
59
+ rake (~> 13.0)
60
+ rspec (~> 3.0)
61
+ rspec-expectations (~> 3.10.1)
62
+ rspec-its (~> 1.3.0)
63
+ rubocop (~> 1.7)
64
+
65
+ BUNDLED WITH
66
+ 2.2.22
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Lucas Falk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # DspBlueprintParser
2
+
3
+ Small Ruby gem to handle parsing of Dyson Sphere Program's blueprint data.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'dsp_blueprint_parser'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install dsp_blueprint_parser
20
+
21
+ ## Usage
22
+
23
+ Module `DspBlueprintParser` has a single static method `parse` which takes the DSP blueprint string to be parsed.
24
+
25
+ ```ruby
26
+ DspBlueprintParser::parse(str_blueprint)
27
+ ```
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/LRFalk01/dsp_blueprint_parser.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'dsp_blueprint_parser'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/dsp_blueprint_parser/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'dsp_blueprint_parser'
7
+ spec.version = DspBlueprintParser::VERSION
8
+ spec.authors = ['Lucas Falk']
9
+ spec.email = ['LRFalk01@gmail.com']
10
+
11
+ spec.summary = 'Parse Dyson Sphere Program blueprint string'
12
+ spec.description = 'Parse Dyson Sphere Program blueprint string'
13
+ spec.homepage = 'https://github.com/LRFalk01/DSP-Blueprint-Parser'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 3.0'
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = spec.homepage
21
+ # spec.metadata['changelog_uri'] = spec.homepage
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "example-gem", "~> 1.0"
34
+
35
+ # For more information and examples about making a new gem, checkout our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
37
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'zlib'
5
+ require 'stringio'
6
+ require 'base64'
7
+
8
+ require_relative 'dsp_blueprint_parser/version'
9
+ require_relative 'dsp_blueprint_parser/blueprint_data'
10
+ require_relative 'dsp_blueprint_parser/icon_layout'
11
+ require_relative 'dsp_blueprint_parser/area'
12
+ require_relative 'dsp_blueprint_parser/building'
13
+ require_relative 'dsp_blueprint_parser/binary_reader'
14
+ require_relative 'dsp_blueprint_parser/parser'
15
+
16
+ # module to receive a Dyson Sphere Program blueprint string and parse it
17
+ module DspBlueprintParser
18
+ class Error < StandardError; end
19
+
20
+ # @param str_blueprint [String]
21
+ # @return [BlueprintData]
22
+ def self.parse(str_blueprint)
23
+ return if str_blueprint.size < 28
24
+ return unless str_blueprint.start_with? 'BLUEPRINT:'
25
+
26
+ parser = Parser.new(str_blueprint)
27
+ parser.parse
28
+ end
29
+ end
@@ -0,0 +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
@@ -0,0 +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
@@ -0,0 +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
@@ -0,0 +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
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DspBlueprintParser
4
+ module IconLayout
5
+ NONE = 0
6
+ NO_ICON = 1
7
+ ONE_ICON = 10
8
+ ONE_ICON_SMALL = 11
9
+ TWO_ICON_46 = 20
10
+ TWO_ICON_53 = 21
11
+ TWO_ICON_59 = 22
12
+ TWO_ICON_57 = 23
13
+ TWO_ICON_51 = 24
14
+ THREE_ICON_813 = 30
15
+ THREE_ICON_279 = 31
16
+ THREE_ICON_573 = 32
17
+ THREE_ICON_591 = 33
18
+ FOUR_ICON_7913 = 40
19
+ FOUR_ICON_8462 = 41
20
+ FIVE_ICON_57913 = 50
21
+ FIVE_ICON_PENTA = 51
22
+ end
23
+ end
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DspBlueprintParser
4
+ # class to orchestrate parsing
5
+ class Parser
6
+ SECONDS_AT_EPOC = 62_135_596_800
7
+
8
+ # @param [String] str_blueprint
9
+ def initialize(str_blueprint)
10
+ @str_blueprint = str_blueprint
11
+ end
12
+
13
+ # @return [BlueprintData]
14
+ def parse
15
+ blueprint = BlueprintData.new
16
+ reader = get_reader(@str_blueprint)
17
+
18
+ parse_metadata(blueprint, @str_blueprint, reader)
19
+ parse_areas(blueprint, reader)
20
+ parse_buildings(blueprint, reader)
21
+
22
+ blueprint
23
+ end
24
+
25
+ private
26
+
27
+ # @param ticks [Integer]
28
+ # @return [Time]
29
+ def ticks_to_epoch(ticks)
30
+ # 10mil ticks per second
31
+ seconds = ticks / 10_000_000
32
+
33
+ Time.at(seconds - SECONDS_AT_EPOC)
34
+ end
35
+
36
+ # @param str_blueprint [String]
37
+ # @return [Array<String>]
38
+ def get_header_segments(str_blueprint)
39
+ header_end = str_blueprint.index('"')
40
+ header = str_blueprint[10..header_end - 1]
41
+ header.split(',')
42
+ end
43
+
44
+ # @param str_blueprint [String]
45
+ # @return [BinaryReader]
46
+ def get_reader(str_blueprint)
47
+ header_end = str_blueprint.index('"')
48
+ blueprint_end = str_blueprint[header_end + 1..].index('"') + header_end
49
+ blueprint_compressed = str_blueprint[header_end + 1..blueprint_end]
50
+
51
+ gz = Zlib::GzipReader.new(StringIO.new(Base64.decode64(blueprint_compressed)))
52
+ blueprint_decompressed = gz.each_byte.to_a
53
+
54
+ BinaryReader.new(blueprint_decompressed)
55
+ end
56
+
57
+ # @param [BlueprintData] blueprint
58
+ # @param [BinaryReader] reader
59
+ def parse_areas(blueprint, reader)
60
+ reader.read_i8.times do
61
+ area = Area.new
62
+ area.index = reader.read_i8
63
+ area.parent_index = reader.read_i8
64
+ area.tropic_anchor = reader.read_i16
65
+ area.area_segments = reader.read_i16
66
+ area.anchor_local_offset_x = reader.read_i16
67
+ area.anchor_local_offset_y = reader.read_i16
68
+ area.width = reader.read_i16
69
+ area.height = reader.read_i16
70
+
71
+ blueprint.areas << area
72
+ end
73
+ end
74
+
75
+ # @param [BlueprintData] blueprint
76
+ # @param [BinaryReader] reader
77
+ def parse_buildings(blueprint, reader)
78
+ reader.read_i32.times do
79
+ building = Building.new
80
+ building.index = reader.read_i32
81
+ building.area_index = reader.read_i8
82
+ building.local_offset_x = reader.read_single
83
+ building.local_offset_y = reader.read_single
84
+ building.local_offset_z = reader.read_single
85
+ building.local_offset_x2 = reader.read_single
86
+ building.local_offset_y2 = reader.read_single
87
+ building.local_offset_z2 = reader.read_single
88
+ building.yaw = reader.read_single
89
+ building.yaw2 = reader.read_single
90
+ building.item_id = reader.read_i16
91
+ building.model_index = reader.read_i16
92
+ building.temp_output_obj_idx = reader.read_i32
93
+ building.temp_input_obj_idx = reader.read_i32
94
+ building.output_to_slot = reader.read_i8
95
+ building.input_from_slot = reader.read_i8
96
+ building.output_from_slot = reader.read_i8
97
+ building.input_to_slot = reader.read_i8
98
+ building.output_offset = reader.read_i8
99
+ building.input_offset = reader.read_i8
100
+ building.recipe_id = reader.read_i16
101
+ building.filter_fd = reader.read_i16
102
+
103
+ reader.read_i16.times do
104
+ building.parameters << reader.read_i32
105
+ end
106
+
107
+ blueprint.buildings << building
108
+ end
109
+ end
110
+
111
+ # @param [BlueprintData] blueprint
112
+ # @param [String] str_blueprint
113
+ # @param [BinaryReader] reader
114
+ def parse_metadata(blueprint, str_blueprint, reader)
115
+ header_segments = get_header_segments(str_blueprint)
116
+
117
+ blueprint.icon_layout = header_segments[1].to_i
118
+ blueprint.icon0 = header_segments[2].to_i
119
+ blueprint.icon1 = header_segments[3].to_i
120
+ blueprint.icon2 = header_segments[4].to_i
121
+ blueprint.icon3 = header_segments[5].to_i
122
+ blueprint.icon4 = header_segments[6].to_i
123
+
124
+ blueprint.time = ticks_to_epoch(header_segments[8].to_i)
125
+ blueprint.game_version = header_segments[9]
126
+ blueprint.short_description = CGI.unescape(header_segments[10])
127
+ blueprint.description = CGI.unescape(header_segments[11])
128
+
129
+ blueprint.version = reader.read_i32
130
+ blueprint.cursor_offset_x = reader.read_i32
131
+ blueprint.cursor_offset_y = reader.read_i32
132
+ blueprint.cursor_target_area = reader.read_i32
133
+ blueprint.drag_box_size_x = reader.read_i32
134
+ blueprint.drag_box_size_y = reader.read_i32
135
+ blueprint.primary_area_idx = reader.read_i32
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DspBlueprintParser
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dsp_blueprint_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lucas Falk
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-08-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Parse Dyson Sphere Program blueprint string
14
+ email:
15
+ - LRFalk01@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".idea/.gitignore"
22
+ - ".idea/dsp_blueprint_parser.iml"
23
+ - ".idea/misc.xml"
24
+ - ".idea/modules.xml"
25
+ - ".idea/vcs.xml"
26
+ - ".rspec"
27
+ - ".rubocop.yml"
28
+ - CHANGELOG.md
29
+ - Gemfile
30
+ - Gemfile.lock
31
+ - LICENSE.txt
32
+ - README.md
33
+ - Rakefile
34
+ - bin/console
35
+ - bin/setup
36
+ - dsp_blueprint_parser.gemspec
37
+ - lib/dsp_blueprint_parser.rb
38
+ - lib/dsp_blueprint_parser/area.rb
39
+ - lib/dsp_blueprint_parser/binary_reader.rb
40
+ - lib/dsp_blueprint_parser/blueprint_data.rb
41
+ - lib/dsp_blueprint_parser/building.rb
42
+ - lib/dsp_blueprint_parser/icon_layout.rb
43
+ - lib/dsp_blueprint_parser/parser.rb
44
+ - lib/dsp_blueprint_parser/version.rb
45
+ homepage: https://github.com/LRFalk01/DSP-Blueprint-Parser
46
+ licenses:
47
+ - MIT
48
+ metadata:
49
+ homepage_uri: https://github.com/LRFalk01/DSP-Blueprint-Parser
50
+ source_code_uri: https://github.com/LRFalk01/DSP-Blueprint-Parser
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '3.0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 3.2.22
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Parse Dyson Sphere Program blueprint string
70
+ test_files: []