Skip to content

Commit

Permalink
Handle Switch BNPs with rules.txt
Browse files Browse the repository at this point in the history
(Also Clippy)
  • Loading branch information
NiceneNerd committed Jul 4, 2024
1 parent 09444e8 commit df4ed29
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 44 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## Added

- Added `cargo dist` integration to provide simpler install and update methods

### Fixed

- Restored missing Package button to Window menu
- Fixed option descriptions not showing on multiple choice
- Fixed misidentification of Switch BNPs with a `rules.txt` as Wii U mods


## [0.12.0]
Expand Down
10 changes: 5 additions & 5 deletions crates/uk-content/src/actor/params/rgbw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ use crate::{
)]
pub struct Key {
#[name = "StateKey"]
pub state_key: String32,
pub state_key: String32,
#[name = "SystemKey"]
pub system_key: String32,
}

impl ToString for Key {
fn to_string(&self) -> std::string::String {
jstr!("StateKey: {&self.state_key} :: SystemKey: {&self.system_key}")
impl std::fmt::Display for Key {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
jstr!("StateKey: {&self.state_key} :: SystemKey: {&self.system_key}").fmt(f)
}
}

Expand Down Expand Up @@ -129,7 +129,7 @@ impl From<RagdollBlendWeight> for ParameterIO {
jstr!("State_{&lexical::to_string(idx + 1)}"),
ParameterList {
objects: objs!("Setting" => key.into()),
lists: lists!(
lists: lists!(
"InputWeightList" => ParameterList::new()
.with_objects(state.into_iter().enumerate().map(
|(i, (name, rate))| {
Expand Down
2 changes: 1 addition & 1 deletion crates/uk-editor/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use fs_err as fs;
use rayon::prelude::*;
use uk_content::{resource::ResourceData, util::IndexMap};
use uk_manager::{core::Manager, settings::Platform};
use uk_mod::{pack::sanitise, unpack::ParallelZipReader, zstd::zstd_safe::WriteBuf, Meta};
use uk_mod::{pack::sanitise, unpack::ParallelZipReader, Meta};

#[derive(Debug, Clone)]
pub struct Project {
Expand Down
6 changes: 3 additions & 3 deletions crates/uk-manager/src/bnp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,10 @@ pub fn convert_bnp(core: &crate::core::Manager, path: &Path) -> Result<PathBuf>
)
})?;
let tempfile = std::env::temp_dir();
let meta = if let Some(rules_path) = tempdir.join("rules.txt").exists_then() {
ModPacker::parse_rules(rules_path)?
let meta = if let Some(info_path) = tempdir.join("info.json").exists_then() {
ModPacker::parse_info(info_path)?
} else {
ModPacker::parse_info(tempdir.join("info.json")).context("Failed to parse BNP metadata")?
ModPacker::parse_rules(tempdir.join("rules.txt")).context("Failed to parse BNP metadata")?
};
let name = meta.name.clone();
let new_mod = ModPacker::new(tempdir, tempfile.as_path(), Some(meta), vec![
Expand Down
12 changes: 11 additions & 1 deletion crates/uk-mod/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct Manifest {
#[serde(rename = "content")]
pub content_files: BTreeSet<String>,
#[serde(rename = "aoc")]
pub aoc_files: BTreeSet<String>,
pub aoc_files: BTreeSet<String>,
}

impl Manifest {
Expand Down Expand Up @@ -216,6 +216,16 @@ pub enum ModPlatform {
Universal,
}

impl std::fmt::Display for ModPlatform {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ModPlatform::Specific(Endian::Big) => "Wii U".fmt(f),
ModPlatform::Specific(Endian::Little) => "Switch".fmt(f),
ModPlatform::Universal => "any platform".fmt(f),
}
}
}

#[inline(always)]
fn default_api() -> String {
env!("CARGO_PKG_VERSION").into()
Expand Down
26 changes: 13 additions & 13 deletions crates/uk-mod/src/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,27 @@ impl std::fmt::Debug for ModPacker {
#[serde(default)]
#[serde_as]
struct InfoJson {
name: String,
desc: String,
name: String,
desc: String,
#[serde(deserialize_with = "serde_with::As::<DefaultOnError>::deserialize")]
version: String,
version: String,
platform: String,
options: BnpOptions,
options: BnpOptions,
}

#[derive(Debug, Deserialize, Default)]
struct BnpOptions {
#[serde(default)]
multi: Vec<BnpOption>,
multi: Vec<BnpOption>,
#[serde(default)]
single: Vec<BnpGroup>,
}

#[derive(Debug, Deserialize)]
struct BnpOption {
name: String,
desc: String,
folder: PathBuf,
name: String,
desc: String,
folder: PathBuf,
default: Option<bool>,
}

Expand Down Expand Up @@ -141,10 +141,10 @@ impl RequireValue {

#[derive(Debug, Deserialize)]
struct BnpGroup {
name: String,
desc: String,
name: String,
desc: String,
required: Option<RequireValue>,
options: Vec<BnpOption>,
options: Vec<BnpOption>,
}

impl From<BnpGroup> for ExclusiveOptionGroup {
Expand Down Expand Up @@ -582,7 +582,7 @@ impl ModPacker {
})
.transpose()?
.unwrap_or_default(),
aoc_files: aoc_dir
aoc_files: aoc_dir
.map(|aoc| {
log::info!("Collecting DLC resources");
self_.collect_resources(aoc)
Expand Down Expand Up @@ -660,7 +660,7 @@ impl ModPacker {
)?));
log::info!("Collecting resources for options");
for root in self.collect_roots() {
self.current_root = root.clone();
self.current_root.clone_from(&root);
self.pack_root(root).with_context(|| {
format!(
"Failed to package mod root at {} for mod {}",
Expand Down
41 changes: 21 additions & 20 deletions crates/uk-mod/src/unpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ impl std::fmt::Debug for ZipData {

#[self_referencing]
pub struct ParallelZipReader {
data: ZipData,
data: ZipData,
#[borrows(data)]
#[covariant]
zip: piz::ZipArchive<'this>,
zip: piz::ZipArchive<'this>,
#[borrows(zip)]
#[covariant]
files: HashMap<&'this Path, &'this piz::read::FileMetadata<'this>>,
Expand Down Expand Up @@ -477,14 +477,14 @@ static RSTB_EXCLUDE_NAMES: &[&str] = &["ActorInfo.product.byml"];

// #[derive(Debug)]
pub struct ModUnpacker {
dump: Arc<ResourceReader>,
dump: Arc<ResourceReader>,
manifest: Option<Manifest>,
mods: Vec<ModReader>,
endian: Endian,
lang: Language,
rstb: DashMap<String, Option<u32>>,
hashes: StockHashTable,
out_dir: PathBuf,
mods: Vec<ModReader>,
endian: Endian,
lang: Language,
rstb: DashMap<String, Option<u32>>,
hashes: StockHashTable,
out_dir: PathBuf,
}

impl ModUnpacker {
Expand Down Expand Up @@ -566,18 +566,19 @@ impl ModUnpacker {
Ok(Err(e)) => anyhow_ext::bail!(e),
Ok(Ok(_)) => (),
Err(e) => {
anyhow::bail!(e
.downcast::<std::string::String>()
.or_else(|e| {
e.downcast::<&'static str>().map(|s| Box::new((*s).into()))
})
.unwrap_or_else(|_| {
Box::new(
"An unknown error occured, check the log for possible \
anyhow::bail!(
e.downcast::<std::string::String>()
.or_else(|e| {
e.downcast::<&'static str>().map(|s| Box::new((*s).into()))
})
.unwrap_or_else(|_| {
Box::new(
"An unknown error occured, check the log for possible \
details."
.to_string(),
)
}))
.to_string(),
)
})
)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ impl Logger {
let mut file = if path.exists() {
fs_err::OpenOptions::new().append(true).open(path)
} else {
fs_err::create_dir_all(path.parent().expect("Weird log path")).expect("Yikes, folder problem");
fs_err::create_dir_all(path.parent().expect("Weird log path"))
.expect("Yikes, folder problem");
fs_err::File::create(path)
}
.unwrap();
Expand Down

0 comments on commit df4ed29

Please sign in to comment.