feat: update to new spec version

This commit is contained in:
Timo Ley 2023-09-01 12:08:45 +02:00
parent 8411bd1619
commit 6b74d78747
5 changed files with 76 additions and 13 deletions

View file

@ -8,4 +8,5 @@ serde = { version = "1.0", features = ["derive"] }
serde-enum-str = "0.3"
serde_json = "1.0"
url = {version = "2.2.2", features = ["serde"]}
thiserror = "1.0.30"
addonscript-versioning = { path = "../versioning" }

View file

@ -4,7 +4,7 @@ use addonscript_versioning::Version;
use serde::{Deserialize, Serialize};
use url::Url;
use crate::{AddonDescriptor, enums::APIFeature, LaunchConfig};
use crate::{AddonDescriptor, enums::APIFeature, Patch};
use super::{AddonScript, File, Hashes, Meta};
@ -49,9 +49,9 @@ pub struct EnvBuilderResponse {
pub addonscript: AddonScript,
pub files: Vec<File>,
#[serde(skip_serializing_if = "Option::is_none")]
pub launch_client: Option<LaunchConfig>,
pub launch_client: Option<Patch>,
#[serde(skip_serializing_if = "Option::is_none")]
pub launch_server: Option<LaunchConfig>,
pub launch_server: Option<Patch>,
}
#[derive(Debug, Serialize, Deserialize)]

View file

@ -11,7 +11,7 @@ pub enum Flag {
Launch,
Env,
Expected,
Library,
Patch,
}
#[derive(Debug, Deserialize_enum_str, Serialize_enum_str, PartialEq, Eq, Hash)]
@ -21,6 +21,7 @@ pub enum InstallAction {
Extract,
Rename,
Inject,
Library,
#[serde(other)]
Unknown(String),
}
@ -42,4 +43,23 @@ pub enum Side {
Server,
#[default]
Both,
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase")]
pub enum ArgumentMode {
Replace,
Append,
Expand,
Override,
}
impl Side {
pub fn compatbile_with(&self, other: &Self) -> bool {
match self {
Side::Client => other == &Self::Client || other == &Self::Both,
Side::Server => other == &Self::Server || other == &Self::Both,
Side::Both => true,
}
}
}

View file

@ -0,0 +1,6 @@
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("The parsed AddonScript manifest violates the AddonScript spec")]
InvalidFormat,
}

View file

@ -1,7 +1,8 @@
use std::collections::HashSet;
use addonscript_versioning::{Version, VersionRestriction};
use enums::Side;
use enums::{Side, ArgumentMode};
use error::Error;
use serde::{Deserialize, Serialize};
use url::Url;
@ -11,6 +12,7 @@ pub use self::{
};
pub mod api;
pub mod error;
pub mod enums;
pub mod meta;
@ -30,11 +32,10 @@ pub struct Manifest {
#[serde(default)]
pub instance: bool,
#[serde(default)]
#[deprecated]
pub use_builder: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub launch_client: Option<LaunchConfig>,
#[serde(skip_serializing_if = "Option::is_none")]
pub launch_server: Option<LaunchConfig>,
#[serde(default)]
pub patches: Vec<Patch>,
#[serde(skip_serializing_if = "Option::is_none")]
pub meta: Option<Meta>,
}
@ -120,19 +121,31 @@ pub struct Flags {
}
#[derive(Debug, Serialize, Deserialize)]
pub struct LaunchConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub main_file: Option<String>,
pub struct Patch {
pub side: Side,
#[serde(skip_serializing_if = "Option::is_none")]
pub main_class: Option<String>,
#[serde(default)]
pub arguments: Vec<String>,
pub arguments: Vec<GameArgument>,
#[serde(default)]
pub jvm_arguments: Vec<String>,
#[serde(default)]
pub replace_jvm_arguments: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub java_version: Option<u16>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct GameArgument {
pub mode: ArgumentMode,
#[serde(skip_serializing_if = "Option::is_none")]
pub key: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub value: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub raw: Option<String>,
}
impl VersionlessManifest {
pub fn get_version(&self) -> u8 {
match &self.addonscript {
@ -175,3 +188,26 @@ impl Flags {
false
}
}
impl Manifest {
pub fn get_file(&self, qualifier: String) -> Option<&File> {
for file in &self.files {
if file.qualifier == qualifier {
return Some(file);
}
}
None
}
}
impl GameArgument {
pub fn format_argument(&self) -> Result<String, Error> {
if let Some(raw) = &self.raw {
Ok(raw.clone())
} else {
let key = self.key.clone().ok_or(Error::InvalidFormat)?;
let value = self.value.clone().unwrap_or_else(|| "".to_string());
Ok(format!("--{} {}", key, value))
}
}
}