1- use clap:: { crate_version, Arg , ArgGroup , ArgMatches , Command } ;
1+ use clap:: { crate_version, Arg , ArgAction , ArgGroup , ArgMatches , Command } ;
22use context:: { Context , Mode } ;
33use extended:: ExtendedValidator ;
44use oob:: fix_oob;
5- use std:: { error:: Error , fs, path:: Path } ;
5+ use std:: { collections :: HashMap , error:: Error , fs, path:: Path } ;
66use tes3:: esp:: Plugin ;
77use toml:: { Table , Value } ;
88use validators:: Validator ;
99
10+ use crate :: ltex:: deduplicate_ltex;
11+
1012mod context;
1113mod extended;
1214mod handlers;
15+ mod ltex;
1316mod oob;
1417mod util;
1518mod validators;
@@ -20,6 +23,10 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
2023fn main ( ) -> Result < ( ) , Box < dyn Error > > {
2124 let args = Command :: new ( "StandardsValidator" )
2225 . args ( & [
26+ Arg :: new ( "ltexdedup" )
27+ . long ( "trim-ltex" )
28+ . value_name ( "output file" )
29+ . help ( "Remove unused landscape textures and save the trimmed output to a new file. Warning: overwrites the output file!" ) ,
2330 Arg :: new ( "ooboutput" )
2431 . long ( "fix-out-of-bounds" )
2532 . value_name ( "output file" )
@@ -60,6 +67,13 @@ fn main() -> Result<(), Box<dyn Error>> {
6067 "Squared distance at which two objects with the same id, \
6168 scale, and orientation are considered duplicates.",
6269 ) ,
70+ Arg :: new ( "replaceltex" )
71+ . long ( "replace-ltex" )
72+ . num_args ( 2 )
73+ . action ( ArgAction :: Append )
74+ . requires ( "ltexdedup" )
75+ . value_names ( [ "original" , "new" ] )
76+ . help ( "Replaces all uses of landscape textures with the original id with the new one" ) ,
6377 Arg :: new ( "mode" )
6478 . required ( true )
6579 . value_parser ( [ "PT" , "TD" , "TR" , "Vanilla" ] )
@@ -70,16 +84,22 @@ fn main() -> Result<(), Box<dyn Error>> {
7084 . help ( "C:/path/to/plugin.esp" ) ,
7185 ] )
7286 . groups ( [
73- ArgGroup :: new ( "g_validator" ) . args ( [ "duplicatethreshold" ] ) ,
87+ ArgGroup :: new ( "g_ltex" ) . args ( [ "ltexdedup" ] ) ,
88+ ArgGroup :: new ( "g_ltexreplace" )
89+ . args ( [ "replaceltex" ] )
90+ . requires ( "g_ltex" ) ,
91+ ArgGroup :: new ( "g_validator" )
92+ . args ( [ "duplicatethreshold" ] )
93+ . conflicts_with ( "g_ltex" ) ,
7494 ArgGroup :: new ( "g_extended" )
7595 . args ( [ "extended" , "names" ] )
76- . conflicts_with ( "g_validator" ) ,
96+ . conflicts_with_all ( [ "g_validator" , "g_ltex" ] ) ,
7797 ArgGroup :: new ( "g_autoload" )
7898 . arg ( "dontautoload" )
7999 . requires ( "g_extended" ) ,
80100 ArgGroup :: new ( "g_oob" )
81101 . arg ( "ooboutput" )
82- . conflicts_with_all ( [ "g_validator" , "g_extended" ] ) ,
102+ . conflicts_with_all ( [ "g_validator" , "g_extended" , "g_ltex" ] ) ,
83103 ] )
84104 . version ( crate_version ! ( ) )
85105 . get_matches ( ) ;
@@ -94,6 +114,9 @@ fn main() -> Result<(), Box<dyn Error>> {
94114 if let Some ( output) = args. get_one :: < String > ( "ooboutput" ) {
95115 return run_oob_fixes ( paths. next ( ) . unwrap ( ) , output) ;
96116 }
117+ if let Some ( output) = args. get_one :: < String > ( "ltexdedup" ) {
118+ return run_ltex_dedup ( paths. next ( ) . unwrap ( ) , output, & args) ;
119+ }
97120
98121 validate ( paths. next ( ) . unwrap ( ) , & args)
99122}
@@ -212,3 +235,21 @@ fn run_oob_fixes(input: &str, output: &str) -> Result<(), Box<dyn Error>> {
212235 plugin. save_path ( output) ?;
213236 Ok ( ( ) )
214237}
238+
239+ fn run_ltex_dedup ( input : & str , output : & str , args : & ArgMatches ) -> Result < ( ) , Box < dyn Error > > {
240+ let mut replacements = HashMap :: new ( ) ;
241+ if args. contains_id ( "replaceltex" ) {
242+ let vals: Vec < Vec < & String > > = args
243+ . get_occurrences ( "replaceltex" )
244+ . unwrap ( )
245+ . map ( Iterator :: collect)
246+ . collect ( ) ;
247+ for pair in vals {
248+ replacements. insert ( pair[ 0 ] . clone ( ) , pair[ 1 ] . clone ( ) ) ;
249+ }
250+ }
251+ let mut plugin = load_plugin ( input, None ) ?;
252+ deduplicate_ltex ( & mut plugin, replacements) ?;
253+ plugin. save_path ( output) ?;
254+ Ok ( ( ) )
255+ }
0 commit comments