fixerup
This commit is contained in:
+14
-1
@@ -13,7 +13,7 @@ use failure::{err_msg, format_err};
|
||||
|
||||
use mnml_core::construct::{Construct, ConstructSkeleton};
|
||||
use mnml_core::instance::{Instance};
|
||||
use mnml_core::instance;
|
||||
use mnml_core::player::{Player};
|
||||
|
||||
use http::MnmlHttpError;
|
||||
use names::{name as generate_name};
|
||||
@@ -33,6 +33,19 @@ pub struct Account {
|
||||
pub subscribed: bool,
|
||||
}
|
||||
|
||||
impl Account {
|
||||
pub fn to_player(&self, tx: &mut Transaction) -> Result<Player, Error> {
|
||||
let constructs = team(tx, self)?;
|
||||
|
||||
let img = match self.subscribed {
|
||||
true => Some(self.img),
|
||||
false => None,
|
||||
};
|
||||
|
||||
Ok(Player::new(self.id, Some(self.img), &self.name, constructs))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<postgres::rows::Row<'a>> for Account {
|
||||
type Error = Error;
|
||||
|
||||
|
||||
+3
-3
@@ -679,7 +679,7 @@ pub fn instance_practice(tx: &mut Transaction, account: &Account) -> Result<Inst
|
||||
.set_time_control(TimeControl::Practice)
|
||||
.set_name(bot.name.clone())?;
|
||||
|
||||
let player = Player::from_account(tx, account)?;
|
||||
let player = account.to_player(tx)?;
|
||||
|
||||
instance.add_player(player.clone())?;
|
||||
instance.add_player(bot)?;
|
||||
@@ -702,7 +702,7 @@ pub fn pvp(tx: &mut Transaction, a: &Account, b: &Account) -> Result<Instance, E
|
||||
instance = instance_create(tx, instance)?;
|
||||
|
||||
for account in [a, b].iter() {
|
||||
let acc_p = Player::from_account(tx, &account)?;
|
||||
let acc_p = account.to_player(tx)?;
|
||||
let player = player_create(tx, acc_p, instance.id, account)?;
|
||||
instance.add_player(player)?;
|
||||
}
|
||||
@@ -795,7 +795,7 @@ pub fn bot_instance() -> Instance {
|
||||
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let player = Player::new(player_account, &"test".to_string(), constructs).set_bot(true);
|
||||
let player = Player::new(player_account, None, &"test".to_string(), constructs).set_bot(true);
|
||||
|
||||
instance.add_player(player).expect("could not add player");
|
||||
instance.player_ready(player_account).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user