added zip file support and passing story as parameter
This commit is contained in:
@@ -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> =
|
||||
|
||||
Reference in New Issue
Block a user