Skip to content

Commit

Permalink
Extension - Update to latest arma-rs (#10312)
Browse files Browse the repository at this point in the history
  • Loading branch information
PabstMirror authored Sep 17, 2024
1 parent af6f969 commit dc36bee
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 39 deletions.
72 changes: 59 additions & 13 deletions Cargo.lock

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

Binary file modified ace.dll
Binary file not shown.
Binary file modified ace_x64.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion extension/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name = "ace"
crate-type = ["cdylib"]

[dependencies]
arma-rs = { version = "1.10.5", features = ["uuid"] }
arma-rs = { version = "1.11.0", default-features = false, features = ["extension", "uuid"]}
uuid = { version = "1.10.0", features = ["v4"] }
rand = "0.8.5"
rand_chacha = "0.3.1"
Expand Down
6 changes: 3 additions & 3 deletions extension/src/ballistics/atmosphere.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use arma_rs::FromArma;
use arma_rs::{FromArma, FromArmaError};

use super::map::Map;
use crate::common::Temperature;
Expand All @@ -10,12 +10,12 @@ pub enum AtmosphereModel {
}

impl FromArma for AtmosphereModel {
fn from_arma(s: String) -> Result<Self, String> {
fn from_arma(s: String) -> Result<Self, FromArmaError> {
let s = s.trim_matches('"');
match s.to_lowercase().as_str() {
"icao" => Ok(Self::Icao),
"asm" => Ok(Self::Asm),
_ => Err(String::from("unexpected model")),
_ => Err(FromArmaError::InvalidValue("unexpected model".into())),
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions extension/src/ballistics/drag.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::approx_constant)]

use arma_rs::FromArma;
use arma_rs::{FromArma, FromArmaError};

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum DragFunction {
Expand All @@ -13,15 +13,17 @@ pub enum DragFunction {
}

impl FromArma for DragFunction {
fn from_arma(s: String) -> Result<Self, String> {
fn from_arma(s: String) -> Result<Self, FromArmaError> {
match s.as_str() {
"1" => Ok(Self::G1),
"2" => Ok(Self::G2),
"5" => Ok(Self::G5),
"6" => Ok(Self::G6),
"7" => Ok(Self::G7),
"8" => Ok(Self::G8),
_ => Err(format!("Unknown drag function: {s}")),
_ => Err(FromArmaError::InvalidValue(format!(
"Unknown drag function: {s}"
))),
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions extension/src/common/types/height.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ops::Deref;

use arma_rs::FromArma;
use arma_rs::{FromArma, FromArmaError};

#[derive(Debug, Clone, Copy)]
/// Height in meters
Expand All @@ -13,8 +13,10 @@ impl Height {
}

impl FromArma for Height {
fn from_arma(value: String) -> Result<Self, String> {
Ok(Self(value.parse::<f64>().map_err(|_| "Invalid height")?))
fn from_arma(value: String) -> Result<Self, FromArmaError> {
Ok(Self(value.parse::<f64>().map_err(|_| {
FromArmaError::InvalidValue("Invalid height".into())
})?))
}
}

Expand Down
12 changes: 5 additions & 7 deletions extension/src/common/types/muzzle_velocity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ops::Deref;

use arma_rs::FromArma;
use arma_rs::{FromArma, FromArmaError};

#[derive(Debug, Clone, Copy)]
/// Muzzle velocity in m/s
Expand All @@ -14,12 +14,10 @@ impl MuzzleVelocity {
}

impl FromArma for MuzzleVelocity {
fn from_arma(value: String) -> Result<Self, String> {
Ok(Self(
value
.parse::<f64>()
.map_err(|_| "Invalid muzzle velocity")?,
))
fn from_arma(value: String) -> Result<Self, FromArmaError> {
Ok(Self(value.parse::<f64>().map_err(|_| {
FromArmaError::InvalidValue("Invalid muzzle velocity".into())
})?))
}
}

Expand Down
24 changes: 17 additions & 7 deletions extension/src/common/types/temperature.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use arma_rs::FromArma;
use arma_rs::{FromArma, FromArmaError};

#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Temperature(f64);
Expand Down Expand Up @@ -35,25 +35,35 @@ impl Temperature {
}

impl FromArma for Temperature {
fn from_arma(s: String) -> Result<Self, String> {
fn from_arma(s: String) -> Result<Self, FromArmaError> {
if s.is_empty() {
return Err(String::from("unexpected empty string"));
return Err(FromArmaError::InvalidValue(
"unexpected empty string".into(),
));
}
match s.chars().next().unwrap() {
'c' => {
let temp = s[1..].parse::<f64>().map_err(|e| format!("{e}"))?;
let temp = s[1..]
.parse::<f64>()
.map_err(|e| FromArmaError::InvalidValue(format!("{e}")))?;
Ok(Self::new_celsius(temp))
}
'f' => {
let temp = s[1..].parse::<f64>().map_err(|e| format!("{e}"))?;
let temp = s[1..]
.parse::<f64>()
.map_err(|e| FromArmaError::InvalidValue(format!("{e}")))?;
Ok(Self::new_fahrenheit(temp))
}
'k' => {
let temp = s[1..].parse::<f64>().map_err(|e| format!("{e}"))?;
let temp = s[1..]
.parse::<f64>()
.map_err(|e| FromArmaError::InvalidValue(format!("{e}")))?;
Ok(Self::new_kelvin(temp))
}
_ => {
let temp = s.parse::<f64>().map_err(|e| format!("{e}"))?;
let temp = s
.parse::<f64>()
.map_err(|e| FromArmaError::InvalidValue(format!("{e}")))?;
Ok(Self::new_celsius(temp))
}
}
Expand Down
4 changes: 2 additions & 2 deletions extension/src/common/types/vector3.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use arma_rs::{FromArma, IntoArma};
use arma_rs::{FromArma, FromArmaError, IntoArma};

#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Vector3 {
Expand Down Expand Up @@ -52,7 +52,7 @@ impl Vector3 {
}

impl FromArma for Vector3 {
fn from_arma(s: String) -> Result<Self, String> {
fn from_arma(s: String) -> Result<Self, FromArmaError> {
let data = <[f64; 3]>::from_arma(s)?;
Ok(Self {
x: data[0],
Expand Down

0 comments on commit dc36bee

Please sign in to comment.