Skip to content

Commit

Permalink
Merge pull request #88 from ryantaylor/skirmish
Browse files Browse the repository at this point in the history
Game Type Parsing
  • Loading branch information
ryantaylor authored Feb 12, 2024
2 parents 504ecbb + e34ccad commit 5193389
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 38 deletions.
14 changes: 12 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
vault_coh (4.0.0)
vault_coh (5.0.0)

GEM
remote: https://rubygems.org/
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Vault

[![Gem Version](https://badge.fury.io/rb/vault_coh.svg)](https://badge.fury.io/rb/vault_coh) [![Documentation](https://img.shields.io/badge/View-Documentation-blue.svg)](https://rubydoc.info/github/ryantaylor/vault-rb/v3.0.0)
[![Gem Version](https://badge.fury.io/rb/vault_coh.svg)](https://badge.fury.io/rb/vault_coh) [![Documentation](https://img.shields.io/badge/View-Documentation-blue.svg)](https://rubydoc.info/github/ryantaylor/vault-rb/v5.0.0)

A native Ruby client wrapper for the [vault](https://github.com/ryantaylor/vault) Company of Heroes replay parser, integrated via a Rust native extension.

Expand All @@ -24,7 +24,7 @@ bytes = File.read('/path/to/replay.rec').unpack('C*')
replay = VaultCoh::Replay.from_bytes(bytes)
puts replay.version
```
All information available from parsing can be found in the [documentation](https://rubydoc.info/github/ryantaylor/vault-rb/v3.0.0).
All information available from parsing can be found in the [documentation](https://rubydoc.info/github/ryantaylor/vault-rb/v5.0.0).

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion ext/vault_coh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ crate-type = ["cdylib"]
[dependencies]
magnus = { version = "0.6" }
serde_magnus = { version = "0.8" }
vault = { version = "7", features = ["magnus", "serde"] }
vault = { version = "8", features = ["magnus", "serde"] }
30 changes: 21 additions & 9 deletions ext/vault_coh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use vault::commands::{
BuildGlobalUpgrade, BuildSquad, SelectBattlegroup, SelectBattlegroupAbility, Unknown,
UseBattlegroupAbility,
};
use vault::{Command, Faction, Map, Message, Player, Replay, Team};
use vault::{Command, Map, Message, Player, Replay};

#[magnus::init]
fn init() -> Result<(), Error> {
Expand All @@ -16,7 +16,9 @@ fn init() -> Result<(), Error> {
replay.define_singleton_method("from_bytes", function!(from_bytes, 1))?;
replay.define_method("version", method!(Replay::version, 0))?;
replay.define_method("timestamp", method!(Replay::timestamp, 0))?;
replay.define_method("game_type", method!(game_type_string, 0))?;
replay.define_method("matchhistory_id", method!(Replay::matchhistory_id, 0))?;
replay.define_method("mod_uuid", method!(mod_uuid_string, 0))?;
replay.define_method("map", method!(Replay::map, 0))?;
replay.define_method("map_filename", method!(Replay::map_filename, 0))?;
replay.define_method(
Expand All @@ -43,8 +45,8 @@ fn init() -> Result<(), Error> {
let player = module.define_class("Player", class::object())?;
player.define_method("name", method!(Player::name, 0))?;
player.define_method("human?", method!(Player::human, 0))?;
player.define_method("faction", method!(Player::faction, 0))?;
player.define_method("team", method!(Player::team, 0))?;
player.define_method("faction", method!(faction_string, 0))?;
player.define_method("team", method!(team_value, 0))?;
player.define_method("battlegroup", method!(Player::battlegroup, 0))?;
player.define_method("steam_id", method!(Player::steam_id, 0))?;
player.define_method("profile_id", method!(Player::profile_id, 0))?;
Expand All @@ -62,12 +64,6 @@ fn init() -> Result<(), Error> {
message.define_method("message", method!(Message::message, 0))?;
message.define_method("to_h", method!(Message::to_h, 0))?;

let faction = module.define_class("Faction", class::object())?;
faction.define_method("value", method!(Faction::to_string, 0))?;

let team = module.define_class("Team", class::object())?;
team.define_method("value", method!(Team::value, 0))?;

let command = module.define_class("Command", class::object())?;
command.define_method("to_h", method!(Command::to_h, 0))?;

Expand Down Expand Up @@ -144,3 +140,19 @@ fn from_bytes(input: Vec<u8>) -> Result<Replay, Error> {
Replay::from_bytes(&input)
.map_err(|err| Error::new(exception::runtime_error(), err.to_string()))
}

fn mod_uuid_string(rb_self: &Replay) -> String {
rb_self.mod_uuid().to_string()
}

fn game_type_string(rb_self: &Replay) -> String {
rb_self.game_type().to_string()
}

fn faction_string(rb_self: &Player) -> String {
rb_self.faction().to_string()
}

fn team_value(rb_self: &Player) -> usize {
rb_self.team().value()
}
15 changes: 4 additions & 11 deletions lib/vault_coh/faction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@
module VaultCoh
# Identifiers for the Company of Heroes 3 factions.
class Faction
AMERICANS = 'Americans'
BRITISH = 'British'
WEHRMACHT = 'Wehrmacht'
AFRIKAKORPS = 'AfrikaKorps'

# String identifier of the given faction.
#
# @see https://docs.rs/vault/3.0.0/vault/enum.Faction.html
#
# @return [AMERICANS|BRITISH|WEHRMACHT|AFRIKAKORPS]
def value; end
AMERICANS = 'americans'
BRITISH = 'british_africa'
WEHRMACHT = 'germans'
AFRIKAKORPS = 'afrika_korps'
end
end
11 changes: 11 additions & 0 deletions lib/vault_coh/game_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module VaultCoh
# Identifiers for the Company of Heroes 3 game types.
class GameType
SKIRMISH = 'skirmish'
MULTIPLAYER = 'multiplayer'
AUTOMATCH = 'automatch'
CUSTOM = 'custom'
end
end
4 changes: 2 additions & 2 deletions lib/vault_coh/player.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def human?; end

# The faction selected by the player in this match.
#
# @return [Faction]
# @return [Faction::AMERICANS|Faction::WEHRMACHT|Faction::BRITISH|Faction::AFRIKAKORPS]
def faction; end

# The team the player was assigned to. Currently only head-to-head
# matchups are supported (max two teams).
#
# @return [Team]
# @return [Team::FIRST|Team::SECOND]
def team; end

# The pbgid of the battlegroup the player selected, or +nil+ if no
Expand Down
24 changes: 22 additions & 2 deletions lib/vault_coh/replay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,34 @@ def version; end
# @return [String]
def timestamp; end

# The type of game this replay represents. Note that this information
# is parsed on a best-effort basis and therefore may not always be
# correct. Also note that it's currently not known if there's a way to
# differentiate between automatch and custom games for replays recorded
# before the replay system release in patch 1.4.0. Games played before
# that patch will be marked as either +skirmish+ (for local AI games) or
# +multiplayer+ (for networked custom or automatch games). Games recorded
# on or after patch 1.4.0 will properly differentiate between +custom+
# and +automatch+ games.
#
# @return [GameType::SKIRMISH|GameType::MULTIPLAYER|GameType::AUTOMATCH|GameType::CUSTOM]
def game_type; end

# The ID used by Relic to track this match on their internal servers.
# This ID can be matched with an ID of the same name returned by
# Relic’s CoH3 stats API, enabling linkage between replay files and
# statistical information for a match.
# statistical information for a match. When the game type is +skirmish+,
# there is no ID assigned by Relic, so this will be +nil+.
#
# @return [Integer] unsigned, 64 bits
# @return [Integer|NilClass] unsigned, 64 bits
def matchhistory_id; end

# The UUID of the base game mod this replay ran on. If no mod was used,
# this will be a nil UUID (all zeroes).
#
# @return [String]
def mod_uuid; end

# Map information for this match.
#
# @return [Map]
Expand Down
7 changes: 0 additions & 7 deletions lib/vault_coh/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,5 @@ module VaultCoh
class Team
FIRST = 0
SECOND = 1

# Integer representation of the assigned team.
#
# @see https://docs.rs/vault/3.0.0/vault/enum.Team.html
#
# @return [FIRST|SECOND]
def value; end
end
end
2 changes: 1 addition & 1 deletion lib/vault_coh/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module VaultCoh
VERSION = '4.0.0'
VERSION = '5.0.0'
end

0 comments on commit 5193389

Please sign in to comment.