Skip to content

Commit dc115ed

Browse files
committed
Slightly improve the main file, switch to xxhash-rust for hashing
1 parent 8aed771 commit dc115ed

File tree

4 files changed

+225
-232
lines changed

4 files changed

+225
-232
lines changed

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
[package]
22
name = "rvpacker-json-txt"
3-
version = "1.0.0"
3+
version = "1.1.0"
44
edition = "2021"
55

66
[dependencies]
77
rayon = "^1.10.0"
88
serde = "^1.0.197"
99
serde_json = "^1.0.116"
10-
indexmap = "2.2.6"
11-
sys-locale = "0.3.1"
12-
clap = { version = "4.5.7", features = ["wrap_help"] }
13-
rand = "0.8.5"
14-
color-print = "0.3.6"
15-
fancy-regex = "0.13.0"
16-
fnv = "1.0.7"
10+
indexmap = "^2.2.6"
11+
sys-locale = "^0.3.1"
12+
clap = { version = "^4.5.7", features = ["wrap_help"] }
13+
rand = "^0.8.5"
14+
color-print = "^0.3.6"
15+
fancy-regex = "^0.13.0"
16+
xxhash-rust = {version = "0.8.11", features = ["xxh3"]}

src/main.rs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::{
55
env::args,
66
fs::{create_dir_all, read_to_string},
77
path::{Path, PathBuf},
8-
process::exit,
98
time::Instant,
109
};
1110
use sys_locale::get_locale;
@@ -19,7 +18,6 @@ use write::*;
1918
mod shuffle;
2019
use shuffle::shuffle_words;
2120

22-
#[derive(Debug, Clone, Copy)]
2321
enum Language {
2422
English,
2523
Russian,
@@ -145,8 +143,6 @@ impl<'a> ProgramLocalization<'a> {
145143
}
146144
}
147145

148-
static ALLOWED_LANGUAGES: [&str; 2] = ["ru", "en"];
149-
150146
fn get_game_type(system_file_path: &Path) -> &str {
151147
let system_obj: Value = from_str(&read_to_string(system_file_path).unwrap()).unwrap();
152148
let game_title: String = system_obj["gameTitle"].as_str().unwrap().to_lowercase();
@@ -164,13 +160,15 @@ fn determine_language() -> Language {
164160
let args_vec: Vec<String> = args().collect();
165161

166162
for (i, arg) in args_vec.iter().enumerate() {
167-
if (arg == "-l" || arg == "--language")
168-
&& ALLOWED_LANGUAGES.contains(&args_vec[i + 1].as_str())
169-
{
163+
if arg == "-l" || arg == "--language" {
170164
locale = args_vec[i + 1].to_string();
171165
}
172166
}
173167

168+
if let Some((first, _)) = locale.split_once('_') {
169+
locale = first.to_string()
170+
}
171+
174172
match locale.as_str() {
175173
"ru" | "uk" | "be" => Language::Russian,
176174
_ => Language::English,
@@ -222,20 +220,18 @@ fn main() {
222220
.hide_default_value(true)
223221
.display_order(2);
224222

225-
const ALLOWED_DISABLE_PROCESSING_VALUES: [&str; 4] = ["maps", "other", "system", "plugins"];
226223
let disable_processing_arg: Arg = Arg::new("disable-processing")
227224
.long("disable-processing")
228225
.value_delimiter(',')
229226
.value_name(localization.disable_processing_arg_type)
230227
.help(cformat!(
231-
"{}\n{} --disable-processing=maps,other,system.<bold>\n[{} {}]</bold>",
228+
"{}\n{} --disable-processing=maps,other,system.<bold>\n[{} maps, other, system, plugins]</bold>",
232229
localization.disable_processing_arg_desc,
233230
localization.example,
234231
localization.possible_values,
235-
ALLOWED_DISABLE_PROCESSING_VALUES.join(", ")
236232
))
237233
.global(true)
238-
.value_parser(ALLOWED_DISABLE_PROCESSING_VALUES)
234+
.value_parser(["maps", "other", "system", "plugins"])
239235
.display_order(2);
240236

241237
let disable_custom_parsing_flag: Arg = Arg::new("disable-custom-parsing")
@@ -251,13 +247,12 @@ fn main() {
251247
.value_name(localization.language_arg_type)
252248
.global(true)
253249
.help(cformat!(
254-
"{}\n{} --language en.<bold>\n[{} {}]</bold>",
250+
"{}\n{} --language en.<bold>\n[{} en, ru]</bold>",
255251
localization.language_arg_desc,
256252
localization.example,
257253
localization.possible_values,
258-
ALLOWED_LANGUAGES.join(", ")
259254
))
260-
.value_parser(ALLOWED_LANGUAGES)
255+
.value_parser(["en", "ru"])
261256
.display_order(98);
262257

263258
let log_flag: Arg = Arg::new("log")
@@ -308,7 +303,7 @@ fn main() {
308303
.hide_possible_values(true);
309304

310305
let matches: ArgMatches = cli.get_matches();
311-
let command: &str = matches.subcommand_name().unwrap_or_else(|| exit(1));
306+
let command: &str = matches.subcommand_name().unwrap();
312307

313308
let (
314309
disable_maps_processing,
@@ -370,10 +365,6 @@ fn main() {
370365
)
371366
};
372367

373-
if !maps_path.exists() || !other_path.exists() {
374-
panic!("{}", localization.translation_dirs_missing);
375-
}
376-
377368
let system_file_path: PathBuf = original_path.join("System.json");
378369

379370
let game_type: &str = if disable_custom_parsing {
@@ -421,11 +412,9 @@ fn main() {
421412
start_time.elapsed().as_secs_f64()
422413
);
423414
} else {
424-
let shuffle_level: u8 = *matches
425-
.subcommand_matches(command)
426-
.unwrap()
427-
.get_one::<u8>("shuffle_level")
428-
.unwrap();
415+
if !maps_path.exists() || !other_path.exists() {
416+
panic!("{}", localization.translation_dirs_missing);
417+
}
429418

430419
let plugins_path: PathBuf = input_dir.join("translation/plugins");
431420

@@ -438,6 +427,12 @@ fn main() {
438427
create_dir_all(&output_path).unwrap();
439428
create_dir_all(&plugins_output_path).unwrap();
440429

430+
let shuffle_level: u8 = *matches
431+
.subcommand_matches(command)
432+
.unwrap()
433+
.get_one::<u8>("shuffle_level")
434+
.unwrap();
435+
441436
if !disable_maps_processing {
442437
write_maps(
443438
&maps_path,

0 commit comments

Comments
 (0)