Skip to content

Commit

Permalink
Launch: support for presets (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson authored Nov 2, 2023
1 parent 3e7b841 commit 984c10b
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ git2 = { workspace = true }
glob = "0.3.1"
num_cpus = "1.16.0"
rayon = "1.8.0"
regex = "1.10.2"
reqwest = { version = "0.11.22", features = ["blocking", "json"] }
rhai = "1.16.3"
rust-embed = "8.0.0"
Expand Down
52 changes: 45 additions & 7 deletions bin/src/commands/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{

use clap::{ArgMatches, Command};
use hemtt_common::project::{hemtt::LaunchOptions, ProjectConfig};
use regex::Regex;
use steamlocate::SteamDir;

use crate::{error::Error, link::create_link};
Expand Down Expand Up @@ -77,6 +78,38 @@ pub fn execute(matches: &ArgMatches) -> Result<(), Error> {
path.display().to_string()
});

let mut meta = None;
let meta_path = std::env::current_dir()?.join("meta.cpp");
if meta_path.exists() {
let content = std::fs::read_to_string(meta_path)?;
let regex = Regex::new(r"publishedid\s*=\s*(\d+);").unwrap();
if let Some(id) = regex.captures(&content).map(|c| c[1].to_string()) {
meta = Some(id);
}
}

let mut workshop = launch.workshop().to_vec();

for preset in launch.presets() {
let html = std::env::current_dir()?
.join(".hemtt/presets")
.join(preset)
.with_extension("html");
if !html.exists() {
return Err(Error::PresetNotFound(preset.to_string()));
}
let html = std::fs::read_to_string(html)?;
let regex = Regex::new(
r#"(?m)href="https:\/\/steamcommunity\.com\/sharedfiles\/filedetails\/\?id=(\d+)""#,
)
.unwrap();
for id in regex.captures_iter(&html).map(|c| c[1].to_string()) {
if !workshop.contains(&id) {
workshop.push(id);
}
}
}

// climb to the workshop folder
if !launch.workshop().is_empty() {
let Some(common) = arma3dir.path.parent() else {
Expand All @@ -89,19 +122,24 @@ pub fn execute(matches: &ArgMatches) -> Result<(), Error> {
if !workshop_folder.exists() {
return Err(Error::WorkshopNotFound);
};
for load_mod in launch.workshop() {
let mod_path = workshop_folder.join(load_mod);
for load_mod in workshop {
if Some(load_mod.clone()) == meta {
warn!(
"Skipping mod {} as it is the same as the project's meta.cpp id",
load_mod
);
continue;
}
let mod_path = workshop_folder.join(&load_mod);
if !mod_path.exists() {
return Err(Error::WorkshopModNotFound(load_mod.to_string()));
return Err(Error::WorkshopModNotFound(load_mod));
};
mods.push(mod_path.display().to_string());
}
}

if !launch.dlc().is_empty() {
for dlc in launch.dlc() {
mods.push(dlc.to_mod().to_string());
}
for dlc in launch.dlc() {
mods.push(dlc.to_mod().to_string());
}

let ctx = super::dev::execute(matches, launch.optionals())?;
Expand Down
3 changes: 3 additions & 0 deletions bin/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub enum Error {
WorkshopNotFound,
#[error("Workshop mod not found: {0}")]
WorkshopModNotFound(String),
#[error("Preset not found: {0}")]
PresetNotFound(String),

#[error("Main prefix not found: {0}")]
MainPrefixNotFound(String),

Expand Down
9 changes: 8 additions & 1 deletion book/commands/launch.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ mainprefix = "z"
workshop = [
"450814997", # CBA_A3's Workshop ID
]
presets = [
"main", # .html presets from .hemtt/presets/
]
dlc = [
"Western Sahara",
]
Expand Down Expand Up @@ -81,6 +84,10 @@ dlc = [

A list of workshop IDs to launch with your mod. These are not subscribed to, and will need to be manually subscribed to in Steam.

### presets

A list of `.html` presets to launch with your mod. Exported from the Arma 3 Launcher, and kept in `.hemtt/presets/`.

### dlc

A list of DLCs to launch with your mod. The fullname or short-code can be used.
Expand Down Expand Up @@ -110,7 +117,7 @@ The name of the Arma 3 executable to launch. This is usually `arma3` or `arma3_x

## Options

### -e, --executable <executable>
### -e, --executable &lt;executable&gt;

The Arma 3 executable to launch. Overrides the `executable` option in the configuration file.

Expand Down
10 changes: 10 additions & 0 deletions libs/common/src/project/hemtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ pub struct LaunchOptions {
/// DLCs that should be launched with the mod
dlc: Vec<DLC>,

#[serde(default)]
/// HTML presets that should be launched with the mod
presets: Vec<String>,

#[serde(default)]
/// Optional addons that should be built into the mod
optionals: Vec<String>,
Expand All @@ -99,6 +103,12 @@ impl LaunchOptions {
&self.dlc
}

#[must_use]
/// HTML presets that should be launched with the mod
pub fn presets(&self) -> &[String] {
&self.presets
}

#[must_use]
/// Optional addons that should be built into the mod
pub fn optionals(&self) -> &[String] {
Expand Down

0 comments on commit 984c10b

Please sign in to comment.