Made server and client 1

This commit is contained in:
2026-05-08 23:24:42 +01:00
parent 7db9406ced
commit 7e5874ffbb
14 changed files with 52 additions and 1 deletions
+73
View File
@@ -0,0 +1,73 @@
use crate::{
HashMap,
fs,
debug,
Deserialize,
Serialize,
Mutex,
Arc,
};
#[derive(Debug, Deserialize, Serialize)]
pub struct Character
{
name: String,
gender: String,
eye_color: String,
pronoun_subject: String,
pronoun_object: String,
pronoun_deppos: String,
pronoun_indpos: String,
pronoun_reflex: String,
animation: String,
head: String,
hair: String,
torso: String,
arm: String,
leg: String,
hair_color: String,
top_clothing: String,
bottom_clothing: String,
shoes: String,
}
impl Character
{
pub fn new(new_name: String) -> Character
{
Character
{
name: new_name,
gender: "".to_string(),
eye_color: "".to_string(),
pronoun_subject: "".to_string(),
pronoun_object: "".to_string(),
pronoun_deppos: "".to_string(),
pronoun_indpos: "".to_string(),
pronoun_reflex: "".to_string(),
animation: "".to_string(),
head: "".to_string(),
hair: "".to_string(),
torso: "".to_string(),
arm: "".to_string(),
leg: "".to_string(),
hair_color: "".to_string(),
top_clothing: "".to_string(),
bottom_clothing: "".to_string(),
shoes: "".to_string(),
}
}
}
pub async fn character_parse()
-> 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| { return err.to_string() });
// Serialise this to a HashMap
let characters: HashMap<String, Character> =
serde_json::from_str(&file_contents)
.expect("JSON was not well-formatted");
debug!("{:?}",characters);
Ok(Arc::new(Mutex::new(characters)))
}