-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show mint mods in public server list
- Loading branch information
Showing
11 changed files
with
402 additions
and
122 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod mod_info; | ||
|
||
use std::path::{Path, PathBuf}; | ||
|
||
use anyhow::{bail, Context, Result}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
use std::collections::BTreeSet; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Tags from mod.io. | ||
#[derive(Debug, Clone)] | ||
pub struct ModioTags { | ||
pub qol: bool, | ||
pub gameplay: bool, | ||
pub audio: bool, | ||
pub visual: bool, | ||
pub framework: bool, | ||
pub versions: BTreeSet<String>, | ||
pub required_status: RequiredStatus, | ||
pub approval_status: ApprovalStatus, | ||
} | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub enum RequiredStatus { | ||
RequiredByAll, | ||
Optional, | ||
} | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] | ||
pub enum ApprovalStatus { | ||
Verified, | ||
Approved, | ||
Sandbox, | ||
} | ||
|
||
/// Whether a mod can be resolved by clients or not | ||
#[derive(Debug, Clone, Eq, Ord, PartialEq, PartialOrd, Hash)] | ||
pub enum ResolvableStatus { | ||
Unresolvable(String), | ||
Resolvable, | ||
} | ||
|
||
/// Returned from ModStore | ||
#[derive(Debug, Clone)] | ||
pub struct ModInfo { | ||
pub provider: &'static str, | ||
pub name: String, | ||
pub spec: ModSpecification, // unpinned version | ||
pub versions: Vec<ModSpecification>, // pinned versions TODO make this a different type | ||
pub resolution: ModResolution, | ||
pub suggested_require: bool, | ||
pub suggested_dependencies: Vec<ModSpecification>, // ModResponse | ||
pub modio_tags: Option<ModioTags>, // only available for mods from mod.io | ||
pub modio_id: Option<u32>, // only available for mods from mod.io | ||
} | ||
|
||
/// Returned from ModProvider | ||
#[derive(Debug, Clone)] | ||
pub enum ModResponse { | ||
Redirect(ModSpecification), | ||
Resolve(ModInfo), | ||
} | ||
|
||
/// Points to a mod, optionally a specific version | ||
#[derive( | ||
Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize, | ||
)] | ||
pub struct ModSpecification { | ||
pub url: String, | ||
} | ||
|
||
impl ModSpecification { | ||
pub fn new(url: String) -> Self { | ||
Self { url } | ||
} | ||
pub fn satisfies_dependency(&self, other: &ModSpecification) -> bool { | ||
// TODO this hack works surprisingly well but is still a complete hack and should be replaced | ||
self.url.starts_with(&other.url) || other.url.starts_with(&self.url) | ||
} | ||
} | ||
|
||
/// Points to a specific version of a specific mod | ||
#[derive(Debug, Clone, Eq, Ord, PartialEq, PartialOrd, Hash)] | ||
pub struct ModResolution { | ||
pub url: String, | ||
pub status: ResolvableStatus, | ||
} | ||
|
||
impl ModResolution { | ||
pub fn resolvable(url: String) -> Self { | ||
Self { | ||
url, | ||
status: ResolvableStatus::Resolvable, | ||
} | ||
} | ||
pub fn unresolvable(url: String, name: String) -> Self { | ||
Self { | ||
url, | ||
status: ResolvableStatus::Unresolvable(name), | ||
} | ||
} | ||
/// Used to get the URL if resolvable or just return the mod name if not | ||
pub fn get_resolvable_url_or_name(&self) -> &str { | ||
match &self.status { | ||
ResolvableStatus::Resolvable => &self.url, | ||
ResolvableStatus::Unresolvable(name) => name, | ||
} | ||
} | ||
} | ||
|
||
/// Stripped down mod info stored in the mod pak to be used in game | ||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct Meta { | ||
pub version: String, | ||
pub mods: Vec<MetaMod>, | ||
} | ||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct MetaMod { | ||
pub name: String, | ||
pub approval: ApprovalStatus, | ||
} | ||
impl Meta { | ||
pub fn to_server_list_string(&self) -> String { | ||
use itertools::Itertools; | ||
|
||
["mint".into(), self.version.clone()] | ||
.into_iter() | ||
.chain( | ||
self.mods | ||
.iter() | ||
.sorted_by_key(|m| (std::cmp::Reverse(m.approval), &m.name)) | ||
.flat_map(|m| { | ||
[ | ||
match m.approval { | ||
ApprovalStatus::Verified => 'V', | ||
ApprovalStatus::Approved => 'A', | ||
ApprovalStatus::Sandbox => 'S', | ||
} | ||
.into(), | ||
m.name.replace(';', ""), | ||
] | ||
}), | ||
) | ||
.join(";") | ||
} | ||
} |
Oops, something went wrong.