Skip to content

Commit

Permalink
feat: move var setting in args to macro, add justfile (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
LIMPIX31 authored Aug 6, 2024
1 parent dfdeb6b commit 5f62149
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
31 changes: 13 additions & 18 deletions crates/spuz_wrench/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use itertools::Itertools;
use spuz_spawner::{LaunchMod, Layer};
use tracing::debug;

use crate::set_vars;

cfg_if! {
if #[cfg(target_os = "windows")] {
const SEP: &str = ";";
Expand Down Expand Up @@ -36,9 +38,8 @@ where
it.as_ref().to_string_lossy().into_owned()
})
.join(SEP);
for arg in &mut *launch_mod.java_args {
*arg = arg.replace("${classpath}", &cp);
}

set_vars!(launch_mod.java_args, "classpath", &cp);
debug!("{len} items added to the classpath");
}
}
Expand All @@ -49,9 +50,7 @@ pub struct NativesDir<'a>(pub &'a Path);
impl<'a> Layer for NativesDir<'a> {
fn apply(self, launch_mod: &mut LaunchMod) {
let str_path = self.0.to_string_lossy();
for arg in &mut *launch_mod.java_args {
*arg = arg.replace("${natives_directory}", &str_path);
}
set_vars!(launch_mod.java_args, "natives_directory", &str_path);
debug!("Library(natives) path set to {:?}", self.0);
}
}
Expand All @@ -65,12 +64,12 @@ pub struct VersionInfo<'a> {

impl Layer for VersionInfo<'_> {
fn apply(self, launch_mod: &mut LaunchMod) {
for arg in &mut *launch_mod.app_args {
*arg = arg.replace("${version_name}", self.id);
*arg = arg.replace("${version_type}", self.version_type);
*arg = arg.replace("${user_type}", "msa");
*arg = arg.replace("${assets_index_name}", self.asset_index_id);
}
set_vars!(launch_mod.app_args, {
"version_name" => self.id,
"version_type" => self.version_type,
"user_type" => "msa",
"assets_index_name" => self.asset_index_id,
});
}
}

Expand All @@ -80,9 +79,7 @@ pub struct AssersDir<'a>(pub &'a Path);
impl<'a> Layer for AssersDir<'a> {
fn apply(self, launch_mod: &mut LaunchMod) {
let str_path = self.0.to_string_lossy();
for arg in &mut *launch_mod.app_args {
*arg = arg.replace("${assets_root}", &str_path);
}
set_vars!(launch_mod.app_args, "assets_root", &str_path);
debug!("Assets directory set to {:?}", &self.0);
}
}
Expand All @@ -93,9 +90,7 @@ pub struct GameDir<'a>(pub &'a Path);
impl<'a> Layer for GameDir<'a> {
fn apply(self, launch_mod: &mut LaunchMod) {
let str_path = self.0.to_string_lossy();
for arg in &mut *launch_mod.app_args {
*arg = arg.replace("${game_directory}", &str_path);
}
set_vars!(launch_mod.app_args, "game_directory", &str_path);
debug!("Game(instance) directory set to {:?}", &self.0);
}
}
1 change: 1 addition & 0 deletions crates/spuz_wrench/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod internal;
pub mod macros;
mod mandep;
mod opts;

Expand Down
13 changes: 13 additions & 0 deletions crates/spuz_wrench/src/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[macro_export]
macro_rules! set_vars {
($target:expr, $name:literal, $value:expr) => {
for arg in &mut *$target {
*arg = arg.replace(concat!("${", $name, "}"), $value);
}
};
($target:expr, { $($name:literal => $value:expr,)* }) => {
for arg in &mut *$target {
$(*arg = arg.replace(concat!("${", $name, "}"), $value);)*
}
};
}
4 changes: 2 additions & 2 deletions crates/spuz_wrench/src/mandep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ impl<'a> Layer for ManifestLayer<'a> {
}

fn push_modern_arguments(rulcomp: &RuleCompilance, args: &Arguments, launch_mod: &mut LaunchMod) {
for arg in args.jvm.iter() {
for arg in &args.jvm {
push_modern_arg(rulcomp, launch_mod.java_args, arg);
}

for arg in args.game.iter() {
for arg in &args.game {
push_modern_arg(rulcomp, launch_mod.app_args, arg);
}
}
Expand Down
6 changes: 6 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fmt:
cargo +nightly fmt --all

lint:
cargo clippy --all-targets --all-features -- -D warnings
cargo +nightly fmt --all -- --check

0 comments on commit 5f62149

Please sign in to comment.