Skip to content

Commit 64577a7

Browse files
committed
app: fix tracking empty saves
1 parent 983a051 commit 64577a7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

crates/common/src/saves.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ const PACKED_LEN: usize = {
1111
}
1212
};
1313

14+
pub fn empty() -> Vec<Packed> {
15+
(0..PACKED_LEN).map(|_| 0).collect()
16+
}
17+
1418
pub fn pack_bools(bools: &[bool]) -> Vec<Packed> {
1519
let mut bytes = Vec::with_capacity(bools.len() / PACKED_SIZE + 1);
1620
for chunk in bools.chunks(PACKED_SIZE) {

crates/companion-app/src/saves.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serde::Deserialize;
44

55
use tracing::error;
66

7-
use common::saves::pack_bools;
7+
use common::saves::{empty, pack_bools};
88

99
#[derive(Debug, Deserialize)]
1010
pub struct SaveFile {
@@ -37,6 +37,9 @@ pub fn read_save_packed(path: &Path) -> Option<Vec<common::saves::Packed>> {
3737
let save = SaveFile::load(path)
3838
.inspect_err(|e| error!("failed to load save file: {e}"))
3939
.ok()?;
40+
if save.fact_saves.is_empty() {
41+
return Some(empty());
42+
}
4043
let bools = save.learned_as_bools();
4144
Some(pack_bools(&bools))
4245
}

0 commit comments

Comments
 (0)