legacympt-rs/addonscript/src/manifest/mod.rs
2021-08-29 15:14:10 +02:00

101 lines
2.2 KiB
Rust

use crate::manifest::{installer::Installer, link::Link};
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use url::Url;
pub mod installer;
pub mod link;
#[derive(Deserialize, Serialize, Debug)]
pub struct Manifest {
pub id: String,
#[serde(rename = "type")]
pub manifest_type: ManifestType,
pub versions: Vec<Version>,
pub repositories: Vec<Repository>,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Repository {
pub id: String,
#[serde(rename = "type")]
pub repo_type: RepositoryType,
pub url: Url,
}
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "lowercase")]
pub enum RepositoryType {
Maven,
Curseforge,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Version {
pub version: String,
pub mcversion: Vec<String>,
#[serde(default)]
pub files: Vec<File>,
#[serde(default)]
pub relations: Vec<Relation>,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Relation {
pub id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub file: Option<File>,
#[serde(skip_serializing_if = "Option::is_none")]
pub versions: Option<String>,
#[serde(rename = "type")]
pub relation_type: RelationType,
pub options: HashSet<FileOpt>,
}
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "lowercase")]
pub enum RelationType {
Mod,
Modloader,
}
#[derive(Deserialize, Serialize, Debug, Hash, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum FileOpt {
Required,
Client,
Server,
Included,
}
#[derive(Deserialize, Serialize, Debug)]
#[serde(untagged)]
pub enum File {
Link {
id: Option<String>,
installer: Installer,
link: Link,
options: Option<HashSet<FileOpt>>,
},
Maven {
installer: Installer,
artifact: String,
repository: String,
},
}
impl File {
pub fn installer(&self) -> &Installer {
match self {
File::Link { installer, .. } => installer,
File::Maven { installer, .. } => installer,
}
}
}
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "lowercase")]
pub enum ManifestType {
Modpack,
}