Compare commits

...

2 Commits

Author SHA1 Message Date
aa019d4ea9 pick the newest character for a slot when recreating
Some checks failed
continuous-integration/drone/push Build is failing
2023-01-29 23:57:17 -07:00
8157db4c69 set tech level correctly when reading from postgres 2023-01-29 23:56:28 -07:00
3 changed files with 11 additions and 9 deletions

View File

@ -0,0 +1,2 @@
alter table player_character
add created_at timestamptz default current_timestamp not null;

View File

@ -244,7 +244,7 @@ impl From<PgCharacter> for CharacterEntity {
prop_y: other.prop_y,
},
techs: CharacterTechniques {
techs: other.techs.iter().enumerate().take(19).filter(|(_, t)| **t != 0xFF).map(|(i, t)| (tech::Technique::from_value(i as u8), TechLevel(*t)) ).collect()
techs: other.techs.iter().enumerate().take(19).filter(|(_, t)| **t != 0xFF).map(|(i, t)| (tech::Technique::from_value(i as u8), TechLevel(*t + 1)) ).collect()
},
config: CharacterConfig {
raw_data: vec_to_array(other.config)

View File

@ -276,17 +276,17 @@ async fn create_character(conn: &mut sqlx::PgConnection, char: NewCharacterEntit
async fn get_characters_by_user(conn: &mut sqlx::PgConnection, user: &UserAccountEntity) -> Result<[Option<CharacterEntity>; 4], GatewayError>
{
let mut stream = sqlx::query_as::<_, PgCharacter>("select * from player_character where user_account = $1 and slot < 4 order by slot")
let stream = sqlx::query_as::<_, PgCharacter>("select * from player_character where user_account = $1 and slot < 4 order by created_at;")
.bind(user.id.0)
.fetch(conn);
const NONE: Option<CharacterEntity> = None;
let mut result = [NONE; 4];
while let Some(character) = stream.try_next().await? {
let index = character.slot as usize;
result[index] = Some(character.into())
}
Ok(result)
Ok(stream.fold(core::array::from_fn(|_| None), |mut acc, char| {
if let Ok(char) = char {
let slot = char.slot as usize;
acc[slot] = Some(char.into())
}
acc
}).await)
}
async fn save_character(conn: &mut sqlx::PgConnection, char: &CharacterEntity) -> Result<(), GatewayError>