OneLauncher-Cracked/packages/oneclient_common/src/patch.rs
Maciek 0ab544f265
feat: custom cluster instances (#859)
* feat: added adding new instances of a cluster with 'start from scratch' option enabling user to create a vanilla/modded cluster; fixed couple pre-existing bugs that wouldn't let other loaders boot up

* feat: fully implemented cluster creation modal design

* chore: refactoring

* feat: expanded the tags section on customization step; found that fabric doesnt work with 1.8.9

* feat: added gallery covers handling for new cluster instances

* feat: added 'redirecting' from fabric to orinthe on versions pre-1.14

* feat: added java-version-override

* feat: added loader types migrations (right now they dont migrate mods because there are no bundles)

* chore: wider loader dropdown for multiloader cluster (if it will be used in the future)

* chore: fixed more issues with isolated and shared dir, with migrations and instances naming

* chore: refactor; taken the loader version dropdown from version picker view back to loader selector

* chore: deleted Quilt from UI

---------

Co-authored-by: LynithDev <61880709+LynithDev@users.noreply.github.com>
2026-09-29 19:08:21 +02:00

55 lines
1.4 KiB
Rust

use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "lowercase")]
pub enum Patch<T> {
#[default]
Unchanged,
Clear,
Set(T),
}
impl<T> Patch<T> {
pub fn is_unchanged(&self) -> bool {
matches!(self, Self::Unchanged)
}
pub fn apply_to_option(&self, slot: &mut Option<T>)
where
T: Clone,
{
match self {
Self::Unchanged => {}
Self::Clear => *slot = None,
Self::Set(value) => *slot = Some(value.clone()),
}
}
pub fn into_db_patch(self) -> Option<Option<T>> {
match self {
Self::Unchanged => None,
Self::Clear => Some(None),
Self::Set(value) => Some(Some(value)),
}
}
}
impl Patch<String> {
pub fn apply_to_command_option(&self, slot: &mut Option<String>) {
match self {
Self::Unchanged => {}
Self::Clear => *slot = None,
Self::Set(value) => *slot = Some(value.trim().to_owned()),
}
}
}
impl Patch<&str> {
pub fn apply_to_command_option(&self, slot: &mut Option<String>) {
match self {
Self::Unchanged => {}
Self::Clear => *slot = None,
Self::Set(value) => *slot = Some(value.trim().to_owned()),
}
}
}