Skip to main content

elemental_driver/families/version_json/patch/
mod.rs

1mod apply;
2mod storage;
3
4use elemental_schema::mojang::piston::{
5    PistonMetaData, PistonMetaGenericArgument, PistonMetaLibraries, PistonMetaLogging,
6};
7use serde::{Deserialize, Serialize};
8
9pub use apply::{apply_metadata_patches, apply_metadata_patches_traced};
10pub(crate) use storage::baseline_path;
11pub use storage::{apply_patches_with_mode, apply_scoped_patches, read_base_metadata};
12
13/// How metadata patches are applied to a version JSON instance.
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
15#[serde(rename_all = "lowercase")]
16pub enum PatchMode {
17    /// Virtual patch (`vpatch`): overlays patches in memory without touching `<instance>.json`.
18    #[default]
19    Virtual,
20    /// Physical patch (`patch`): backs up the clean baseline and writes merged metadata to `<instance>.json`.
21    Physical,
22}
23
24/// Declarative transformation applied on top of a base [`PistonMetaData`].
25#[derive(Debug, Clone, Default, Serialize, Deserialize)]
26pub struct MetadataPatch {
27    #[serde(default)]
28    pub priority: i32,
29    #[serde(default, skip_serializing_if = "Vec::is_empty")]
30    pub before: Vec<String>,
31    #[serde(default, skip_serializing_if = "Vec::is_empty")]
32    pub after: Vec<String>,
33    #[serde(default, skip_serializing_if = "Option::is_none")]
34    pub main_class: Option<String>,
35    #[serde(default, skip_serializing_if = "Vec::is_empty")]
36    pub remove_library_prefixes: Vec<String>,
37    #[serde(default, skip_serializing_if = "Vec::is_empty")]
38    pub add_libraries: Vec<PistonMetaLibraries>,
39    #[serde(default, skip_serializing_if = "Vec::is_empty")]
40    pub game_arguments: Vec<PistonMetaGenericArgument>,
41    #[serde(default, skip_serializing_if = "Vec::is_empty")]
42    pub jvm_arguments: Vec<PistonMetaGenericArgument>,
43    #[serde(default, skip_serializing_if = "Option::is_none")]
44    pub logging: Option<PistonMetaLogging>,
45    #[serde(default, skip_serializing_if = "Option::is_none")]
46    pub java_major_version: Option<usize>,
47}
48
49/// A [`MetadataPatch`] identified by its owning addon or layer ID and effective mode.
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct NamedMetadataPatch {
52    pub id: String,
53    #[serde(default)]
54    pub effective_mode: PatchMode,
55    pub patch: MetadataPatch,
56}
57
58/// Effective diff produced by applying a single [`NamedMetadataPatch`] step.
59#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct MetadataPatchStepDiff {
61    pub id: String,
62    pub priority: i32,
63    pub effective_mode: PatchMode,
64    #[serde(default, skip_serializing_if = "Option::is_none")]
65    pub main_class: Option<(String, String)>,
66    #[serde(default, skip_serializing_if = "Vec::is_empty")]
67    pub removed_libraries: Vec<String>,
68    #[serde(default, skip_serializing_if = "Vec::is_empty")]
69    pub replaced_libraries: Vec<String>,
70    #[serde(default, skip_serializing_if = "Vec::is_empty")]
71    pub added_libraries: Vec<String>,
72    #[serde(default, skip_serializing_if = "Vec::is_empty")]
73    pub added_game_arguments: Vec<PistonMetaGenericArgument>,
74    #[serde(default, skip_serializing_if = "Vec::is_empty")]
75    pub added_jvm_arguments: Vec<PistonMetaGenericArgument>,
76    pub logging_changed: bool,
77    #[serde(default, skip_serializing_if = "Option::is_none")]
78    pub java_major_version: Option<(usize, usize)>,
79}
80
81/// Merged [`PistonMetaData`] paired with per-step patch diffs in execution order.
82#[derive(Debug, Clone)]
83pub struct PatchTrace {
84    pub metadata: PistonMetaData,
85    pub steps: Vec<MetadataPatchStepDiff>,
86}