elemental-driver 0.1.0

Driver library for Elemental, providing implementations for interacting with different modloaders and game versions.
Documentation
use std::path::PathBuf;

use anyhow::Result;
use elemental_core::runtime::RuntimeValidationMode;

use super::parse_argument_string;

#[derive(Clone)]
pub struct LaunchResolution {
    pub width: String,
    pub height: String,
}

#[derive(Clone)]
pub struct QuickPlayOptions {
    pub path: Option<String>,
    pub multiplayer: Option<String>,
    pub singleplayer: Option<String>,
    pub realms: Option<String>,
}

#[derive(Clone)]
pub struct VersionJsonLaunchConfig {
    pub runtime_major_version: Option<usize>,
    pub runtime_executable_path: Option<PathBuf>,
    pub runtime_validation: RuntimeValidationMode,
    pub launcher_name: Option<String>,
    pub launcher_version: Option<String>,
    pub client_id: Option<String>,
    pub resolution: Option<LaunchResolution>,
    pub quick_play: Option<QuickPlayOptions>,
    pub extra_jvm_arguments: Vec<String>,
    pub extra_game_arguments: Vec<String>,
}

impl LaunchResolution {
    pub fn new(width: String, height: String) -> Self {
        Self { width, height }
    }
}

impl QuickPlayOptions {
    pub fn new(
        path: Option<String>,
        multiplayer: Option<String>,
        singleplayer: Option<String>,
        realms: Option<String>,
    ) -> Self {
        Self {
            path,
            multiplayer,
            singleplayer,
            realms,
        }
    }
}

impl VersionJsonLaunchConfig {
    pub fn new() -> Self {
        Self {
            runtime_major_version: None,
            runtime_executable_path: None,
            runtime_validation: RuntimeValidationMode::Strict,
            launcher_name: None,
            launcher_version: None,
            client_id: None,
            resolution: None,
            quick_play: None,
            extra_jvm_arguments: Vec::new(),
            extra_game_arguments: Vec::new(),
        }
    }

    pub fn set_extra_jvm_arguments(mut self, extra_jvm_arguments: Vec<String>) -> Self {
        self.extra_jvm_arguments = extra_jvm_arguments;
        self
    }

    pub fn set_runtime_executable_path(mut self, runtime_executable_path: PathBuf) -> Self {
        self.runtime_executable_path = Some(runtime_executable_path);
        self
    }

    pub fn set_runtime_validation(mut self, runtime_validation: RuntimeValidationMode) -> Self {
        self.runtime_validation = runtime_validation;
        self
    }

    pub fn set_extra_game_arguments(mut self, extra_game_arguments: Vec<String>) -> Self {
        self.extra_game_arguments = extra_game_arguments;
        self
    }

    pub fn try_set_extra_jvm_argument_string(
        mut self,
        extra_jvm_argument_string: String,
    ) -> Result<Self> {
        self.extra_jvm_arguments = parse_argument_string(extra_jvm_argument_string.as_str())?;
        Ok(self)
    }

    pub fn try_set_extra_game_argument_string(
        mut self,
        extra_game_argument_string: String,
    ) -> Result<Self> {
        self.extra_game_arguments = parse_argument_string(extra_game_argument_string.as_str())?;
        Ok(self)
    }
}

impl Default for VersionJsonLaunchConfig {
    fn default() -> Self {
        Self::new()
    }
}