added character documentation and split Clothing into a sub-struct

of Character
This commit is contained in:
2026-05-16 14:06:49 +01:00
parent 99a5b03290
commit 6d012dbe6b
6 changed files with 108 additions and 25 deletions
+25 -16
View File
@@ -4,12 +4,14 @@ use crate::{
File,
HashMap,
debug,
info,
Deserialize,
Serialize,
Mutex,
Arc,
};
#[derive(Debug, Deserialize, Serialize, Clone)]
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
#[serde(default)]
pub struct Character
{
name: String,
@@ -20,14 +22,20 @@ pub struct Character
pronoun_deppos: String,
pronoun_indpos: String,
pronoun_reflex: String,
head: String,
hair: String,
torso: String,
arm: String,
leg: String,
head_shape: String,
hair_style: String,
torso_shape: String,
arm_shape: String,
leg_shape: String,
hair_color: String,
top_clothing: String,
bottom_clothing: String,
clothing: Clothing,
}
#[derive(Debug,Deserialize,Serialize,Clone,Default)]
#[serde(default)]
pub struct Clothing
{
top: String,
bottom: String,
shoes: String,
}
impl Character {
@@ -41,15 +49,15 @@ impl Character {
"pronoun_deppos" => self.pronoun_deppos = value.to_string(),
"pronoun_indpos" => self.pronoun_indpos = value.to_string(),
"pronoun_reflex" => self.pronoun_reflex = value.to_string(),
"head" => self.head = value.to_string(),
"hair" => self.hair = value.to_string(),
"torso" => self.torso = value.to_string(),
"arm" => self.arm = value.to_string(),
"leg" => self.leg = value.to_string(),
"head_shape" => self.head_shape = value.to_string(),
"hair_style" => self.hair_style = value.to_string(),
"torso_shape" => self.torso_shape = value.to_string(),
"arm_shape" => self.arm_shape = value.to_string(),
"leg_shape" => self.leg_shape = value.to_string(),
"hair_color" => self.hair_color = value.to_string(),
"top_clothing" => self.top_clothing = value.to_string(),
"bottom_clothing" => self.bottom_clothing = value.to_string(),
"shoes" => self.shoes = value.to_string(),
"clothing.top" => self.clothing.top = value.to_string(),
"clothing.bottom" => self.clothing.bottom = value.to_string(),
"clothing.shoes" => self.clothing.shoes = value.to_string(),
_ => return Err(()),
}
@@ -72,6 +80,7 @@ pub fn character_parse(archive: &mut ZipArchive<File>)
let characters: HashMap<String, Character> =
serde_json::from_str(&file_contents)
.map_err (|err| format!("Invalid JSON in characters.json: {err}"))?;
info!("Parsed characters from characters.json");
debug!("{characters:?}");
Ok(Arc::new(Mutex::new(characters)))
}
+2
View File
@@ -71,6 +71,8 @@ pub fn character_parse
drop(characters);
api::modify_data(data_to_send, "change".to_string(), String::new(), character_name, vec![]);
},
// These two are mainly just actions performed by the frontend client, so just tell the client to move/animate
// the character and not much other processing needed on the serverside
"to"|"animate" =>
{
sum_index += 1;