Fixed character editing

This commit is contained in:
Joshua Barretto 2021-12-13 00:55:25 +00:00
parent 408fe1e6b6
commit dd95d69dc4
4 changed files with 28 additions and 12 deletions

View File

@ -108,6 +108,7 @@ pub enum Event {
SetViewDistance(u32),
Outcome(Outcome),
CharacterCreated(CharacterId),
CharacterEdited(CharacterId),
CharacterError(String),
}
@ -844,6 +845,7 @@ impl Client {
}
pub fn edit_character(&mut self, alias: String, id: CharacterId, body: comp::Body) {
println!("Edit character");
self.character_list.loading = true;
self.send_msg(ClientGeneral::EditCharacter { alias, id, body });
}
@ -2043,6 +2045,9 @@ impl Client {
ServerGeneral::CharacterCreated(character_id) => {
events.push(Event::CharacterCreated(character_id));
},
ServerGeneral::CharacterEdited(character_id) => {
events.push(Event::CharacterEdited(character_id));
},
ServerGeneral::CharacterSuccess => {
debug!("client is now in ingame state on server");
if let Some(vd) = self.view_distance {

View File

@ -277,8 +277,8 @@ pub fn load_character_list(player_uuid_: &str, connection: &Connection) -> Chara
let mut stmt = connection.prepare_cached(
"
SELECT character_id,
alias
FROM character
alias
FROM character
WHERE player_uuid = ?1
ORDER BY character_id",
)?;
@ -507,7 +507,7 @@ pub fn edit_character(
let (body,) = editable_components;
let mut stmt = transaction
.prepare_cached("UPDATE body SET variant = ?1, body_data = ?2 WHERE character_id = ?3")?;
.prepare_cached("UPDATE body SET variant = ?1, body_data = ?2 WHERE body_id = ?3")?;
let (body_variant, body_data) = convert_body_to_database_json(&body)?;
stmt.execute(&[
@ -875,7 +875,7 @@ fn delete_pets(
#[rustfmt::skip]
let mut stmt = transaction.prepare_cached("
DELETE
DELETE
FROM body
WHERE body_id IN rarray(?1)"
)?;
@ -1038,7 +1038,7 @@ pub fn update(
let mut stmt = transaction.prepare_cached(
"
REPLACE
REPLACE
INTO skill (entity_id,
skill,
level)

View File

@ -225,6 +225,7 @@ impl Mode {
}
pub fn edit(name: String, character_id: CharacterId, body: humanoid::Body) -> Self {
println!("Begin edit");
// TODO: Load these from the server (presumably from a .ron) to allow for easier
// modification of custom starting weapons
let mainhand = Some(STARTER_SWORD);
@ -264,6 +265,7 @@ enum InfoContent {
Deletion(usize),
LoadingCharacters,
CreatingCharacter,
EditingCharacter,
DeletingCharacter,
CharacterError(String),
}
@ -441,6 +443,7 @@ impl Controls {
info_content,
Some(InfoContent::LoadingCharacters)
| Some(InfoContent::CreatingCharacter)
| Some(InfoContent::EditingCharacter)
| Some(InfoContent::DeletingCharacter)
) && !client.character_list().loading
{
@ -740,6 +743,11 @@ impl Controls {
.size(fonts.cyri.scale(24))
.into()
},
InfoContent::EditingCharacter => {
Text::new(i18n.get("char_selection.editing_character"))
.size(fonts.cyri.scale(24))
.into()
},
InfoContent::DeletingCharacter => {
Text::new(i18n.get("char_selection.deleting_character"))
.size(fonts.cyri.scale(24))
@ -1247,6 +1255,12 @@ impl Controls {
tooltip::text(i18n.get("common.rand_name"), tooltip_style)
});
let confirm_msg = if let Some(character_id) = character_id {
Message::ConfirmEdit(*character_id)
} else {
Message::CreateCharacter
};
let name_input = BackgroundContainer::new(
Image::new(imgs.name_input)
.height(Length::Units(40))
@ -1258,11 +1272,7 @@ impl Controls {
Message::Name,
)
.size(25)
.on_submit(if let Some(character_id) = character_id {
Message::ConfirmEdit(*character_id)
} else {
Message::CreateCharacter
}),
.on_submit(confirm_msg.clone()),
)
.padding(Padding::new().horizontal(7).top(5));
@ -1284,7 +1294,7 @@ impl Controls {
i18n.get("common.create"),
FILL_FRAC_ONE,
button_style,
(!name.is_empty()).then_some(Message::CreateCharacter),
(!name.is_empty()).then_some(confirm_msg),
);
let create: Element<Message> = if name.is_empty() {
@ -1435,7 +1445,7 @@ impl Controls {
character_id,
body: comp::Body::Humanoid(*body),
});
self.mode = Mode::select(Some(InfoContent::CreatingCharacter));
self.mode = Mode::select(Some(InfoContent::EditingCharacter));
println!("Message::ConfirmEdit");
}
},

View File

@ -301,6 +301,7 @@ impl SessionState {
},
client::Event::Outcome(outcome) => outcomes.push(outcome),
client::Event::CharacterCreated(_) => {},
client::Event::CharacterEdited(_) => {},
client::Event::CharacterError(error) => {
global_state.client_error = Some(error);
},