feat(tui): add worlds tab with dynamic icon heights
This commit is contained in:
1 parent
c3a26eaac2
commit
24a8afe29b
6 files changed
+182
-15
No files matched your search
@@ -6,6 +6,7 @@ pub mod mods;
|
||||
pub mod resource_packs;
|
||||
pub mod screenshots;
|
||||
pub mod shaders;
|
||||
pub mod worlds;
|
||||
|
||||
pub use launch::LaunchError;
|
||||
pub use loader::{get_installer, GameVersion, ModLoaderInstaller, VanillaInstaller};
|
||||
@@ -14,3 +15,4 @@ pub use models::{InstanceConfig, ModLoader};
|
||||
pub use mods::{scan_mods, toggle_mod, ModEntry};
|
||||
pub use resource_packs::scan_resource_packs;
|
||||
pub use shaders::scan_shaders;
|
||||
pub use worlds::scan_worlds;
|
||||
@@ -0,0 +1,53 @@
|
||||
use std::path::Path;
|
||||
|
||||
use super::mods::{make_icon_pixels, ModEntry};
|
||||
|
||||
pub fn scan_worlds(instances_dir: &Path, instance_name: &str) -> Vec<ModEntry> {
|
||||
let saves_dir = instances_dir
|
||||
.join(instance_name)
|
||||
.join(".minecraft")
|
||||
.join("saves");
|
||||
|
||||
let read_dir = match std::fs::read_dir(&saves_dir) {
|
||||
Ok(rd) => rd,
|
||||
Err(_) => return Vec::new(),
|
||||
};
|
||||
|
||||
let mut entries = Vec::new();
|
||||
|
||||
for entry in read_dir.flatten() {
|
||||
let path = entry.path();
|
||||
if !path.is_dir() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let file_name = match path.file_name().and_then(|n| n.to_str()) {
|
||||
Some(n) => n.to_string(),
|
||||
None => continue,
|
||||
};
|
||||
|
||||
let (enabled, file_stem) = if file_name.ends_with(".disabled") {
|
||||
(false, file_name.trim_end_matches(".disabled").to_string())
|
||||
} else {
|
||||
(true, file_name.clone())
|
||||
};
|
||||
|
||||
let icon_bytes = std::fs::read(path.join("icon.png")).ok();
|
||||
let icon_lines = icon_bytes
|
||||
.as_ref()
|
||||
.and_then(|bytes| make_icon_pixels(bytes, 12, 6));
|
||||
|
||||
entries.push(ModEntry {
|
||||
file_stem: file_stem.clone(),
|
||||
name: file_stem,
|
||||
description: String::new(),
|
||||
enabled,
|
||||
icon_bytes,
|
||||
path,
|
||||
icon_lines,
|
||||
});
|
||||
}
|
||||
|
||||
entries.sort_by(|a, b| a.name.to_lowercase().cmp(&b.name.to_lowercase()));
|
||||
entries
|
||||
}
|
||||
Reference in new issue
Block a user