From c7a695fc1eb567eb7e4e26fde51077871fa17de9 Mon Sep 17 00:00:00 2001 From: Linkatplug Date: Sat, 5 Dec 2026 03:43:01 +0100 Subject: [PATCH] Launcher : exporter les decors d'origine, creer un mod vide MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - « Exporter les decors d'origine » : PNG 320x200 dans mods\_decors_originaux (ignore par le jeu), dossier ouvert a la fin - « Nouveau mod » : cree mods\\hd et son mod.ini, puis ouvre hd\ Co-Authored-By: Claude Opus 5.5 --- launcher/src/main.rs | 69 ++++++++++++++++++++++++++++++++++++++++++++ launcher/src/mods.rs | 55 +++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) diff --git a/launcher/src/main.rs b/launcher/src/main.rs index aca8d84..7b36439 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -574,6 +574,10 @@ struct App { upscayl: Option, upscayl_models: Vec, upscayl_model: String, + new_mod_name: String, + mod_msg: Option<(bool, String)>, + /// dossier à ouvrir quand la tâche en cours réussit + open_after: Option, art: Art, tx: Sender, rx: Receiver, @@ -623,6 +627,9 @@ impl App { upscayl: None, upscayl_models: Vec::new(), upscayl_model: mods::DEFAULT_MODEL.to_string(), + new_mod_name: String::new(), + mod_msg: None, + open_after: None, art: Art::default(), tx, rx, @@ -774,6 +781,8 @@ impl App { let mut open_dir = false; let mut refresh = false; let mut create = false; + let mut export = false; + let mut new_mod = false; card(ui, |ui| { title(ui, tr("Mods et décors HD", "Mods & HD backgrounds")); ui.add_enabled_ui(!running, |ui| { @@ -850,6 +859,33 @@ impl App { ui.hyperlink_to("Upscayl", "https://upscayl.org"); }); } + ui.separator(); + ui.label(RichText::new(tr("Faire son propre pack HD", "Make your own HD pack")).strong()); + if ui + .add_enabled(can_create, egui::Button::new(tr("Exporter les décors d'origine", "Export original backgrounds"))) + .clicked() + { + export = true; + } + ui.label(RichText::new(format!( + "{} mods\\{}", + tr("PNG 320×200 à agrandir avec l'outil de votre choix. Dossier :", "320×200 PNGs to upscale with any tool. Folder:"), + mods::EXPORT_DIR + )).weak().small()); + ui.horizontal(|ui| { + ui.add(egui::TextEdit::singleline(&mut self.new_mod_name).hint_text(tr("Nom du mod", "Mod name")).desired_width(200.0)); + let ok = !mods::id_from_name(&self.new_mod_name).is_empty(); + if ui.add_enabled(ok, egui::Button::new(tr("Nouveau mod", "New mod"))).clicked() { + new_mod = true; + } + }); + ui.label(RichText::new(tr( + "Crée mods\\\\hd : déposez-y les PNG agrandis sous le même nom (LOC01.png), image entière, ratio 16:10 (1280×800 par exemple).", + "Creates mods\\\\hd: drop the upscaled PNGs there with the same name (LOC01.png), whole image, 16:10 (e.g. 1280×800).", + )).weak().small()); + if let Some((good, m)) = &self.mod_msg { + ui.label(RichText::new(m).color(if *good { OK } else { BAD })); + } }); if running { ui.label(RichText::new(tr("En jeu : « Décors HD » se change aussi avec F12.", "In game: toggle « HD backgrounds » with F12.")).weak()); @@ -866,6 +902,36 @@ impl App { if create { self.create_hd_pack(); } + if export { + self.export_originals(); + } + if new_mod { + self.new_mod(); + } + } + + /// décors d'origine en PNG 320×200 dans mods/_decors_originaux (ignoré par le jeu), puis ouvre le dossier + fn export_originals(&mut self) { + let (Some(game), Some(mdir)) = (self.checks.game_dir.clone(), self.mods_dir()) else { return }; + let out = mdir.join(mods::EXPORT_DIR); + let cmd = format!("python -I tools\\hd_export.py \"{}\" \"{}\"", game.display(), out.display()); + self.open_after = Some(out); + self.mod_msg = None; + self.start_task("hd-export", vec![cmd]); + } + + fn new_mod(&mut self) { + let Some(mdir) = self.mods_dir() else { return }; + let en = self.cfg.lang == Lang::En; + self.mod_msg = Some(match mods::create_mod(&mdir, &self.new_mod_name) { + Ok(hd) => { + saves::open_folder(&hd); + self.new_mod_name.clear(); + self.reload_mods(); + (true, if en { format!("Created: {}", hd.display()) } else { format!("Créé : {}", hd.display()) }) + } + Err(e) => (false, e), + }); } fn saves_dir(&self) -> Option { @@ -1235,6 +1301,9 @@ impl App { Msg::TaskDone { ok } => { self.last_ok = Some(ok); self.busy = Busy::No; + if let Some(d) = self.open_after.take().filter(|_| ok) { + saves::open_folder(&d); + } self.reload_mods(); self.recheck(); } diff --git a/launcher/src/mods.rs b/launcher/src/mods.rs index bec4f44..6aa9d91 100644 --- a/launcher/src/mods.rs +++ b/launcher/src/mods.rs @@ -182,6 +182,61 @@ pub fn upscayl_models(bin: &Path) -> Vec { pub const DEFAULT_MODEL: &str = "digital-art-4x"; +/// dossier des décors d'origine exportés en PNG : commence par « _ », donc ignoré par le jeu +pub const EXPORT_DIR: &str = "_decors_originaux"; + +/// nom de dossier d'un mod tiré du nom affiché : lettres, chiffres, « - » et « _ » +pub fn id_from_name(name: &str) -> String { + let mut id = String::new(); + for c in name.trim().chars() { + let c = match c { + 'à' | 'â' | 'ä' => 'a', + 'é' | 'è' | 'ê' | 'ë' => 'e', + 'î' | 'ï' => 'i', + 'ô' | 'ö' => 'o', + 'ù' | 'û' | 'ü' => 'u', + 'ç' => 'c', + c => c, + }; + if c.is_ascii_alphanumeric() || c == '-' || c == '_' { + id.push(c.to_ascii_lowercase()); + } else if !id.ends_with('_') { + id.push('_'); + } + } + id.trim_matches('_').to_string() +} + +/// crée mods//hd/ et son mod.ini ; renvoie le dossier hd +pub fn create_mod(mods_dir: &Path, name: &str) -> Result { + let id = id_from_name(name); + if id.is_empty() { + return Err("nom vide / empty name".into()); + } + let dir = mods_dir.join(&id); + if dir.exists() { + return Err(format!("mods\\{id} existe déjà / already exists")); + } + let hd = dir.join("hd"); + std::fs::create_dir_all(&hd).map_err(|e| e.to_string())?; + std::fs::write( + dir.join("mod.ini"), + format!("[mod]\nname={}\nauthor=\ndescription=Décors HD : déposez les PNG dans hd\\ (même nom que le PCX, ratio 16:10)\n", name.trim()), + ) + .map_err(|e| e.to_string())?; + Ok(hd) +} + +#[cfg(test)] +mod tests { + #[test] + fn ids() { + assert_eq!(super::id_from_name(" Décors à la main! "), "decors_a_la_main"); + assert_eq!(super::id_from_name("_x"), "x"); + assert_eq!(super::id_from_name("***"), ""); + } +} + /// dossier du mod créé pour un modèle : hd_upscayl pour le modèle par défaut, hd_upscayl_ sinon pub fn pack_id(model: &str) -> String { if model == DEFAULT_MODEL { "hd_upscayl".into() } else { format!("hd_upscayl_{model}") }