diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4012ea3..ef84ad4 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -38,16 +38,6 @@ jobs: with: path: assets/saves key: assets/saves - - name: Set cargo environment variables - shell: bash - run: | - echo "EU4_IRONMAN_TOKENS=$current_dir/assets/tokens/eu4.txt" >> $GITHUB_ENV - echo "CK3_IRONMAN_TOKENS=$current_dir/assets/tokens/ck3.txt" >> $GITHUB_ENV - echo "IMPERATOR_TOKENS=$current_dir/assets/tokens/imperator.txt" >> $GITHUB_ENV - echo "HOI4_IRONMAN_TOKENS=$current_dir/assets/tokens/hoi4.txt" >> $GITHUB_ENV - echo "VIC3_IRONMAN_TOKENS=$current_dir/assets/tokens/vic3.txt" >> $GITHUB_ENV - env: - current_dir: ${{ github.workspace }} - name: Build run: cargo build --all --verbose --release - name: create save assets directory diff --git a/.gitignore b/.gitignore index 551175b..03fd4f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ /target -assets/tokens/*.txt \ No newline at end of file +assets/tokens \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 9eb7cbc..bc409bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -86,7 +86,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "ck3save" version = "0.4.3" -source = "git+https://github.com/rakaly/ck3save.git#a5f2c23383afc0a48491740b9ef7376b4c38e032" +source = "git+https://github.com/rakaly/ck3save.git#9e24fe28a6846e434a3cd7ca28b4b2cc4187caba" dependencies = [ "flate2", "jomini", @@ -157,7 +157,7 @@ dependencies = [ [[package]] name = "eu4save" version = "0.8.2" -source = "git+https://github.com/rakaly/eu4save.git#9cf25b0ddc5abb8aee6aa15b49830834783af1ad" +source = "git+https://github.com/rakaly/eu4save.git#064b192f072d853089ca924437f3234dba62302b" dependencies = [ "flate2", "jomini", @@ -227,7 +227,7 @@ checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "hoi4save" version = "0.3.4" -source = "git+https://github.com/rakaly/hoi4save.git#d377f8f43de2e2d90315d6fa8b714d44e932aa5b" +source = "git+https://github.com/rakaly/hoi4save.git#566f6295d03b41f97729f6660a8dd841dd2ac8a5" dependencies = [ "jomini", "serde", @@ -237,7 +237,7 @@ dependencies = [ [[package]] name = "imperator-save" version = "0.4.2" -source = "git+https://github.com/rakaly/imperator-save.git#aa5c642163678bdb060bdb462506c682436ebe6f" +source = "git+https://github.com/rakaly/imperator-save.git#cfb66c02e5873216c6a0a44bda0ffdaee7be06a4" dependencies = [ "flate2", "jomini", @@ -265,9 +265,9 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "jomini" -version = "0.26.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99a28ecf49b71fc2496fc667d7d6988fe412e84f0f81495f25181d9f3a51899a" +checksum = "be7b64a1ef85c738f94811efc8e1863077c0b1a727e7e798c96a79ffa3822841" dependencies = [ "itoa", "jomini_derive", @@ -630,7 +630,7 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "vic3save" version = "0.1.0" -source = "git+https://github.com/pdx-tools/pdx-tools#f219ff982ca8e53d29afdc5b28a01603088ac328" +source = "git+https://github.com/pdx-tools/pdx-tools#45cb24326cd1b777589dfb4e2b64097a199fb8c6" dependencies = [ "flate2", "getrandom", diff --git a/build.rs b/build.rs index a594550..bc67e54 100644 --- a/build.rs +++ b/build.rs @@ -1,17 +1,13 @@ -use std::env; use std::path::Path; fn main() { - if env::var("EU4_IRONMAN_TOKENS").is_err() { - panic!("librakaly needs to be built with EU4_IRONMAN_TOKENS specified") - } - - if env::var("CK3_IRONMAN_TOKENS").is_err() { - panic!("librakaly needs to be built with CK3_IRONMAN_TOKENS specified") - } - - if env::var("IMPERATOR_TOKENS").is_err() { - panic!("librakaly needs to be built with IMPERATOR_TOKENS specified") + std::fs::create_dir_all("assets/tokens").expect("to create tokens directory"); + for game in ["ck3", "hoi4", "eu4", "imperator", "vic3"] { + let fp = format!("assets/tokens/{game}.txt"); + let p = std::path::Path::new(&fp); + if !p.exists() { + std::fs::write(p, "").expect("to write file"); + } } let crate_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 0b9956d..4edbb34 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ mod errors; mod file; mod melter; +mod tokens; use crate::errors::LibError; use errors::PdsError; diff --git a/src/melter.rs b/src/melter.rs index a1c1f61..8cf2232 100644 --- a/src/melter.rs +++ b/src/melter.rs @@ -1,10 +1,15 @@ -use std::io::Cursor; - -use crate::errors::LibError; +use crate::{ + errors::LibError, + tokens::{ + ck3_tokens_resolver, eu4_tokens_resolver, hoi4_tokens_resolver, imperator_tokens_resolver, + vic3_tokens_resolver, + }, +}; use ck3save::Ck3Melter; use eu4save::Eu4Melter; use hoi4save::Hoi4Melter; use imperator_save::ImperatorMelter; +use std::io::Cursor; use vic3save::Vic3Melter; pub enum MeltedBufferResult { @@ -43,7 +48,7 @@ impl<'a> Melter for Eu4Melter<'a> { let doc = self .on_failed_resolve(eu4save::FailedResolveStrategy::Stringify) .verbatim(true) - .melt(&mut out, &eu4save::EnvTokens)?; + .melt(&mut out, eu4_tokens_resolver())?; if self.input_encoding().is_text() { Ok(MeltedBuffer::Text { @@ -69,7 +74,7 @@ impl<'a> Melter for Ck3Melter<'a> { let doc = self .on_failed_resolve(ck3save::FailedResolveStrategy::Stringify) .verbatim(true) - .melt(&mut out, &ck3save::EnvTokens)?; + .melt(&mut out, &ck3_tokens_resolver())?; if matches!(self.input_encoding(), ck3save::Encoding::TextZip) { Ok(MeltedBuffer::Text { @@ -95,7 +100,7 @@ impl<'a> Melter for ImperatorMelter<'a> { let doc = self .on_failed_resolve(imperator_save::FailedResolveStrategy::Stringify) .verbatim(true) - .melt(&mut out, &imperator_save::EnvTokens)?; + .melt(&mut out, &imperator_tokens_resolver())?; if matches!(self.input_encoding(), imperator_save::Encoding::TextZip) { Ok(MeltedBuffer::Text { @@ -121,7 +126,7 @@ impl<'a> Melter for Hoi4Melter<'a> { let doc = self .on_failed_resolve(hoi4save::FailedResolveStrategy::Stringify) .verbatim(true) - .melt(&mut out, &hoi4save::EnvTokens)?; + .melt(&mut out, &hoi4_tokens_resolver())?; Ok(MeltedBuffer::Binary { body: out.into_inner(), @@ -140,7 +145,7 @@ impl<'a> Melter for Vic3Melter<'a> { let doc = self .on_failed_resolve(vic3save::FailedResolveStrategy::Stringify) .verbatim(true) - .melt(&mut out, &vic3save::EnvTokens)?; + .melt(&mut out, &vic3_tokens_resolver())?; if matches!(self.input_encoding(), vic3save::Encoding::TextZip) { Ok(MeltedBuffer::Text { diff --git a/src/tokens.rs b/src/tokens.rs new file mode 100644 index 0000000..fda96e2 --- /dev/null +++ b/src/tokens.rs @@ -0,0 +1,27 @@ +pub fn eu4_tokens_resolver() -> eu4save::BasicTokenResolver { + let data = include_bytes!("../assets/tokens/eu4.txt"); + eu4save::BasicTokenResolver::from_text_lines(&data[..]).expect("embedded tokens invalid format") +} + +pub fn ck3_tokens_resolver() -> ck3save::BasicTokenResolver { + let data = include_bytes!("../assets/tokens/ck3.txt"); + ck3save::BasicTokenResolver::from_text_lines(&data[..]).expect("embedded tokens invalid format") +} + +pub fn vic3_tokens_resolver() -> vic3save::BasicTokenResolver { + let data = include_bytes!("../assets/tokens/vic3.txt"); + vic3save::BasicTokenResolver::from_text_lines(&data[..]) + .expect("embedded tokens invalid format") +} + +pub fn imperator_tokens_resolver() -> imperator_save::BasicTokenResolver { + let data = include_bytes!("../assets/tokens/imperator.txt"); + imperator_save::BasicTokenResolver::from_text_lines(&data[..]) + .expect("embedded tokens invalid format") +} + +pub fn hoi4_tokens_resolver() -> hoi4save::BasicTokenResolver { + let data = include_bytes!("../assets/tokens/hoi4.txt"); + hoi4save::BasicTokenResolver::from_text_lines(&data[..]) + .expect("embedded tokens invalid format") +}