supcom2_replay_parser 0.3.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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/rspec +29 -0
- data/bin/setup +8 -0
- data/exe/supcom2_replay_parser +5 -0
- data/lib/supcom2_replay_parser/data.rb +33 -0
- data/lib/supcom2_replay_parser/game_options.rb +17 -0
- data/lib/supcom2_replay_parser/players_info.rb +40 -0
- data/lib/supcom2_replay_parser/version.rb +3 -0
- data/lib/supcom2_replay_parser.rb +57 -0
- data/supcom2_replay_parser.gemspec +26 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9bfda5dd83e97db2ea6db211fc1d2e86293337d0bc3697859e9ce1478e23ae9c
|
4
|
+
data.tar.gz: a6273fb8f51c069e4bd0a7ab1712cc83c98b30628bf02b018d3cd7d74c227d83
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fa55ef1a2247f29b9250e5fd667a6a047d041e21557c6e52adfe55cb83eb27c238237193ee3755e4f9676a83004782105523647a568da6a082e25ff8af169b6b
|
7
|
+
data.tar.gz: 4276c6dc862ebef33abe1288c2ab94a7d90c82b6fcfdd5872204e3d908008528aa38e76eddf39c75800b0649714ea167d66b1a720e04462b330d43803eaf3417
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.6.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 SupDex
|
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,46 @@
|
|
1
|
+
# Supcom2ReplayParser
|
2
|
+
|
3
|
+
Gem for parsing replays of Supreme Commander 2. It returns all info about players, map and game options from replay
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'supcom2_replay_parser'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install supcom2_replay_parser
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```
|
24
|
+
require 'pp'
|
25
|
+
replay_info = SupCom2ReplayParser.call(file_path)
|
26
|
+
pp replay_info
|
27
|
+
|
28
|
+
###
|
29
|
+
{:game_version=>"Supreme Commander v1.26",
|
30
|
+
:replay_version=>"Replay v1.9",
|
31
|
+
:players_info=>
|
32
|
+
[{:nickname=>"lvl0 <| m.o.b", :color=>:orange, :faction=>:cybran, :team=>1},
|
33
|
+
{:nickname=>"HUECTRUM", :color=>:white, :faction=>:uef, :team=>2}],
|
34
|
+
:game_options=>
|
35
|
+
{"FogOfWar"=>"explored",
|
36
|
+
"NoRushOption"=>"Off",
|
37
|
+
"AllowObservers"=>"",
|
38
|
+
"TeamSpawn"=>"fixed",
|
39
|
+
"Victory"=>"demoralization",
|
40
|
+
"map"=>"[2] Spring Duel"}}
|
41
|
+
###
|
42
|
+
```
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "supcom2_replay_parser"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/rspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/setup
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module SupCom2ReplayParser
|
2
|
+
module Data
|
3
|
+
FACTIONS = {
|
4
|
+
"@@" => :illuminate,
|
5
|
+
"\u0000@" => :cybran,
|
6
|
+
"\u0080?" => :uef
|
7
|
+
}.freeze
|
8
|
+
|
9
|
+
COLORS = {
|
10
|
+
"@@" => :purple,
|
11
|
+
"\u0000@" => :red,
|
12
|
+
"\u00A0@" => :white,
|
13
|
+
"\u0080?" => :green,
|
14
|
+
"\u0000\u0000" => :blue,
|
15
|
+
"\u0010A" => :orange,
|
16
|
+
"\u0000A" => :yellow,
|
17
|
+
"\u00E0@" => :turquoise,
|
18
|
+
"\u00C0@" => :khaki,
|
19
|
+
"\u0080@" => :brown
|
20
|
+
}.freeze
|
21
|
+
|
22
|
+
TEAMS = {
|
23
|
+
"\u0000@" => 1,
|
24
|
+
"@@" => 2,
|
25
|
+
"\u0080@" => 3,
|
26
|
+
"\u00A0@" => 4,
|
27
|
+
"\u00C0@" => 5,
|
28
|
+
"\u00E0@" => 6,
|
29
|
+
"\u0000A" => 7,
|
30
|
+
"\u0010A" => 8
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SupCom2ReplayParser
|
2
|
+
module GameOptions
|
3
|
+
FIELDS = %w[
|
4
|
+
FogOfWar
|
5
|
+
NoRushOption
|
6
|
+
AllowObservers
|
7
|
+
TeamSpawn
|
8
|
+
Victory
|
9
|
+
].freeze
|
10
|
+
|
11
|
+
def self.call(line)
|
12
|
+
options = Hash[line.scan(/(#{FIELDS.join('|')})+\0{1}\u{ 3 }{0,1}\u{ 1 }{1}([^[[:cntrl:]]]{0,})[[:cntrl:]]{1}/)]
|
13
|
+
|
14
|
+
options.merge!('map' => line.scan(/name+[[:cntrl:]]{2}<{1}[^[[:cntrl:]]]+>{1}([^[[:cntrl:]]]+)[[:cntrl:]]{1}/).to_a.dig(-1, 0))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module SupCom2ReplayParser
|
2
|
+
module PlayersInfo
|
3
|
+
extend self
|
4
|
+
|
5
|
+
PLAYERS_FIELDS = %w[
|
6
|
+
PlayerName
|
7
|
+
PlayerColor
|
8
|
+
Faction
|
9
|
+
Team
|
10
|
+
].freeze
|
11
|
+
|
12
|
+
def call(line)
|
13
|
+
prepare_data(line.scan(/(?:#{PLAYERS_FIELDS.join('|')})+[[:cntrl:]]{2}[^[[:cntrl:]]]{0,}[^\u{ 1 }]+/))
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def prepare_data(data)
|
19
|
+
data = data.each_slice(PLAYERS_FIELDS.size).to_a
|
20
|
+
|
21
|
+
data.each_with_object([]) do |elements, acum|
|
22
|
+
player = {}
|
23
|
+
|
24
|
+
elements.each do |element|
|
25
|
+
if element.start_with?('PlayerName')
|
26
|
+
player[:nickname] = element.encode('iso-8859-1').force_encoding('utf-8').gsub(/[[:cntrl:]]|PlayerName/, '')
|
27
|
+
elsif element.start_with?('PlayerColor')
|
28
|
+
player[:color] = Data::COLORS[element[-2..-1]]
|
29
|
+
elsif element.start_with?('Faction')
|
30
|
+
player[:faction] = Data::FACTIONS[element[-2..-1]]
|
31
|
+
elsif element.start_with?('Team')
|
32
|
+
player[:team] = Data::TEAMS[element[-2..-1]]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
acum << player
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'supcom2_replay_parser/version'
|
2
|
+
require 'supcom2_replay_parser/data'
|
3
|
+
require 'supcom2_replay_parser/game_options'
|
4
|
+
require 'supcom2_replay_parser/players_info'
|
5
|
+
|
6
|
+
module SupCom2ReplayParser
|
7
|
+
extend self
|
8
|
+
|
9
|
+
ALLOWED_EXTENSION = '.SC2ReplayDLC'
|
10
|
+
|
11
|
+
def call(filepath)
|
12
|
+
raise Exception, "Allowed only files with extension #{ALLOWED_EXTENSION}" unless allow_file_extension?(filepath)
|
13
|
+
|
14
|
+
replay_info = {}
|
15
|
+
|
16
|
+
file_lines = File.new(filepath, encoding: 'ISO-8859-1:UTF-8')
|
17
|
+
|
18
|
+
file_lines.each do |line|
|
19
|
+
current_line = file_lines.lineno
|
20
|
+
|
21
|
+
if current_line == 1
|
22
|
+
replay_info[:game_version] = line.sub(/[[:cntrl:]]/, '').chomp
|
23
|
+
end
|
24
|
+
|
25
|
+
if current_line == 2
|
26
|
+
replay_info[:replay_version] = line.sub(/[[:cntrl:]]/, '').chomp
|
27
|
+
end
|
28
|
+
|
29
|
+
if current_line == 4 || current_line == 5
|
30
|
+
next if !has_line_full_needed_data?(line) && current_line == 4
|
31
|
+
|
32
|
+
raise Exception, 'Replay is broken' unless has_line_full_needed_data?(line)
|
33
|
+
|
34
|
+
replay_info.merge!({
|
35
|
+
players_info: PlayersInfo.call(line),
|
36
|
+
game_options: GameOptions.call(line)
|
37
|
+
})
|
38
|
+
|
39
|
+
break
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
raise Exception, 'Replay is broken' if replay_info.empty?
|
44
|
+
|
45
|
+
replay_info
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def has_line_full_needed_data?(line)
|
51
|
+
line.match?(/(#{GameOptions::FIELDS.join('|')})/)
|
52
|
+
end
|
53
|
+
|
54
|
+
def allow_file_extension?(file)
|
55
|
+
File.extname(file) == ALLOWED_EXTENSION
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "supcom2_replay_parser/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'supcom2_replay_parser'
|
8
|
+
spec.version = Supcom2ReplayParser::VERSION
|
9
|
+
spec.author = 'SupDex'
|
10
|
+
spec.email = 'symeton@gmail.com'
|
11
|
+
|
12
|
+
spec.summary = 'SupCom2ReplayParser - Gem for parsing replays of game Supreme Commander 2'
|
13
|
+
spec.homepage = 'https://github.com/Symeton/supcom2_replay_parser'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.9"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: supcom2_replay_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SupDex
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.9'
|
27
|
+
description:
|
28
|
+
email: symeton@gmail.com
|
29
|
+
executables:
|
30
|
+
- supcom2_replay_parser
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".ruby-version"
|
37
|
+
- ".travis.yml"
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- bin/console
|
43
|
+
- bin/rspec
|
44
|
+
- bin/setup
|
45
|
+
- exe/supcom2_replay_parser
|
46
|
+
- lib/supcom2_replay_parser.rb
|
47
|
+
- lib/supcom2_replay_parser/data.rb
|
48
|
+
- lib/supcom2_replay_parser/game_options.rb
|
49
|
+
- lib/supcom2_replay_parser/players_info.rb
|
50
|
+
- lib/supcom2_replay_parser/version.rb
|
51
|
+
- supcom2_replay_parser.gemspec
|
52
|
+
homepage: https://github.com/Symeton/supcom2_replay_parser
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubygems_version: 3.0.1
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: SupCom2ReplayParser - Gem for parsing replays of game Supreme Commander 2
|
75
|
+
test_files: []
|