feat: update to new spec version
This commit is contained in:
parent
8411bd1619
commit
6b74d78747
5 changed files with 76 additions and 13 deletions
|
@ -8,4 +8,5 @@ serde = { version = "1.0", features = ["derive"] }
|
||||||
serde-enum-str = "0.3"
|
serde-enum-str = "0.3"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
url = {version = "2.2.2", features = ["serde"]}
|
url = {version = "2.2.2", features = ["serde"]}
|
||||||
|
thiserror = "1.0.30"
|
||||||
addonscript-versioning = { path = "../versioning" }
|
addonscript-versioning = { path = "../versioning" }
|
|
@ -4,7 +4,7 @@ use addonscript_versioning::Version;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::{AddonDescriptor, enums::APIFeature, LaunchConfig};
|
use crate::{AddonDescriptor, enums::APIFeature, Patch};
|
||||||
|
|
||||||
use super::{AddonScript, File, Hashes, Meta};
|
use super::{AddonScript, File, Hashes, Meta};
|
||||||
|
|
||||||
|
@ -49,9 +49,9 @@ pub struct EnvBuilderResponse {
|
||||||
pub addonscript: AddonScript,
|
pub addonscript: AddonScript,
|
||||||
pub files: Vec<File>,
|
pub files: Vec<File>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub launch_client: Option<LaunchConfig>,
|
pub launch_client: Option<Patch>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub launch_server: Option<LaunchConfig>,
|
pub launch_server: Option<Patch>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub enum Flag {
|
||||||
Launch,
|
Launch,
|
||||||
Env,
|
Env,
|
||||||
Expected,
|
Expected,
|
||||||
Library,
|
Patch,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize_enum_str, Serialize_enum_str, PartialEq, Eq, Hash)]
|
#[derive(Debug, Deserialize_enum_str, Serialize_enum_str, PartialEq, Eq, Hash)]
|
||||||
|
@ -21,6 +21,7 @@ pub enum InstallAction {
|
||||||
Extract,
|
Extract,
|
||||||
Rename,
|
Rename,
|
||||||
Inject,
|
Inject,
|
||||||
|
Library,
|
||||||
#[serde(other)]
|
#[serde(other)]
|
||||||
Unknown(String),
|
Unknown(String),
|
||||||
}
|
}
|
||||||
|
@ -43,3 +44,22 @@ pub enum Side {
|
||||||
#[default]
|
#[default]
|
||||||
Both,
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
6
crates/model/src/error.rs
Normal file
6
crates/model/src/error.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
use thiserror::Error;
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
pub enum Error {
|
||||||
|
#[error("The parsed AddonScript manifest violates the AddonScript spec")]
|
||||||
|
InvalidFormat,
|
||||||
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use addonscript_versioning::{Version, VersionRestriction};
|
use addonscript_versioning::{Version, VersionRestriction};
|
||||||
use enums::Side;
|
use enums::{Side, ArgumentMode};
|
||||||
|
use error::Error;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -11,6 +12,7 @@ pub use self::{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod api;
|
pub mod api;
|
||||||
|
pub mod error;
|
||||||
pub mod enums;
|
pub mod enums;
|
||||||
pub mod meta;
|
pub mod meta;
|
||||||
|
|
||||||
|
@ -30,11 +32,10 @@ pub struct Manifest {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub instance: bool,
|
pub instance: bool,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
#[deprecated]
|
||||||
pub use_builder: bool,
|
pub use_builder: bool,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(default)]
|
||||||
pub launch_client: Option<LaunchConfig>,
|
pub patches: Vec<Patch>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub launch_server: Option<LaunchConfig>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub meta: Option<Meta>,
|
pub meta: Option<Meta>,
|
||||||
}
|
}
|
||||||
|
@ -120,19 +121,31 @@ pub struct Flags {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct LaunchConfig {
|
pub struct Patch {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
pub side: Side,
|
||||||
pub main_file: Option<String>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub main_class: Option<String>,
|
pub main_class: Option<String>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub arguments: Vec<String>,
|
pub arguments: Vec<GameArgument>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub jvm_arguments: Vec<String>,
|
pub jvm_arguments: Vec<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub replace_jvm_arguments: bool,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub java_version: Option<u16>,
|
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 {
|
impl VersionlessManifest {
|
||||||
pub fn get_version(&self) -> u8 {
|
pub fn get_version(&self) -> u8 {
|
||||||
match &self.addonscript {
|
match &self.addonscript {
|
||||||
|
@ -175,3 +188,26 @@ impl Flags {
|
||||||
false
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue