Skip to content

Commit da751a7

Browse files
committed
Don't autodetect stuff with warnings
1 parent 68b9c22 commit da751a7

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

calmare-cli/src/main.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,16 @@ fn write_scena(game: Option<CliGame>, buf: &[u8], lookup: Option<&dyn Lookup>) -
168168
Game::FcEvo, Game::ScEvo, Game::TcEvo, Game::ZeroEvo, Game::AoEvo, // Evo
169169
Game::Zero, Game::Ao, // Geofront
170170
] {
171+
let mut ctx = calmare::Context::new(game, lookup);
171172
if game.is_ed7() {
172-
if let Ok(scena) = ED7Scena::read(game, buf) {
173-
return Ok(calmare::to_string(game, &calmare::Content::ED7Scena(scena), lookup))
174-
}
173+
let Ok(scena) = ED7Scena::read(game, buf) else { continue };
174+
calmare::ed7::write(&mut ctx, &scena);
175175
} else {
176-
if let Ok(scena) = ED6Scena::read(game, buf) {
177-
return Ok(calmare::to_string(game, &calmare::Content::ED6Scena(scena), lookup))
178-
}
176+
let Ok(scena) = ED6Scena::read(game, buf) else { continue };
177+
calmare::ed6::write(&mut ctx, &scena);
178+
}
179+
if !ctx.has_warn {
180+
return Ok(ctx.finish());
179181
}
180182
}
181183
eyre::bail!("could not parse script; specify --game for more details")

calmare/src/common.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub fn func(f: &mut Context, func: &Code) {
3434
Err(err) => {
3535
f.kw("flat").suf(":");
3636
if let Some(err) = err {
37+
f.warn();
3738
write!(f, " // {err}");
3839
}
3940
f.line();
@@ -523,6 +524,7 @@ fn expr(f: &mut Context, e: &Expr) {
523524
for (i, e) in stack.into_iter().enumerate() {
524525
if i != 0 {
525526
f.kw("¤");
527+
f.warn();
526528
}
527529
expr_prio(f, e, 0);
528530
}

calmare/src/writer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ enum Space {
1111
pub struct Context<'a> {
1212
pub game: Game,
1313
pub decompile: bool,
14+
pub has_warn: bool,
1415
indent: usize,
1516
space: Space,
1617
pub lookup: &'a dyn Lookup,
@@ -22,6 +23,7 @@ impl<'a> Context<'a> {
2223
Self {
2324
game,
2425
decompile: true,
26+
has_warn: false,
2527
indent: 0,
2628
space: Space::None,
2729
lookup: lookup.unwrap_or_else(|| themelios::lookup::default_for(game)),
@@ -34,6 +36,10 @@ impl<'a> Context<'a> {
3436
self
3537
}
3638

39+
pub fn warn(&mut self) {
40+
self.has_warn = true;
41+
}
42+
3743
pub fn finish(self) -> String {
3844
self.out
3945
}

0 commit comments

Comments
 (0)