Skip to content

Commit

Permalink
Use imperator constant mem melting
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbabcock committed Jan 17, 2024
1 parent bb41a43 commit a8deea6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 34 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 16 additions & 26 deletions src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use hoi4save::{
file::{Hoi4ParsedFileKind, Hoi4Text},
Hoi4File,
};
use imperator_save::{
file::{ImperatorParsedFileKind, ImperatorText},
ImperatorFile,
};
use imperator_save::{file::ImperatorText, ImperatorFile};
use jomini::{
json::{DuplicateKeyMode, JsonOptions},
TextTape,
Expand Down Expand Up @@ -124,28 +121,21 @@ impl JsonCommand {
}
Some(x) if x == "rome" => {
let file = ImperatorFile::from_slice(&data)?;
let mut zip_sink = Vec::new();
let parsed_file = file.parse(&mut zip_sink)?;
match parsed_file.kind() {
ImperatorParsedFileKind::Text(text) => text
.reader()
.json()
.with_options(options)
.to_writer(std::io::stdout()),
ImperatorParsedFileKind::Binary(binary) => {
let melted = binary
.melter()
.verbatim(verbatim)
.on_failed_resolve(strategy)
.melt(&imperator_save::EnvTokens)?;
ImperatorText::from_slice(melted.data())
.context("unable to parse melted imperator output")?
.reader()
.json()
.with_options(options)
.to_writer(std::io::stdout())
}
}
let mut out = Cursor::new(Vec::new());
let text = if !matches!(file.encoding(), imperator_save::Encoding::Text) {
file.melter()
.on_failed_resolve(strategy)
.verbatim(verbatim)
.melt(&mut out, &imperator_save::EnvTokens)?;
ImperatorText::from_slice(out.get_ref().as_slice())?
} else {
ImperatorText::from_slice(&data)?
};

text.reader()
.json()
.with_options(options)
.to_writer(std::io::stdout())
}
Some(x) if x == "hoi4" => {
let file = Hoi4File::from_slice(&data)?;
Expand Down
8 changes: 2 additions & 6 deletions src/melt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,11 @@ impl Melter {
}
MelterKind::Imperator => {
let file = imperator_save::ImperatorFile::from_slice(data)?;
let mut zip_sink = Vec::new();
let parsed_file = file.parse(&mut zip_sink)?;
let binary = parsed_file.as_binary().context("not imperator binary")?;
let out = binary
let out = file
.melter()
.on_failed_resolve(self.options.resolve)
.verbatim(self.options.retain)
.melt(&imperator_save::EnvTokens)?;
writer.write_all(out.data())?;
.melt(writer, &imperator_save::EnvTokens)?;
Ok(MeltedDocument::Imperator(out))
}
MelterKind::Vic3 => {
Expand Down

0 comments on commit a8deea6

Please sign in to comment.