Switch Character wire representation to store details as JSON

This commit is contained in:
2026-09-05 13:14:57 -04:00
parent 353e25ad77
commit 61b975a9eb
8 changed files with 23 additions and 11 deletions

1
Cargo.lock generated
View File

@@ -5061,6 +5061,7 @@ dependencies = [
"implicit-clone",
"luminescent-dreams-common 0.2.0",
"serde",
"serde_json",
"uuid 1.24.0",
"wasm-bindgen",
"webauthn-rs-proto",

View File

@@ -96,7 +96,7 @@ impl Command<CharacterId> for CreateCharacter {
#[derive(Debug)]
pub struct UpdateCharacter {
pub character_id: CharacterId,
pub data: Vec<u8>,
pub data: serde_json::Value,
}
impl Command<()> for UpdateCharacter {

View File

@@ -1468,7 +1468,7 @@ impl DbHandle {
character.game_id.as_str(),
character.user_id.as_str(),
character.system,
character.data
serde_json::to_vec(&character.details).map_err(Fatal::MalformedObject)?,
],
)?;
character.id
@@ -1480,7 +1480,7 @@ impl DbHandle {
character.game_id.as_str(),
character.user_id.as_str(),
character.system,
character.data
serde_json::to_vec(&character.details).map_err(Fatal::MalformedObject)?,
],
)?;
character.id
@@ -2324,12 +2324,22 @@ fn game_from_row(row: &Row<'_>) -> Result<GameOverview, rusqlite::Error> {
}
fn character_from_row(row: &Row<'_>) -> Result<Character, rusqlite::Error> {
let bytes = row.get::<usize, Vec<u8>>(4)?;
let details = serde_json::from_slice(&bytes).map_err(|err| {
rusqlite::Error::FromSqlConversionFailure(
bytes.len(),
rusqlite::types::Type::Blob,
Box::new(err),
)
})?;
Ok(Character {
id: CharacterId::from(row.get::<usize, String>(0)?),
game_id: GameId::from(row.get::<usize, String>(1)?),
user_id: UserId::from(row.get::<usize, String>(2)?),
system: row.get::<usize, String>(3)?,
data: row.get::<usize, Vec<u8>>(4)?,
details,
})
}

View File

@@ -1138,7 +1138,7 @@ impl Substrate {
pub async fn update_character(
&self,
id: &CharacterId,
character: Vec<u8>,
character: serde_json::Value,
) -> Result<Result<Character, Error>, Fatal> {
self.with_readonly_state_and_db(clone!(id, move |_, db| {
Box::pin(async move {
@@ -1146,7 +1146,7 @@ impl Substrate {
return Ok(Err(Error::NotFound(id.to_string())));
};
saved_character.data = character;
saved_character.details = character;
let _ = db.save_character(saved_character.clone())?;
Ok(Ok(saved_character))

View File

@@ -129,7 +129,7 @@ pub async fn handle_update_character(
&app,
UpdateCharacter {
character_id,
data: sheet.data,
data: sheet.details,
},
Some(&user),
))

View File

@@ -7,6 +7,7 @@ edition = "2021"
implicit-clone = { workspace = true }
luminescent-dreams-common = { workspace = true }
serde = { workspace = true }
serde_json.workspace = true
uuid = { workspace = true }
wasm-bindgen = { workspace = true }
webauthn-rs-proto = "0.5.4"

View File

@@ -222,7 +222,7 @@ pub struct Character {
pub game_id: GameId,
pub user_id: UserId,
pub system: String,
pub data: Vec<u8>,
pub details: serde_json::Value,
}
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]

View File

@@ -133,7 +133,7 @@ impl TryFrom<visions_types::Character> for Character {
let system: System =
serde_json::from_str(&sheet.system).map_err(|_| UnsupportedGameType)?;
let details = serde_json::from_slice::<Sheet>(&sheet.data).unwrap_or({
let details = serde_json::from_value::<Sheet>(sheet.details).unwrap_or({
match system {
System::Candela => Sheet::Candela(Candela::default()),
System::Cypher => Sheet::Cypher(Cypher::default()),
@@ -156,14 +156,14 @@ impl From<Character> for visions_types::Character {
Sheet::Cypher(_) => System::Cypher,
};
let data = serde_json::to_vec(&val.details).unwrap();
let details = serde_json::to_value(val.details).unwrap();
visions_types::Character {
id: val.id,
game_id: val.game_id,
user_id: val.user_id,
system: serde_json::to_string(&system).unwrap(),
data,
details,
}
}
}