| 31 | block_index: usize, |
| 32 | explain: String, |
| 33 | image_path: String, |
| 34 | ) -> SaveData { |
| 35 | SaveData { |
| 36 | script, |
| 37 | block_index, |
| 38 | explain, |
| 39 | image_path, |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | impl Executor { |
| 45 | pub(crate) fn load_save_data(&mut self) -> Result<(), EngineError> { |
| 46 | let mut load_items: Vec<ModelRc<SaveItem>> = Vec::with_capacity(10); |
| 47 | for i in 0..10 { |
| 48 | let path = format!("{}{}.toml", ENGINE_CONFIG.save_path(), i); |
| 49 | if let Ok(content) = fs::read_to_string(&path) { |
| 50 | let wrapper: SaveDataWrapper = |
| 51 | toml::from_str(&content).map_err(|e| SaveError::Deserialize { |
| 52 | path: path.clone(), |
| 53 | source: e, |
| 54 | })?; |
| 55 | let mut load_page = Vec::with_capacity(16); |
| 56 | for SaveData { |
| 57 | script, |
| 58 | block_index, |
| 59 | explain, |
| 60 | image_path, |
| 61 | } in wrapper.save_data |
| 62 | { |
| 63 | let image = Image::load_from_path(Path::new(&image_path)).unwrap_or_default(); |
| 64 | load_page.push(SaveItem { |
| 65 | bg: image, |
| 66 | explain: explain.to_shared_string(), |
| 67 | index: block_index as i32, |
| 68 | name: script.to_shared_string(), |
| 69 | }); |
| 70 | } |
| 71 | load_items.push(Rc::new(VecModel::from(load_page)).into()); |
| 72 | } else { |
| 73 | let wrapper = SaveDataWrapper { |
| 74 | save_data: vec![ |
| 75 | SaveData::new( |
| 76 | "".to_string(), |
| 77 | 0, |
| 78 | "空的".to_string(), |
| 79 | "".to_string() |