added zip file support and passing story as parameter

This commit is contained in:
2026-05-14 00:49:10 +01:00
parent fbd315ed7b
commit e5a3d0d7b7
9 changed files with 792 additions and 31 deletions
+9 -4
View File
@@ -1,6 +1,8 @@
use crate::{
ZipArchive,
Read,
File,
HashMap,
fs,
debug,
Deserialize,
Serialize,
@@ -30,12 +32,15 @@ pub struct Character
shoes: String,
}
pub async fn character_parse()
pub async fn character_parse(archive: &mut ZipArchive<File>)
-> Result<Arc<Mutex<HashMap<String, Character>>>,String>
{
// Get the JSON file to a string
let file_contents: String = fs::read_to_string("stories/characters.json")
.unwrap_or_else(|err| { err.to_string() });
let mut characters_file = archive.by_name("characters.json")
.map_err (|err| format!("Unable to read story file: {}",err))?;
let mut file_contents = String::new();
characters_file.read_to_string(&mut file_contents)
.map_err (|err| format!("Unable to read story file to string: {}",err))?;
// Serialise this to a HashMap
let characters: HashMap<String, Character> =